## Class RandomWalkIterator<V,​E>

• Type Parameters:
V - vertex type
E - edge type
All Implemented Interfaces:
java.util.Iterator<V>, GraphIterator<V,​E>

@Deprecated
public class RandomWalkIterator<V,​E>
extends AbstractGraphIterator<V,​E>
Deprecated.
A random walk iterator for a directed or undirected graph.

At each step the iterator selects a random (uniformly distributed) edge out of the current vertex and follows it to the next vertex. In case of directed graphs the outgoing edge set is used. See wikipedia for more details.

In case a weighted walk is desired, edges are selected with probability respective to its weight (out of the total weight of the edges). The walk can be bounded by number of steps (default Long#MAX_VALUE . When the bound is reached the iterator is considered exhausted. Calling next() on exhausted iterator will throw NoSuchElementException. In case a sink (i.e. no edges) vertex is reached, any consecutive calls to next() will throw NoSuchElementException.

For this iterator to work correctly the graph must not be modified during iteration. Currently there are no means to ensure that, nor to fail-fast. The results of such modifications are undefined.

Author:
Assaf Mizrachi

• ### Fields inherited from class org.jgrapht.traverse.AbstractGraphIterator

crossComponentTraversal, graph, nListeners, reusableEdgeEvent, reusableVertexEvent, reuseEvents
• ### Constructor Summary

Constructors
Constructor Description
RandomWalkIterator​(Graph<V,​E> graph)
Deprecated.
Creates a new iterator for the specified graph.
RandomWalkIterator​(Graph<V,​E> graph, V startVertex)
Deprecated.
Creates a new iterator for the specified graph.
RandomWalkIterator​(Graph<V,​E> graph, V startVertex, boolean isWeighted)
Deprecated.
Creates a new iterator for the specified graph.
RandomWalkIterator​(Graph<V,​E> graph, V startVertex, boolean isWeighted, long maxSteps)
Deprecated.
Creates a new iterator for the specified graph.
RandomWalkIterator​(Graph<V,​E> graph, V startVertex, boolean isWeighted, long maxSteps, java.util.Random rng)
Deprecated.
Creates a new iterator for the specified graph.
• ### Method Summary

All Methods
Modifier and Type Method Description
protected void encounterVertex​(V vertex, E edge)
Deprecated.
Update data structures every time we see a vertex.
boolean hasNext()
Deprecated.

protected boolean isExhausted()
Deprecated.
Check if this walk is exhausted.
V next()
Deprecated.

• ### Methods inherited from class org.jgrapht.traverse.AbstractGraphIterator

addTraversalListener, createEdgeTraversalEvent, createVertexTraversalEvent, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, getGraph, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setCrossComponentTraversal, setReuseEvents
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Methods inherited from interface java.util.Iterator

forEachRemaining
• ### Constructor Detail

• #### RandomWalkIterator

public RandomWalkIterator​(Graph<V,​E> graph)
Deprecated.
Creates a new iterator for the specified graph. Iteration will start at arbitrary vertex. Walk is un-weighted and bounded by Long#MAX_VALUE steps.
Parameters:
graph - the graph to be iterated.
Throws:
java.lang.IllegalArgumentException - if graph==null or does not contain startVertex
• #### RandomWalkIterator

public RandomWalkIterator​(Graph<V,​E> graph,
V startVertex)
Deprecated.
Creates a new iterator for the specified graph. Iteration will start at the specified start vertex. If the specified start vertex is  null, Iteration will start at an arbitrary graph vertex. Walk is un-weighted and bounded by Long#MAX_VALUE steps.
Parameters:
graph - the graph to be iterated.
startVertex - the vertex iteration to be started.
Throws:
java.lang.IllegalArgumentException - if graph==null or does not contain startVertex
• #### RandomWalkIterator

public RandomWalkIterator​(Graph<V,​E> graph,
V startVertex,
boolean isWeighted)
Deprecated.
Creates a new iterator for the specified graph. Iteration will start at the specified start vertex. If the specified start vertex is  null, Iteration will start at an arbitrary graph vertex. Walk is bounded by Long#MAX_VALUE steps.
Parameters:
graph - the graph to be iterated.
startVertex - the vertex iteration to be started.
isWeighted - set to true if a weighted walk is desired.
Throws:
java.lang.IllegalArgumentException - if graph==null or does not contain startVertex
• #### RandomWalkIterator

public RandomWalkIterator​(Graph<V,​E> graph,
V startVertex,
boolean isWeighted,
long maxSteps)
Deprecated.
Creates a new iterator for the specified graph. Iteration will start at the specified start vertex. If the specified start vertex is  null, Iteration will start at an arbitrary graph vertex. Walk is bounded by the provided number steps.
Parameters:
graph - the graph to be iterated.
startVertex - the vertex iteration to be started.
isWeighted - set to true if a weighted walk is desired.
maxSteps - number of steps before walk is exhausted.
Throws:
java.lang.IllegalArgumentException - if graph==null or does not contain startVertex
• #### RandomWalkIterator

public RandomWalkIterator​(Graph<V,​E> graph,
V startVertex,
boolean isWeighted,
long maxSteps,
java.util.Random rng)
Deprecated.
Creates a new iterator for the specified graph. Iteration will start at the specified start vertex. If the specified start vertex is  null, Iteration will start at an arbitrary graph vertex. Walk is bounded by the provided number steps.
Parameters:
graph - the graph to be iterated.
startVertex - the vertex iteration to be started.
isWeighted - set to true if a weighted walk is desired.
maxSteps - number of steps before walk is exhausted.
rng - the random number generator to use
Throws:
java.lang.IllegalArgumentException - if graph==null or does not contain startVertex
• ### Method Detail

• #### isExhausted

protected boolean isExhausted()
Deprecated.
Check if this walk is exhausted. Calling next() on exhausted iterator will throw NoSuchElementException.
Returns:
trueif this iterator is exhausted, false otherwise.
• #### encounterVertex

protected void encounterVertex​(V vertex,
E edge)
Deprecated.
Update data structures every time we see a vertex.
Parameters:
vertex - the vertex encountered
edge - the edge via which the vertex was encountered, or null if the vertex is a starting point
• #### hasNext

public boolean hasNext()
Deprecated.
• #### next

public V next()
Deprecated.