use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class CarFlagEncoderTest method testSetSpeed0_issue367.
@Test
public void testSetSpeed0_issue367() {
IntsRef edgeFlags = em.createEdgeFlags();
accessEnc.setBool(false, edgeFlags, true);
accessEnc.setBool(true, edgeFlags, true);
encoder.setSpeed(false, edgeFlags, encoder.speedFactor * 0.49);
// one direction effects the other direction as one encoder for speed but this is not true for access
assertEquals(0, avSpeedEnc.getDecimal(false, edgeFlags), .1);
assertEquals(0, avSpeedEnc.getDecimal(true, edgeFlags), .1);
assertFalse(accessEnc.getBool(false, edgeFlags));
assertTrue(accessEnc.getBool(true, edgeFlags));
// so always call this method with reverse=true too
encoder.setSpeed(true, edgeFlags, encoder.speedFactor * 0.49);
assertFalse(accessEnc.getBool(true, edgeFlags));
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class CarFlagEncoderTest method testSpeed.
@Test
public void testSpeed() {
// limit bigger than default road speed
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "trunk");
way.setTag("maxspeed", "110");
IntsRef edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(100, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
way.clearTags();
way.setTag("highway", "residential");
way.setTag("surface", "cobblestone");
edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(30, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
way.clearTags();
way.setTag("highway", "track");
edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(15, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
way.clearTags();
way.setTag("highway", "track");
way.setTag("tracktype", "grade1");
edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(20, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
way.clearTags();
way.setTag("highway", "secondary");
way.setTag("surface", "compacted");
edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(30, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
way.clearTags();
way.setTag("highway", "secondary");
way.setTag("motorroad", "yes");
edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(90, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
way.clearTags();
way.setTag("highway", "motorway");
// this tag should be ignored
way.setTag("motorroad", "yes");
edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(100, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
way.clearTags();
way.setTag("highway", "motorway_link");
// this tag should be ignored
way.setTag("motorroad", "yes");
edgeFlags = encoder.handleWayTags(em.createEdgeFlags(), way);
assertEquals(70, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
try {
avSpeedEnc.setDecimal(false, em.createEdgeFlags(), -1);
assertTrue(false);
} catch (IllegalArgumentException ex) {
}
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class CarFlagEncoderTest method testMaxValue.
@Test
public void testMaxValue() {
CarFlagEncoder instance = new CarFlagEncoder(10, 0.5, 0);
EncodingManager em = EncodingManager.create(instance);
DecimalEncodedValue avSpeedEnc = em.getDecimalEncodedValue(EncodingManager.getKey(instance, "average_speed"));
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "motorway_link");
way.setTag("maxspeed", "60 mph");
IntsRef edgeFlags = instance.handleWayTags(em.createEdgeFlags(), way);
// double speed = AbstractFlagEncoder.parseSpeed("60 mph");
// => 96.56 * 0.9 => 86.9
assertEquals(86.9, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
assertEquals(86.9, avSpeedEnc.getDecimal(true, edgeFlags), 1e-1);
// test that maxPossibleValue is not exceeded
way = new ReaderWay(2);
way.setTag("highway", "motorway_link");
way.setTag("maxspeed", "70 mph");
edgeFlags = instance.handleWayTags(em.createEdgeFlags(), way);
assertEquals(101.5, avSpeedEnc.getDecimal(false, edgeFlags), .1);
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class CarFlagEncoderTest method testSetAccess.
@Test
public void testSetAccess() {
IntsRef edgeFlags = em.createEdgeFlags();
accessEnc.setBool(false, edgeFlags, true);
accessEnc.setBool(true, edgeFlags, true);
assertTrue(accessEnc.getBool(false, edgeFlags));
assertTrue(accessEnc.getBool(true, edgeFlags));
accessEnc.setBool(false, edgeFlags, true);
accessEnc.setBool(true, edgeFlags, false);
assertTrue(accessEnc.getBool(false, edgeFlags));
assertFalse(accessEnc.getBool(true, edgeFlags));
accessEnc.setBool(false, edgeFlags, false);
accessEnc.setBool(true, edgeFlags, true);
assertFalse(accessEnc.getBool(false, edgeFlags));
assertTrue(accessEnc.getBool(true, edgeFlags));
accessEnc.setBool(false, edgeFlags, false);
accessEnc.setBool(true, edgeFlags, false);
assertFalse(accessEnc.getBool(true, edgeFlags));
}
use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.
the class CarFlagEncoderTest method testPrivateTag.
@Test
public void testPrivateTag() {
// allow private access
CarFlagEncoder carEncoder = new CarFlagEncoder(new PMap("block_private=false"));
FlagEncoder bikeEncoder = new BikeFlagEncoder(new PMap("block_private=false"));
EncodingManager em = new EncodingManager.Builder().add(carEncoder).add(bikeEncoder).build();
FastestWeighting weighting = new FastestWeighting(carEncoder);
FastestWeighting bikeWeighting = new FastestWeighting(bikeEncoder);
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "secondary");
assertNotEquals(EncodingManager.Access.CAN_SKIP, carEncoder.getAccess(way));
IntsRef edgeFlags = em.handleWayTags(way, em.createRelationFlags());
assertEquals(60, weighting.calcEdgeWeight(GHUtility.createMockedEdgeIteratorState(1000, edgeFlags), false), 0.1);
assertEquals(200, bikeWeighting.calcEdgeWeight(GHUtility.createMockedEdgeIteratorState(1000, edgeFlags), false), 0.1);
way.setTag("highway", "secondary");
way.setTag("access", "private");
assertNotEquals(EncodingManager.Access.CAN_SKIP, carEncoder.getAccess(way));
edgeFlags = em.handleWayTags(way, em.createRelationFlags());
assertEquals(600, weighting.calcEdgeWeight(GHUtility.createMockedEdgeIteratorState(1000, edgeFlags), false), 0.1);
// private should influence bike only slightly
assertEquals(240, bikeWeighting.calcEdgeWeight(GHUtility.createMockedEdgeIteratorState(1000, edgeFlags), false), 0.1);
}
Aggregations