Class Walk

All Implemented Interfaces:
Iterable<Integer>
Direct Known Subclasses:
Trail

public class Walk extends VertexList
A walk is a sequence of graph vertices such that any two consecutive vertices form an edge of the graph. Vertices can repeat. Edges can repeat. In order to ensure these properties are respected, call validate. A walk is closed if the last vertex equals the first one. The length of a walk is its number of edges.
Author:
Cristian Frăsinaru
See Also:
  • Field Details

    • numEdges

      protected int numEdges
  • Constructor Details

    • Walk

      public Walk(Graph graph)
    • Walk

      public Walk(Graph graph, int initialCapacity)
    • Walk

      public Walk(Graph graph, int[] vertices)
  • Method Details

    • type

      protected String type()
    • checkEdge

      protected void checkEdge(Edge e)
    • checkEdges

      protected final void checkEdges()
    • isValid

      public boolean isValid()
      Returns:
      false if the vertices do not represent the intendended structure.
    • add

      public boolean add(int v)
      Adds the vertex at the end of the walk, trail or path.
      Overrides:
      add in class VertexList
      Parameters:
      v - a vertex number
      Returns:
      true if the walk was modified as a result of this invocation.
    • isDirected

      public boolean isDirected()
      Returns:
      true, if it belongs to a directed graph.
    • isClosed

      public boolean isClosed()
      Returns:
      true, if the first vertex equals the last one.
    • length

      public int length()
      The length of the walk, trail, path or cycle (number of edges).
      Returns:
      the number of edges.
    • computeEdgesWeight

      public double computeEdgesWeight()
      Returns:
      the sum of the edge weights.
    • reverse

      public void reverse()
      Reverses the walk. 1-2-3 becomes 3-2-1. In case of directed graphs we have to check the reversed walk is valid.
    • toString

      public String toString()
      Overrides:
      toString in class VertexCollection
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class VertexCollection
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class VertexCollection