|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.knime.base.util.math.Combinations
public final class Combinations
This class comes in handy if you want to compute combinations and process
them in some way. A combination is a subset of k elements from a
set of m elements.
The rank(int[]) and unrank(long) methods are based on
Gary D. Knott: "A Numbering System for Combinations", CACM, 17(1), 1974,
pp. 45-46.
The enumerate(Callback), and
enumerate(long, long, Callback) methods are based on
Charles J. Mifsud: "Algorithm 154: Combination in lexicographical order",
CACM, 6(3), 1963, p. 103.
| Nested Class Summary | |
|---|---|
static interface |
Combinations.Callback
Callback interface used by the various visit methods. |
| Constructor Summary | |
|---|---|
Combinations(int n,
int k)
Create a combination object. |
|
| Method Summary | |
|---|---|
void |
enumerate(Combinations.Callback callback)
Enumerates all combinations and calls the callback for each combination. |
void |
enumerate(int threads,
Combinations.Callback callback)
Enumerates all combinations and calls the callback for each combination. |
void |
enumerate(long from,
long to,
Combinations.Callback callback)
Enumerates all combinations from rank from until rank to (inclusive). |
long |
getNumberOfCombinations()
Returns the number of possible combinations for n and k specified in the constructor. |
static long |
getNumberOfCombinations(int n,
int k)
Returns the number of possible combinations when selecting k elements from a set of n elements (without repetition). |
static BigInteger |
getNumberOfCombinationsBig(int n,
int k)
Returns the number of possible combinations when selecting k elements from a set of n elements (without repetition). |
long |
rank(int[] p)
Computes the unique rank of the given combination. |
int[] |
unrank(long k)
Creates the unique combination associated with the given rank number. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Combinations(int n,
int k)
n - the total number of elementsk - the number of selected elements| Method Detail |
|---|
public long getNumberOfCombinations()
public long rank(int[] p)
p - a valid combination
getNumberOfCombinations() - 1.public int[] unrank(long k)
k - the rank, a number between 0 and
getNumberOfCombinations() - 1.
public static long getNumberOfCombinations(int n,
int k)
n - the size of the setk - the number of selected elements
ArithmeticException - if an overflow occurs during computing. In
this case you can use getNumberOfCombinationsBig(int, int)
instead (which is slower, but works for arbitrary big numbers).
public static BigInteger getNumberOfCombinationsBig(int n,
int k)
n - the size of the setk - the number of selected elements
public void enumerate(Combinations.Callback callback)
callback - the callback class
public void enumerate(long from,
long to,
Combinations.Callback callback)
from - the first combination to be enumeratedto - the last combination to be enumeratedcallback - the callback
public void enumerate(int threads,
Combinations.Callback callback)
throws InterruptedException
threads - the number of threads to usecallback - the callback class
InterruptedException - if this thread was interrupted while waiting
for the enumeration to finish
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||