Search in sources :

Example 66 with GraphBuilder

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

the class BlockAreaWeightingTest method setUp.

@BeforeEach
public void setUp() {
    encoder = new CarFlagEncoder();
    em = EncodingManager.create(Arrays.asList(encoder));
    graph = new GraphBuilder(em).create();
    // 0-1
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
    updateDistancesFor(graph, 0, 0.00, 0.00);
    updateDistancesFor(graph, 1, 0.01, 0.01);
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 67 with GraphBuilder

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

the class FootFlagEncoderTest method testGraph.

@Test
public void testGraph() {
    Graph g = new GraphBuilder(encodingManager).create();
    g.edge(0, 1).setDistance(10).set(footAvgSpeedEnc, 10.0).set(footAccessEnc, true, true);
    g.edge(0, 2).setDistance(10).set(footAvgSpeedEnc, 5.0).set(footAccessEnc, true, true);
    g.edge(1, 3).setDistance(10).set(footAvgSpeedEnc, 10.0).set(footAccessEnc, true, true);
    EdgeExplorer out = g.createEdgeExplorer(AccessFilter.outEdges(footEncoder.getAccessEnc()));
    assertEquals(GHUtility.asSet(1, 2), GHUtility.getNeighbors(out.setBaseNode(0)));
    assertEquals(GHUtility.asSet(0, 3), GHUtility.getNeighbors(out.setBaseNode(1)));
    assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(out.setBaseNode(2)));
}
Also used : Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.jupiter.api.Test)

Example 68 with GraphBuilder

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

the class OSMTurnRelationParserTest method testGetRestrictionAsEntries.

@Test
public void testGetRestrictionAsEntries() {
    CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
    final Map<Long, Integer> osmNodeToInternal = new HashMap<>();
    final Map<Integer, Long> internalToOSMEdge = new HashMap<>();
    osmNodeToInternal.put(3L, 3);
    // edge ids are only stored if they occurred before in an OSMRelation
    internalToOSMEdge.put(3, 3L);
    internalToOSMEdge.put(4, 4L);
    OSMTurnRelationParser parser = new OSMTurnRelationParser(encoder.toString(), 1, OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR));
    GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager.Builder().add(encoder).addTurnCostParser(parser).build()).create();
    EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage, encoder);
    TurnCostParser.ExternalInternalMap map = new TurnCostParser.ExternalInternalMap() {

        @Override
        public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
            return osmNodeToInternal.getOrDefault(nodeOsmId, -1);
        }

        @Override
        public long getOsmIdOfInternalEdge(int edgeId) {
            Long l = internalToOSMEdge.get(edgeId);
            if (l == null)
                return -1;
            return l;
        }
    };
    // TYPE == ONLY
    OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, OSMTurnRelation.Type.ONLY);
    parser.addRelationToTCStorage(instance, map, ghStorage);
    TurnCostStorage tcs = ghStorage.getTurnCostStorage();
    DecimalEncodedValue tce = parser.getTurnCostEnc();
    assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 6)));
    assertEquals(0, tcs.get(tce, 4, 3, 3), .1);
    assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 2)));
    // TYPE == NOT
    instance = new OSMTurnRelation(4, 3, 3, OSMTurnRelation.Type.NOT);
    parser.addRelationToTCStorage(instance, map, ghStorage);
    assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 3)));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) OSMTurnRelation(com.graphhopper.reader.OSMTurnRelation) HashMap(java.util.HashMap) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) GraphBuilder(com.graphhopper.storage.GraphBuilder) TurnCostStorage(com.graphhopper.storage.TurnCostStorage) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) EdgeBasedRoutingAlgorithmTest(com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest) Test(org.junit.jupiter.api.Test)

Example 69 with GraphBuilder

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

the class FastestWeightingTest method calcWeightAndTime_withTurnCosts_shortest.

@Test
public void calcWeightAndTime_withTurnCosts_shortest() {
    Graph graph = new GraphBuilder(encodingManager).create();
    Weighting weighting = new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
    EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
    // turn costs are given in seconds
    setTurnCost(graph, 0, 1, 2, 5);
    // todo: for the shortest weighting turn costs cannot be interpreted as seconds? at least when they are added
    // to the weight? how much should they contribute ?
    // assertEquals(105, AbstractWeighting.calcWeightWithTurnWeight(weighting, edge, false, 0), 1.e-6);
    assertEquals(6000 + 5000, 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 70 with GraphBuilder

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

the class FastestWeightingTest method calcWeightAndTime_withTurnCosts.

@Test
public void calcWeightAndTime_withTurnCosts() {
    Graph graph = new GraphBuilder(encodingManager).create();
    Weighting weighting = new FastestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
    EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
    // turn costs are given in seconds
    setTurnCost(graph, 0, 1, 2, 5);
    assertEquals(6 + 5, GHUtility.calcWeightWithTurnWeight(weighting, edge, false, 0), 1.e-6);
    assertEquals(6000 + 5000, 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)

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