|
32 | 32 | import java.util.List;
|
33 | 33 |
|
34 | 34 | import static com.graphhopper.util.EdgeIterator.ANY_EDGE;
|
35 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
36 |
| -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 35 | +import static org.junit.jupiter.api.Assertions.*; |
37 | 36 |
|
38 | 37 | public class AlternativeRouteEdgeCHTest {
|
39 | 38 | private final DecimalEncodedValue speedEnc = new DecimalEncodedValueImpl("speed", 5, 5, false);
|
@@ -183,4 +182,46 @@ void turnRestrictionAtConnectingNode() {
|
183 | 182 | assertEquals(IntArrayList.from(s, t), pathInfos.get(j).path.calcNodes(), "alternatives must start/end at start/end node");
|
184 | 183 | }
|
185 | 184 | }
|
| 185 | + |
| 186 | + @Test |
| 187 | + void distanceTimeAndWeight() { |
| 188 | + final BaseGraph graph = new BaseGraph.Builder(em).withTurnCosts(true).create(); |
| 189 | + // 0-1-2-3---| |
| 190 | + // \ | |
| 191 | + // 5-6-7-8 |
| 192 | + graph.edge(0, 1).setDistance(500).set(speedEnc, 60); |
| 193 | + graph.edge(1, 2).setDistance(500).set(speedEnc, 60); |
| 194 | + graph.edge(2, 3).setDistance(500).set(speedEnc, 60); |
| 195 | + graph.edge(2, 5).setDistance(1000).set(speedEnc, 60); |
| 196 | + graph.edge(3, 7).setDistance(1500).set(speedEnc, 60); |
| 197 | + graph.edge(5, 6).setDistance(500).set(speedEnc, 60); |
| 198 | + graph.edge(6, 7).setDistance(500).set(speedEnc, 60); |
| 199 | + graph.edge(7, 8).setDistance(500).set(speedEnc, 60); |
| 200 | + graph.freeze(); |
| 201 | + CHConfig chConfig = CHConfig.edgeBased("profile", new SpeedWeighting(speedEnc, turnCostEnc, graph.getTurnCostStorage(), Double.POSITIVE_INFINITY)); |
| 202 | + PrepareContractionHierarchies contractionHierarchies = PrepareContractionHierarchies.fromGraph(graph, chConfig); |
| 203 | + contractionHierarchies.useFixedNodeOrdering(NodeOrderingProvider.fromArray(7, 6, 0, 2, 4, 5, 1, 3, 8)); |
| 204 | + PrepareContractionHierarchies.Result res = contractionHierarchies.doWork(); |
| 205 | + RoutingCHGraph routingCHGraph = RoutingCHGraphImpl.fromGraph(graph, res.getCHStorage(), res.getCHConfig()); |
| 206 | + final int s = 0; |
| 207 | + final int t = 8; |
| 208 | + PMap hints = new PMap(); |
| 209 | + AlternativeRouteEdgeCH altDijkstra = new AlternativeRouteEdgeCH(routingCHGraph, hints); |
| 210 | + List<AlternativeRouteEdgeCH.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(s, t); |
| 211 | + assertTrue(pathInfos.size() > 1, "the graph, contraction order and alternative route algorith must be such that " + |
| 212 | + "there is at least one alternative path, otherwise this test makes no sense"); |
| 213 | + AlternativeRouteEdgeCH.AlternativeInfo best = pathInfos.get(0); |
| 214 | + assertEquals(3500, best.path.getDistance()); |
| 215 | + assertEquals(58.3333, best.path.getWeight(), 1.e-3); |
| 216 | + assertEquals(58333, best.path.getTime(), 10); |
| 217 | + assertEquals(IntArrayList.from(0, 1, 2, 5, 6, 7, 8), best.path.calcNodes()); |
| 218 | + for (int j = 1; j < pathInfos.size(); j++) { |
| 219 | + Path alternative = pathInfos.get(j).path; |
| 220 | + assertEquals(3500, alternative.getDistance()); |
| 221 | + assertEquals(58.3333, alternative.getWeight(), 1.e-3); |
| 222 | + assertEquals(58333, alternative.getTime(), 1); |
| 223 | + assertEquals(IntArrayList.from(0, 1, 2, 3, 7, 8), alternative.calcNodes()); |
| 224 | + } |
| 225 | + } |
| 226 | + |
186 | 227 | }
|
0 commit comments