Search in sources :

Example 41 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class EncodingManagerTest method testSharedEncodedValues.

@Test
public void testSharedEncodedValues() {
    EncodingManager manager = EncodingManager.create("car,foot,bike,motorcycle,mtb");
    for (FlagEncoder tmp : manager.fetchEdgeEncoders()) {
        AbstractFlagEncoder encoder = (AbstractFlagEncoder) tmp;
        BooleanEncodedValue accessEnc = encoder.getAccessEnc();
        BooleanEncodedValue roundaboutEnc = manager.getBooleanEncodedValue(Roundabout.KEY);
        ReaderWay way = new ReaderWay(1);
        way.setTag("highway", "primary");
        way.setTag("junction", "roundabout");
        IntsRef edgeFlags = manager.handleWayTags(way, manager.createRelationFlags());
        assertTrue(accessEnc.getBool(false, edgeFlags));
        if (!encoder.getName().equals("foot"))
            assertFalse(accessEnc.getBool(true, edgeFlags), encoder.getName());
        assertTrue(roundaboutEnc.getBool(false, edgeFlags), encoder.getName());
        way.clearTags();
        way.setTag("highway", "tertiary");
        way.setTag("junction", "circular");
        edgeFlags = manager.handleWayTags(way, manager.createRelationFlags());
        assertTrue(accessEnc.getBool(false, edgeFlags));
        if (!encoder.getName().equals("foot"))
            assertFalse(accessEnc.getBool(true, edgeFlags), encoder.getName());
        assertTrue(roundaboutEnc.getBool(false, edgeFlags), encoder.getName());
    }
}
Also used : BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 42 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class EncodingManagerTest method testCompatibilityBug.

@Test
public void testCompatibilityBug() {
    EncodingManager manager2 = EncodingManager.create(new DefaultFlagEncoderFactory(), "bike2");
    ReaderWay osmWay = new ReaderWay(1);
    osmWay.setTag("highway", "footway");
    osmWay.setTag("name", "test");
    BikeFlagEncoder singleBikeEnc = (BikeFlagEncoder) manager2.getEncoder("bike2");
    IntsRef flags = manager2.handleWayTags(osmWay, manager2.createRelationFlags());
    double singleSpeed = singleBikeEnc.avgSpeedEnc.getDecimal(false, flags);
    assertEquals(4, singleSpeed, 1e-3);
    assertEquals(singleSpeed, singleBikeEnc.avgSpeedEnc.getDecimal(true, flags), 1e-3);
    EncodingManager manager = EncodingManager.create(new DefaultFlagEncoderFactory(), "bike2,bike,foot");
    FootFlagEncoder foot = (FootFlagEncoder) manager.getEncoder("foot");
    BikeFlagEncoder bike = (BikeFlagEncoder) manager.getEncoder("bike2");
    flags = manager.handleWayTags(osmWay, manager.createRelationFlags());
    assertEquals(singleSpeed, bike.avgSpeedEnc.getDecimal(false, flags), 1e-2);
    assertEquals(singleSpeed, bike.avgSpeedEnc.getDecimal(true, flags), 1e-2);
    assertEquals(5, foot.avgSpeedEnc.getDecimal(false, flags), 1e-2);
    assertEquals(5, foot.avgSpeedEnc.getDecimal(true, flags), 1e-2);
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 43 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class FootFlagEncoderTest method testGetSpeed.

@Test
public void testGetSpeed() {
    IntsRef fl = encodingManager.createEdgeFlags();
    footAccessEnc.setBool(false, fl, true);
    footAccessEnc.setBool(true, fl, true);
    footAvgSpeedEnc.setDecimal(false, fl, 10);
    assertEquals(10, footAvgSpeedEnc.getDecimal(false, fl), 1e-1);
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 44 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class FootFlagEncoderTest method testCombined.

@Test
public void testCombined() {
    Graph g = new GraphBuilder(encodingManager).create();
    EdgeIteratorState edge = g.edge(0, 1);
    edge.set(footAvgSpeedEnc, 10.0).set(footAccessEnc, true, true);
    edge.set(carAvSpeedEnc, 100.0).set(carAccessEnc, true, false);
    assertEquals(10, edge.get(footAvgSpeedEnc), 1e-1);
    assertTrue(edge.get(footAccessEnc));
    assertTrue(edge.getReverse(footAccessEnc));
    assertEquals(100, edge.get(carAvSpeedEnc), 1e-1);
    assertTrue(edge.get(carAccessEnc));
    assertFalse(edge.getReverse(carAccessEnc));
    IntsRef raw = encodingManager.createEdgeFlags();
    footAvgSpeedEnc.setDecimal(false, raw, 10);
    footAccessEnc.setBool(false, raw, true);
    footAccessEnc.setBool(true, raw, true);
    assertEquals(0, carAvSpeedEnc.getDecimal(false, raw), 1e-1);
}
Also used : Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 45 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class FootFlagEncoderTest method testSlowHiking.

@Test
public void testSlowHiking() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "track");
    way.setTag("sac_scale", "hiking");
    IntsRef flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertEquals(FootFlagEncoder.MEAN_SPEED, footAvgSpeedEnc.getDecimal(false, flags), 1e-1);
    way.setTag("highway", "track");
    way.setTag("sac_scale", "mountain_hiking");
    flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertEquals(FootFlagEncoder.SLOW_SPEED, footAvgSpeedEnc.getDecimal(false, flags), 1e-1);
}
Also used : 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