Search in sources :

Example 96 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState 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));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) DefaultTurnCostProvider(com.graphhopper.routing.weighting.DefaultTurnCostProvider) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 97 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class HeadingEdgeFilterTest method getHeading.

@Test
public void getHeading() {
    GHPoint point = new GHPoint(55.67093, 12.577294);
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager.Builder().add(carEncoder).build();
    GraphHopperStorage g = new GraphBuilder(encodingManager).create();
    EdgeIteratorState edge = g.edge(0, 1);
    g.getNodeAccess().setNode(0, 55.671044, 12.5771583);
    g.getNodeAccess().setNode(1, 55.6704136, 12.5784324);
    // GHUtility.setSpeed(50, 0, carEncoder, edge.getFlags());
    assertEquals(131.2, HeadingEdgeFilter.getHeadingOfGeometryNearPoint(edge, point, 20), .1);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphBuilder(com.graphhopper.storage.GraphBuilder) GHPoint(com.graphhopper.util.shapes.GHPoint) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 98 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class BlockAreaWeightingTest method testBlockedById.

@Test
public void testBlockedById() {
    GraphEdgeIdFinder.BlockArea bArea = new GraphEdgeIdFinder.BlockArea(graph);
    EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
    BlockAreaWeighting instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
    assertEquals(94.35, instance.calcEdgeWeight(edge, false), .01);
    GHIntHashSet set = new GHIntHashSet();
    set.add(0);
    bArea.add(null, set);
    instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
    assertEquals(Double.POSITIVE_INFINITY, instance.calcEdgeWeight(edge, false), .01);
}
Also used : GraphEdgeIdFinder(com.graphhopper.storage.GraphEdgeIdFinder) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test)

Example 99 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class AlternativeRouteEdgeCH method sharedDistanceWithShortest.

private double sharedDistanceWithShortest(Path path) {
    double sharedDistance = 0.0;
    List<EdgeIteratorState> edges = path.calcEdges();
    for (EdgeIteratorState edge : edges) {
        if (alternatives.get(0).nodes.contains(edge.getBaseNode()) && alternatives.get(0).nodes.contains(edge.getAdjNode())) {
            sharedDistance += edge.getDistance();
        }
    }
    return sharedDistance;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 100 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class AlternativeRouteEdgeCH method sharedDistance.

private double sharedDistance(Path path) {
    double sharedDistance = 0.0;
    List<EdgeIteratorState> edges = path.calcEdges();
    for (EdgeIteratorState edge : edges) {
        if (nodesInCurrentAlternativeSetContains(edge.getBaseNode()) && nodesInCurrentAlternativeSetContains(edge.getAdjNode())) {
            sharedDistance += edge.getDistance();
        }
    }
    return sharedDistance;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Aggregations

EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)137 Test (org.junit.jupiter.api.Test)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)25 Test (org.junit.Test)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)17 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)13 Snap (com.graphhopper.storage.index.Snap)12 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)11 CHEdgeIteratorState (com.graphhopper.util.CHEdgeIteratorState)11 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)10 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)10 NodeAccess (com.graphhopper.storage.NodeAccess)10 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)7 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 GHPoint (com.graphhopper.util.shapes.GHPoint)6 Fun (org.mapdb.Fun)6 IntArrayList (com.carrotsearch.hppc.IntArrayList)5