Search in sources :

Example 36 with State

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

the class GraphVisualizer method initRightPanel.

private void initRightPanel(Container pane) {
    /* right panel holds trip pattern and stop metadata */
    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(new BorderLayout());
    pane.add(rightPanel, BorderLayout.LINE_END);
    JTabbedPane rightPanelTabs = new JTabbedPane();
    rightPanel.add(rightPanelTabs, BorderLayout.LINE_END);
    // a place to print out the details of a path
    pathStates = new JList<State>();
    JScrollPane stScrollPane = new JScrollPane(pathStates);
    stScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    rightPanelTabs.addTab("path states", stScrollPane);
    // when you select a path component state, it prints the backedge's metadata
    pathStates.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            outgoingEdges.clearSelection();
            incomingEdges.clearSelection();
            @SuppressWarnings("unchecked") JList<State> theList = (JList<State>) e.getSource();
            State st = (State) theList.getSelectedValue();
            Edge edge = st.getBackEdge();
            reactToEdgeSelection(edge, false);
        }
    });
    metadataList = new JList<String>();
    metadataModel = new DefaultListModel<String>();
    metadataList.setModel(metadataModel);
    JScrollPane mdScrollPane = new JScrollPane(metadataList);
    mdScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    rightPanelTabs.addTab("metadata", mdScrollPane);
    // This is where matched annotations from an annotation search go
    annotationMatches = new JList<GraphBuilderAnnotation>();
    annotationMatches.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            @SuppressWarnings("unchecked") JList<GraphBuilderAnnotation> theList = (JList<GraphBuilderAnnotation>) e.getSource();
            GraphBuilderAnnotation anno = theList.getSelectedValue();
            if (anno == null)
                return;
            showGraph.drawAnotation(anno);
        }
    });
    annotationMatchesModel = new DefaultListModel<GraphBuilderAnnotation>();
    annotationMatches.setModel(annotationMatchesModel);
    JScrollPane amScrollPane = new JScrollPane(annotationMatches);
    amScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    rightPanelTabs.addTab("annotations", amScrollPane);
    Dimension size = new Dimension(200, 1600);
    amScrollPane.setMaximumSize(size);
    amScrollPane.setPreferredSize(size);
    stScrollPane.setMaximumSize(size);
    stScrollPane.setPreferredSize(size);
    mdScrollPane.setMaximumSize(size);
    mdScrollPane.setPreferredSize(size);
    rightPanelTabs.setMaximumSize(size);
    rightPanel.setMaximumSize(size);
}
Also used : GraphBuilderAnnotation(org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) State(org.opentripplanner.routing.core.State) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 37 with State

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

the class ShowGraph method drawNewEdges.

private void drawNewEdges() {
    if (drawEdges) {
        strokeWeight(1);
        // white
        stroke(255, 255, 255);
        noFill();
        while (!newSPTEdges.isEmpty()) {
            State leaf = newSPTEdges.poll();
            if (leaf != null) {
                if (leaf.getBackEdge() != null) {
                    drawEdge(leaf.getBackEdge());
                }
            }
        }
    }
}
Also used : State(org.opentripplanner.routing.core.State)

Example 38 with State

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

the class ShowGraph method drawGraphPath.

private void drawGraphPath(GraphPath gp) {
    // draw edges in different colors according to mode
    for (State s : gp.states) {
        TraverseMode mode = s.getBackMode();
        Edge e = s.getBackEdge();
        if (e == null)
            continue;
        if (mode != null && mode.isTransit()) {
            stroke(200, 050, 000);
            strokeWeight(6);
            drawEdge(e);
        }
        if (e instanceof StreetEdge) {
            StreetTraversalPermission stp = ((StreetEdge) e).getPermission();
            if (stp == StreetTraversalPermission.PEDESTRIAN) {
                stroke(000, 200, 000);
                strokeWeight(6);
                drawEdge(e);
            } else if (stp == StreetTraversalPermission.BICYCLE) {
                stroke(000, 000, 200);
                strokeWeight(6);
                drawEdge(e);
            } else if (stp == StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE) {
                stroke(000, 200, 200);
                strokeWeight(6);
                drawEdge(e);
            } else if (stp == StreetTraversalPermission.ALL) {
                stroke(200, 200, 200);
                strokeWeight(6);
                drawEdge(e);
            } else {
                stroke(64, 64, 64);
                strokeWeight(6);
                drawEdge(e);
            }
        }
    }
    // mark key vertices
    lastLabelY = -999;
    labelState(gp.states.getFirst(), "begin");
    for (State s : gp.states) {
        Edge e = s.getBackEdge();
        if (e instanceof TransitBoardAlight) {
            if (((TransitBoardAlight) e).boarding) {
                labelState(s, "board");
            } else {
                labelState(s, "alight");
            }
        }
    }
    labelState(gp.states.getLast(), "end");
    if (VIDEO) {
        // freeze on final path for a few frames
        for (int i = 0; i < 10; i++) saveVideoFrame();
        resetVideoFrameNumber();
    }
}
Also used : TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) State(org.opentripplanner.routing.core.State) TraverseMode(org.opentripplanner.routing.core.TraverseMode) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge) Point(java.awt.Point)

Example 39 with State

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

