function find($start, $destination, $active, $recordList) { // global $recordList; // print_r($recordList); $nullList = array(); // static $recordList; // $returnList=array(); // $recordList=array(); // $neighbourList=array(); //find the neighbour of start node first array_push($recordList, $start); if ($active == 0) { $neighbourList = findNodeActiveNeighbour($start, $recordList); } else { $neighbourList = findNodeNeighbour($start, $recordList); } // print_r($neighbourList); // echo "<br>"; // print_r($recordList); //check if the start node has neighbour //if it do not have neighbours, return null means the search is end //if it has neighbours,check whether their neighbour is destination node or not //if the eighbour is not the destination node,change the start node to its neighbour to see whether they can find the destination node or not if (count($neighbourList) == 0 || $neighbourList == null) { return $nullList; } else { //the node already searched has recorded to a list so they won't be searched again //then check all the neighbours to see it is a destination node or not $listList = array(); $min = 0; $minArray = array(); for ($i = 0; $i < count($neighbourList); $i++) { array_push($recordList, $neighbourList[$i]); } for ($i = 0; $i < count($neighbourList); $i++) { //if yes, add this node to return list,then return the returnList if ($neighbourList[$i] == $destination) { //echo $neighbourList[$i]."xx"; //array_push($recordList,$destination); $result = array(); $result[0] = $neighbourList[$i]; $result[1] = $start; return $result; } } for ($i = 0; $i < count($neighbourList); $i++) { $tempList = find($neighbourList[$i], $destination, $active, $recordList); array_push($tempList, $start); // print_r($tempList); // echo "<br>"; if ($i == 0) { $min = count($tempList); $minArray = $tempList; } else { // $tempList=find($neighbourList[$i],$destination,$active); // array_push($tempList,$start); // print_r($tempList); // echo "<br>"; if ($min <= 1) { $min = count($tempList); $minArray = $tempList; } else { if (count($tempList) > 1) { if (count($tempList) < $min) { $minArray = $tempList; $min = count($tempList); } } } } } if ($min > 1) { return $minArray; } else { return $nullList; } } }
function delete($nid) { $row = getNodeByNid($nid); // $row['isActive']="no"; //delete the whole pattern $list = array(); $list[0] = $row['nid']; iniRecordList($list); if ($row['isConnector'] == 2) { return "domainFail"; } else { if ($row['isConnector'] == 1) { if (countPatternNodes($row['pid']) > 1) { return "patternFail"; } $neighbourList = findNodeNeighbour($row['nid']); $did = getDidByNid($nid); $domainId = getDomainByDid($did)['nid']; if (count($neighbourList) > 1) { for ($i = 0; $i < count($neighbourList); $i++) { if ($neighbourList[$i] != $domainId) { if (count(sendMessageIgnoreInactive($neighbourList[$i], $domainId, $list)) == 0) { return "fail"; } } } deleteNodesByNid($row['nid']); deleteLinksByNid($row['nid']); return "connectorSuccess"; } else { //get all neighbors of this domain, includes one connector node $tempDid = $neighbourList[0]; //echo "did ".$tempDid."</br>"; $tempNeighbourList = findNodeNeighbour($tempDid); $tempCount = 0; for ($i = 0; $i < count($tempNeighbourList); $i++) { $tempNode = $tempNeighbourList[$i]; if ($tempDid == getDidByNid($tempNode)) { $tempCount++; } } //echo "count ".$tempCount; if ($tempCount >= 1) { deleteNodesByNid($row['nid']); deleteLinksByNid($row['nid']); return "connectorSuccess"; } else { $domainNeighborList = findNodeNeighbour($domainId); $domainNeighborsCount = count($domainNeighborList); if ($domainNeighborsCount >= 2) { $list[0] = $domainId; iniRecordList($list); for ($i = 0; $i < $domainNeighborsCount; $i++) { for ($j = 0; $j < $domainNeighborsCount; $j++) { if ($domainNeighborList[$i] != $domainNeighborList[$j]) { if (count(sendMessageIgnoreInactive($domainNeighborList[$i], $domainNeighborList[$j], $list)) == 0) { return "fail"; } } } } } deleteNodesByNid($domainId); deleteLinksByNid($domainId); deleteNodesByNid($row['nid']); deleteLinksByNid($row['nid']); return $domainId; } } } else { $neighbourList = findNodeNeighbour($row['nid']); $pid = getPidByNid($nid); // echo $pid; $connectorId = getConnectorByPid($pid)['nid']; // echo $connectorId; for ($i = 0; $i < count($neighbourList); $i++) { // echo $neighbourList[$i]; if ($neighbourList[$i] == $connectorId) { } else { if (count(sendMessageIgnoreInactive($neighbourList[$i], $connectorId, $list)) == 0) { return "fail"; } } } deleteLinksByNid($row['nid']); deleteNodesByNid($row['nid']); return "normalSuccess"; } } }