use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class GraphHopperIT method testRoundaboutInstructionsWithCH.
@Test
public void testRoundaboutInstructionsWithCH() {
String tmpOsmFile = DIR + "/monaco.osm.gz";
String tmpVehicle = "car";
String tmpImportVehicles = "car,bike";
String tmpWeightCalcStr = "fastest";
GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(tmpImportVehicles)).importOrLoad();
assertEquals(tmpVehicle, tmpHopper.getDefaultVehicle().toString());
assertEquals(2, tmpHopper.getCHFactoryDecorator().getPreparations().size());
GHResponse rsp = tmpHopper.route(new GHRequest(43.745084, 7.430513, 43.745247, 7.430347).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
PathWrapper arsp = rsp.getBest();
assertEquals(2, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
rsp = tmpHopper.route(new GHRequest(43.745968, 7.42907, 43.745832, 7.428614).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
arsp = rsp.getBest();
assertEquals(2, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
rsp = tmpHopper.route(new GHRequest(43.745948, 7.42914, 43.746173, 7.428834).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
arsp = rsp.getBest();
assertEquals(1, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
rsp = tmpHopper.route(new GHRequest(43.735817, 7.417096, 43.735666, 7.416587).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
arsp = rsp.getBest();
assertEquals(2, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class GraphHopperIT method testPointHint.
@Test
public void testPointHint() {
GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/Laufamholzstrasse.osm.xml").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car"));
tmpHopper.importOrLoad();
GHRequest req = new GHRequest(49.46553, 11.154669, 49.465244, 11.152577).setVehicle("car").setWeighting("fastest");
req.setPointHints(new ArrayList<>(Arrays.asList("Laufamholzstraße, 90482, Nürnberg, Deutschland", "")));
GHResponse rsp = tmpHopper.route(req);
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
GHPoint snappedPoint = rsp.getBest().getWaypoints().toGHPoint(0);
assertEquals(49.465686, snappedPoint.getLat(), .000001);
assertEquals(11.154605, snappedPoint.getLon(), .000001);
req.setPointHints(new ArrayList<>(Arrays.asList("", "")));
rsp = tmpHopper.route(req);
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
snappedPoint = rsp.getBest().getWaypoints().toGHPoint(0);
assertEquals(49.465502, snappedPoint.getLat(), .000001);
assertEquals(11.154498, snappedPoint.getLon(), .000001);
// Match to closest edge, since hint was not found
req.setPointHints(new ArrayList<>(Arrays.asList("xy", "")));
rsp = tmpHopper.route(req);
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
snappedPoint = rsp.getBest().getWaypoints().toGHPoint(0);
assertEquals(49.465502, snappedPoint.getLat(), .000001);
assertEquals(11.154498, snappedPoint.getLon(), .000001);
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class GraphHopperIT method testNorthBayreuthDestination.
@Test
public void testNorthBayreuthDestination() {
GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/north-bayreuth.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car,generic", 8));
tmpHopper.importOrLoad();
GHRequest req = new GHRequest(49.985307, 11.50628, 49.985731, 11.507465).setVehicle("car").setWeighting("fastest");
GHResponse rsp = tmpHopper.route(req);
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
assertEquals(550, rsp.getBest().getDistance(), 1);
req = new GHRequest(49.985307, 11.50628, 49.985731, 11.507465).setVehicle("generic").setWeighting("generic");
rsp = tmpHopper.route(req);
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
assertEquals(550, rsp.getBest().getDistance(), 1);
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class GraphHopperIT method testTurnCostsOnOff.
@Test
public void testTurnCostsOnOff() {
GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/moscow.osm.gz").setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car|turn_costs=true"));
tmpHopper.importOrLoad();
// with turn costs (default if none-CH and turn cost enabled)
GHRequest req = new GHRequest(55.813357, 37.5958585, 55.811042, 37.594689);
GHResponse rsp = tmpHopper.route(req);
assertEquals(1044, rsp.getBest().getDistance(), 1);
// without turn costs
req.getHints().put(Routing.EDGE_BASED, "false");
rsp = tmpHopper.route(req);
assertEquals(400, rsp.getBest().getDistance(), 1);
// with turn costs
req.getHints().put(Routing.EDGE_BASED, "true");
rsp = tmpHopper.route(req);
assertEquals(1044, rsp.getBest().getDistance(), 1);
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class OSMTurnRelationTest method testGetRestrictionAsEntries.
@Test
public void testGetRestrictionAsEntries() {
CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
final Map<Long, Integer> osmNodeToInternal = new HashMap<Long, Integer>();
final Map<Integer, Long> internalToOSMEdge = new HashMap<Integer, Long>();
osmNodeToInternal.put(3L, 3);
// edge ids are only stored if they occured before in an OSMRelation
internalToOSMEdge.put(3, 3L);
internalToOSMEdge.put(4, 4L);
GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager(encoder)).create();
EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage);
OSMReader osmReader = new OSMReader(ghStorage) {
@Override
public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
return osmNodeToInternal.get(nodeOsmId);
}
@Override
public long getOsmIdOfInternalEdge(int edgeId) {
Long l = internalToOSMEdge.get(edgeId);
if (l == null)
return -1;
return l;
}
};
EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer();
// TYPE == ONLY
OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, Type.ONLY);
Collection<OSMTurnRelation.TurnCostTableEntry> result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
assertEquals(2, result.size());
Iterator<OSMTurnRelation.TurnCostTableEntry> iter = result.iterator();
OSMTurnRelation.TurnCostTableEntry entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(6, entry.edgeTo);
assertEquals(3, entry.nodeVia);
entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(2, entry.edgeTo);
assertEquals(3, entry.nodeVia);
// TYPE == NOT
instance = new OSMTurnRelation(4, 3, 3, Type.NOT);
result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
assertEquals(1, result.size());
iter = result.iterator();
entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(3, entry.edgeTo);
assertEquals(3, entry.nodeVia);
}
Aggregations