use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class BlockAreaWeightingTest method setUp.
@BeforeEach
public void setUp() {
encoder = new CarFlagEncoder();
em = EncodingManager.create(Arrays.asList(encoder));
graph = new GraphBuilder(em).create();
// 0-1
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
updateDistancesFor(graph, 0, 0.00, 0.00);
updateDistancesFor(graph, 1, 0.01, 0.01);
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class FootFlagEncoderTest method testGraph.
@Test
public void testGraph() {
Graph g = new GraphBuilder(encodingManager).create();
g.edge(0, 1).setDistance(10).set(footAvgSpeedEnc, 10.0).set(footAccessEnc, true, true);
g.edge(0, 2).setDistance(10).set(footAvgSpeedEnc, 5.0).set(footAccessEnc, true, true);
g.edge(1, 3).setDistance(10).set(footAvgSpeedEnc, 10.0).set(footAccessEnc, true, true);
EdgeExplorer out = g.createEdgeExplorer(AccessFilter.outEdges(footEncoder.getAccessEnc()));
assertEquals(GHUtility.asSet(1, 2), GHUtility.getNeighbors(out.setBaseNode(0)));
assertEquals(GHUtility.asSet(0, 3), GHUtility.getNeighbors(out.setBaseNode(1)));
assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(out.setBaseNode(2)));
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class OSMTurnRelationParserTest method testGetRestrictionAsEntries.
@Test
public void testGetRestrictionAsEntries() {
CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
final Map<Long, Integer> osmNodeToInternal = new HashMap<>();
final Map<Integer, Long> internalToOSMEdge = new HashMap<>();
osmNodeToInternal.put(3L, 3);
// edge ids are only stored if they occurred before in an OSMRelation
internalToOSMEdge.put(3, 3L);
internalToOSMEdge.put(4, 4L);
OSMTurnRelationParser parser = new OSMTurnRelationParser(encoder.toString(), 1, OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR));
GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager.Builder().add(encoder).addTurnCostParser(parser).build()).create();
EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage, encoder);
TurnCostParser.ExternalInternalMap map = new TurnCostParser.ExternalInternalMap() {
@Override
public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
return osmNodeToInternal.getOrDefault(nodeOsmId, -1);
}
@Override
public long getOsmIdOfInternalEdge(int edgeId) {
Long l = internalToOSMEdge.get(edgeId);
if (l == null)
return -1;
return l;
}
};
// TYPE == ONLY
OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, OSMTurnRelation.Type.ONLY);
parser.addRelationToTCStorage(instance, map, ghStorage);
TurnCostStorage tcs = ghStorage.getTurnCostStorage();
DecimalEncodedValue tce = parser.getTurnCostEnc();
assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 6)));
assertEquals(0, tcs.get(tce, 4, 3, 3), .1);
assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 2)));
// TYPE == NOT
instance = new OSMTurnRelation(4, 3, 3, OSMTurnRelation.Type.NOT);
parser.addRelationToTCStorage(instance, map, ghStorage);
assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 3)));
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class FastestWeightingTest method calcWeightAndTime_withTurnCosts_shortest.
@Test
public void calcWeightAndTime_withTurnCosts_shortest() {
Graph graph = new GraphBuilder(encodingManager).create();
Weighting weighting = new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
// turn costs are given in seconds
setTurnCost(graph, 0, 1, 2, 5);
// todo: for the shortest weighting turn costs cannot be interpreted as seconds? at least when they are added
// to the weight? how much should they contribute ?
// assertEquals(105, AbstractWeighting.calcWeightWithTurnWeight(weighting, edge, false, 0), 1.e-6);
assertEquals(6000 + 5000, GHUtility.calcMillisWithTurnMillis(weighting, edge, false, 0), 1.e-6);
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class FastestWeightingTest method calcWeightAndTime_withTurnCosts.
@Test
public void calcWeightAndTime_withTurnCosts() {
Graph graph = new GraphBuilder(encodingManager).create();
Weighting weighting = new FastestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
// turn costs are given in seconds
setTurnCost(graph, 0, 1, 2, 5);
assertEquals(6 + 5, GHUtility.calcWeightWithTurnWeight(weighting, edge, false, 0), 1.e-6);
assertEquals(6000 + 5000, GHUtility.calcMillisWithTurnMillis(weighting, edge, false, 0), 1.e-6);
}
Aggregations