Search in sources :

Example 66 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class LinkingTest method testStopsLinkedIdentically.

/**
 * Test that all the stops are linked identically
 * to the street network on two builds of similar graphs
 * with additional stops in one.
 *
 * We do this by building the graphs and then comparing the stop tree caches.
 */
@Test
public void testStopsLinkedIdentically() throws UnsupportedEncodingException {
    // build the graph without the added stops
    Graph g1 = buildGraphNoTransit();
    addRegularStopGrid(g1);
    link(g1);
    Graph g2 = buildGraphNoTransit();
    addExtraStops(g2);
    addRegularStopGrid(g2);
    link(g2);
    // compare the linkages
    for (TransitStop ts : Iterables.filter(g1.getVertices(), TransitStop.class)) {
        Collection<Edge> stls = stls(ts.getOutgoing());
        assertTrue(stls.size() >= 1);
        StreetTransitLink exemplar = (StreetTransitLink) stls.iterator().next();
        TransitStop other = (TransitStop) g2.getVertex(ts.getLabel());
        Collection<Edge> ostls = stls(other.getOutgoing());
        assertEquals("Unequal number of links from stop " + ts, stls.size(), ostls.size());
        StreetTransitLink oe = (StreetTransitLink) ostls.iterator().next();
        assertEquals(exemplar.getToVertex().getLat(), oe.getToVertex().getLat(), 1e-10);
        assertEquals(exemplar.getToVertex().getLon(), oe.getToVertex().getLon(), 1e-10);
    }
    // compare the stop tree caches
    g1.index(new DefaultStreetVertexIndexFactory());
    g2.index(new DefaultStreetVertexIndexFactory());
    g1.rebuildVertexAndEdgeIndices();
    g2.rebuildVertexAndEdgeIndices();
    StopTreeCache s1 = g1.index.getStopTreeCache();
    StopTreeCache s2 = g2.index.getStopTreeCache();
    // convert the caches to be by stop label
    Map<String, int[]> l1 = cacheByLabel(s1);
    Map<String, int[]> l2 = cacheByLabel(s2);
    // do the comparison
    for (Entry<String, int[]> e : l1.entrySet()) {
        // graph 2 should contain all stops in graph 1 (and a few more)
        assertTrue(l2.containsKey(e.getKey()));
        TObjectIntMap<String> g1t = jaggedArrayToVertexMap(e.getValue(), g1);
        TObjectIntMap<String> g2t = jaggedArrayToVertexMap(l2.get(e.getKey()), g2);
        for (TObjectIntIterator<String> it = g1t.iterator(); it.hasNext(); ) {
            it.advance();
            assertTrue(g2t.containsKey(it.key()));
            int newv = g2t.get(it.key());
            assertTrue("At " + it.key() + " from stop " + g1.getVertex(e.getKey()) + ", difference in walk distances: " + it.value() + "m without extra stops," + newv + "m with", Math.abs(it.value() - newv) <= EPSILON);
        }
    }
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) LineString(com.vividsolutions.jts.geom.LineString) StopTreeCache(org.opentripplanner.profile.StopTreeCache) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 67 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method traceOld.

