Search in sources :

Example 46 with GraphBuilder

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

the class ExpressionVisitorTest method before.

@BeforeEach
public void before() {
    StringEncodedValue sev = new StringEncodedValue("country", 10);
    lookup = new GraphBuilder(new EncodingManager.Builder().add(sev).build()).create().getEncodingManager();
    sev.setString(false, new IntsRef(1), "DEU");
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) StringEncodedValue(com.graphhopper.routing.ev.StringEncodedValue) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 47 with GraphBuilder

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

the class DataFlagEncoderTest method reverseEdge.

@Test
public void reverseEdge() {
    Graph graph = new GraphBuilder(encodingManager).create();
    EdgeIteratorState edge = graph.edge(0, 1);
    ReaderWay osmWay = new ReaderWay(0);
    osmWay.setTag("highway", "primary");
    osmWay.setTag("maxspeed:forward", "10");
    long flags = encoder.handleWayTags(osmWay, 1, 0);
    edge.setFlags(flags);
    assertEquals(10, encoder.getMaxspeed(edge, motorVehicleInt, false), .1);
    assertEquals(-1, encoder.getMaxspeed(edge, motorVehicleInt, true), .1);
    edge = edge.detach(true);
    assertEquals(-1, encoder.getMaxspeed(edge, motorVehicleInt, false), .1);
    assertEquals(10, encoder.getMaxspeed(edge, motorVehicleInt, true), .1);
}
Also used : Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.Test)

Example 48 with GraphBuilder

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

the class DataFlagEncoderTest method setAccess.

@Test
public void setAccess() {
    Graph graph = new GraphBuilder(encodingManager).create();
    EdgeIteratorState edge = graph.edge(0, 1);
    edge.setFlags(encoder.setAccess(edge.getFlags(), true, true));
    assertTrue(encoder.isForward(edge, motorVehicleInt));
    assertTrue(encoder.isBackward(edge, motorVehicleInt));
    edge.setFlags(encoder.setAccess(edge.getFlags(), true, false));
    assertTrue(encoder.isForward(edge, motorVehicleInt));
    assertFalse(encoder.isBackward(edge, motorVehicleInt));
    edge = edge.detach(true);
    assertFalse(encoder.isForward(edge, motorVehicleInt));
    assertTrue(encoder.isBackward(edge, motorVehicleInt));
    edge = edge.detach(true);
    assertTrue(encoder.isForward(edge, motorVehicleInt));
    assertFalse(encoder.isBackward(edge, motorVehicleInt));
    edge.setFlags(encoder.setAccess(edge.getFlags(), false, false));
    assertFalse(encoder.isForward(edge, motorVehicleInt));
    assertFalse(encoder.isBackward(edge, motorVehicleInt));
}
Also used : Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 49 with GraphBuilder

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

the class CHEdgeIteratorTest method testUpdateFlags.

@Test
public void testUpdateFlags() {
    CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager(carFlagEncoder);
    FastestWeighting weighting = new FastestWeighting(carFlagEncoder);
    EdgeFilter carOutFilter = new DefaultEdgeFilter(carFlagEncoder, false, true);
    GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).setCHGraph(weighting).create();
    CHGraph g = ghStorage.getGraph(CHGraph.class, weighting);
    g.edge(0, 1).setDistance(12).setFlags(carFlagEncoder.setProperties(10, true, true));
    g.edge(0, 2).setDistance(13).setFlags(carFlagEncoder.setProperties(20, true, true));
    ghStorage.freeze();
    assertEquals(2, GHUtility.count(g.getAllEdges()));
    assertEquals(1, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    EdgeIteratorState iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(1, iter.getAdjNode());
    assertEquals(carFlagEncoder.setProperties(10, true, true), iter.getFlags());
    // update setProperties
    iter.setFlags(carFlagEncoder.setProperties(20, true, false));
    assertEquals(12, iter.getDistance(), 1e-4);
    // update distance
    iter.setDistance(10);
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(0, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(carFlagEncoder.setProperties(20, true, false), iter.getFlags());
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(1, GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(1)).size());
    assertEquals(0, GHUtility.getNeighbors(g.createEdgeExplorer(carOutFilter).setBaseNode(1)).size());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CHGraph(com.graphhopper.storage.CHGraph) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 50 with GraphBuilder

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

the class PrinctonReaderTest method testMediumRead.

@Test
public void testMediumRead() throws IOException {
    Graph graph = new GraphBuilder(encodingManager).create();
    new PrinctonReader(graph).setStream(new GZIPInputStream(PrinctonReader.class.getResourceAsStream("mediumEWD.txt.gz"))).read();
    assertEquals(250, graph.getNodes());
    EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
    assertEquals(13, count(explorer.setBaseNode(244)));
    assertEquals(11, count(explorer.setBaseNode(16)));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.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