Search in sources :

Example 1 with RoadAccess

use of com.graphhopper.routing.ev.RoadAccess in project graphhopper by graphhopper.

the class FastestWeighting method calcEdgeWeight.

@Override
public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse) {
    double speed = reverse ? edgeState.getReverse(avSpeedEnc) : edgeState.get(avSpeedEnc);
    if (speed == 0)
        return Double.POSITIVE_INFINITY;
    double time = edgeState.getDistance() / speed * SPEED_CONV;
    if (roadAccessEnc != null) {
        RoadAccess access = edgeState.get(roadAccessEnc);
        if (access == RoadAccess.DESTINATION)
            time *= destinationPenalty;
        else if (access == RoadAccess.PRIVATE)
            time *= privatePenalty;
    }
    // add direction penalties at start/stop/via points
    boolean unfavoredEdge = edgeState.get(EdgeIteratorState.UNFAVORED_EDGE);
    if (unfavoredEdge)
        time += headingPenalty;
    return time;
}
Also used : RoadAccess(com.graphhopper.routing.ev.RoadAccess)

Example 2 with RoadAccess

use of com.graphhopper.routing.ev.RoadAccess in project graphhopper by graphhopper.

the class OSMRoadAccessParserTest method countryRule.

@Test
void countryRule() {
    EncodingManager em = EncodingManager.create("car");
    EnumEncodedValue<RoadAccess> roadAccessEnc = em.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class);
    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));
    OSMRoadAccessParser parser = new OSMRoadAccessParser(roadAccessEnc, OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR));
    IntsRef relFlags = em.createRelationFlags();
    ReaderWay way = new ReaderWay(27L);
    way.setTag("highway", "track");
    way.setTag("country_rule", new CountryRule() {

        @Override
        public RoadAccess getAccess(ReaderWay readerWay, TransportationMode transportationMode, RoadAccess currentRoadAccess) {
            return RoadAccess.DESTINATION;
        }
    });
    parser.handleWayTags(e1.getFlags(), way, relFlags);
    assertEquals(RoadAccess.DESTINATION, e1.get(roadAccessEnc));
    // if there is no country rule we get the default value
    way.removeTag("country_rule");
    parser.handleWayTags(e2.getFlags(), way, relFlags);
    assertEquals(RoadAccess.YES, e2.get(roadAccessEnc));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) RoadAccess(com.graphhopper.routing.ev.RoadAccess) 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) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 3 with RoadAccess

use of com.graphhopper.routing.ev.RoadAccess in project graphhopper by graphhopper.

the class OSMRoadAccessParser method handleWayTags.

@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
    RoadAccess accessValue = YES;
    RoadAccess tmpAccessValue;
    for (String restriction : restrictions) {
        tmpAccessValue = RoadAccess.find(readerWay.getTag(restriction, "yes"));
        if (tmpAccessValue != null && tmpAccessValue.ordinal() > accessValue.ordinal()) {
            accessValue = tmpAccessValue;
        }
    }
    CountryRule countryRule = readerWay.getTag("country_rule", null);
    if (countryRule != null)
        accessValue = countryRule.getAccess(readerWay, TransportationMode.CAR, accessValue);
    roadAccessEnc.setEnum(false, edgeFlags, accessValue);
    return edgeFlags;
}
Also used : RoadAccess(com.graphhopper.routing.ev.RoadAccess) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule)

Aggregations

RoadAccess (com.graphhopper.routing.ev.RoadAccess)3 CountryRule (com.graphhopper.routing.util.countryrules.CountryRule)2 ReaderWay (com.graphhopper.reader.ReaderWay)1 EncodingManager (com.graphhopper.routing.util.EncodingManager)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 TransportationMode (com.graphhopper.routing.util.TransportationMode)1 Graph (com.graphhopper.storage.Graph)1 GraphBuilder (com.graphhopper.storage.GraphBuilder)1 IntsRef (com.graphhopper.storage.IntsRef)1 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)1 Test (org.junit.jupiter.api.Test)1