本文整理汇总了Java中org.jgrapht.traverse.TopologicalOrderIterator.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java TopologicalOrderIterator.hasNext方法的具体用法?Java TopologicalOrderIterator.hasNext怎么用?Java TopologicalOrderIterator.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.traverse.TopologicalOrderIterator
的用法示例。
在下文中一共展示了TopologicalOrderIterator.hasNext方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: orderClassesByHierarchy
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
private List< Type > orderClassesByHierarchy( List< Type > classes )
{
DirectedGraph< Type, DefaultEdge > classHierarchyGraph = new DefaultDirectedGraph< Type, DefaultEdge >( DefaultEdge.class );
// Pass 1: add vertexes.
for ( Type aClass : classes )
classHierarchyGraph.addVertex( aClass );
// Pass 2: add edges.
for ( Type subClass : classes )
{
Type closestSuperClass = null;
for ( Type potentialSuperClass : classes )
{
if ( !potentialSuperClass.equals( subClass ) && isSubclass( potentialSuperClass, subClass ) )
{
if ( closestSuperClass == null || !isSubclass( potentialSuperClass, closestSuperClass ) )
closestSuperClass = potentialSuperClass;
}
}
if ( closestSuperClass != null )
classHierarchyGraph.addEdge( closestSuperClass, subClass );
}
TopologicalOrderIterator< Type, DefaultEdge > iter = new TopologicalOrderIterator< Type, DefaultEdge >( classHierarchyGraph );
List< Type > orderedClasses = new ArrayList< Type >();
while ( iter.hasNext() )
orderedClasses.add( iter.next() );
Collections.reverse( orderedClasses );
return orderedClasses;
}
示例6: getOrderedList
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
public List<Class> getOrderedList() {
List<Class> result = new ArrayList<Class>();
TopologicalOrderIterator<Class, DefaultEdge> orderIterator;
orderIterator = new TopologicalOrderIterator<Class, DefaultEdge>(g);
while (orderIterator.hasNext()) {
result.add(orderIterator.next());
}
return result;
}
示例7: 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());
}
示例8: cacheRegex
import org.jgrapht.traverse.TopologicalOrderIterator; //导入方法依赖的package包/类
private static void cacheRegex(String regex) {
String r = expandRegex(regex);
Automaton automaton = new RegExp(r, RegExp.NONE).toAutomaton();
automaton.expandSingleton();
// We convert this to a graph without self-loops in order to determine the topological order
DirectedGraph<State, DefaultEdge> regexGraph = new DefaultDirectedGraph<State, DefaultEdge>(
DefaultEdge.class);
Set<State> visitedStates = new HashSet<State>();
Queue<State> states = new LinkedList<State>();
State initialState = automaton.getInitialState();
states.add(initialState);
while (!states.isEmpty()) {
State currentState = states.poll();
if (visitedStates.contains(currentState))
continue;
if (!regexGraph.containsVertex(currentState))
regexGraph.addVertex(currentState);
for (Transition t : currentState.getTransitions()) {
// Need to get rid of back edges, otherwise there is no topological order!
if (!t.getDest().equals(currentState)) {
regexGraph.addVertex(t.getDest());
regexGraph.addEdge(currentState, t.getDest());
states.add(t.getDest());
CycleDetector<State, DefaultEdge> det = new CycleDetector<State, DefaultEdge>(
regexGraph);
if (det.detectCycles()) {
regexGraph.removeEdge(currentState, t.getDest());
}
}
}
visitedStates.add(currentState);
}
TopologicalOrderIterator<State, DefaultEdge> iterator = new TopologicalOrderIterator<State, DefaultEdge>(
regexGraph);
List<State> topologicalOrder = new ArrayList<State>();
while (iterator.hasNext()) {
topologicalOrder.add(iterator.next());
}
regexStateCache.put(regex, topologicalOrder);
regexAutomatonCache.put(regex, automaton);
}
示例9: 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())
);
}
}
示例10: 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);
}
}
}