Package org.graph4j.traversal
Class MaximumCardinalityIterator
java.lang.Object
org.graph4j.traversal.MaximumCardinalityIterator
- All Implemented Interfaces:
IntIterator
Implements an iterator that performs Maximum Cardinality Search (MCS)
algorithm on an undirected graph.
MCS is a graph traversal algorithm which orders the vertices based on their
cardinality in non-increasing order. The
cardinality of a vertex is defined as the number of its neighbors,
which have been already visited by this iterator. At each step, the iterator
chooses a vertex with maximum cardinality, breaking ties arbitrarily.
- Author:
- Cristian Frăsinaru
-
Constructor Summary
ConstructorsConstructorDescriptionMaximumCardinalityIterator(Graph graph) Creates an iterator starting with the first vertex of the graph (the one at index 0)MaximumCardinalityIterator(Graph graph, int start) Creates an iterator starting with the specified vertex. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graph4j.util.IntIterator
remove
-
Constructor Details
-
MaximumCardinalityIterator
Creates an iterator starting with the first vertex of the graph (the one at index 0)- Parameters:
graph- the input graph.
-
MaximumCardinalityIterator
Creates an iterator starting with the specified vertex.- Parameters:
graph- the input graph.start- the start vertex number.- Throws:
InvalidVertexException- if the graph does not contain the start vertex.
-
-
Method Details
-
hasNext
public boolean hasNext()Description copied from interface:IntIteratorReturnstrueif the iteration has more elements.- Specified by:
hasNextin interfaceIntIterator- Returns:
trueif the iteration has more elements,falseotherwise.
-
next
public int next()Description copied from interface:IntIteratorReturns the next element in the iteration.- Specified by:
nextin interfaceIntIterator- Returns:
- the next element in the iteration.
-
currentVertexId
public int currentVertexId() -
cardinality
public int cardinality()
-