本文整理汇总了Java中org.paukov.combinatorics.Generator类的典型用法代码示例。如果您正苦于以下问题:Java Generator类的具体用法?Java Generator怎么用?Java Generator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Generator类属于org.paukov.combinatorics包,在下文中一共展示了Generator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createStates
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
public void createStates()
{
// Create the initial vector of 2 elements (0 and 1 to represent black and white)
ICombinatoricsVector<Integer> originalVector = Factory.createVector(new Integer[] { 0, 1 });
// Set the second parameter as 9, since we are permutating with 9 discs.
Generator<Integer> gen = Factory.createPermutationWithRepetitionGenerator(originalVector, 9);
for (ICombinatoricsVector<Integer> permuation : gen)
{
int[][] generatedState = new int[3][3];
List<Integer> listOfGeneratedStates = permuation.getVector();
int numOfState = 0;
for(int y = 0; y < 3; y++)
{
for(int x = 0; x < 3; x++)
{
generatedState[x][y] = listOfGeneratedStates.get(numOfState);
numOfState++;
}
}
setOfStates.add(generatedState);
}
}
示例2: simple_combinations
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void simple_combinations() {
System.out.println("===== Simple Combinations: =====");
// Create the initial vector
ICombinatoricsVector<String> initialVector = Factory
.createVector(new String[]{"red", "black", "white", "green",
"blue"});
// Create a simple combination generator to generate 3-combinations of
// the initial vector
Generator<String> gen = Factory.createSimpleCombinationGenerator(
initialVector, 3);
// Print all possible combinations
for (ICombinatoricsVector<String> combination : gen) {
System.out.println(combination);
}
}
示例3: multi_combinations
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void multi_combinations() {
System.out.println("===== Multi Combinations: =====");
// Create the initial vector of (apple, orange)
ICombinatoricsVector<String> initialVector = Factory
.createVector(new String[]{"apple", "orange"});
// Create a multi-combination generator to generate 3-combinations of
// the initial vector
Generator<String> gen = Factory.createMultiCombinationGenerator(
initialVector, 3);
// Print all possible combinations
for (ICombinatoricsVector<String> combination : gen) {
System.out.println(combination);
}
}
示例4: permutation_with_repetitions
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void permutation_with_repetitions() {
System.out.println("===== Permutation With Repetitions: =====");
// Create the initial set/vector of 2 elements (apple, orange)
ICombinatoricsVector<String> originalVector = Factory
.createVector(new String[]{"apple", "orange"});
// Create the generator by calling the appropriate method in the Factory
// class
Generator<String> gen = Factory
.createPermutationWithRepetitionGenerator(originalVector, 3);
// Print the result
for (ICombinatoricsVector<String> perm : gen)
System.out.println(perm);
}
示例5: permutation_without_repetitions
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void permutation_without_repetitions() {
System.out.println("===== Permutations Without Repetitions: =====");
// Create the initial set/vector of 3 elements (apple, orange, cherry)
ICombinatoricsVector<String> originalVector = Factory
.createVector(new String[]{"apple", "orange", "cherry"});
// Create the permutation generator by calling the appropriate method in
// the Factory class
Generator<String> gen = Factory
.createPermutationGenerator(originalVector);
// Print the result
for (ICombinatoricsVector<String> perm : gen)
System.out.println(perm);
}
示例6: complex_combination_indexes_example
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void complex_combination_indexes_example() {
System.out.println("===== Complex Combination Indexes Example (List partitions): =====");
// A list of elements
String[] elements = new String[]{"A", "B", "B", "C"};
// create a combinatorics vector of indexes (1, 1, 3)
ICombinatoricsVector<Integer> indixesVector = Factory
.createVector(new Integer[]{1, 1, 3});
// Create a complex-combination generator
Generator<ICombinatoricsVector<Integer>> complexGenerator = new ComplexCombinationGenerator<Integer>(
indixesVector, 2);
// Iterate the elements
for (ICombinatoricsVector<ICombinatoricsVector<Integer>> combination : complexGenerator) {
String str = ComplexCombinationGenerator.convertIndexes2String(
elements, combination);
System.out.println(str);
}
}
示例7: complex_combination_example
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void complex_combination_example() {
System.out.println("complexCombinationExample");
System.out.println("===== Complex Combination Example: =====");
// create a combinatorics vector (A, B, B, C)
ICombinatoricsVector<String> vector = Factory
.createVector(new String[]{"A", "B", "B", "C"});
// Create a complex-combination generator
Generator<ICombinatoricsVector<String>> gen = new ComplexCombinationGenerator<String>(
vector, 2);
// Iterate the combinations
for (ICombinatoricsVector<ICombinatoricsVector<String>> comb : gen) {
System.out.println(ComplexCombinationGenerator.convert2String(comb)
+ " - " + comb);
}
}
示例8: simple_subsets
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void simple_subsets() {
System.out.println("===== All subsets: =====");
// Create an initial vector/set
ICombinatoricsVector<String> initialSet = Factory
.createVector(new String[]{"one", "two", "three"});
// Create an instance of the subset generator
Generator<String> gen = Factory.createSubSetGenerator(initialSet);
// Print the subsets
for (ICombinatoricsVector<String> subSet : gen) {
System.out.println(subSet);
}
}
示例9: duplicate_subsets
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void duplicate_subsets() {
System.out.println("===== All subsets with duplicates: =====");
// Create an initial vector/set (a, b, a, c)
ICombinatoricsVector<String> initialSet = Factory
.createVector(new String[]{"a", "b", "a", "c"});
// Create an instance of the subset generator
Generator<String> gen = Factory
.createSubSetGenerator(initialSet, false);
// Print the subsets
for (ICombinatoricsVector<String> subSet : gen) {
System.out.println(subSet);
}
}
示例10: simple_with_equal_elements_permutation
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
static void simple_with_equal_elements_permutation() {
System.out.println("===== Simple With Equal Elements Permutations: =====");
// Create the initial vector
ICombinatoricsVector<Integer> initialVector = Factory
.createVector(new Integer[]{1, 1, 2, 2});
// Create the generator
Generator<Integer> generator = Factory
.createPermutationGenerator(initialVector);
for (ICombinatoricsVector<Integer> perm : generator) {
System.out.println(perm);
}
}
示例11: all_permutations_of_all_combination
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
/**
* This example recreates the issue 14.
* https://code.google.com/p/combinatoricslib/issues/detail?id=14
*
* It generates all permutations of a given length where repetition is NOT allowed,
* from a larger set of elements.
*/
static void all_permutations_of_all_combination() {
System.out.println("===== All permutations of all combination: =====");
// Create the initial vector of 4 elements (apple, orange, cherry, raspberry)
ICombinatoricsVector<String> originalVector = Factory.createVector(
new String[] { "apple", "orange", "cherry", "raspberry" }
);
// Create the combination generator by calling the appropriate method in the Factory class
Generator<String> combinations = Factory.createSimpleCombinationGenerator(originalVector, 3);
// Print all permutations for all simple 3-combinations
for (ICombinatoricsVector<String> comb : combinations){
Generator<String> permutations = Factory.createPermutationGenerator(comb);
for(ICombinatoricsVector<String> perm : permutations){
System.out.println(perm);
}
}
}
示例12: simpleEmptyPermutation
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
@Test
public void simpleEmptyPermutation() {
ArrayList<Integer> array = new ArrayList<Integer>();
ICombinatoricsVector<Integer> corePermutation = Factory
.createVector(array);
Generator<Integer> generator = Factory
.createPermutationGenerator(corePermutation);
System.out.println("Number of permutations is: "
+ generator.getNumberOfGeneratedObjects());
assertEquals(0, generator.getNumberOfGeneratedObjects());
Iterator<ICombinatoricsVector<Integer>> iterator = generator.iterator();
while (iterator.hasNext()) {
iterator.next();
System.out.println(iterator);
}
List<ICombinatoricsVector<Integer>> list = generator
.generateAllObjects();
assertEquals(0, list.size());
}
示例13: allIdenticalPermutation
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
@Test
public void allIdenticalPermutation() {
ICombinatoricsVector<String> initialVector = Factory
.createVector(new String[] { "a", "a", "a" });
Generator<String> generator = Factory
.createPermutationGenerator(initialVector);
Iterator<ICombinatoricsVector<String>> iterator = generator.iterator();
while (iterator.hasNext()) {
iterator.next();
System.out.println(iterator);
}
List<ICombinatoricsVector<String>> list = generator
.generateAllObjects();
assertEquals(1, list.size());
assertEquals("CombinatoricsVector=([a, a, a], size=3)", list.get(0)
.toString());
}
示例14: simpleOnePartition
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
@Test
public void simpleOnePartition() {
Generator<Integer> partitionGenerator = Factory
.createPartitionGenerator(1);
Iterator<ICombinatoricsVector<Integer>> partitionIterator = partitionGenerator
.iterator();
System.out.println("Number of partition is: "
+ partitionGenerator.getNumberOfGeneratedObjects());
assertEquals(1, partitionGenerator.getNumberOfGeneratedObjects());
while (partitionIterator.hasNext()) {
partitionIterator.next();
System.out.println(partitionIterator);
}
List<ICombinatoricsVector<Integer>> list = partitionGenerator
.generateAllObjects();
assertEquals(1, list.size());
assertEquals("CombinatoricsVector=([1], size=1)", list.get(0)
.toString());
}
示例15: simpleEmptyPartition
import org.paukov.combinatorics.Generator; //导入依赖的package包/类
@Test
public void simpleEmptyPartition() {
Generator<Integer> partitionGenerator = Factory
.createPartitionGenerator(0);
Iterator<ICombinatoricsVector<Integer>> partitionIterator = partitionGenerator
.iterator();
System.out.println("Number of partition is: "
+ partitionGenerator.getNumberOfGeneratedObjects());
assertEquals(0, partitionGenerator.getNumberOfGeneratedObjects());
while (partitionIterator.hasNext()) {
partitionIterator.next();
System.out.println(partitionIterator);
}
List<ICombinatoricsVector<Integer>> list = partitionGenerator
.generateAllObjects();
assertEquals(0, list.size());
}