Search in sources :

Example 1 with GraphBuilder

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

the class PrinctonReaderTest method testRead.

@Test
public void testRead() {
    Graph graph = new GraphBuilder(encodingManager).create();
    new PrinctonReader(graph).setStream(PrinctonReader.class.getResourceAsStream("tinyEWD.txt")).read();
    assertEquals(8, graph.getNodes());
    EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
    assertEquals(2, count(explorer.setBaseNode(0)));
    assertEquals(3, count(explorer.setBaseNode(6)));
}
Also used : Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 2 with GraphBuilder

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

the class OSMTurnRelationTest method testGetRestrictionAsEntries.

@Test
public void testGetRestrictionAsEntries() {
    CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
    final Map<Long, Integer> osmNodeToInternal = new HashMap<Long, Integer>();
    final Map<Integer, Long> internalToOSMEdge = new HashMap<Integer, Long>();
    osmNodeToInternal.put(3L, 3);
    // edge ids are only stored if they occured before in an OSMRelation
    internalToOSMEdge.put(3, 3L);
    internalToOSMEdge.put(4, 4L);
    GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager(encoder)).create();
    EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage);
    OSMReader osmReader = new OSMReader(ghStorage) {

        @Override
        public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
            return osmNodeToInternal.get(nodeOsmId);
        }

        @Override
        public long getOsmIdOfInternalEdge(int edgeId) {
            Long l = internalToOSMEdge.get(edgeId);
            if (l == null)
                return -1;
            return l;
        }
    };
    EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer();
    // TYPE == ONLY
    OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, Type.ONLY);
    Collection<OSMTurnRelation.TurnCostTableEntry> result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(2, result.size());
    Iterator<OSMTurnRelation.TurnCostTableEntry> iter = result.iterator();
    OSMTurnRelation.TurnCostTableEntry entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(6, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(2, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    // TYPE == NOT
    instance = new OSMTurnRelation(4, 3, 3, Type.NOT);
    result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(1, result.size());
    iter = result.iterator();
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(3, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HashMap(java.util.HashMap) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test) EdgeBasedRoutingAlgorithmTest(com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)

Example 3 with GraphBuilder

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

the class GenericWeightingTest method setUp.

@Before
public void setUp() {
    ReaderWay way = new ReaderWay(27l);
    way.setTag("highway", "primary");
    way.setTag("maxspeed", "10");
    way.setTag("maxheight", "4.4");
    graph = new GraphBuilder(em).create();
    // 0-1
    graph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    graph.getEdgeIteratorState(0, 1).setFlags(encoder.handleWayTags(way, 1, 0));
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) ReaderWay(com.graphhopper.reader.ReaderWay) Before(org.junit.Before)

Example 4 with GraphBuilder

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

the class PrincetonReaderTest method testRead.

@Test
public void testRead() {
    Graph graph = new GraphBuilder(encodingManager).create();
    new PrincetonReader(graph).setStream(PrincetonReader.class.getResourceAsStream("tinyEWD.txt")).read();
    assertEquals(8, graph.getNodes());
    EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
    assertEquals(2, count(explorer.setBaseNode(0)));
    assertEquals(3, count(explorer.setBaseNode(6)));
}
Also used : Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 5 with GraphBuilder

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

the class EdgeBasedRoutingAlgorithmTest method createStorage.

private GraphHopperStorage createStorage(EncodingManager em) {
    GraphHopperStorage ghStorage = new GraphBuilder(em).create();
    tcs = ghStorage.getTurnCostStorage();
    return ghStorage;
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage)

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