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);
}
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());
}
}
}
}
}
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();
}
}
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);
}
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");
}
}
Aggregations