Search in sources :

Example 6 with GraphBuilder

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

the class AlternativeRouteCHTest method createTestGraph.

public GraphHopperStorage createTestGraph(EncodingManager tmpEM) {
    final GraphHopperStorage graph = new GraphBuilder(tmpEM).create();
    /*

           9      11
          /\     /  \
         1  2-3-4-10-12
         \   /   \
         5--6-7---8
        
         */
    // Make all edges the length of T, the distance around v than an s->v->t path
    // has to be locally-shortest to be considered.
    // So we get all three alternatives.
    GHUtility.setSpeed(60, 60, carFE, graph.edge(5, 6).setDistance(10000), graph.edge(6, 3).setDistance(10000), graph.edge(3, 4).setDistance(10000), graph.edge(4, 10).setDistance(10000), graph.edge(6, 7).setDistance(10000), graph.edge(7, 8).setDistance(10000), graph.edge(8, 4).setDistance(10000), graph.edge(5, 1).setDistance(10000), graph.edge(1, 9).setDistance(10000), graph.edge(9, 2).setDistance(10000), graph.edge(2, 3).setDistance(10000), graph.edge(4, 11).setDistance(9000), graph.edge(11, 12).setDistance(9000), graph.edge(12, 10).setDistance(10000));
    graph.freeze();
    return graph;
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage)

Example 7 with GraphBuilder

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

the class HeadingResolverTest method straightEdges.

@Test
public void straightEdges() {
    // 0 1 2
    // \|/
    // 7 -- 8 --- 3
    // /|\
    // 6 5 4
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 49.5073, 1.5545);
    na.setNode(1, 49.5002, 2.3895);
    na.setNode(2, 49.4931, 3.3013);
    na.setNode(3, 48.8574, 3.2025);
    na.setNode(4, 48.2575, 3.0651);
    na.setNode(5, 48.2393, 2.2576);
    na.setNode(6, 48.2246, 1.2249);
    na.setNode(7, 48.8611, 1.2194);
    na.setNode(8, 48.8538, 2.3950);
    // edge 0
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 0).setDistance(10));
    // edge 1
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 1).setDistance(10));
    // edge 2
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 2).setDistance(10));
    // edge 3
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 3).setDistance(10));
    // edge 4
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 4).setDistance(10));
    // edge 5
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 5).setDistance(10));
    // edge 6
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 6).setDistance(10));
    // edge 7
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 7).setDistance(10));
    HeadingResolver resolver = new HeadingResolver(graph);
    // using default tolerance
    assertEquals(IntArrayList.from(7, 6, 0), resolver.getEdgesWithDifferentHeading(8, 90));
    assertEquals(IntArrayList.from(7, 6, 0), resolver.setTolerance(100).getEdgesWithDifferentHeading(8, 90));
    assertEquals(IntArrayList.from(7, 6, 5, 4, 2, 1, 0), resolver.setTolerance(10).getEdgesWithDifferentHeading(8, 90));
    assertEquals(IntArrayList.from(7, 6, 5, 1, 0), resolver.setTolerance(60).getEdgesWithDifferentHeading(8, 90));
    assertEquals(IntArrayList.from(1), resolver.setTolerance(170).getEdgesWithDifferentHeading(8, 180));
    assertEquals(IntArrayList.from(2, 1, 0), resolver.setTolerance(130).getEdgesWithDifferentHeading(8, 180));
    assertEquals(IntArrayList.from(5, 4, 3), resolver.setTolerance(90).getEdgesWithDifferentHeading(8, 315));
    assertEquals(IntArrayList.from(6, 5, 4, 3, 2), resolver.setTolerance(50).getEdgesWithDifferentHeading(8, 315));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) NodeAccess(com.graphhopper.storage.NodeAccess) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 8 with GraphBuilder

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

the class EdgeElevationInterpolatorTest method setUp.

@SuppressWarnings("resource")
@BeforeEach
public void setUp() {
    graph = new GraphBuilder(encodingManager = new EncodingManager.Builder().add(new CarFlagEncoder()).add(new FootFlagEncoder()).build()).set3D(true).create();
    roadEnvEnc = encodingManager.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class);
    edgeElevationInterpolator = createEdgeElevationInterpolator();
    relFlags = encodingManager.createRelationFlags();
    interpolatableWay = createInterpolatableWay();
    normalWay = new ReaderWay(0);
    normalWay.setTag("highway", "primary");
}
Also used : RoadEnvironment(com.graphhopper.routing.ev.RoadEnvironment) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphBuilder(com.graphhopper.storage.GraphBuilder) ReaderWay(com.graphhopper.reader.ReaderWay) FootFlagEncoder(com.graphhopper.routing.util.FootFlagEncoder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with GraphBuilder

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

the class RoundTripRoutingTest method createSquareGraph.

private Graph createSquareGraph() {
    // simple square
    // 1 | 0 1 2
    // 0 | 7   3
    // -1 | 6 5 4
    // ---|------
    // |-1 0 1
    GraphHopperStorage graph = new GraphBuilder(em).create();
    for (int i = 0; i < 8; ++i) {
        GHUtility.setSpeed(60, true, true, carFE, graph.edge(i, (i + 1) % 8).setDistance(1));
    }
    updateDistancesFor(graph, 0, 1, -1);
    updateDistancesFor(graph, 1, 1, 0);
    updateDistancesFor(graph, 2, 1, 1);
    updateDistancesFor(graph, 3, 0, 1);
    updateDistancesFor(graph, 4, -1, 1);
    updateDistancesFor(graph, 5, -1, 0);
    updateDistancesFor(graph, 6, -1, -1);
    updateDistancesFor(graph, 7, 0, -1);
    return graph;
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) GHPoint(com.graphhopper.util.shapes.GHPoint) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage)

Example 10 with GraphBuilder

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

the class RoundTripRoutingTest method createTestGraph.

private Graph createTestGraph() {
    Graph graph = new GraphBuilder(em).withTurnCosts(true).create();
    AlternativeRouteTest.initTestGraph(graph, carFE);
    return graph;
}
Also used : QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder)

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