de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous
Class CombinationIterator

java.lang.Object
  extended by de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.CombinationIterator

public class CombinationIterator
extends Object

This class can be used for iterating over all possible combinations (in the sense of combinatorics).

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)
          This method returns an index for the sorted entries of a combination combi.
 long getNumberOfCombinations(int elements)
          Returns the number of possible combinations.
 boolean next()
          Steps to the next combination.
 void reset()
          This method resets 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
See Also:
reset()

next

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

Returns:
true if the method does not run out of range, false otherwise
Throws:
IllegalArgumentException - if the method setCurrentLength(int)was not used to set the current used number of selected elements

getCombination

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

Returns:
a clone of the internal combination

getIndex

public long getIndex(int[] combi)
This method returns an index for the sorted entries of a combination combi.

Parameters:
combi - the combination
Returns:
the index

reset

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

Throws:
IllegalArgumentException - if the method setCurrentLength(int) was not used to set the current used number of selected elements