Search in sources :

Example 41 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class FastestWeightingTest method calcWeightAndTime_uTurnCosts.

@Test
public void calcWeightAndTime_uTurnCosts() {
    Graph graph = new GraphBuilder(encodingManager).create();
    Weighting weighting = new FastestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage(), 40));
    EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
    assertEquals(6 + 40, GHUtility.calcWeightWithTurnWeight(weighting, edge, false, 0), 1.e-6);
    assertEquals((6 + 40) * 1000, GHUtility.calcMillisWithTurnMillis(weighting, edge, false, 0), 1.e-6);
}
Also used : Graph(com.graphhopper.storage.Graph) VirtualEdgeIteratorState(com.graphhopper.routing.querygraph.VirtualEdgeIteratorState) GHUtility.createMockedEdgeIteratorState(com.graphhopper.util.GHUtility.createMockedEdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.jupiter.api.Test)

Example 42 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class FastestWeightingTest method testTime.

@Test
public void testTime() {
    FlagEncoder tmpEnc = new Bike2WeightFlagEncoder();
    GraphHopperStorage g = new GraphBuilder(EncodingManager.create(tmpEnc)).create();
    Weighting w = new FastestWeighting(tmpEnc);
    IntsRef edgeFlags = GHUtility.setSpeed(15, 15, tmpEnc, g.getEncodingManager().createEdgeFlags());
    tmpEnc.getAverageSpeedEnc().setDecimal(true, edgeFlags, 10.0);
    EdgeIteratorState edge = GHUtility.createMockedEdgeIteratorState(100000, edgeFlags);
    assertEquals(375 * 60 * 1000, w.calcEdgeMillis(edge, false));
    assertEquals(600 * 60 * 1000, w.calcEdgeMillis(edge, true));
    g.close();
}
Also used : Bike2WeightFlagEncoder(com.graphhopper.routing.util.Bike2WeightFlagEncoder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Bike2WeightFlagEncoder(com.graphhopper.routing.util.Bike2WeightFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) VirtualEdgeIteratorState(com.graphhopper.routing.querygraph.VirtualEdgeIteratorState) GHUtility.createMockedEdgeIteratorState(com.graphhopper.util.GHUtility.createMockedEdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 43 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class CustomModelParserTest method setup.

@BeforeEach
void setup() {
    encoder = new CarFlagEncoder();
    countryEnc = new StringEncodedValue("country", 10);
    encodingManager = new EncodingManager.Builder().add(encoder).add(countryEnc).add(new EnumEncodedValue<>(Surface.KEY, Surface.class)).build();
    graph = new GraphBuilder(encodingManager).create();
    avgSpeedEnc = encoder.getAverageSpeedEnc();
    roadClassEnc = encodingManager.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) RoadClass(com.graphhopper.routing.ev.RoadClass) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 44 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder 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 45 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder 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)

Aggregations

GraphBuilder (com.graphhopper.storage.GraphBuilder)98 Test (org.junit.jupiter.api.Test)60 Graph (com.graphhopper.storage.Graph)48 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 NodeAccess (com.graphhopper.storage.NodeAccess)30 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)22 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)21 EncodingManager (com.graphhopper.routing.util.EncodingManager)19 Test (org.junit.Test)16 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)14 ConnectedComponents (com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents)12 Dijkstra (com.graphhopper.routing.Dijkstra)10 Path (com.graphhopper.routing.Path)10 ReaderWay (com.graphhopper.reader.ReaderWay)9 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)6 IntsRef (com.graphhopper.storage.IntsRef)6 Random (java.util.Random)6