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));
}
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());
}
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);
}
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();
}
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);
}
Aggregations