|
Orbital library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object orbital.algorithm.Combinatorical
public abstract class Combinatorical
Class for combinatorical operations.
This class can be used to perform combinatorical operations
using the iterator methods of an instance of Combinatorical
(usually) obtained via getInstance(int,boolean,int,boolean)
.
Instances of this class will help to iterate over all
elements of such a combinatorial set like permutations or combinations.
Apart from methods for forward and backward navigation,
a priori counting queries are provided to determine the
number of elements in advance.
Combinatorical c = Combinatorical.getPermutations(5, false);
System.out.println(c.count());
while (c.hasNext()) {
int[] v = c.next();
System.out.println(orbital.math.MathUtilities.format(v));
}
getInstance(int,boolean,int,boolean)
,
Serialized FormConstructor Summary | |
---|---|
Combinatorical()
|
Method Summary | |
---|---|
static java.util.ListIterator |
asIterator(Combinatorical c)
Get an iterator view of a combinatorical iterator. |
abstract int |
count()
Returns the number of combinatorical tuples that araise from this sequence. |
static Combinatorical |
getCombinations(int r,
int n,
boolean repetition)
Get all r-combinations of n elements. |
static Combinatorical |
getInstance(int r,
boolean combinations,
int n,
boolean repetition)
Get a combinatorical instance. |
static Combinatorical |
getPermutations(int[] n)
Get all (generalized) permutations elements. |
static Combinatorical |
getPermutations(int n,
boolean repetition)
|
static Combinatorical |
getPermutations(int r,
int n,
boolean repetition)
Get all r-permutations of n elements. |
abstract boolean |
hasNext()
Whether this sequence has a next combinatorical tuple. |
abstract boolean |
hasPrevious()
Whether this sequence has a previous combinatorical tuple. |
abstract int[] |
next()
Get the next combinatorical tuple. |
abstract int[] |
previous()
Get the previous combinatorical tuple. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Combinatorical()
Method Detail |
---|
public abstract int count()
public abstract boolean hasNext()
public abstract int[] next()
java.util.NoSuchElementException
- if not hasNext().public abstract boolean hasPrevious()
public abstract int[] previous()
java.util.NoSuchElementException
- if not hasPrevious().public static Combinatorical getInstance(int r, boolean combinations, int n, boolean repetition)
r
- the size of the tuples.
The number of elements to choose out of n.combinations
- whether only combinations are allowed, or every permutation.
Permutations are the bijective maps from {1,...,M} to {1,...,M}.
Combinations are those permutations ignoring order and(!) whose elements are always sorted.
So this is like the difference between a set and a listn
- the number of elements choosable. n = |M|.repetition
- whether elements in a tuple are allowed to repeat.getPermutations(int, int, boolean)
,
getCombinations(int, int, boolean)
public static Combinatorical getPermutations(int r, int n, boolean repetition)
r
- the size of the tuples to permute.
The number of elements to choose out of n per tuple.n
- the number of elements choosable. n = |M|.repetition
- whether elements in a tuple are allowed to repeat.
The permutations with repetition contain nr,
those without repetition contain nPr tuples.public static Combinatorical getPermutations(int n, boolean repetition)
public static Combinatorical getPermutations(int[] n)
n
- the numbers of elements choosable. r := n.length is the size of the tuples
and n[i] is the number of elements choosable for the element at index i of the tuple.
They are numbered 0, ..., n[i]-1.public static Combinatorical getCombinations(int r, int n, boolean repetition)
r
- the size of the tuples to combinate.
The number of elements to choose out of n per tuple.n
- the number of elements choosable. n = |M|.repetition
- whether elements in a tuple are allowed to repeat.
The combinations with repetition contain (n + rr -1),
those without repetition contain nCr = (nr) tuples.public static final java.util.ListIterator asIterator(Combinatorical c)
|
Orbital library 1.3.0: 11 Apr 2009 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |