Search in sources :

Example 1 with NonLocalizedString

use of org.opentripplanner.util.NonLocalizedString in project OpenTripPlanner by opentripplanner.

the class VCubDataSource method makeStation.

public BikeRentalStation makeStation(Map<String, String> attributes) {
    BikeRentalStation brstation = new BikeRentalStation();
    brstation.id = attributes.get("bm:GID").trim();
    String[] coordinates = attributes.get("bm:geometry").trim().split(" ");
    if (coordinates.length >= 2) {
        brstation.x = Double.parseDouble(coordinates[1]);
        brstation.y = Double.parseDouble(coordinates[0]);
    }
    if (brstation.x == 0 || brstation.y == 0)
        return null;
    brstation.name = new NonLocalizedString(attributes.get("bm:NOM"));
    boolean connected = "CONNECTEE".equalsIgnoreCase(attributes.get("bm:ETAT"));
    brstation.realTimeData = connected;
    String nbPlaces = attributes.get("bm:NBPLACES");
    if (nbPlaces != null)
        brstation.spacesAvailable = Integer.parseInt(nbPlaces);
    String nbVelos = attributes.get("bm:NBVELOS");
    if (nbVelos != null)
        brstation.bikesAvailable = Integer.parseInt(nbVelos);
    @SuppressWarnings("unused") String type = attributes.get("bm:TYPE");
    /*
         * Please see http://www.vcub.fr/stations-vcub-1 for more information on rules of VCUB vs
         * VCUB+. Apparently both network are compatible, VCUB+ only offer more renting options
         * which are not handled by OTP anyway.
         */
    brstation.networks = new HashSet<String>();
    brstation.networks.add("VCUB");
    brstation.networks.add("VCUB+");
    return brstation;
}
Also used : NonLocalizedString(org.opentripplanner.util.NonLocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 2 with NonLocalizedString

use of org.opentripplanner.util.NonLocalizedString in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitter method getClosestVertex.

/**
 * Used to link origin and destination points to graph non destructively.
 *
 * Split edges don't replace existing ones and only temporary edges and vertices are created.
 *
 * Will throw ThrivialPathException if origin and destination Location are on the same edge
 *
 * @param location
 * @param options
 * @param endVertex true if this is destination vertex
 * @return
 */
public Vertex getClosestVertex(GenericLocation location, RoutingRequest options, boolean endVertex) {
    if (destructiveSplitting) {
        throw new RuntimeException("Origin and destination search is used with destructive splitting. Something is wrong!");
    }
    if (endVertex) {
        LOG.debug("Finding end vertex for {}", location);
    } else {
        LOG.debug("Finding start vertex for {}", location);
    }
    Coordinate coord = location.getCoordinate();
    // TODO: add nice name
    String name;
    if (location.name == null || location.name.isEmpty()) {
        if (endVertex) {
            name = "Destination";
        } else {
            name = "Origin";
        }
    } else {
        name = location.name;
    }
    TemporaryStreetLocation closest = new TemporaryStreetLocation(UUID.randomUUID().toString(), coord, new NonLocalizedString(name), endVertex);
    TraverseMode nonTransitMode = TraverseMode.WALK;
    // It can be null in tests
    if (options != null) {
        TraverseModeSet modes = options.modes;
        if (modes.getCar())
            // for park and ride we will start in car mode and walk to the end vertex
            if (endVertex && (options.parkAndRide || options.kissAndRide)) {
                nonTransitMode = TraverseMode.WALK;
            } else {
                nonTransitMode = TraverseMode.CAR;
            }
        else if (modes.getWalk())
            nonTransitMode = TraverseMode.WALK;
        else if (modes.getBicycle())
            nonTransitMode = TraverseMode.BICYCLE;
    }
    if (!link(closest, nonTransitMode, options)) {
        LOG.warn("Couldn't link {}", location);
    }
    return closest;
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) Coordinate(com.vividsolutions.jts.geom.Coordinate) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) TraverseMode(org.opentripplanner.routing.core.TraverseMode) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) LineString(com.vividsolutions.jts.geom.LineString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString)

Example 3 with NonLocalizedString

use of org.opentripplanner.util.NonLocalizedString in project OpenTripPlanner by opentripplanner.

the class PortlandCustomNamer method nameAccordingToDestination.

private String nameAccordingToDestination(Graph graph, StreetEdge e, int maxDepth) {
    if (maxDepth == 0) {
        return null;
    }
    Vertex toVertex = e.getToVertex();
    for (StreetEdge out : Iterables.filter(toVertex.getOutgoing(), StreetEdge.class)) {
        if (out.hasBogusName()) {
            String name = nameAccordingToDestination(graph, out, maxDepth - 1);
            if (name == null) {
                continue;
            }
            e.setName(new NonLocalizedString(name));
            return name;
        } else {
            String name = out.getName();
            e.setName(new NonLocalizedString(name));
            return name;
        }
    }
    return null;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) NonLocalizedString(org.opentripplanner.util.NonLocalizedString)

Example 4 with NonLocalizedString

use of org.opentripplanner.util.NonLocalizedString in project OpenTripPlanner by opentripplanner.

the class PortlandCustomNamer method nameAccordingToOrigin.

