Module org.jhotdraw8.graph
Package org.jhotdraw8.graph.path.algo
Class AllWalksSpliterator<V,A,C extends Number & Comparable<C>,E>
java.lang.Object
java.util.Spliterators.AbstractSpliterator<OrderedPair<ImmutableList<E>,C>>
org.jhotdraw8.collection.enumerator.AbstractEnumerator<OrderedPair<ImmutableList<E>,C>>
org.jhotdraw8.graph.path.algo.AllWalksSpliterator<V,A,C,E>
- Type Parameters:
V- the vertex data typeA- the arrow data typeC- the cost number typeE- the element type of the path
- All Implemented Interfaces:
Spliterator<OrderedPair<ImmutableList<E>,,C>> BareEnumerator<OrderedPair<ImmutableList<E>,,C>> Enumerator<OrderedPair<ImmutableList<E>,C>>
public class AllWalksSpliterator<V,A,C extends Number & Comparable<C>,E>
extends AbstractEnumerator<OrderedPair<ImmutableList<E>,C>>
Iterates over all walks from a set of start vertices to a set of goal
vertices using a breadth-first search.
Only enumerates walks that contain a goal once.
Expected run time: The enumeration of all walks in a graph is NP-complete. (Because counting paths is #P-complete).
Only run this algorithm on acyclic graphs. In graphs with cycles the
algorithm may run out of space, and will then throw a
IllegalStateException.
In an acyclic graph, the algorithm will return paths (a path is a walk
that only contains each vertex once).
References:
- Leslie G. Valiant. (1979)
- The Complexity of Enumeration and Reliability Problems. Chapter 4. Some #P-complete problems. Item 11. S-T CONNECTEDNESS math.cmu.edu
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jhotdraw8.collection.enumerator.Enumerator
Enumerator.OfDouble, Enumerator.OfInt, Enumerator.OfLongNested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
Fields inherited from class org.jhotdraw8.collection.enumerator.AbstractEnumerator
currentFields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED -
Constructor Summary
ConstructorsConstructorDescriptionAllWalksSpliterator(@NonNull Iterable<V> startVertices, @NonNull Predicate<V> goalPredicate, @NonNull Function<V, Iterable<Arc<V, A>>> nextArcsFunction, @NonNull Function<ArcBackLinkWithCost<V, A, C>, OrderedPair<ImmutableList<E>, C>> sequenceFunction, int maxDepth, @NonNull C maxCost, @NonNull C zero, @NonNull Function3<V, V, A, C> costFunction, @NonNull BiFunction<C, C, C> sumFunction) Creates a new instance. -
Method Summary
Methods inherited from class org.jhotdraw8.collection.enumerator.AbstractEnumerator
currentMethods inherited from class java.util.Spliterators.AbstractSpliterator
characteristics, estimateSize, trySplitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jhotdraw8.collection.enumerator.Enumerator
tryAdvanceMethods inherited from interface java.util.Spliterator
characteristics, estimateSize, forEachRemaining, getComparator, getExactSizeIfKnown, hasCharacteristics, trySplit
-
Constructor Details
-
AllWalksSpliterator
public AllWalksSpliterator(@NonNull Iterable<V> startVertices, @NonNull Predicate<V> goalPredicate, @NonNull Function<V, Iterable<Arc<V, A>>> nextArcsFunction, @NonNull Function<ArcBackLinkWithCost<V, A, C>, OrderedPair<ImmutableList<E>, C>> sequenceFunction, int maxDepth, @NonNull C maxCost, @NonNull C zero, @NonNull Function3<V, V, A, C> costFunction, @NonNull BiFunction<C, C, C> sumFunction) Creates a new instance.- Parameters:
startVertices- the set of start verticesgoalPredicate- the goal predicatenextArcsFunction- the next arcs functionsequenceFunction- the function that maps back links to a sequencemaxDepth- the maximal depth (inclusive) of the search Must be >= 0.maxCost- the maximal cost (inclusive) of a sequence Must be >= zero.zero- the zero cost valuecostFunction- the cost function.sumFunction- the function for adding two cost values
-
-
Method Details
-
moveNext
public boolean moveNext()- Returns:
- true on success
- Throws:
IllegalStateException- if the underlying queue runs out of space
-