gieri
(usa Linux Mint)
Enviado em 07/09/2013 - 12:35h
cassio88 escreveu:
Bom, vamos ser práticos.
Experimenta
https://github.com/kay/PHP-Dijkstra
Os arquivos que você precisa ter no seu micro são
Dijkstra.php
PriorityQueue.php
runTest.php
Acabei de testar no meu micro e o resultado foi
Array ( [0] => a [1] => b [2] => c [3] => j [4] => f [5] => i )
tome cuidado, pois todos os 3 precisam começar com <?php e acabar com ?>
Como não sei exatamente qual sua necessidade, espero ter apontado para o caminho certo
O caminho das pedras é pesquisar no google por
PHP SHORTEST PATH
dá um monte de possíveis soluções
depois, por favor dê um retorno se resolveu seu problema (e aí você fecha o tópico) ou se eu estou "viajando na maionese"
um abraço
Amigo fiz aqui e funcionou entre um ponto e outro. Como faço para usar com vários pontos.
A configuração do meu ficou assim:
<?php
/*
* Author: doug@neverfear.org
*/
require("Dijkstra.php");
function runTest() {
$g = new Graph();
$g->addedge("1001", "1002", 1);
$g->addedge("1001", "1007", 1);
$g->addedge("1002", "1001", 1);
$g->addedge("1002", "1003", 1);
$g->addedge("1002", "1008", 1);
$g->addedge("1003", "1002", 1);
$g->addedge("1003", "1004", 1);
$g->addedge("1003", "1009", 1);
$g->addedge("1004", "1003", 1);
$g->addedge("1004", "1005", 1);
$g->addedge("1004", "1010", 1);
$g->addedge("1005", "1004", 1);
$g->addedge("1005", "1006", 1);
$g->addedge("1005", "1011", 1);
$g->addedge("1006", "1005", 1);
$g->addedge("1006", "1012", 1);
$g->addedge("1007", "1001", 1);
$g->addedge("1007", "1008", 1);
$g->addedge("1007", "1013", 1);
$g->addedge("1008", "1002", 1);
$g->addedge("1008", "1007", 1);
$g->addedge("1008", "1009", 1);
$g->addedge("1008", "1014", 1);
$g->addedge("1009", "1003", 1);
$g->addedge("1009", "1008", 1);
$g->addedge("1009", "1010", 1);
$g->addedge("1009", "1015", 1);
$g->addedge("1010", "1004", 1);
$g->addedge("1010", "1009", 1);
$g->addedge("1010", "1011", 1);
$g->addedge("1010", "1016", 1);
$g->addedge("1011", "1005", 1);
$g->addedge("1011", "1010", 1);
$g->addedge("1011", "1012", 1);
$g->addedge("1011", "1017", 1);
$g->addedge("1012", "1006", 1);
$g->addedge("1012", "1011", 1);
$g->addedge("1012", "1018", 1);
$g->addedge("1013", "1007", 1);
$g->addedge("1013", "1014", 1);
$g->addedge("1013", "1019", 1);
$g->addedge("1014", "1008", 1);
$g->addedge("1014", "1013", 1);
$g->addedge("1014", "1015", 1);
$g->addedge("1014", "1020", 1);
$g->addedge("1015", "1009", 1);
$g->addedge("1015", "1014", 1);
$g->addedge("1015", "1016", 1);
$g->addedge("1015", "1021", 1);
$g->addedge("1016", "1010", 1);
$g->addedge("1016", "1015", 1);
$g->addedge("1016", "1017", 1);
$g->addedge("1016", "1022", 1);
$g->addedge("1017", "1011", 1);
$g->addedge("1017", "1016", 1);
$g->addedge("1017", "1018", 1);
$g->addedge("1017", "1023", 1);
$g->addedge("1018", "1012", 1);
$g->addedge("1018", "1017", 1);
$g->addedge("1018", "1024", 1);
$g->addedge("1019", "1013", 1);
$g->addedge("1019", "1020", 1);
$g->addedge("1019", "1025", 1);
$g->addedge("1020", "1014", 1);
$g->addedge("1020", "1019", 1);
$g->addedge("1020", "1021", 1);
$g->addedge("1020", "1026", 1);
$g->addedge("1021", "1015", 1);
$g->addedge("1021", "1020", 1);
$g->addedge("1021", "1022", 1);
$g->addedge("1021", "1027", 1);
$g->addedge("1022", "1016", 1);
$g->addedge("1022", "1021", 1);
$g->addedge("1022", "1023", 1);
$g->addedge("1022", "1028", 1);
$g->addedge("1023", "1017", 1);
$g->addedge("1023", "1022", 1);
$g->addedge("1023", "1024", 1);
$g->addedge("1023", "1029", 1);
$g->addedge("1024", "1018", 1);
$g->addedge("1024", "1023", 1);
$g->addedge("1024", "1030", 1);
$g->addedge("1025", "1019", 1);
$g->addedge("1025", "1026", 1);
$g->addedge("1025", "1031", 1);
$g->addedge("1026", "1020", 1);
$g->addedge("1026", "1025", 1);
$g->addedge("1026", "1027", 1);
$g->addedge("1026", "1032", 1);
$g->addedge("1027", "1021", 1);
$g->addedge("1027", "1026", 1);
$g->addedge("1027", "1028", 1);
$g->addedge("1027", "1033", 1);
$g->addedge("1028", "1022", 1);
$g->addedge("1028", "1027", 1);
$g->addedge("1028", "1029", 1);
$g->addedge("1028", "1034", 1);
$g->addedge("1029", "1023", 1);
$g->addedge("1029", "1028", 1);
$g->addedge("1029", "1030", 1);
$g->addedge("1029", "1035", 1);
$g->addedge("1030", "1024", 1);
$g->addedge("1030", "1029", 1);
$g->addedge("1030", "1036", 1);
$g->addedge("1031", "1025", 1);
$g->addedge("1031", "1032", 1);
$g->addedge("1032", "1026", 1);
$g->addedge("1032", "1031", 1);
$g->addedge("1032", "1033", 1);
$g->addedge("1033", "1027", 1);
$g->addedge("1033", "1032", 1);
$g->addedge("1033", "1034", 1);
$g->addedge("1034", "1028", 1);
$g->addedge("1034", "1033", 1);
$g->addedge("1034", "1035", 1);
$g->addedge("1035", "1029", 1);
$g->addedge("1035", "1034", 1);
$g->addedge("1035", "1036", 1);
$g->addedge("1036", "1030", 1);
$g->addedge("1036", "1035", 1);
list($distances, $prev) = $g->paths_from("1001");
$path = $g->paths_to($prev, "1036");
print_r($path);
}
runTest();
?>