protected void traceOld() {
    HashSet<Vertex> seenVertices = new HashSet<Vertex>();
    DisplayVertex selected = (DisplayVertex) nearbyVertices.getSelectedValue();
    if (selected == null) {
        System.out.println("no vertex selected");
        return;
    }
    Vertex v = selected.vertex;
    System.out.println("initial vertex: " + v);
    Queue<Vertex> toExplore = new LinkedList<Vertex>();
    toExplore.add(v);
    seenVertices.add(v);
    while (!toExplore.isEmpty()) {
        Vertex src = toExplore.poll();
        for (Edge e : src.getOutgoing()) {
            Vertex tov = e.getToVertex();
            if (!seenVertices.contains(tov)) {
                seenVertices.add(tov);
                toExplore.add(tov);
            }
        }
    }
    showGraph.setHighlightedVertices(seenVertices);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 68 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method trace.

protected void trace() {
    DisplayVertex selected = (DisplayVertex) nearbyVertices.getSelectedValue();
    if (selected == null) {
        return;
    }
    Vertex v = selected.vertex;
    if (tracingVertex != v) {
        tracingVertex = v;
        closed = new HashSet<Vertex>();
        open = new HashSet<Vertex>();
        open.add(v);
        seen = new HashSet<Vertex>();
    }
    HashSet<Vertex> newOpen = new HashSet<Vertex>();
    for (Vertex v2 : open) {
        closed.add(v2);
        for (Edge e : v2.getOutgoing()) {
            Vertex target = e.getToVertex();
            if (closed.contains(target)) {
                continue;
            }
            newOpen.add(target);
        }
    }
    seen.addAll(newOpen);
    open = newOpen;
    showGraph.setHighlightedVertices(seen);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 69 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method reactToEdgeSelection.

private void reactToEdgeSelection(Edge selected, boolean outgoing) {
    if (selected == null) {
        return;
    }
    showGraph.highlightEdge(selected);
    /* for turns, highlight the outgoing street's ends */
    if (selected instanceof StreetEdge) {
        List<Vertex> vertices = new ArrayList<Vertex>();
        List<Edge> edges = new ArrayList<Edge>();
        Vertex tov = selected.getToVertex();
        for (Edge og : tov.getOutgoing()) {
            if (og instanceof StreetEdge) {
                edges.add(og);
                vertices.add(og.getToVertex());
                break;
            }
        }
        Vertex fromv = selected.getFromVertex();
        for (Edge ic : fromv.getIncoming()) {
            if (ic instanceof StreetEdge) {
                edges.add(ic);
                vertices.add(ic.getFromVertex());
                break;
            }
        }
        // showGraph.setHighlightedVertices(vertices);
        showGraph.setHighlightedEdges(edges);
    }
    /* add the connected vertices to the list of vertices */
    VertexList nearbyModel = (VertexList) nearbyVertices.getModel();
    List<Vertex> vertices = nearbyModel.selected;
    Vertex v;
    if (outgoing) {
        v = selected.getToVertex();
    } else {
        v = selected.getFromVertex();
    }
    if (!vertices.contains(v)) {
        vertices.add(v);
        nearbyModel = new VertexList(vertices);
        // this should just be an event, but for
        nearbyVertices.setModel(nearbyModel);
    // some reason, JList doesn't implement
    // the right event.
    }
    /* set up metadata tab */
    metadataModel.clear();
    getMetadata(selected);
    // fromv
    Vertex fromv = selected.getFromVertex();
    getMetadata(fromv);
    if (selected instanceof StreetEdge) {
    // TODO ElevationProfileSegment do not exist anymore
    // getMetadata(((StreetEdge) selected).getElevationProfileSegment());
    }
    metadataList.revalidate();
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 70 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method initControlButtons.

private void initControlButtons() {
    /* buttons at bottom */
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(0, 3));
    leftPanel.add(buttonPanel, BorderLayout.PAGE_END);
    JButton zoomDefaultButton = new JButton("Zoom to default");
    zoomDefaultButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            showGraph.zoomToDefault();
        }
    });
    buttonPanel.add(zoomDefaultButton);
    final JFrame frame = this;
    JButton zoomToNodeButton = new JButton("Zoom to node");
    zoomToNodeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String nodeName = (String) JOptionPane.showInputDialog(frame, "Node id", JOptionPane.PLAIN_MESSAGE);
            Vertex v = getGraph().getVertex(nodeName);
            if (v == null) {
                System.out.println("no such node " + nodeName);
            } else {
                showGraph.zoomToVertex(v);
            }
        }
    });
    buttonPanel.add(zoomToNodeButton);
    JButton zoomToLocationButton = new JButton("Zoom to location");
    zoomToLocationButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String result = JOptionPane.showInputDialog("Enter the location (lat lon)");
            if (result == null || result.length() == 0)
                return;
            String[] tokens = result.split("[\\s,]+");
            double lat = Double.parseDouble(tokens[0]);
            double lon = Double.parseDouble(tokens[1]);
            Coordinate c = new Coordinate(lon, lat);
            showGraph.zoomToLocation(c);
        }
    });
    buttonPanel.add(zoomToLocationButton);
    JButton zoomOutButton = new JButton("Zoom out");
    zoomOutButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            showGraph.zoomOut();
        }
    });
    buttonPanel.add(zoomOutButton);
    JButton routeButton2 = new JButton("Route");
    routeButton2.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // String initialFrom = "";
            // Object selected = nearbyVertices.getSelectedValue();
            // if (selected != null) {
            // initialFrom = selected.toString();
            // }
            // RouteDialog dlg = new RouteDialog(frame, initialFrom); // modal
            String from = sourceVertex.getText();
            String to = sinkVertex.getText();
            route(from, to);
        }
    });
    buttonPanel.add(routeButton2);
    JButton findButton = new JButton("Find node");
    findButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String nodeName = (String) JOptionPane.showInputDialog(frame, "Node id", JOptionPane.PLAIN_MESSAGE);
            Vertex v = getGraph().getVertex(nodeName);
            if (v == null) {
                System.out.println("no such node " + nodeName);
            } else {
                showGraph.highlightVertex(v);
                ArrayList<Vertex> l = new ArrayList<Vertex>();
                l.add(v);
                verticesSelected(l);
            }
        }
    });
    buttonPanel.add(findButton);
    JButton findEdgeButton = new JButton("Find edge");
    findEdgeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String edgeName = (String) JOptionPane.showInputDialog(frame, "Edge name like", JOptionPane.PLAIN_MESSAGE);
            for (Vertex gv : getGraph().getVertices()) {
                for (Edge edge : gv.getOutgoing()) {
                    if (edge.getName() != null && edge.getName().contains(edgeName)) {
                        showGraph.highlightVertex(gv);
                        ArrayList<Vertex> l = new ArrayList<Vertex>();
                        l.add(gv);
                        verticesSelected(l);
                    }
                }
            }
        }
    });
    buttonPanel.add(findEdgeButton);
    JButton checkButton = new JButton("Check graph");
    checkButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            checkGraph();
        }
    });
    buttonPanel.add(checkButton);
    JButton traceButton = new JButton("Trace");
    traceButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            trace();
        }
    });
    buttonPanel.add(traceButton);
    // annotation search button
    JButton annotationButton = new JButton("Find annotations");
    annotationButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            findAnnotation();
        }
    });
    buttonPanel.add(annotationButton);
    JButton findEdgeByIdButton = new JButton("Find edge ID");
    findEdgeByIdButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String edgeIdStr = (String) JOptionPane.showInputDialog(frame, "Edge ID", JOptionPane.PLAIN_MESSAGE);
            Integer edgeId = Integer.parseInt(edgeIdStr);
            Edge edge = getGraph().getEdgeById(edgeId);
            if (edge != null) {
                showGraph.highlightEdge(edge);
                showGraph.highlightVertex(edge.getFromVertex());
            } else {
                System.out.println("Found no edge with ID " + edgeIdStr);
            }
        }
    });
    buttonPanel.add(findEdgeByIdButton);
    JButton snapButton = new JButton("Snap location");
    snapButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            LOG.error("StreetIndex.getClosestPointOnStreet no longer exists.");
        }
    });
    buttonPanel.add(snapButton);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

Edge (org.opentripplanner.routing.graph.Edge)113 Vertex (org.opentripplanner.routing.graph.Vertex)61 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)53 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)26 HashSet (java.util.HashSet)23 State (org.opentripplanner.routing.core.State)22 Coordinate (com.vividsolutions.jts.geom.Coordinate)19 Graph (org.opentripplanner.routing.graph.Graph)19 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)18 Test (org.junit.Test)17 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)17 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)17 ArrayList (java.util.ArrayList)16 LineString (com.vividsolutions.jts.geom.LineString)15 GraphPath (org.opentripplanner.routing.spt.GraphPath)15 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)12 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 Stop (org.onebusaway.gtfs.model.Stop)9 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)9