Search in sources :

Example 6 with IntsRef

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

the class DecimalEncodedValueImplTest method testInfinityWithMinValue.

@Test
public void testInfinityWithMinValue() {
    DecimalEncodedValueImpl testEnc = new DecimalEncodedValueImpl("test", 3, -6, 0.1, false, false, false, true);
    testEnc.init(new EncodedValue.InitializerConfig());
    IntsRef intsRef = new IntsRef(1);
    testEnc.setDecimal(false, intsRef, Double.POSITIVE_INFINITY);
    assertEquals(Double.POSITIVE_INFINITY, testEnc.getDecimal(false, intsRef), .1);
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 7 with IntsRef

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

the class DecimalEncodedValueImplTest method testNegateReverse.

@Test
public void testNegateReverse() {
    DecimalEncodedValueImpl testEnc = new DecimalEncodedValueImpl("test", 4, 0, 0.5, false, true, false, false);
    testEnc.init(new EncodedValue.InitializerConfig());
    IntsRef intsRef = new IntsRef(1);
    testEnc.setDecimal(false, intsRef, 5.5);
    assertEquals(5.5, testEnc.getDecimal(false, intsRef), .1);
    assertEquals(-5.5, testEnc.getDecimal(true, intsRef), .1);
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 8 with IntsRef

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

the class DecimalEncodedValueImplTest method setMaxToInfinity.

@Test
public void setMaxToInfinity() {
    DecimalEncodedValueImpl testEnc = new DecimalEncodedValueImpl("test", 3, 0, 1, false, false, false, true);
    testEnc.init(new EncodedValue.InitializerConfig());
    IntsRef intsRef = new IntsRef(1);
    assertEquals(0, testEnc.getDecimal(false, intsRef), .1);
    testEnc.setDecimal(false, intsRef, Double.POSITIVE_INFINITY);
    assertEquals(Double.POSITIVE_INFINITY, testEnc.getDecimal(false, intsRef), .1);
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 9 with IntsRef

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

the class OSMReader method preprocessRelations.

/**
 * This method is called for each relation during the first pass of {@link WaySegmentParser}
 */
protected void preprocessRelations(ReaderRelation relation) {
    if (!relation.isMetaRelation() && relation.hasTag("type", "route")) {
        // we keep track of all route relations, so they are available when we create edges later
        for (ReaderRelation.Member member : relation.getMembers()) {
            if (member.getType() != ReaderRelation.Member.WAY)
                continue;
            IntsRef oldRelationFlags = getRelFlagsMap(member.getRef());
            IntsRef newRelationFlags = encodingManager.handleRelationTags(relation, oldRelationFlags);
            putRelFlagsMap(member.getRef(), newRelationFlags);
        }
    }
    if (relation.hasTag("type", "restriction")) {
        // we keep the osm way ids that occur in turn relations, because this way we know for which GH edges
        // we need to remember the associated osm way id. this is just an optimization that is supposed to save
        // memory compared to simply storing the osm way ids in a long array where the array index is the GH edge
        // id.
        List<OSMTurnRelation> turnRelations = createTurnRelations(relation);
        for (OSMTurnRelation turnRelation : turnRelations) {
            osmWayIdSet.add(turnRelation.getOsmIdFrom());
            osmWayIdSet.add(turnRelation.getOsmIdTo());
        }
    }
}
Also used : IntsRef(com.graphhopper.storage.IntsRef)

Example 10 with IntsRef

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

the class GraphHopperTest method testSRTMWithTunnelInterpolation.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testSRTMWithTunnelInterpolation(boolean withTunnelInterpolation) {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "shortest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
    if (!withTunnelInterpolation) {
        hopper.getEncodingManagerBuilder().add(new OSMRoadEnvironmentParser() {

            @Override
            public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
                // do not change RoadEnvironment to avoid triggering tunnel interpolation
                return edgeFlags;
            }
        }).addIfAbsent(new DefaultFlagEncoderFactory(), vehicle);
    }
    hopper.setElevationProvider(new SRTMProvider(DIR));
    hopper.importOrLoad();
    GHPoint from = new GHPoint(43.7405647, 7.4299266);
    GHPoint to = new GHPoint(43.7378990, 7.4279780);
    // make sure we hit tower nodes, because all we really want is test the elevation interpolation
    assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(from.lat, from.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
    assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(to.lat, to.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
    GHResponse rsp = hopper.route(new GHRequest(from, to).setProfile(profile));
    ResponsePath res = rsp.getBest();
    PointList pointList = res.getPoints();
    assertEquals(6, pointList.size());
    assertTrue(pointList.is3D());
    if (withTunnelInterpolation) {
        assertEquals(351.8, res.getDistance(), .1);
        assertEquals(17, pointList.getEle(0), .1);
        assertEquals(19.04, pointList.getEle(1), .1);
        assertEquals(21.67, pointList.getEle(2), .1);
        assertEquals(25.03, pointList.getEle(3), .1);
        assertEquals(28.65, pointList.getEle(4), .1);
        assertEquals(34.00, pointList.getEle(5), .1);
    } else {
        assertEquals(358.3, res.getDistance(), .1);
        assertEquals(17.0, pointList.getEle(0), .1);
        assertEquals(23.0, pointList.getEle(1), .1);
        assertEquals(23.0, pointList.getEle(2), .1);
        assertEquals(41.0, pointList.getEle(3), .1);
        assertEquals(19.0, pointList.getEle(4), .1);
        assertEquals(34.0, pointList.getEle(5), .1);
    }
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) OSMRoadEnvironmentParser(com.graphhopper.routing.util.parsers.OSMRoadEnvironmentParser) IntsRef(com.graphhopper.storage.IntsRef) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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