Search in sources :

Example 1 with DirectedGraph

use of org.onebusaway.transit_data_federation.impl.DirectedGraph in project onebusaway-application-modules by camsys.

the class RouteBeanServiceImpl method getStopsInOrder.

private List<StopEntry> getStopsInOrder(StopSequenceCollection block) {
    DirectedGraph<StopEntry> graph = new DirectedGraph<StopEntry>();
    for (StopSequence sequence : block.getStopSequences()) {
        StopEntry prev = null;
        for (StopEntry stop : sequence.getStops()) {
            if (prev != null) {
                // We do this to avoid cycles
                if (!graph.isConnected(stop, prev))
                    graph.addEdge(prev, stop);
            }
            prev = stop;
        }
    }
    StopGraphComparator c = new StopGraphComparator(graph);
    return graph.getTopologicalSort(c);
}
Also used : DirectedGraph(org.onebusaway.transit_data_federation.impl.DirectedGraph) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopGraphComparator(org.onebusaway.transit_data_federation.impl.StopGraphComparator) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence)

Example 2 with DirectedGraph

use of org.onebusaway.transit_data_federation.impl.DirectedGraph in project onebusaway-application-modules by camsys.

the class FederatedTransitDataBundleCreator method getTaskList.

private List<TaskDefinition> getTaskList(ApplicationContext context) throws UnknownTaskException {
    Map<String, TaskDefinition> taskDefinitions = context.getBeansOfType(TaskDefinition.class);
    Map<String, TaskDefinition> taskDefinitionsByTaskName = getTaskDefinitionsByName(taskDefinitions);
    DirectedGraph<String> graph = new DirectedGraph<String>();
    for (TaskDefinition taskDefinition : taskDefinitions.values()) {
        String taskName = taskDefinition.getTaskName();
        graph.addNode(taskName);
        String before = taskDefinition.getBeforeTaskName();
        if (before != null) {
            if (!taskDefinitionsByTaskName.containsKey(before))
                throw new UnknownTaskException(before);
            graph.addEdge(taskName, before);
        }
        List<String> afters = taskDefinition.getAfterTaskNames();
        if (!CollectionsLibrary.isEmpty(afters)) {
            for (String after : afters) {
                if (!taskDefinitionsByTaskName.containsKey(after))
                    throw new UnknownTaskException(after);
                graph.addEdge(after, taskName);
            }
        }
    }
    List<String> taskNames = graph.getTopologicalSort(null);
    List<TaskDefinition> taskDefinitionsInOrder = new ArrayList<TaskDefinition>();
    for (String taskName : taskNames) {
        TaskDefinition task = taskDefinitionsByTaskName.get(taskName);
        taskDefinitionsInOrder.add(task);
    }
    return taskDefinitionsInOrder;
}
Also used : TaskDefinition(org.onebusaway.transit_data_federation.bundle.model.TaskDefinition) DirectedGraph(org.onebusaway.transit_data_federation.impl.DirectedGraph) ArrayList(java.util.ArrayList)

Aggregations

DirectedGraph (org.onebusaway.transit_data_federation.impl.DirectedGraph)2 ArrayList (java.util.ArrayList)1 TaskDefinition (org.onebusaway.transit_data_federation.bundle.model.TaskDefinition)1 StopGraphComparator (org.onebusaway.transit_data_federation.impl.StopGraphComparator)1 StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1