Search in sources :

Example 51 with IntsRef

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

the class FastestWeightingTest method testTime.

@Test
public void testTime() {
    FlagEncoder tmpEnc = new Bike2WeightFlagEncoder();
    GraphHopperStorage g = new GraphBuilder(EncodingManager.create(tmpEnc)).create();
    Weighting w = new FastestWeighting(tmpEnc);
    IntsRef edgeFlags = GHUtility.setSpeed(15, 15, tmpEnc, g.getEncodingManager().createEdgeFlags());
    tmpEnc.getAverageSpeedEnc().setDecimal(true, edgeFlags, 10.0);
    EdgeIteratorState edge = GHUtility.createMockedEdgeIteratorState(100000, edgeFlags);
    assertEquals(375 * 60 * 1000, w.calcEdgeMillis(edge, false));
    assertEquals(600 * 60 * 1000, w.calcEdgeMillis(edge, true));
    g.close();
}
Also used : Bike2WeightFlagEncoder(com.graphhopper.routing.util.Bike2WeightFlagEncoder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Bike2WeightFlagEncoder(com.graphhopper.routing.util.Bike2WeightFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) VirtualEdgeIteratorState(com.graphhopper.routing.querygraph.VirtualEdgeIteratorState) GHUtility.createMockedEdgeIteratorState(com.graphhopper.util.GHUtility.createMockedEdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 52 with IntsRef

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

the class FastestWeightingTest method testSpeed0.

@Test
public void testSpeed0() {
    Weighting instance = new FastestWeighting(encoder);
    IntsRef edgeFlags = encodingManager.createEdgeFlags();
    encoder.getAverageSpeedEnc().setDecimal(false, edgeFlags, 0);
    assertEquals(1.0 / 0, instance.calcEdgeWeight(createMockedEdgeIteratorState(10, edgeFlags), false), 1e-8);
    // 0 / 0 returns NaN but calcWeight should not return NaN!
    assertEquals(1.0 / 0, instance.calcEdgeWeight(createMockedEdgeIteratorState(0, edgeFlags), false), 1e-8);
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 53 with IntsRef

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

the class OSMMaxSpeedParserTest method countryRule.

@Test
void countryRule() {
    EncodingManager em = EncodingManager.create("car");
    DecimalEncodedValue maxSpeedEnc = em.getDecimalEncodedValue(MaxSpeed.KEY);
    Graph graph = new GraphBuilder(em).create();
    FlagEncoder encoder = em.getEncoder("car");
    EdgeIteratorState e1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
    EdgeIteratorState e2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
    OSMMaxSpeedParser parser = new OSMMaxSpeedParser(maxSpeedEnc);
    IntsRef relFlags = em.createRelationFlags();
    ReaderWay way = new ReaderWay(29L);
    way.setTag("highway", "living_street");
    way.setTag("country_rule", new CountryRule() {

        @Override
        public double getMaxSpeed(ReaderWay readerWay, TransportationMode transportationMode, double currentMaxSpeed) {
            return 5;
        }
    });
    parser.handleWayTags(e1.getFlags(), way, relFlags);
    assertEquals(5, e1.get(maxSpeedEnc), .1);
    // without a country_rule we get the default value
    way.removeTag("country_rule");
    parser.handleWayTags(e2.getFlags(), way, relFlags);
    assertEquals(MaxSpeed.UNSET_SPEED, e2.get(maxSpeedEnc), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) TransportationMode(com.graphhopper.routing.util.TransportationMode) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 54 with IntsRef

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

the class OSMRoadClassParserTest method testSimpleTags.

@Test
public void testSimpleTags() {
    ReaderWay readerWay = new ReaderWay(1);
    IntsRef edgeFlags = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    parser.handleWayTags(edgeFlags, readerWay, relFlags);
    assertEquals(RoadClass.PRIMARY, rcEnc.getEnum(false, edgeFlags));
    edgeFlags = em.createEdgeFlags();
    readerWay.setTag("highway", "unknownstuff");
    parser.handleWayTags(edgeFlags, readerWay, relFlags);
    assertEquals(RoadClass.OTHER, rcEnc.getEnum(false, edgeFlags));
    edgeFlags = em.createEdgeFlags();
    readerWay.setTag("highway", "motorway_link");
    parser.handleWayTags(edgeFlags, readerWay, relFlags);
    assertEquals(RoadClass.MOTORWAY, rcEnc.getEnum(false, edgeFlags));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 55 with IntsRef

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

the class OSMHazmatParserTest method testNoNPE.

@Test
public void testNoNPE() {
    ReaderWay readerWay = new ReaderWay(1);
    IntsRef intsRef = em.createEdgeFlags();
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Hazmat.YES, hazEnc.getEnum(false, intsRef));
}
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