the shortest route from class 2 to 20 is :
ต้นทาง 2 => ปลายทาง 20 = 44 (กิโลเมตร) destinations [4]: Follow the route to the classes (2-16-21-20).
อยากให้แสดงแบบนี้อะครับ ต้องทำอย่างไร
the shortest route from class 2 to 20 is :
ต้นทาง 2 => ปลายทาง 20 = 44 (กิโลเมตร)
destinations [4]: Follow the route to the classes (สารคาม - กันทร - ยางตลาด - กาฬสิน ).
<?php
include("dijkstra.php");
include("connect.php");
// I is the infinite distance.
define('I',1000);
// Size of the matrix
$sql="SELECT * FROM tb_busstop";
$query=mysql_query($sql);
$num_row=mysql_num_rows($query);//?????????????
$matrixWidth = $num_row; //????????????????????????????
$i=0;
// $points is an array in the following format: (router1,router2,distance-between-them)
$points[] = array();
while ($row = mysql_fetch_assoc($query)) {
$points[] = array(
$row['station_id'],
$row['station_id2'],
$row['distance'],
$row['route_id']
);
$i++;
}
$ourMap = array();
// Read in the points and push them into the map
for ($i=0,$m=count($points); $i<$m; $i++) {
$x = $points[$i][0];
$y = $points[$i][1];
$c = $points[$i][2];
$r = $points[$i][3];
$ourMap[$x][$y] = $c;
$ourMap[$y][$x] = $c;
}
// ensure that the distance from a node to itself is always zero
// Purists may want to edit this bit out.
for ($i=0; $i < $matrixWidth; $i++) {
for ($k=0; $k < $matrixWidth; $k++) {
if ($i == $k) $ourMap[$i][$k] = 0;
}
}
// initialize the algorithm class
$dijkstra = new Dijkstra($ourMap, I,$matrixWidth);
// $dijkstra->findShortestPath(0,13); to find only path from field 0 to field 13...
$fromClass = $_POST['fromClass'];
$toClass = $_POST['toClass'];
$dijkstra->findShortestPath($fromClass, $toClass);
// Display the results
echo '<pre>';
//echo "the map looks like:\n\n";
//echo $dijkstra -> printMap($ourMap);
echo "\n\n the shortest route from class ".$fromClass." to ".$toClass." is :\n";
echo $dijkstra -> getResults((int)$toClass);
echo '</pre>';
?>