本文整理汇总了Java中org.jgrapht.traverse.TopologicalOrderIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java TopologicalOrderIterator.next方法的具体用法?Java TopologicalOrderIterator.next怎么用?Java TopologicalOrderIterator.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.traverse.TopologicalOrderIterator
的用法示例。
在下文中一共展示了TopologicalOrderIterator.next方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParameterOrdering
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
private List<Field> getParameterOrdering(DirectedGraph<Field, DefaultEdge> dependencyGraph) {
CycleDetector<Field, DefaultEdge> cycleDetector = new CycleDetector<Field, DefaultEdge>(dependencyGraph);
if (cycleDetector.detectCycles()) {
throw new RuntimeException("Cyclic dependency detected!");
} else {
TopologicalOrderIterator<Field, DefaultEdge> orderIterator;
Field f;
orderIterator = new TopologicalOrderIterator<Field, DefaultEdge>(dependencyGraph);
List<Field> output = new ArrayList<>(dependencyGraph.vertexSet().size());
while (orderIterator.hasNext()) {
f = orderIterator.next();
output.add(f);
}
return output;
}
}
示例2: build
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
private void build(Task task, ImmutableList.Builder<RunnableTaskDag> entriesBuilder, ImmutableMap.Builder<TaskId, Task> tasksBuilder)
{
DefaultDirectedGraph<TaskId, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
worker(graph, task, null, tasksBuilder, Sets.newHashSet());
CycleDetector<TaskId, DefaultEdge> cycleDetector = new CycleDetector<>(graph);
if ( cycleDetector.detectCycles() )
{
throw new RuntimeException("The Task DAG contains cycles: " + task);
}
TopologicalOrderIterator<TaskId, DefaultEdge> orderIterator = new TopologicalOrderIterator<>(graph);
while ( orderIterator.hasNext() )
{
TaskId taskId = orderIterator.next();
Set<DefaultEdge> taskIdEdges = graph.edgesOf(taskId);
Set<TaskId> processed = taskIdEdges
.stream()
.map(graph::getEdgeSource)
.filter(edge -> !edge.equals(taskId) && !edge.getId().equals(""))
.collect(Collectors.toSet());
entriesBuilder.add(new RunnableTaskDag(taskId, processed));
}
}
示例3: orderDag
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
private List<Handler<? extends Intent<? extends Resolution>>> orderDag(DirectedAcyclicGraph<Handler<? extends Intent<? extends Resolution>>, DefaultEdge> dag)
{
TopologicalOrderIterator<Handler<? extends Intent<? extends Resolution>>, DefaultEdge> topOrder = new TopologicalOrderIterator<>(dag);
List<Handler<? extends Intent<? extends Resolution>>> ordered = new ArrayList<>();
while(topOrder.hasNext()) {
Handler<? extends Intent<? extends Resolution>> handler = topOrder.next();
ordered.add(handler);
logger.debug("Added [{}] to ordered handler list", handler);
}
return ordered;
}
示例4: testCycleDetection
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
public void testCycleDetection() {
DefaultDirectedGraph<String, Object> g = new DefaultDirectedGraph<String, Object>(Object.class);
// Add vertices, e.g. equations.
g.addVertex("A");
g.addVertex("B");
g.addEdge("A", "B");
g.addVertex("D");
g.addVertex("A");
g.addEdge("D", "A");
g.addVertex("B");
g.addVertex("C");
g.addEdge("B", "C");
g.addVertex("G");
g.addVertex("H");
g.addEdge("G", "H");
g.addVertex("C");
g.addVertex("D");
g.addEdge("C", "D");
System.out.println(g.toString());
// Are there cycles in the dependencies.
CycleDetector<String, Object> cycleDetector = new CycleDetector<String, Object>(g);
// Cycle(s) detected.
if (cycleDetector.detectCycles()) {
System.out.println("Cycles detected.");
// Get all vertices involved in cycles.
Set<String> cycleVertices = cycleDetector.findCycles();
// Loop through vertices trying to find disjoint cycles.
while (!cycleVertices.isEmpty()) {
System.out.println("Cycle:");
// Get a vertex involved in a cycle.
Iterator<String> iterator = cycleVertices.iterator();
String cycle = iterator.next();
// Get all vertices involved with this vertex.
Set<String> subCycle = cycleDetector.findCyclesContainingVertex(cycle);
for (String sub : subCycle) {
System.out.println(" " + sub);
// Remove vertex so that this cycle is not encountered
// again.
cycleVertices.remove(sub);
}
}
}
// No cycles. Just output properly ordered vertices.
else {
TopologicalOrderIterator<String, Object> orderIterator = new TopologicalOrderIterator<String, Object>(g);
System.out.println("\nOrdering:");
while (orderIterator.hasNext()) {
String v = orderIterator.next();
System.out.println(v);
}
}
}
示例5: testClassfication
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
@Test
public void testClassfication() {
Automaton a = new RegExp("az+g(at|yg)").toAutomaton();
Gnfa g = Converter.INSTANCE.getGnfaFromAutomaton(a);
StateEliminator.INSTANCE.handleTrivialCases(g);
TopologicalOrderIterator<State, Transition> topOrder =
new TopologicalOrderIterator(g);
while (topOrder.hasNext()) {
State next = topOrder.next();
LOGGER.debug(next.getDotLabel());
}
Classifier.INSTANCE.classify(g);
LOGGER.debug(g.toDot());
}
示例6: getExtensionList
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
@Override
public ExtensionList getExtensionList() {
// Gets the list of all extensions
List<ExtensionFeatureDescription> extensionFeatures = applicationContext.getBeansOfType(ExtensionFeature.class).values().stream()
.map(ExtensionFeature::getFeatureDescription)
.sorted(Comparator.comparing(ExtensionFeatureDescription::getName))
.collect(Collectors.toList());
// Computing the dependencies
DefaultDirectedGraph<String, DefaultEdge> g = new DefaultDirectedGraph<>(DefaultEdge.class);
// Adds the extensions as vertexes
extensionFeatures.forEach(extensionFeatureDescription ->
g.addVertex(extensionFeatureDescription.getId())
);
// Adds the dependencies as edges
extensionFeatures.forEach(source ->
source.getOptions().getDependencies().forEach(target ->
g.addEdge(target, source.getId())
));
// Cycle detection
CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(g);
// If there are cycles
if (cycleDetector.detectCycles()) {
List<List<String>> cycles = new ArrayList<>();
Set<String> cycleVertices = cycleDetector.findCycles();
while (!cycleVertices.isEmpty()) {
List<String> subCycleList = new ArrayList<>();
// Get a vertex involved in a cycle.
Iterator<String> iterator = cycleVertices.iterator();
String cycle = iterator.next();
// Get all vertices involved with this vertex.
Set<String> subCycle = cycleDetector.findCyclesContainingVertex(cycle);
for (String sub : subCycle) {
subCycleList.add(sub);
// Remove vertex so that this cycle is not encountered again.
cycleVertices.remove(sub);
}
// Adds to the list of cycles
cycles.add(subCycleList);
}
// Throws an exception
throw new ExtensionCycleException(cycles);
}
// No cycle
else {
// Topological order to collect the leaf dependencies first
// See https://en.wikipedia.org/wiki/Dependency_graph
TopologicalOrderIterator<String, DefaultEdge> orderIterator =
new TopologicalOrderIterator<>(g);
// Order to extensions to load
List<String> order = new ArrayList<>();
while (orderIterator.hasNext()) {
String extension = orderIterator.next();
order.add(extension);
}
// Indexation of extensions per ID
Map<String, ExtensionFeatureDescription> index = extensionFeatures.stream().collect(Collectors.toMap(
ExtensionFeatureDescription::getId,
Function.identity()
));
// OK
return new ExtensionList(
order.stream()
.map(index::get)
.collect(Collectors.toList())
);
}
}
示例7: displayCyclesInfo
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
public static void displayCyclesInfo(
DefaultDirectedGraph<String, DefaultEdge> g) {
// Are there cycles in the dependencies.
CycleDetector<String, DefaultEdge> cycleDetector;
cycleDetector = new CycleDetector<String, DefaultEdge>(g);
// Cycle(s) detected.
if (cycleDetector.detectCycles()) {
Iterator<String> iterator;
Set<String> cycleVertices;
Set<String> subCycle;
String cycle;
System.out.println("Cycles detected.");
// Get all vertices involved in cycles.
cycleVertices = new HashSet<String>(cycleDetector.findCycles());
System.out.println("cv: " + cycleVertices);
for (String x1 : cycleVertices) {
System.out.println("SUBCYC: " + x1 + "\n" + cycleDetector.findCyclesContainingVertex(x1));
}
if (true) {
return;
}
// Loop through vertices trying to find disjoint cycles.
while (! cycleVertices.isEmpty()) {
System.out.println("Cycle:");
// Get a vertex involved in a cycle.
iterator = cycleVertices.iterator();
cycle = iterator.next();
// Get all vertices involved with this vertex.
subCycle = cycleDetector.findCyclesContainingVertex(cycle);
for (String sub : subCycle) {
System.out.println(" " + sub);
// Remove vertex so that this cycle is not encountered
// again.
cycleVertices.remove(sub);
}
}
}
// No cycles. Just output properly ordered vertices.
else {
String v;
TopologicalOrderIterator<String, DefaultEdge> orderIterator;
orderIterator =
new TopologicalOrderIterator<String, DefaultEdge>(g);
System.out.println("\nOrdering:");
while (orderIterator.hasNext()) {
v = orderIterator.next();
System.out.println(v);
}
}
}