Search in sources :

Example 26 with TraverseModeSet

use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.

the class OSMDatabase method processRestriction.

/**
 * Store turn restrictions.
 *
 * @param relation
 */
private void processRestriction(OSMRelation relation) {
    long from = -1, to = -1, via = -1;
    for (OSMRelationMember member : relation.getMembers()) {
        String role = member.getRole();
        if (role.equals("from")) {
            from = member.getRef();
        } else if (role.equals("to")) {
            to = member.getRef();
        } else if (role.equals("via")) {
            via = member.getRef();
        }
    }
    if (from == -1 || to == -1 || via == -1) {
        LOG.warn(addBuilderAnnotation(new TurnRestrictionBad(relation.getId(), "One of from|via|to edges are empty in relation")));
        return;
    }
    TraverseModeSet modes = new TraverseModeSet(TraverseMode.BICYCLE, TraverseMode.CAR);
    String exceptModes = relation.getTag("except");
    if (exceptModes != null) {
        for (String m : exceptModes.split(";")) {
            if (m.equals("motorcar")) {
                modes.setCar(false);
            } else if (m.equals("bicycle")) {
                modes.setBicycle(false);
                LOG.debug(addBuilderAnnotation(new TurnRestrictionException(via, from)));
            }
        }
    }
    TurnRestrictionTag tag;
    if (relation.isTag("restriction", "no_right_turn")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.NO_TURN, Direction.RIGHT, relation.getId());
    } else if (relation.isTag("restriction", "no_left_turn")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.NO_TURN, Direction.LEFT, relation.getId());
    } else if (relation.isTag("restriction", "no_straight_on")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.NO_TURN, Direction.STRAIGHT, relation.getId());
    } else if (relation.isTag("restriction", "no_u_turn")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.NO_TURN, Direction.U, relation.getId());
    } else if (relation.isTag("restriction", "only_straight_on")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.ONLY_TURN, Direction.STRAIGHT, relation.getId());
    } else if (relation.isTag("restriction", "only_right_turn")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.ONLY_TURN, Direction.RIGHT, relation.getId());
    } else if (relation.isTag("restriction", "only_left_turn")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.ONLY_TURN, Direction.LEFT, relation.getId());
    } else if (relation.isTag("restriction", "only_u_turn")) {
        tag = new TurnRestrictionTag(via, TurnRestrictionType.ONLY_TURN, Direction.U, relation.getId());
    } else {
        LOG.warn(addBuilderAnnotation(new TurnRestrictionUnknown(relation.getId(), relation.getTag("restriction"))));
        return;
    }
    tag.modes = modes.clone();
    // set the time periods for this restriction, if applicable
    if (relation.hasTag("day_on") && relation.hasTag("day_off") && relation.hasTag("hour_on") && relation.hasTag("hour_off")) {
        try {
            tag.time = RepeatingTimePeriod.parseFromOsmTurnRestriction(relation.getTag("day_on"), relation.getTag("day_off"), relation.getTag("hour_on"), relation.getTag("hour_off"));
        } catch (NumberFormatException e) {
            LOG.info("Unparseable turn restriction: " + relation.getId());
        }
    }
    turnRestrictionsByFromWay.put(from, tag);
    turnRestrictionsByToWay.put(to, tag);
}
Also used : TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet)

Example 27 with TraverseModeSet

use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method testTriangleInequalityDrivingOnly.

@Test
public void testTriangleInequalityDrivingOnly() {
    TraverseModeSet modes = new TraverseModeSet(TraverseMode.CAR);
    checkTriangleInequality(modes);
}
Also used : TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) Test(org.junit.Test)

Example 28 with TraverseModeSet

use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method testTriangleInequalityWalkTransitMultiSPT.

@Test
public void testTriangleInequalityWalkTransitMultiSPT() {
    TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT);
    checkTriangleInequality(modes);
}
Also used : TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) Test(org.junit.Test)

Example 29 with TraverseModeSet

use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method testTriangleInequalityWalkingOnlyBasicSPT.

@Test
public void testTriangleInequalityWalkingOnlyBasicSPT() {
    TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK);
    checkTriangleInequality(modes);
}
Also used : TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) Test(org.junit.Test)

Example 30 with TraverseModeSet

use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method testTriangleInequalityDrivingOnlyBasicSPT.

@Test
public void testTriangleInequalityDrivingOnlyBasicSPT() {
    TraverseModeSet modes = new TraverseModeSet(TraverseMode.CAR);
    checkTriangleInequality(modes);
}
Also used : TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) Test(org.junit.Test)

Aggregations

TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)44 Test (org.junit.Test)25 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)17 Graph (org.opentripplanner.routing.graph.Graph)14 Edge (org.opentripplanner.routing.graph.Edge)10 Vertex (org.opentripplanner.routing.graph.Vertex)10 Coordinate (com.vividsolutions.jts.geom.Coordinate)8 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)8 GenericLocation (org.opentripplanner.common.model.GenericLocation)8 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)8 LocalDate (org.joda.time.LocalDate)7 ProfileRequest (org.opentripplanner.profile.ProfileRequest)7 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)7 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 GraphPath (org.opentripplanner.routing.spt.GraphPath)6 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)5 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)5 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)5 LineString (com.vividsolutions.jts.geom.LineString)4 ArrayList (java.util.ArrayList)4