Class RandomWalk<V>

  • Type Parameters:
    V - the type parameter
    All Implemented Interfaces:
    GraphTraversal<V>, Serializable

    public class RandomWalk<V>
    extends Object
    implements GraphTraversal<V>, Serializable

    Performs a random walk over the vertices in the graph. If the graph is weighted, the next vertex is randomly selected proportional to the successor vertices' weight. If the graph is not weighted, the next vertex is uniformly randomly selected.

    Author:
    David B. Bracewell
    See Also:
    Serialized Form
    • Constructor Detail

      • RandomWalk

        public RandomWalk​(Graph<V> graph)
        Default Constructor testPath(source);
        Parameters:
        graph - The graph we will visit
      • RandomWalk

        public RandomWalk​(Graph<V> graph,
                          boolean isWeighted)
        Default Constructor
        Parameters:
        graph - The graph we will visit
        isWeighted - True if use weights to determine the next step
    • Method Detail

      • iterator

        public Iterator<V> iterator​(V startingVertex)
        Description copied from interface: GraphTraversal
        An iterator to traverse the graph starting at the given vertex
        Specified by:
        iterator in interface GraphTraversal<V>
        Parameters:
        startingVertex - the starting point
        Returns:
        the iterator
      • walk

        public V walk​(V startingVertex,
                      int numberOfSteps)
        Selecte a vertex by taking a given number of steps from the starting vertex
        Parameters:
        startingVertex - the starting vertex
        numberOfSteps - the number of steps
        Returns:
        the vertex ended upon after the given number of steps.