Search in sources :

Example 46 with ReaderWay

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

the class CarFlagEncoderTest method testIssue_1256.

@Test
public void testIssue_1256() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("route", "ferry");
    way.setTag("estimated_distance", 257);
    CarFlagEncoder lowFactorCar = new CarFlagEncoder(10, 1, 0);
    EncodingManager.create(lowFactorCar);
    List<EncodedValue> list = new ArrayList<>();
    lowFactorCar.setEncodedValueLookup(em);
    lowFactorCar.createEncodedValues(list);
    assertEquals(2.5, encoder.ferrySpeedCalc.getSpeed(way), .1);
    assertEquals(.5, lowFactorCar.ferrySpeedCalc.getSpeed(way), .1);
}
Also used : EncodedValue(com.graphhopper.routing.ev.EncodedValue) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) ArrayList(java.util.ArrayList) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.jupiter.api.Test)

Example 47 with ReaderWay

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

the class CarFlagEncoderTest method testMilitaryAccess.

@Test
public void testMilitaryAccess() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "track");
    way.setTag("access", "military");
    assertTrue(encoder.getAccess(way).canSkip());
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.jupiter.api.Test)

Example 48 with ReaderWay

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

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

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

the class CarFlagEncoderTest method testFordAccess.

@Test
public void testFordAccess() {
    ReaderNode node = new ReaderNode(0, 0.0, 0.0);
    node.setTag("ford", "yes");
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "unclassified");
    way.setTag("ford", "yes");
    // Node and way are initially blocking
    assertTrue(encoder.isBlockFords());
    assertTrue(encoder.getAccess(way).canSkip());
    assertTrue(encoder.isBarrier(node));
    CarFlagEncoder tmpEncoder = new CarFlagEncoder(new PMap("block_fords=false"));
    EncodingManager.create(tmpEncoder);
    assertTrue(tmpEncoder.getAccess(way).isWay());
    assertFalse(tmpEncoder.isBarrier(node));
}
Also used : ReaderNode(com.graphhopper.reader.ReaderNode) PMap(com.graphhopper.util.PMap) ReaderWay(com.graphhopper.reader.ReaderWay) 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