Search in sources :

Example 51 with ReaderWay

use of com.graphhopper.reader.ReaderWay 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)

Example 52 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class CarFlagEncoderTest method testOneway.

@Test
public void testOneway() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "primary");
    IntsRef flags = encoder.handleWayTags(em.createEdgeFlags(), way);
    assertTrue(accessEnc.getBool(false, flags));
    assertTrue(accessEnc.getBool(true, flags));
    way.setTag("oneway", "yes");
    flags = encoder.handleWayTags(em.createEdgeFlags(), way);
    assertTrue(accessEnc.getBool(false, flags));
    assertFalse(accessEnc.getBool(true, flags));
    way.clearTags();
    way.setTag("highway", "tertiary");
    flags = encoder.handleWayTags(em.createEdgeFlags(), way);
    assertTrue(accessEnc.getBool(false, flags));
    assertTrue(accessEnc.getBool(true, flags));
    way.clearTags();
    way.setTag("highway", "tertiary");
    way.setTag("vehicle:forward", "no");
    flags = encoder.handleWayTags(em.createEdgeFlags(), way);
    assertFalse(accessEnc.getBool(false, flags));
    assertTrue(accessEnc.getBool(true, flags));
    way.clearTags();
    way.setTag("highway", "tertiary");
    way.setTag("vehicle:backward", "no");
    flags = encoder.handleWayTags(em.createEdgeFlags(), way);
    assertTrue(accessEnc.getBool(false, flags));
    assertFalse(accessEnc.getBool(true, flags));
    way.clearTags();
    // This is no one way
    way.setTag("highway", "tertiary");
    way.setTag("vehicle:backward", "designated");
    flags = encoder.handleWayTags(em.createEdgeFlags(), way);
    assertTrue(accessEnc.getBool(false, flags));
    assertTrue(accessEnc.getBool(true, flags));
    way.clearTags();
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 53 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class CarFlagEncoderTest method testMaxSpeed.

@Test
public void testMaxSpeed() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "trunk");
    way.setTag("maxspeed", "500");
    IntsRef relFlags = em.createRelationFlags();
    IntsRef edgeFlags = em.handleWayTags(way, relFlags);
    assertEquals(140, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
    way = new ReaderWay(1);
    way.setTag("highway", "primary");
    way.setTag("maxspeed:backward", "10");
    way.setTag("maxspeed:forward", "20");
    edgeFlags = em.handleWayTags(way, relFlags);
    assertEquals(10, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
    way = new ReaderWay(1);
    way.setTag("highway", "primary");
    way.setTag("maxspeed:forward", "20");
    edgeFlags = em.handleWayTags(way, relFlags);
    assertEquals(20, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
    way = new ReaderWay(1);
    way.setTag("highway", "primary");
    way.setTag("maxspeed:backward", "20");
    edgeFlags = em.handleWayTags(way, relFlags);
    assertEquals(20, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
    way = new ReaderWay(1);
    way.setTag("highway", "motorway");
    way.setTag("maxspeed", "none");
    edgeFlags = em.handleWayTags(way, relFlags);
    assertEquals(135, avSpeedEnc.getDecimal(false, edgeFlags), .1);
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 54 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class FootFlagEncoderTest method testMixSpeedAndSafe.

@Test
public void testMixSpeedAndSafe() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "motorway");
    IntsRef flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertEquals(0, flags.ints[0]);
    way.setTag("sidewalk", "yes");
    flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertEquals(5, footAvgSpeedEnc.getDecimal(false, flags), 1e-1);
    way.clearTags();
    way.setTag("highway", "track");
    flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertEquals(5, footAvgSpeedEnc.getDecimal(false, flags), 1e-1);
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 55 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class FootFlagEncoderTest method testFerrySpeed.

@Test
public void testFerrySpeed() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("route", "ferry");
    // a bit longer than an hour
    way.setTag("duration:seconds", "4000");
    assertEquals(30, footEncoder.ferrySpeedCalc.getSpeed(way), .1);
    IntsRef flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertEquals(15, footAvgSpeedEnc.getDecimal(false, flags), .1);
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Aggregations

ReaderWay (com.graphhopper.reader.ReaderWay)157 Test (org.junit.jupiter.api.Test)119 IntsRef (com.graphhopper.storage.IntsRef)67 Test (org.junit.Test)24 EncodingManager (com.graphhopper.routing.util.EncodingManager)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)9 ReaderRelation (com.graphhopper.reader.ReaderRelation)8 ConditionalTagInspector (com.graphhopper.reader.ConditionalTagInspector)7 Graph (com.graphhopper.storage.Graph)7 DateFormat (java.text.DateFormat)6 Date (java.util.Date)6 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)5 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)5 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)4 PMap (com.graphhopper.util.PMap)4 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)3 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 LongIndexedContainer (com.carrotsearch.hppc.LongIndexedContainer)2