From e3e7e2e6c7eb8fe8f1edac0843ea21376565bfa0 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 27 Mar 2016 22:03:31 +0200 Subject: [PATCH] Coding style fixes. --- Math/Optimization/Graph/Dijkstra.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Math/Optimization/Graph/Dijkstra.php b/Math/Optimization/Graph/Dijkstra.php index d4dd7695d..b9b782f69 100644 --- a/Math/Optimization/Graph/Dijkstra.php +++ b/Math/Optimization/Graph/Dijkstra.php @@ -4,17 +4,19 @@ namespace phpOMS\Math\Optimization\Graph; class Dijkstra { public static function dijkstra(Graph $graph, $source, $target) { - $vertices = array(); - $neighbours = array(); + $vertices = []; + $neighbours = []; foreach ($graph_array as $edge) { array_push($vertices, $edge[0], $edge[1]); - $neighbours[$edge[0]][] = array("end" => $edge[1], "cost" => $edge[2]); - $neighbours[$edge[1]][] = array("end" => $edge[0], "cost" => $edge[2]); + $neighbours[$edge[0]][] = ["end" => $edge[1], "cost" => $edge[2]]; + $neighbours[$edge[1]][] = ["end" => $edge[0], "cost" => $edge[2]]; } $vertices = array_unique($vertices); + $dist = []; + $previous = []; foreach ($vertices as $vertex) { $dist[$vertex] = INF; $previous[$vertex] = NULL; @@ -35,7 +37,7 @@ class Dijkstra { } } - $Q = array_diff($Q, array($u)); + $Q = array_diff($Q, [$u]); if ($dist[$u] == INF || $u == $target) { break; @@ -53,7 +55,7 @@ class Dijkstra { } } - $path = array(); + $path = []; $u = $target; while (isset($previous[$u])) {