use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class FastestWeightingTest method testMinWeightHasSameUnitAs_getWeight.
@Test
public void testMinWeightHasSameUnitAs_getWeight() {
Weighting instance = new FastestWeighting(encoder);
IntsRef flags = GHUtility.setSpeed(encoder.getMaxSpeed(), 0, encoder, encodingManager.createEdgeFlags());
assertEquals(instance.getMinWeight(10), instance.calcEdgeWeight(createMockedEdgeIteratorState(10, flags), false), 1e-8);
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class PathSimplificationTest method testScenario.
@Test
public void testScenario() {
Graph g = new GraphBuilder(carManager).create();
// 0-1-2
// | | |
// 3-4-5 9-10
// | | | |
// 6-7-8--*
NodeAccess na = g.getNodeAccess();
na.setNode(0, 1.2, 1.0);
na.setNode(1, 1.2, 1.1);
na.setNode(2, 1.2, 1.2);
na.setNode(3, 1.1, 1.0);
na.setNode(4, 1.1, 1.1);
na.setNode(5, 1.1, 1.2);
na.setNode(9, 1.1, 1.3);
na.setNode(10, 1.1, 1.4);
na.setNode(6, 1.0, 1.0);
na.setNode(7, 1.0, 1.1);
na.setNode(8, 1.0, 1.2);
ReaderWay w = new ReaderWay(1);
w.setTag("highway", "tertiary");
w.setTag("maxspeed", "10");
IntsRef relFlags = carManager.createRelationFlags();
EdgeIteratorState tmpEdge;
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 1).setDistance(10000)).setName("0-1");
assertNotEquals(EncodingManager.Access.CAN_SKIP, carEncoder.getAccess(w));
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(11000)).setName("1-2");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
w.setTag("maxspeed", "20");
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 3).setDistance(11000));
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 4).setDistance(10000)).setName("1-4");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 5).setDistance(11000)).setName("5-2");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
w.setTag("maxspeed", "30");
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 6).setDistance(11000)).setName("3-6");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 7).setDistance(10000)).setName("4-7");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(5, 8).setDistance(10000)).setName("5-8");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
w.setTag("maxspeed", "40");
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(6, 7).setDistance(11000)).setName("6-7");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 8).setDistance(10000));
PointList list = new PointList();
list.add(1.0, 1.15);
list.add(1.0, 1.16);
tmpEdge.setWayGeometry(list);
tmpEdge.setName("7-8");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
w.setTag("maxspeed", "50");
// missing edge name
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(9, 10).setDistance(10000));
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(8, 9).setDistance(20000));
list.clear();
list.add(1.0, 1.3);
list.add(1.0, 1.3001);
list.add(1.0, 1.3002);
list.add(1.0, 1.3003);
tmpEdge.setName("8-9");
tmpEdge.setWayGeometry(list);
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
// Path is: [0 0-1, 3 1-4, 6 4-7, 9 7-8, 11 8-9, 10 9-10]
ShortestWeighting weighting = new ShortestWeighting(carEncoder);
Path p = new Dijkstra(g, weighting, tMode).calcPath(0, 10);
InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
Map<String, List<PathDetail>> details = PathDetailsFromEdges.calcDetails(p, carManager, weighting, Arrays.asList(AVERAGE_SPEED), new PathDetailsBuilderFactory(), 0);
ResponsePath responsePath = new ResponsePath();
responsePath.setInstructions(wayList);
responsePath.addPathDetails(details);
responsePath.setPoints(p.calcPoints());
int numberOfPoints = p.calcPoints().size();
DouglasPeucker douglasPeucker = new DouglasPeucker();
// Do not simplify anything
douglasPeucker.setMaxDistance(0);
PathSimplification.simplify(responsePath, douglasPeucker, true);
assertEquals(numberOfPoints, responsePath.getPoints().size());
responsePath = new ResponsePath();
responsePath.setInstructions(wayList);
responsePath.addPathDetails(details);
responsePath.setPoints(p.calcPoints());
douglasPeucker.setMaxDistance(100000000);
PathSimplification.simplify(responsePath, douglasPeucker, true);
assertTrue(numberOfPoints > responsePath.getPoints().size());
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class IntEncodedValueImplTest method testNegateReverseDirection.
@Test
public void testNegateReverseDirection() {
IntEncodedValue prop = new IntEncodedValueImpl("test", 5, 0, true, false);
EncodedValue.InitializerConfig config = new EncodedValue.InitializerConfig();
prop.init(config);
IntsRef ref = new IntsRef(1);
prop.setInt(false, ref, 5);
assertEquals(5, prop.getInt(false, ref));
assertEquals(-5, prop.getInt(true, ref));
prop.setInt(true, ref, 2);
assertEquals(-2, prop.getInt(false, ref));
assertEquals(2, prop.getInt(true, ref));
prop.setInt(false, ref, -3);
assertEquals(-3, prop.getInt(false, ref));
assertEquals(3, prop.getInt(true, ref));
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class IntEncodedValueImplTest method testSignedInt.
@Test
public void testSignedInt() {
IntEncodedValue prop = new IntEncodedValueImpl("test", 31, -5, false, true);
EncodedValue.InitializerConfig config = new EncodedValue.InitializerConfig();
prop.init(config);
IntsRef ref = new IntsRef(1);
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
prop.setInt(false, ref, Integer.MAX_VALUE);
});
assertTrue(exception.getMessage().contains("test value too large for encoding"), exception.getMessage());
prop.setInt(false, ref, -5);
assertEquals(-5, prop.getInt(false, ref));
assertEquals(-5, prop.getInt(false, ref));
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class IntEncodedValueImplTest method testDirectedValue.
@Test
public void testDirectedValue() {
IntEncodedValue prop = new IntEncodedValueImpl("test", 10, true);
prop.init(new EncodedValue.InitializerConfig());
IntsRef ref = new IntsRef(1);
prop.setInt(false, ref, 10);
prop.setInt(true, ref, 20);
assertEquals(10, prop.getInt(false, ref));
assertEquals(20, prop.getInt(true, ref));
}
Aggregations