0 && $M > 0 ) { $M–; $X = trim(array_shift( $R )); foreach( $G[$X] as $Y ) { $Y = trim($Y); // See if we got a solution if ( $Y == $B ) { // We did? Construct a result path then array_push( $P, $B ); array_push( $P, $X ); while ( $V[$X] != $A ) { array_push( $P, trim($V[$X]) ); $X = $V[$X]; } array_push( $P, $A ); return array_reverse( $P ); } // First time we visit this node? if ( !array_key_exists($Y, $V) ) { // Store the path so we can track it back, $V[$Y] = $X; // and add it to the "within reach" list array_push( $R, $Y ); } } } return $P; } $time_start = microtime_float(); //Database structure: // E_systems // regionId constellationId systemName systemId jumpNodes security // (INT) (INT) (CHAR) (INT) (CHAR, Jump1:Jump2:Ju..) (CHAR) //Declare arrays to hold Solar System data // //Structure : // $nameArray : (ARRAY[ID] = NAME) // $jumpArray : (ARRAY[NAME] = ARRAY[JUMPS]) // $idArray : (ARRAY[NAME] = ID) $nameArray = array(); $jumpArray = array(); $idArray = array(); //Populate $jumpArray $query="SELECT * FROM e_systems"; $result=mysql_query($query); $previousSystem = ""; $arrayContent = ""; while ($row=mysql_fetch_row($result)) { $regionId = trim($row[0]); $constId = trim($row[1]); $systemName = strtoupper(trim($row[2])); $systemId = trim($row[3]); $secStatus = trim($row[5]); $nameArray[$systemId][0] = $systemName; $nameArray[$systemId][1] = $regionId; $nameArray[$systemId][2] = $constId; $nameArray[$systemId][3] = $secStatus; $idArray[strtoupper($systemName)] = $systemId; $jumpArray[$systemName]= explode(":", strtoupper($row[4])); array_push($jumpArray[$systemName],$systemId); } header("Content-type: text/xml"); $xml_output = "\n\t\n"; $jumpNum = 1; foreach( $jumpArray[$from] as $n ) { if ($n == $to) { $jumpNum = 2; $xml_output_body = "\t\n"; $xml_output_body .= "\t\t$to\n"; $xml_output_body .= "\t\n"; break; } } if ($jumpNum == 1) { foreach( graph_find_path( $jumpArray, $from, $to ) as $n ) { if ($jumpNum > 1) { $xml_output_body .= "\t\n"; $xml_output_body .= "\t\t" . $n . "\n"; $xml_output_body .= "\t\t" . $nameArray[$idArray[$n]][3] . "\n"; $xml_output_body .= "\t\n"; } $jumpNum++; } } if ($jumpNum > 1) { $xml_output_body = "\ttrue\n\t\n\t\t$from\n\t\t" . $nameArray[$idArray[$from]][3] . "\n\t\n" . $xml_output_body; } else { $xml_output_body = "\tfalse\n" . $xml_output_body; } $time_end = microtime_float(); $time = round($time_end - $time_start,5); $xml_output_body .= "\t" . ($jumpNum-1) . "\n"; $xml_output_body .= "\t$time" . "s\n"; $xml_output_body .= ""; echo $xml_output . $xml_output_body; //Display execution time } else { echo "Usage: eve_route.php?from=<origin>&to=<destination>

Output: XML file, containing list of jumps, begining with origin. If no route is possible, then output will be NULL."; } ?>