use of com.graphhopper.routing.util.BikeFlagEncoder in project graphhopper by graphhopper.
the class TurnCostExtensionTest method testMergeFlagsBeforeAdding.
@Test
public void testMergeFlagsBeforeAdding() {
FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3);
FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3);
EncodingManager manager = new EncodingManager(carEncoder, bikeEncoder);
GraphHopperStorage g = new GraphBuilder(manager).create();
initGraph(g);
TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
long carRestricted = carEncoder.getTurnFlags(true, 0);
long bikeRestricted = bikeEncoder.getTurnFlags(true, 0);
int edge23 = getEdge(g, 2, 3).getEdge();
int edge02 = getEdge(g, 0, 2).getEdge();
tcs.addTurnInfo(edge02, 2, edge23, carRestricted | bikeRestricted);
long flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags023), 0);
assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0);
}
use of com.graphhopper.routing.util.BikeFlagEncoder in project graphhopper by graphhopper.
the class CHProfileSelectorTest method setup.
@BeforeEach
public void setup() {
FlagEncoder carEncoder = new CarFlagEncoder();
FlagEncoder bikeEncoder = new BikeFlagEncoder();
encodingManager = EncodingManager.create(carEncoder, bikeEncoder);
fastCar = new Profile("fast_car").setWeighting("fastest").setVehicle("car").setTurnCosts(false);
fastCarEdge = new Profile("fast_car_edge").setWeighting("fastest").setVehicle("car").setTurnCosts(true);
fastCarEdge10 = new Profile("fast_car_edge10").setWeighting("fastest").setVehicle("car").setTurnCosts(true).putHint(Parameters.Routing.U_TURN_COSTS, 10);
fastCarEdge30 = new Profile("fast_car_edge30").setWeighting("fastest").setVehicle("car").setTurnCosts(true).putHint(Parameters.Routing.U_TURN_COSTS, 30);
fastCarEdge50 = new Profile("fast_car_edge50").setWeighting("fastest").setVehicle("car").setTurnCosts(true).putHint(Parameters.Routing.U_TURN_COSTS, 50);
fastBike = new Profile("fast_bike").setWeighting("fastest").setVehicle("bike").setTurnCosts(false);
fastBikeEdge40 = new Profile("fast_bike_edge40").setWeighting("fastest").setVehicle("bike").setTurnCosts(true).putHint(Parameters.Routing.U_TURN_COSTS, 40);
shortCar = new Profile("short_car").setWeighting("shortest").setVehicle("car").setTurnCosts(false);
shortBike = new Profile("short_bike").setWeighting("shortest").setVehicle("bike").setTurnCosts(false);
}
use of com.graphhopper.routing.util.BikeFlagEncoder in project graphhopper by graphhopper.
the class GraphHopperStorageTest method testLoadGraph_implicitEncodedValues_issue1862.
@Test
public void testLoadGraph_implicitEncodedValues_issue1862() {
Helper.removeDir(new File(defaultGraphLoc));
encodingManager = new EncodingManager.Builder().add(createCarFlagEncoder()).add(new BikeFlagEncoder()).build();
graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false).create(defaultSize);
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 12, 23);
na.setNode(1, 8, 13);
na.setNode(2, 2, 10);
na.setNode(3, 5, 9);
GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 2).setDistance(10));
GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 3).setDistance(10));
int nodes = graph.getNodes();
int edges = graph.getAllEdges().length();
graph.flush();
Helper.close(graph);
// load without configured FlagEncoders
GraphHopper hopper = new GraphHopper();
hopper.setProfiles(Arrays.asList(new Profile("p_car").setVehicle("car").setWeighting("fastest"), new Profile("p_bike").setVehicle("bike").setWeighting("fastest")));
hopper.setGraphHopperLocation(defaultGraphLoc);
assertTrue(hopper.load());
graph = hopper.getGraphHopperStorage();
assertEquals(nodes, graph.getNodes());
assertEquals(edges, graph.getAllEdges().length());
Helper.close(graph);
hopper = new GraphHopper();
// load via explicitly configured FlagEncoders then we can define only one profile
hopper.getEncodingManagerBuilder().add(createCarFlagEncoder()).add(new BikeFlagEncoder());
hopper.setProfiles(Collections.singletonList(new Profile("p_car").setVehicle("car").setWeighting("fastest")));
hopper.setGraphHopperLocation(defaultGraphLoc);
assertTrue(hopper.load());
graph = hopper.getGraphHopperStorage();
assertEquals(nodes, graph.getNodes());
assertEquals(edges, graph.getAllEdges().length());
Helper.close(graph);
Helper.removeDir(new File(defaultGraphLoc));
}
use of com.graphhopper.routing.util.BikeFlagEncoder in project graphhopper by graphhopper.
the class TurnCostExtensionTest method testMultipleTurnCosts.
/**
* Test if multiple turn costs can be safely written to the storage and read from it.
*/
@Test
public void testMultipleTurnCosts() {
FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3);
FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3);
EncodingManager manager = new EncodingManager(carEncoder, bikeEncoder);
GraphHopperStorage g = new GraphBuilder(manager).create();
initGraph(g);
TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
// introduce some turn costs
long carRestricted = carEncoder.getTurnFlags(true, 0);
long carCosts = carEncoder.getTurnFlags(false, 2);
long bikeRestricted = bikeEncoder.getTurnFlags(true, 0);
long bikeCosts = bikeEncoder.getTurnFlags(false, 2);
int edge42 = getEdge(g, 4, 2).getEdge();
int edge23 = getEdge(g, 2, 3).getEdge();
int edge31 = getEdge(g, 3, 1).getEdge();
int edge10 = getEdge(g, 1, 0).getEdge();
int edge02 = getEdge(g, 0, 2).getEdge();
int edge24 = getEdge(g, 2, 4).getEdge();
tcs.mergeOrOverwriteTurnInfo(edge42, 2, edge23, carRestricted, true);
tcs.mergeOrOverwriteTurnInfo(edge42, 2, edge23, bikeRestricted, true);
tcs.mergeOrOverwriteTurnInfo(edge23, 3, edge31, carRestricted, true);
tcs.mergeOrOverwriteTurnInfo(edge23, 3, edge31, bikeCosts, true);
tcs.mergeOrOverwriteTurnInfo(edge31, 1, edge10, carCosts, true);
tcs.mergeOrOverwriteTurnInfo(edge31, 1, edge10, bikeRestricted, true);
tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge24, carRestricted, false);
tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge24, bikeRestricted, false);
long flags423 = tcs.getTurnCostFlags(edge42, 2, edge23);
assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags423), 0);
assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags423), 0);
long flags231 = tcs.getTurnCostFlags(edge23, 3, edge31);
assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags231), 0);
assertEquals(2.0, bikeEncoder.getTurnCost(flags231), 0);
long flags310 = tcs.getTurnCostFlags(edge31, 1, edge10);
assertEquals(2.0, carEncoder.getTurnCost(flags310), 0);
assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags310), 0);
long flags024 = tcs.getTurnCostFlags(edge02, 2, edge24);
assertEquals(0.0, carEncoder.getTurnCost(flags024), 0);
assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags024), 0);
// merge per default
tcs.addTurnInfo(edge02, 2, edge23, carRestricted);
tcs.addTurnInfo(edge02, 2, edge23, bikeRestricted);
long flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags023), 0);
assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0);
// overwrite
tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge23, bikeRestricted, false);
flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
assertEquals(0, carEncoder.getTurnCost(flags023), 0);
assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0);
// clear
tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge23, 0, false);
flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
assertEquals(0, carEncoder.getTurnCost(flags023), 0);
assertEquals(0, bikeEncoder.getTurnCost(flags023), 0);
}
use of com.graphhopper.routing.util.BikeFlagEncoder in project graphhopper by graphhopper.
the class TurnCostStorageTest method setup.
@BeforeEach
public void setup() {
FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3);
FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3, false);
manager = EncodingManager.create(carEncoder, bikeEncoder);
}
Aggregations