@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function computePath(Node $source, Node $target) |
42 | 42 | { |
43 | - if(! $this->grid instanceof NodeGrid) |
|
43 | + if (!$this->grid instanceof NodeGrid) |
|
44 | 44 | { |
45 | 45 | throw new \RuntimeException('Invalid Grid'); |
46 | 46 | } |
@@ -52,20 +52,20 @@ discard block |
||
52 | 52 | $priorityQueue->insert($source, 0); |
53 | 53 | $distanceMap->insert($source, 0); |
54 | 54 | |
55 | - while(! $priorityQueue->isEmpty()) |
|
55 | + while (!$priorityQueue->isEmpty()) |
|
56 | 56 | { |
57 | 57 | $node = $priorityQueue->extract(); |
58 | 58 | |
59 | - if($node->getId() === $target->getId()) |
|
59 | + if ($node->getId() === $target->getId()) |
|
60 | 60 | { |
61 | 61 | return new NodePath($previousMap->lookupFrom($node)); |
62 | 62 | } |
63 | 63 | |
64 | 64 | $neighbors = $this->grid->getWalkableNeighbors($node); |
65 | - foreach($neighbors as $neighbor) |
|
65 | + foreach ($neighbors as $neighbor) |
|
66 | 66 | { |
67 | 67 | $alternativeDistance = $distanceMap->lookup($node) + $this->distance->compute($node, $neighbor); |
68 | - if(! $distanceMap->exists($neighbor) || $alternativeDistance < $distanceMap->lookup($neighbor)) |
|
68 | + if (!$distanceMap->exists($neighbor) || $alternativeDistance < $distanceMap->lookup($neighbor)) |
|
69 | 69 | { |
70 | 70 | $priorityQueue->insert($neighbor, $alternativeDistance); |
71 | 71 | $distanceMap->insert($neighbor, $alternativeDistance); |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | |
25 | 25 | public function computeRoute() |
26 | 26 | { |
27 | - if(! $this->graph instanceof NodeGraph) |
|
27 | + if (!$this->graph instanceof NodeGraph) |
|
28 | 28 | { |
29 | 29 | throw new \RuntimeException('Invalid Graph'); |
30 | 30 | } |
31 | 31 | |
32 | 32 | $vertexes = $this->graph->getVertexes(); |
33 | - if(count($vertexes) <= 2) |
|
33 | + if (count($vertexes) <= 2) |
|
34 | 34 | { |
35 | 35 | return new NodePath($vertexes); |
36 | 36 | } |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | |
41 | 41 | $pathMap = new NodeMap(); |
42 | 42 | $pathMap->insert($vertexFrom, $vertexTo); |
43 | - while(! empty($vertexes)) |
|
43 | + while (!empty($vertexes)) |
|
44 | 44 | { |
45 | 45 | $minimalVertexTo = null; |
46 | 46 | $minimalEdge = INF; |
47 | 47 | $edges = $this->graph->getEdgesFrom($vertexFrom); |
48 | - foreach($edges as $vertexToId => $edge) |
|
48 | + foreach ($edges as $vertexToId => $edge) |
|
49 | 49 | { |
50 | 50 | $vertexTo = $this->graph->getVertex($vertexToId); |
51 | - if(! $pathMap->exists($vertexTo) && $edge < $minimalEdge) |
|
51 | + if (!$pathMap->exists($vertexTo) && $edge < $minimalEdge) |
|
52 | 52 | { |
53 | 53 | $minimalVertexTo = $vertexTo; |
54 | 54 | $minimalEdge = $edge; |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | |
31 | 31 | public function computeRoute() |
32 | 32 | { |
33 | - if(! $this->graph instanceof NodeGraph) |
|
33 | + if (!$this->graph instanceof NodeGraph) |
|
34 | 34 | { |
35 | 35 | throw new \RuntimeException('Invalid Graph'); |
36 | 36 | } |
37 | - if(! $this->existingRoute instanceof NodePath) |
|
37 | + if (!$this->existingRoute instanceof NodePath) |
|
38 | 38 | { |
39 | 39 | throw new \RuntimeException('Invalid ExistingRoute'); |
40 | 40 | } |
41 | - if(count($this->existingRoute) < 2) |
|
41 | + if (count($this->existingRoute) < 2) |
|
42 | 42 | { |
43 | 43 | return $this->existingRoute; |
44 | 44 | } |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | do |
49 | 49 | { |
50 | 50 | $improvementMade = false; |
51 | - foreach($this->existingRoute->getKeys() as $iKey) |
|
51 | + foreach ($this->existingRoute->getKeys() as $iKey) |
|
52 | 52 | { |
53 | - foreach($this->existingRoute->getKeys() as $kKey) |
|
53 | + foreach ($this->existingRoute->getKeys() as $kKey) |
|
54 | 54 | { |
55 | - if($iKey == $kKey) |
|
55 | + if ($iKey == $kKey) |
|
56 | 56 | { |
57 | 57 | continue; |
58 | 58 | } |
59 | 59 | $newRoute = $this->twoOptSwap($iKey, $kKey); |
60 | 60 | $newDistance = $this->graph->computeLength($newRoute); |
61 | - if($newDistance < $existingDistance) |
|
61 | + if ($newDistance < $existingDistance) |
|
62 | 62 | { |
63 | 63 | $this->existingRoute = $newRoute; |
64 | 64 | $existingDistance = $newDistance; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | } |
70 | 70 | } |
71 | - } while($improvementMade); |
|
71 | + } while ($improvementMade); |
|
72 | 72 | |
73 | 73 | return $this->existingRoute; |
74 | 74 | } |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | private function twoOptSwap($iKey, $kKey) |
77 | 77 | { |
78 | 78 | $newRouteNodes = array(); |
79 | - foreach($this->existingRoute->getKeys() as $key) |
|
79 | + foreach ($this->existingRoute->getKeys() as $key) |
|
80 | 80 | { |
81 | 81 | if ($key === $iKey) |
82 | 82 | { |
83 | 83 | $newRouteNodes[] = $this->existingRoute->getKey($kKey); |
84 | 84 | } |
85 | - elseif($key === $kKey) |
|
85 | + elseif ($key === $kKey) |
|
86 | 86 | { |
87 | 87 | $newRouteNodes[] = $this->existingRoute->getKey($iKey); |
88 | 88 | } |
@@ -81,12 +81,10 @@ |
||
81 | 81 | if ($key === $iKey) |
82 | 82 | { |
83 | 83 | $newRouteNodes[] = $this->existingRoute->getKey($kKey); |
84 | - } |
|
85 | - elseif($key === $kKey) |
|
84 | + } elseif($key === $kKey) |
|
86 | 85 | { |
87 | 86 | $newRouteNodes[] = $this->existingRoute->getKey($iKey); |
88 | - } |
|
89 | - else |
|
87 | + } else |
|
90 | 88 | { |
91 | 89 | $newRouteNodes[] = $this->existingRoute->getKey($key); |
92 | 90 | } |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | |
31 | 31 | public function computeRoute() |
32 | 32 | { |
33 | - if(! $this->graph instanceof NodeGraph) |
|
33 | + if (!$this->graph instanceof NodeGraph) |
|
34 | 34 | { |
35 | 35 | throw new \RuntimeException('Invalid Graph'); |
36 | 36 | } |
37 | - if(! $this->existingRoute instanceof NodePath) |
|
37 | + if (!$this->existingRoute instanceof NodePath) |
|
38 | 38 | { |
39 | 39 | throw new \RuntimeException('Invalid ExistingRoute'); |
40 | 40 | } |
41 | - if(count($this->existingRoute) < 3) |
|
41 | + if (count($this->existingRoute) < 3) |
|
42 | 42 | { |
43 | 43 | return $this->existingRoute; |
44 | 44 | } |
@@ -48,19 +48,19 @@ discard block |
||
48 | 48 | do |
49 | 49 | { |
50 | 50 | $improvementMade = false; |
51 | - foreach($this->existingRoute->getKeys() as $iKey) |
|
51 | + foreach ($this->existingRoute->getKeys() as $iKey) |
|
52 | 52 | { |
53 | - foreach($this->existingRoute->getKeys() as $jKey) |
|
53 | + foreach ($this->existingRoute->getKeys() as $jKey) |
|
54 | 54 | { |
55 | - foreach($this->existingRoute->getKeys() as $kKey) |
|
55 | + foreach ($this->existingRoute->getKeys() as $kKey) |
|
56 | 56 | { |
57 | - if($iKey == $jKey || $iKey == $kKey || $jKey == $kKey) |
|
57 | + if ($iKey == $jKey || $iKey == $kKey || $jKey == $kKey) |
|
58 | 58 | { |
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | $newRoute = $this->threeOptSwap($iKey, $jKey, $kKey); |
62 | 62 | $newDistance = $this->graph->computeLength($newRoute); |
63 | - if($newDistance < $existingDistance) |
|
63 | + if ($newDistance < $existingDistance) |
|
64 | 64 | { |
65 | 65 | $this->existingRoute = $newRoute; |
66 | 66 | $existingDistance = $newDistance; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
74 | - } while($improvementMade); |
|
74 | + } while ($improvementMade); |
|
75 | 75 | |
76 | 76 | return $this->existingRoute; |
77 | 77 | } |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | private function threeOptSwap($iKey, $jKey, $kKey) |
80 | 80 | { |
81 | 81 | $newRouteNodes = array(); |
82 | - foreach($this->existingRoute->getKeys() as $key) |
|
82 | + foreach ($this->existingRoute->getKeys() as $key) |
|
83 | 83 | { |
84 | 84 | if ($key === $iKey) |
85 | 85 | { |
86 | 86 | $newRouteNodes[] = $this->existingRoute->getKey($kKey); |
87 | 87 | } |
88 | - elseif($key === $jKey) |
|
88 | + elseif ($key === $jKey) |
|
89 | 89 | { |
90 | 90 | $newRouteNodes[] = $this->existingRoute->getKey($iKey); |
91 | 91 | } |
92 | - elseif($key === $kKey) |
|
92 | + elseif ($key === $kKey) |
|
93 | 93 | { |
94 | 94 | $newRouteNodes[] = $this->existingRoute->getKey($jKey); |
95 | 95 | } |
@@ -84,16 +84,13 @@ |
||
84 | 84 | if ($key === $iKey) |
85 | 85 | { |
86 | 86 | $newRouteNodes[] = $this->existingRoute->getKey($kKey); |
87 | - } |
|
88 | - elseif($key === $jKey) |
|
87 | + } elseif($key === $jKey) |
|
89 | 88 | { |
90 | 89 | $newRouteNodes[] = $this->existingRoute->getKey($iKey); |
91 | - } |
|
92 | - elseif($key === $kKey) |
|
90 | + } elseif($key === $kKey) |
|
93 | 91 | { |
94 | 92 | $newRouteNodes[] = $this->existingRoute->getKey($jKey); |
95 | - } |
|
96 | - else |
|
93 | + } else |
|
97 | 94 | { |
98 | 95 | $newRouteNodes[] = $this->existingRoute->getKey($key); |
99 | 96 | } |