private String nameAccordingToOrigin(Graph graph, StreetEdge e, int maxDepth) {
    if (maxDepth == 0) {
        return null;
    }
    Vertex fromVertex = e.getFromVertex();
    for (StreetEdge in : Iterables.filter(fromVertex.getIncoming(), StreetEdge.class)) {
        if (in.hasBogusName()) {
            String name = nameAccordingToOrigin(graph, in, maxDepth - 1);
            if (name == null) {
                continue;
            }
            e.setName(new NonLocalizedString(name));
            return name;
        } else {
            String name = in.getName();
            e.setName(new NonLocalizedString(name));
            return name;
        }
    }
    return null;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) NonLocalizedString(org.opentripplanner.util.NonLocalizedString)

Example 5 with NonLocalizedString

use of org.opentripplanner.util.NonLocalizedString in project OpenTripPlanner by opentripplanner.

the class PartialStreetEdgeTest method testTraversalOfSubdividedEdge.

@Test
public void testTraversalOfSubdividedEdge() {
    Coordinate nearestPoint = new Coordinate(0.5, 2.0);
    List<StreetEdge> edges = new ArrayList<StreetEdge>();
    edges.add(e2);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(_graph, "middle of e2", new NonLocalizedString("foo"), edges, nearestPoint, true);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(_graph, "middle of e2", new NonLocalizedString("foo"), edges, nearestPoint, false);
    RoutingRequest options = new RoutingRequest();
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, v1, v2);
    // All intersections take 10 minutes - we'll notice if one isn't counted.
    double turnDurationSecs = 10.0 * 60.0;
    options.traversalCostModel = (new DummyCostModel(turnDurationSecs));
    options.turnReluctance = (1.0);
    State s0 = new State(options);
    State s1 = e1.traverse(s0);
    State s2 = e2.traverse(s1);
    State s3 = e3.traverse(s2);
    Edge partialE2First = end.getIncoming().iterator().next();
    Edge partialE2Second = start.getOutgoing().iterator().next();
    State partialS0 = new State(options);
    State partialS1 = e1.traverse(partialS0);
    State partialS2A = partialE2First.traverse(partialS1);
    State partialS2B = partialE2Second.traverse(partialS2A);
    State partialS3 = e3.traverse(partialS2B);
    // Should start at the same time.
    assertEquals(s0.getTimeSeconds(), partialS0.getTimeSeconds());
    // Time and cost should be the same up to a rounding difference.
    assertTrue(Math.abs(s3.getTimeSeconds() - partialS3.getTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3.getElapsedTimeSeconds() - partialS3.getElapsedTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3.getWeight() - partialS3.getWeight()) <= 1);
    // All intersections take 0 seconds now.
    options.traversalCostModel = (new DummyCostModel(0.0));
    State s0NoCost = new State(options);
    State s1NoCost = e1.traverse(s0NoCost);
    State s2NoCost = e2.traverse(s1NoCost);
    State s3NoCost = e3.traverse(s2NoCost);
    State partialS0NoCost = new State(options);
    State partialS1NoCost = e1.traverse(partialS0NoCost);
    State partialS2ANoCost = partialE2First.traverse(partialS1NoCost);
    State partialS2BNoCost = partialE2Second.traverse(partialS2ANoCost);
    State partialS3NoCost = e3.traverse(partialS2BNoCost);
    // Time and cost should be the same up to a rounding difference.
    assertTrue(Math.abs(s3NoCost.getTimeSeconds() - partialS3NoCost.getTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3NoCost.getElapsedTimeSeconds() - partialS3NoCost.getElapsedTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3NoCost.getWeight() - partialS3NoCost.getWeight()) <= 1);
    // Difference in duration and weight between now and before should be
    // entirely due to the crossing of 2 intersections at v2 and v3.
    double expectedDifference = 2 * 10 * 60.0;
    double durationDiff = s3.getTimeSeconds() - s3NoCost.getTimeSeconds();
    double partialDurationDiff = partialS3.getTimeSeconds() - partialS3NoCost.getTimeSeconds();
    assertTrue(Math.abs(durationDiff - expectedDifference) <= 1);
    assertTrue(Math.abs(partialDurationDiff - expectedDifference) <= 1);
    // Turn reluctance is 1.0, so weight == duration.
    double weightDiff = s3.getWeight() - s3NoCost.getWeight();
    double partialWeightDiff = partialS3.getWeight() - partialS3NoCost.getWeight();
    assertTrue(Math.abs(weightDiff - expectedDifference) <= 1);
    assertTrue(Math.abs(partialWeightDiff - expectedDifference) <= 1);
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) ArrayList(java.util.ArrayList) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Aggregations

NonLocalizedString (org.opentripplanner.util.NonLocalizedString)31 BikeRentalStation (org.opentripplanner.routing.bike_rental.BikeRentalStation)15 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)10 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)10 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)8 GraphPath (org.opentripplanner.routing.spt.GraphPath)8 Test (org.junit.Test)7 Edge (org.opentripplanner.routing.graph.Edge)7 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)7 Coordinate (com.vividsolutions.jts.geom.Coordinate)6 HashSet (java.util.HashSet)6 State (org.opentripplanner.routing.core.State)6 LineString (com.vividsolutions.jts.geom.LineString)4 LinearLocation (com.vividsolutions.jts.linearref.LinearLocation)4 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)4 TemporaryFreeEdge (org.opentripplanner.routing.edgetype.TemporaryFreeEdge)4 ArrayList (java.util.ArrayList)3 Alert (org.opentripplanner.routing.alertpatch.Alert)3 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)3 Vertex (org.opentripplanner.routing.graph.Vertex)2