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