@@ -137,4 +137,60 @@ public function testOptimizedExit() {
137
137
private function hasVertex (Edge \Base $ edge , Vertex $ vertex ) {
138
138
return $ edge ->getVerticesStart ()->getVertexFirst () === $ vertex || $ edge ->getVerticesTarget ()->getVertexFirst () === $ vertex ;
139
139
}
140
+
141
+ public function testDijkstraAmbiguity2 () {
142
+ $ graph = new Graph ();
143
+
144
+ $ a = $ graph ->createVertex ("a " );
145
+ $ b = $ graph ->createVertex ("b " );
146
+ $ c = $ graph ->createVertex ("c " );
147
+ $ d = $ graph ->createVertex ("d " );
148
+
149
+ $ a ->createEdge ($ b )->setWeight (12 );
150
+ $ a ->createEdge ($ c )->setWeight (42 );
151
+ $ b ->createEdge ($ d )->setWeight (42 );
152
+ $ c ->createEdge ($ d )->setWeight (12 );
153
+
154
+ $ predecessors = MultiDijkstra::findShortestPaths ($ a , $ d );
155
+
156
+ $ paths = MultiDijkstra::getAllPossiblePathsFromPredecesArray ($ a , $ d , $ predecessors );
157
+
158
+ $ this ->assertCount (2 , $ paths );
159
+ $ this ->assertCount (2 , $ paths [0 ]);
160
+ $ this ->assertCount (2 , $ paths [1 ]);
161
+
162
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [0 ][0 ], $ a ));
163
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [0 ][0 ], $ b ));
164
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [0 ][1 ], $ b ));
165
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [0 ][1 ], $ d ));
166
+
167
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [1 ][0 ], $ a ));
168
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [1 ][0 ], $ c ));
169
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [1 ][1 ], $ c ));
170
+ $ this ->assertTrue ($ this ->hasVertex ($ paths [1 ][1 ], $ d ));
171
+ }
172
+
173
+ public function testDijkstraAmbiguity3 () {
174
+ $ graph = new Graph ();
175
+
176
+ $ a = $ graph ->createVertex ("a " );
177
+ $ b = $ graph ->createVertex ("b " );
178
+ $ c = $ graph ->createVertex ("c " );
179
+ $ d = $ graph ->createVertex ("d " );
180
+ $ e = $ graph ->createVertex ("e " );
181
+
182
+ $ a ->createEdge ($ b )->setWeight (12 );
183
+ $ a ->createEdge ($ c )->setWeight (42 );
184
+ $ b ->createEdge ($ d )->setWeight (42 );
185
+ $ c ->createEdge ($ d )->setWeight (12 );
186
+ $ d ->createEdge ($ e )->setWeight (1 );
187
+ $ e ->createEdge ($ d )->setWeight (1 );
188
+
189
+ $ predecessors = MultiDijkstra::findShortestPaths ($ a , $ e );
190
+
191
+ $ paths = MultiDijkstra::getAllPossiblePathsFromPredecesArray ($ a , $ e , $ predecessors );
192
+
193
+ $ this ->assertCount (4 , $ paths );
194
+ }
195
+
140
196
}
0 commit comments