Search in sources :

Example 61 with GraphBuilder

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

the class PrepareRoutingSubnetworksTest method testNodeOrderingRegression.

// Previous two-pass implementation failed on 1 -> 2 -> 0
@Test
public void testNodeOrderingRegression() {
    // 1 -> 2 -> 0 - 3 - 4 - 5
    GraphHopperStorage g = new GraphBuilder(createEncodingManager("car")).create();
    FlagEncoder encoder = g.getEncodingManager().fetchEdgeEncoders().iterator().next();
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 0).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 3).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(3, 4).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(4, 5).setDistance(1));
    PrepareRoutingSubnetworks.PrepareJob job = createJob(g.getEncodingManager(), encoder, NO_TURN_COST_PROVIDER);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(job)).setMinNetworkSize(2);
    int subnetworkEdges = instance.doWork();
    assertEquals(2, subnetworkEdges);
    assertEquals(IntArrayList.from(0, 1), getSubnetworkEdges(g, encoder));
}
Also used : FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 62 with GraphBuilder

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

the class TarjanSCCTest method test481.

@Test
public void test481() {
    // 0->1->3->4->5->6->7
    // \ |      \<-----/
    // 2
    GraphHopperStorage graph = new GraphBuilder(em).create();
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 0).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 3).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 5).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 6).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 7).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(7, 4).setDistance(1));
    TarjanSCC.ConnectedComponents scc = TarjanSCC.findComponentsRecursive(graph, edgeFilter, false);
    List<IntArrayList> components = scc.getComponents();
    assertEquals(3, scc.getTotalComponents());
    assertEquals(2, components.size());
    assertEquals(IntArrayList.from(2, 1, 0), components.get(1));
    assertEquals(IntArrayList.from(7, 6, 5, 4), components.get(0));
    assertEquals(1, scc.getSingleNodeComponents().cardinality());
    assertTrue(scc.getSingleNodeComponents().get(3));
    assertEquals(8, scc.getNodes());
    assertEquals(components.get(0), scc.getBiggestComponent());
    // exclude single
    scc = TarjanSCC.findComponentsRecursive(graph, edgeFilter, true);
    assertTrue(scc.getSingleNodeComponents().isEmpty());
    assertEquals(3, scc.getTotalComponents());
    assertEquals(2, scc.getComponents().size());
    assertEquals(8, scc.getNodes());
}
Also used : GraphBuilder(com.graphhopper.storage.GraphBuilder) IntArrayList(com.carrotsearch.hppc.IntArrayList) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 63 with GraphBuilder

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

the class CustomWeightingTest method testBoolean.

@Test
public void testBoolean() {
    carFE = new CarFlagEncoder();
    BooleanEncodedValue specialEnc = new SimpleBooleanEncodedValue("special", true);
    encodingManager = new EncodingManager.Builder().add(carFE).add(specialEnc).build();
    avSpeedEnc = carFE.getAverageSpeedEnc();
    graph = new GraphBuilder(encodingManager).create();
    BooleanEncodedValue accessEnc = carFE.getAccessEnc();
    EdgeIteratorState edge = graph.edge(0, 1).set(accessEnc, true).setReverse(accessEnc, true).set(avSpeedEnc, 15).set(specialEnc, false).setReverse(specialEnc, true).setDistance(10);
    CustomModel vehicleModel = new CustomModel();
    assertEquals(3.1, createWeighting(vehicleModel).calcEdgeWeight(edge, false), 0.01);
    vehicleModel.addToPriority(If("special == true", MULTIPLY, 0.8));
    vehicleModel.addToPriority(If("special == false", MULTIPLY, 0.4));
    Weighting weighting = createWeighting(vehicleModel);
    assertEquals(6.7, weighting.calcEdgeWeight(edge, false), 0.01);
    assertEquals(3.7, weighting.calcEdgeWeight(edge, true), 0.01);
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.jupiter.api.Test)

Example 64 with GraphBuilder

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

the class CustomWeightingTest method setup.

@BeforeEach
public void setup() {
    carFE = new CarFlagEncoder(new PMap().putObject("speed_two_directions", true));
    encodingManager = new EncodingManager.Builder().add(carFE).add(new OSMTollParser()).add(new OSMHazmatParser()).add(new OSMBikeNetworkTagParser()).build();
    avSpeedEnc = carFE.getAverageSpeedEnc();
    accessEnc = carFE.getAccessEnc();
    maxSpeedEnc = encodingManager.getDecimalEncodedValue(MaxSpeed.KEY);
    roadClassEnc = encodingManager.getEnumEncodedValue(KEY, RoadClass.class);
    graph = new GraphBuilder(encodingManager).create();
}
Also used : OSMTollParser(com.graphhopper.routing.util.parsers.OSMTollParser) GraphBuilder(com.graphhopper.storage.GraphBuilder) RoadClass(com.graphhopper.routing.ev.RoadClass) OSMHazmatParser(com.graphhopper.routing.util.parsers.OSMHazmatParser) GraphBuilder(com.graphhopper.storage.GraphBuilder) OSMBikeNetworkTagParser(com.graphhopper.routing.util.parsers.OSMBikeNetworkTagParser) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 65 with GraphBuilder

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

the class HeadingEdgeFilterTest method getHeading.

@Test
public void getHeading() {
    GHPoint point = new GHPoint(55.67093, 12.577294);
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager.Builder().add(carEncoder).build();
    GraphHopperStorage g = new GraphBuilder(encodingManager).create();
    EdgeIteratorState edge = g.edge(0, 1);
    g.getNodeAccess().setNode(0, 55.671044, 12.5771583);
    g.getNodeAccess().setNode(1, 55.6704136, 12.5784324);
    // GHUtility.setSpeed(50, 0, carEncoder, edge.getFlags());
    assertEquals(131.2, HeadingEdgeFilter.getHeadingOfGeometryNearPoint(edge, point, 20), .1);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphBuilder(com.graphhopper.storage.GraphBuilder) GHPoint(com.graphhopper.util.shapes.GHPoint) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) 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