Search in sources :

Example 21 with IntsRef

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));
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 22 with IntsRef

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) {
    }
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 23 with IntsRef

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);
}
Also used : DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 24 with IntsRef

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));
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 25 with IntsRef

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);
}
Also used : PMap(com.graphhopper.util.PMap) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Aggregations

IntsRef (com.graphhopper.storage.IntsRef)108 Test (org.junit.jupiter.api.Test)96 ReaderWay (com.graphhopper.reader.ReaderWay)67 ReaderRelation (com.graphhopper.reader.ReaderRelation)7 GraphBuilder (com.graphhopper.storage.GraphBuilder)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)5 Graph (com.graphhopper.storage.Graph)5 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)4 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 NodeAccess (com.graphhopper.storage.NodeAccess)3 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)2 RoadEnvironment (com.graphhopper.routing.ev.RoadEnvironment)2 VirtualEdgeIteratorState (com.graphhopper.routing.querygraph.VirtualEdgeIteratorState)2 TransportationMode (com.graphhopper.routing.util.TransportationMode)2 CountryRule (com.graphhopper.routing.util.countryrules.CountryRule)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 PMap (com.graphhopper.util.PMap)2 PointList (com.graphhopper.util.PointList)2