Search in sources :

Example 1 with GraphBuilderAnnotation

use of org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation in project OpenTripPlanner by opentripplanner.

the class Graph method summarizeBuilderAnnotations.

public void summarizeBuilderAnnotations() {
    List<GraphBuilderAnnotation> gbas = this.graphBuilderAnnotations;
    Multiset<Class<? extends GraphBuilderAnnotation>> classes = HashMultiset.create();
    LOG.info("Summary (number of each type of annotation):");
    for (GraphBuilderAnnotation gba : gbas) classes.add(gba.getClass());
    for (Multiset.Entry<Class<? extends GraphBuilderAnnotation>> e : classes.entrySet()) {
        String name = e.getElement().getSimpleName();
        int count = e.getCount();
        LOG.info("    {} - {}", name, count);
    }
}
Also used : GraphBuilderAnnotation(org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation)

Example 2 with GraphBuilderAnnotation

use of org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation in project OpenTripPlanner by opentripplanner.

the class Graph method load.

/**
 * Loading which allows you to specify StreetVertexIndexFactory and inject other implementation.
 * @param in
 * @param level
 * @param indexFactory
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
@SuppressWarnings("unchecked")
public static Graph load(ObjectInputStream in, LoadLevel level, StreetVertexIndexFactory indexFactory) throws IOException, ClassNotFoundException {
    try {
        Graph graph = (Graph) in.readObject();
        LOG.debug("Basic graph info read.");
        if (graph.graphVersionMismatch())
            throw new RuntimeException("Graph version mismatch detected.");
        if (level == LoadLevel.BASIC)
            return graph;
        // vertex edge lists are transient to avoid excessive recursion depth
        // vertex list is transient because it can be reconstructed from edges
        LOG.debug("Loading edges...");
        List<Edge> edges = (ArrayList<Edge>) in.readObject();
        graph.vertices = new HashMap<String, Vertex>();
        for (Edge e : edges) {
            graph.vertices.put(e.getFromVertex().getLabel(), e.getFromVertex());
            graph.vertices.put(e.getToVertex().getLabel(), e.getToVertex());
        }
        LOG.info("Main graph read. |V|={} |E|={}", graph.countVertices(), graph.countEdges());
        graph.index(indexFactory);
        if (level == LoadLevel.FULL) {
            return graph;
        }
        if (graph.debugData) {
            graph.graphBuilderAnnotations = (List<GraphBuilderAnnotation>) in.readObject();
            LOG.debug("Debug info read.");
        } else {
            LOG.warn("Graph file does not contain debug data.");
        }
        return graph;
    } catch (InvalidClassException ex) {
        LOG.error("Stored graph is incompatible with this version of OTP, please rebuild it.");
        throw new IllegalStateException("Stored Graph version error", ex);
    }
}
Also used : PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) GraphBuilderAnnotation(org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge)

Example 3 with GraphBuilderAnnotation

use of org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method testAnnotation.

public void testAnnotation() {
    boolean found = false;
    for (GraphBuilderAnnotation annotation : graph.getBuilderAnnotations()) {
        if (annotation instanceof NegativeHopTime) {
            NegativeHopTime nht = (NegativeHopTime) annotation;
            assertTrue(nht.st0.getDepartureTime() > nht.st1.getArrivalTime());
            found = true;
        }
    }
    assertTrue(found);
}
Also used : NegativeHopTime(org.opentripplanner.graph_builder.annotation.NegativeHopTime) GraphBuilderAnnotation(org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation)

Example 4 with GraphBuilderAnnotation

use of org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation in project OpenTripPlanner by opentripplanner.

the class AnnotationsToHTML method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    if (outPath == null) {
        LOG.error("Saving folder is empty!");
        return;
    }
    outPath = new File(outPath, "report");
    if (outPath.exists()) {
        // Removes all files from report directory
        try {
            FileUtils.cleanDirectory(outPath);
        } catch (IOException e) {
            LOG.error("Failed to clean HTML report directory: " + outPath.toString() + ". HTML report won't be generated!", e);
            return;
        }
    } else {
        // Creates report directory if it doesn't exist yet
        try {
            FileUtils.forceMkdir(outPath);
        } catch (IOException e) {
            e.printStackTrace();
            LOG.error("Failed to create HTML report directory: " + outPath.toString() + ". HTML report won't be generated!", e);
            return;
        }
    }
    // Groups annotations in multimap according to annotation class
    for (GraphBuilderAnnotation annotation : graph.getBuilderAnnotations()) {
        // writer.println("<p>" + annotation.getHTMLMessage() + "</p>");
        // writer.println("<small>" + annotation.getClass().getSimpleName()+"</small>");
        addAnnotation(annotation);
    }
    LOG.info("Creating Annotations log");
    // of annotations is larger than maxNumberOfAnnotationsPerFile
    for (Map.Entry<String, Collection<String>> entry : annotations.asMap().entrySet()) {
        List<String> annotationsList;
        if (entry.getValue() instanceof List) {
            annotationsList = (List<String>) entry.getValue();
        } else {
            annotationsList = new ArrayList<>(entry.getValue());
        }
        addAnnotations(entry.getKey(), annotationsList);
    }
    // this is the first place where actual number of files is known (because it depends on annotations count)
    for (HTMLWriter writer : writers) {
        writer.writeFile(annotationClassOccurences, false);
    }
    try {
        HTMLWriter indexFileWriter = new HTMLWriter("index", (Multimap<String, String>) null);
        indexFileWriter.writeFile(annotationClassOccurences, true);
    } catch (FileNotFoundException e) {
        LOG.error("Index file coudn't be created:{}", e);
    }
    LOG.info("Annotated logs are in {}", outPath);
}
Also used : GraphBuilderAnnotation(org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 5 with GraphBuilderAnnotation

use of org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation 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)

Aggregations

GraphBuilderAnnotation (org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation)6 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 NegativeHopTime (org.opentripplanner.graph_builder.annotation.NegativeHopTime)1 StopUnlinked (org.opentripplanner.graph_builder.annotation.StopUnlinked)1 State (org.opentripplanner.routing.core.State)1 Edge (org.opentripplanner.routing.graph.Edge)1 PatternArriveVertex (org.opentripplanner.routing.vertextype.PatternArriveVertex)1