the class GraphPathToTripPlanConverterTest method testEmptyGraphPath.

/**
 * Test that empty graph paths throw a TrivialPathException
 */
@Test(expected = TrivialPathException.class)
public void testEmptyGraphPath() {
    RoutingRequest options = new RoutingRequest();
    Graph graph = new Graph();
    ExitVertex vertex = new ExitVertex(graph, "Vertex", 0, 0, 0);
    options.rctx = new RoutingContext(options, graph, vertex, vertex);
    GraphPath graphPath = new GraphPath(new State(options), false);
    GraphPathToTripPlanConverter.generateItinerary(graphPath, false, false, locale);
}
Also used : ExitVertex(org.opentripplanner.routing.vertextype.ExitVertex) RoutingContext(org.opentripplanner.routing.core.RoutingContext) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 40 with State

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

the class StreetUtils method pruneFloatingIslands.

public static void pruneFloatingIslands(Graph graph, int maxIslandSize, int islandWithStopMaxSize, String islandLogName) {
    LOG.debug("pruning");
    PrintWriter islandLog = null;
    if (islandLogName != null && !islandLogName.isEmpty()) {
        try {
            islandLog = new PrintWriter(new File(islandLogName));
        } catch (Exception e) {
            LOG.error("Failed to write islands log file", e);
        }
    }
    if (islandLog != null) {
        islandLog.printf("%s\t%s\t%s\t%s\t%s\n", "id", "stopCount", "streetCount", "wkt", "hadRemoved");
    }
    Map<Vertex, Subgraph> subgraphs = new HashMap<Vertex, Subgraph>();
    Map<Vertex, ArrayList<Vertex>> neighborsForVertex = new HashMap<Vertex, ArrayList<Vertex>>();
    // RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT));
    RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
    for (Vertex gv : graph.getVertices()) {
        if (!(gv instanceof StreetVertex)) {
            continue;
        }
        State s0 = new State(gv, options);
        for (Edge e : gv.getOutgoing()) {
            Vertex in = gv;
            if (!(e instanceof StreetEdge || e instanceof StreetTransitLink || e instanceof ElevatorEdge || e instanceof FreeEdge)) {
                continue;
            }
            State s1 = e.traverse(s0);
            if (s1 == null) {
                continue;
            }
            Vertex out = s1.getVertex();
            ArrayList<Vertex> vertexList = neighborsForVertex.get(in);
            if (vertexList == null) {
                vertexList = new ArrayList<Vertex>();
                neighborsForVertex.put(in, vertexList);
            }
            vertexList.add(out);
            vertexList = neighborsForVertex.get(out);
            if (vertexList == null) {
                vertexList = new ArrayList<Vertex>();
                neighborsForVertex.put(out, vertexList);
            }
            vertexList.add(in);
        }
    }
    ArrayList<Subgraph> islands = new ArrayList<Subgraph>();
    /* associate each node with a subgraph */
    for (Vertex gv : graph.getVertices()) {
        if (!(gv instanceof StreetVertex)) {
            continue;
        }
        Vertex vertex = gv;
        if (subgraphs.containsKey(vertex)) {
            continue;
        }
        if (!neighborsForVertex.containsKey(vertex)) {
            continue;
        }
        Subgraph subgraph = computeConnectedSubgraph(neighborsForVertex, vertex);
        if (subgraph != null) {
            for (Iterator<Vertex> vIter = subgraph.streetIterator(); vIter.hasNext(); ) {
                Vertex subnode = vIter.next();
                subgraphs.put(subnode, subgraph);
            }
            islands.add(subgraph);
        }
    }
    LOG.info(islands.size() + " sub graphs found");
    /* remove all tiny subgraphs and large subgraphs without stops */
    for (Subgraph island : islands) {
        boolean hadRemoved = false;
        if (island.stopSize() > 0) {
            // for islands with stops
            if (island.streetSize() < islandWithStopMaxSize) {
                depedestrianizeOrRemove(graph, island);
                hadRemoved = true;
            }
        } else {
            // for islands without stops
            if (island.streetSize() < maxIslandSize) {
                depedestrianizeOrRemove(graph, island);
                hadRemoved = true;
            }
        }
        if (islandLog != null) {
            WriteNodesInSubGraph(island, islandLog, hadRemoved);
        }
    }
    if (graph.removeEdgelessVertices() > 0) {
        LOG.warn("Removed edgeless vertices after pruning islands");
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) State(org.opentripplanner.routing.core.State) Subgraph(org.opentripplanner.common.geometry.Subgraph) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) File(java.io.File) Edge(org.opentripplanner.routing.graph.Edge) PrintWriter(java.io.PrintWriter)

Aggregations

State (org.opentripplanner.routing.core.State)78 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)42 GraphPath (org.opentripplanner.routing.spt.GraphPath)25 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)24 Test (org.junit.Test)23 Edge (org.opentripplanner.routing.graph.Edge)22 Vertex (org.opentripplanner.routing.graph.Vertex)20 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)8 Graph (org.opentripplanner.routing.graph.Graph)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)6 LineString (com.vividsolutions.jts.geom.LineString)5 HashSet (java.util.HashSet)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 StateEditor (org.opentripplanner.routing.core.StateEditor)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)5