use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.
the class AlternativeRouteEdgeCHTest method testAssumptions.
@Test
public void testAssumptions() {
GraphHopperStorage g = createTestGraph(em);
TurnCostProvider turnCostProvider = new DefaultTurnCostProvider(carFE, g.getTurnCostStorage());
CHConfig chConfig = CHConfig.edgeBased("profile", new FastestWeighting(carFE, turnCostProvider));
CHStorage chStorage = g.createCHStorage(chConfig);
RoutingCHGraph chGraph = g.createCHGraph(chStorage, chConfig);
DijkstraBidirectionEdgeCHNoSOD router = new DijkstraBidirectionEdgeCHNoSOD(chGraph);
Path path = router.calcPath(5, 10);
assertTrue(path.isFound());
assertEquals(IntArrayList.from(5, 6, 7, 8, 4, 10), path.calcNodes());
assertEquals(50000.0, path.getDistance(), 0.0);
// 6 -> 3 -> 4 is forbidden
g = createTestGraph(em);
RoutingCHGraph routingCHGraph = prepareCH(g);
router = new DijkstraBidirectionEdgeCHNoSOD(routingCHGraph);
path = router.calcPath(5, 3, ANY_EDGE, GHUtility.getEdge(g, 2, 3).getEdge());
assertEquals(IntArrayList.from(5, 1, 9, 2, 3), path.calcNodes());
assertEquals(40000.0, path.getDistance(), 0.0);
// We can specifically route to the desired in-edge at node 3
// which does not lie upstream of the turn-restriction.
}
use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.
the class QueryRoutingCHGraphTest method setup.
@BeforeEach
public void setup() {
encoder = new CarFlagEncoder(5, 5, 5, true);
encodingManager = EncodingManager.create(encoder);
graph = new GraphBuilder(encodingManager).create();
weighting = new FastestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()));
na = graph.getNodeAccess();
}
use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.
the class EdgeBasedNodeContractorTest method initialize.
private void initialize() {
encoder = new CarFlagEncoder(5, 5, maxCost);
EncodingManager encodingManager = EncodingManager.create(encoder);
graph = new GraphBuilder(encodingManager).create();
chConfigs = Arrays.asList(CHConfig.edgeBased("p1", new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()))), CHConfig.edgeBased("p2", new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage(), 60))));
}
use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.
the class AccessFilterTest method testAccept_fwdLoopShortcut_acceptedByInExplorer.
@Test
public void testAccept_fwdLoopShortcut_acceptedByInExplorer() {
// 0-1
// \|
// 2
GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(2));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 0).setDistance(3));
graph.freeze();
// add loop shortcut in 'fwd' direction
CHConfig chConfig = CHConfig.edgeBased("profile", new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage())));
CHStorage chStore = graph.createCHStorage(chConfig);
CHStorageBuilder chBuilder = new CHStorageBuilder(chStore);
chBuilder.setIdentityLevels();
chBuilder.addShortcutEdgeBased(0, 0, PrepareEncoder.getScFwdDir(), 5, 0, 2, 0, 2);
RoutingCHGraph chGraph = graph.createCHGraph(chStore, chConfig);
RoutingCHEdgeExplorer outExplorer = chGraph.createOutEdgeExplorer();
RoutingCHEdgeExplorer inExplorer = chGraph.createInEdgeExplorer();
IntSet inEdges = new IntHashSet();
IntSet outEdges = new IntHashSet();
RoutingCHEdgeIterator outIter = outExplorer.setBaseNode(0);
while (outIter.next()) {
outEdges.add(outIter.getEdge());
}
RoutingCHEdgeIterator inIter = inExplorer.setBaseNode(0);
while (inIter.next()) {
inEdges.add(inIter.getEdge());
}
// the loop should be accepted by in- and outExplorers
assertEquals(IntHashSet.from(0, 3), outEdges, "Wrong outgoing edges");
assertEquals(IntHashSet.from(2, 3), inEdges, "Wrong incoming edges");
}
use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method testPrepareSubnetwork_withTurnCosts.
@Test
public void testPrepareSubnetwork_withTurnCosts() {
EncodingManager em = createEncodingManager("car|turn_costs=true");
FlagEncoder encoder = em.fetchEdgeEncoders().iterator().next();
// since the middle edge is blocked the upper component is a subnetwork (regardless of turn costs)
GraphHopperStorage g = createSubnetworkTestStorage(em);
PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
instance.setMinNetworkSize(4);
assertEquals(3, instance.doWork());
assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, encoder));
// if we open the edge it won't be a subnetwork anymore
g = createSubnetworkTestStorage(em);
EdgeIteratorState edge = GHUtility.getEdge(g, 3, 4);
GHUtility.setSpeed(10, true, true, encoder, edge);
instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
instance.setMinNetworkSize(4);
assertEquals(0, instance.doWork());
assertEquals(IntArrayList.from(), getSubnetworkEdges(g, encoder));
// ... and now for something interesting: if we open the edge *and* apply turn restrictions it will be a
// subnetwork again
g = createSubnetworkTestStorage(em);
edge = GHUtility.getEdge(g, 3, 4);
GHUtility.setSpeed(10, true, true, encoder, edge);
DecimalEncodedValue turnCostEnc = em.getDecimalEncodedValue(TurnCost.key(encoder.toString()));
g.getTurnCostStorage().set(turnCostEnc, 0, 4, 7, 1);
g.getTurnCostStorage().set(turnCostEnc, 0, 4, 9, 1);
instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
instance.setMinNetworkSize(4);
assertEquals(3, instance.doWork());
assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, encoder));
}
Aggregations