de.jstacs.models.discrete.inhomogeneous
Class CombinationIterator

java.lang.Object
  extended by de.jstacs.models.discrete.inhomogeneous.CombinationIterator

public class CombinationIterator
extends Object

This class can be used for iterating of all possible combinations

Author:
Jens Keilwagen

Constructor Summary
CombinationIterator(int n, int max)
          Creates a new CombinationIterator with n elements and at most max selected elements.
 
Method Summary
 int[] getCombination()
          Returns a clone of the internal combination.
 long getIndex(int[] combi)
          The combi has to be sorted.
 long getNumberOfCombinations(int elements)
          Returns the number of possible combinations
 boolean next()
          Steps to the next combination.
 void reset()
          This method reset the internal combination.
 void setCurrentLength(int current)
          This method sets the current used number of selected elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CombinationIterator

public CombinationIterator(int n,
                           int max)
Creates a new CombinationIterator with n elements and at most max selected elements.

Parameters:
n - the number of elements
max - the maximal number of selected elements
Method Detail

getNumberOfCombinations

public long getNumberOfCombinations(int elements)
                             throws IllegalArgumentException
Returns the number of possible combinations

Parameters:
elements - the number of selected elements
Returns:
the number of possible combinations
Throws:
IllegalArgumentException - if elements < 0

setCurrentLength

public void setCurrentLength(int current)
                      throws IllegalArgumentException
This method sets the current used number of selected elements.

Parameters:
current - the current used number of selected elements
Throws:
IllegalArgumentException - if current < 0 or current > max

next

public boolean next()
             throws IllegalArgumentException
Steps to the next combination.

Returns:
true if the method does not run out of range
Throws:
IllegalArgumentException - if the method setCurrentLength() was not used

getCombination

public int[] getCombination()
Returns a clone of the internal combination.

Returns:
a clone of the internal combination

getIndex

public long getIndex(int[] combi)
The combi has to be sorted.

Parameters:
combi - the combination
Returns:
the index

reset

public void reset()
           throws IllegalArgumentException
This method reset the internal combination.

Throws:
IllegalArgumentException - if the method setCurrentLength() was not used