Search in sources :

Example 71 with EdgeIteratorState

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

the class BlockAreaWeightingTest method testBlockedByShape.

@Test
public void testBlockedByShape() {
    EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
    GraphEdgeIdFinder.BlockArea bArea = new GraphEdgeIdFinder.BlockArea(graph);
    BlockAreaWeighting instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
    assertEquals(94.35, instance.calcEdgeWeight(edge, false), 0.01);
    bArea.add(new Circle(0.01, 0.01, 100));
    assertEquals(Double.POSITIVE_INFINITY, instance.calcEdgeWeight(edge, false), .01);
    bArea = new GraphEdgeIdFinder.BlockArea(graph);
    instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
    // Do not match 1,1 of edge
    bArea.add(new Circle(0.1, 0.1, 100));
    assertEquals(94.35, instance.calcEdgeWeight(edge, false), .01);
}
Also used : Circle(com.graphhopper.util.shapes.Circle) GraphEdgeIdFinder(com.graphhopper.storage.GraphEdgeIdFinder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test)

Example 72 with EdgeIteratorState

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

the class ShortFastestWeightingTest method testShort.

@Test
public void testShort() {
    EdgeIteratorState edge = createMockedEdgeIteratorState(10, GHUtility.setSpeed(50, 0, encoder, encodingManager.createEdgeFlags()));
    Weighting instance = new ShortFastestWeighting(encoder, 0.03);
    assertEquals(1.02, instance.calcEdgeWeight(edge, false), 1e-8);
    // more influence from distance
    instance = new ShortFastestWeighting(encoder, 0.1);
    assertEquals(1.72, instance.calcEdgeWeight(edge, false), 1e-8);
}
Also used : GHUtility.createMockedEdgeIteratorState(com.graphhopper.util.GHUtility.createMockedEdgeIteratorState) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test)

Example 73 with EdgeIteratorState

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

the class CustomModelParserTest method setPriorityForRoadClass.

@Test
void setPriorityForRoadClass() {
    CustomModel customModel = new CustomModel();
    customModel.addToPriority(If("road_class == PRIMARY", MULTIPLY, 0.5));
    CustomWeighting.EdgeToDoubleMapping priorityMapping = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null).getEdgeToPriorityMapping();
    GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
    EdgeIteratorState edge1 = graph.edge(0, 1).setDistance(100).set(roadClassEnc, RoadClass.PRIMARY);
    EdgeIteratorState edge2 = graph.edge(1, 2).setDistance(100).set(roadClassEnc, RoadClass.SECONDARY);
    assertEquals(0.5, priorityMapping.get(edge1, false), 1.e-6);
    assertEquals(1.0, priorityMapping.get(edge2, false), 1.e-6);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) CustomModel(com.graphhopper.util.CustomModel) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 74 with EdgeIteratorState

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

the class OSMMaxSpeedParserTest method countryRule.

@Test
void countryRule() {
    EncodingManager em = EncodingManager.create("car");
    DecimalEncodedValue maxSpeedEnc = em.getDecimalEncodedValue(MaxSpeed.KEY);
    Graph graph = new GraphBuilder(em).create();
    FlagEncoder encoder = em.getEncoder("car");
    EdgeIteratorState e1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
    EdgeIteratorState e2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
    OSMMaxSpeedParser parser = new OSMMaxSpeedParser(maxSpeedEnc);
    IntsRef relFlags = em.createRelationFlags();
    ReaderWay way = new ReaderWay(29L);
    way.setTag("highway", "living_street");
    way.setTag("country_rule", new CountryRule() {

        @Override
        public double getMaxSpeed(ReaderWay readerWay, TransportationMode transportationMode, double currentMaxSpeed) {
            return 5;
        }
    });
    parser.handleWayTags(e1.getFlags(), way, relFlags);
    assertEquals(5, e1.get(maxSpeedEnc), .1);
    // without a country_rule we get the default value
    way.removeTag("country_rule");
    parser.handleWayTags(e2.getFlags(), way, relFlags);
    assertEquals(MaxSpeed.UNSET_SPEED, e2.get(maxSpeedEnc), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) TransportationMode(com.graphhopper.routing.util.TransportationMode) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 75 with EdgeIteratorState

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

the class PrepareRoutingSubnetworksTest method testRemoveNode.

@Test
public void testRemoveNode() {
    FlagEncoder carEncoder = new CarFlagEncoder();
    BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
    EncodingManager em2 = new EncodingManager(carEncoder, bikeEncoder);
    GraphHopperStorage g = createSubnetworkTestStorage2(em2);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, em2.fetchEdgeEncoders());
    EdgeExplorer edgeExplorer = g.createEdgeExplorer();
    assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 4));
    assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 5));
    assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 6));
    // mark certain edges inaccessible for all encoders
    for (EdgeIteratorState edge : Arrays.asList(GHUtility.getEdge(g, 5, 6), GHUtility.getEdge(g, 4, 5), GHUtility.getEdge(g, 4, 6))) {
        for (FlagEncoder encoders : em2.fetchEdgeEncoders()) {
            edge.setFlags(encoders.setAccess(0, false, false));
        }
    }
    assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 4));
    assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 5));
    assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 6));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

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