本文整理汇总了Java中org.paukov.combinatorics.Factory类的典型用法代码示例。如果您正苦于以下问题:Java Factory类的具体用法?Java Factory怎么用?Java Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Factory类属于org.paukov.combinatorics包,在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createStates
import org.paukov.combinatorics.Factory; //导入依赖的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: attrCombTest
import org.paukov.combinatorics.Factory; //导入依赖的package包/类
@Test
public void attrCombTest() {
Attribute isbn = new Attribute("isbn", Type.TEXT);
Attribute author = new Attribute("author", Type.TEXT);
Attribute binding = new Attribute("binding", Type.TEXT);
List<Attribute> attrs = new ArrayList<Attribute>();
attrs.add(isbn);
attrs.add(author);
attrs.add(binding);
ICombinatoricsVector<Attribute> initialVector = Factory.createVector(attrs);
List<Attribute> newAttrs = (List<Attribute>) initialVector;
System.out.println(newAttrs);
}
示例3: simple_combinations
import org.paukov.combinatorics.Factory; //导入依赖的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);
}
}
示例4: multi_combinations
import org.paukov.combinatorics.Factory; //导入依赖的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);
}
}
示例5: permutation_with_repetitions
import org.paukov.combinatorics.Factory; //导入依赖的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);
}
示例6: permutation_without_repetitions
import org.paukov.combinatorics.Factory; //导入依赖的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);
}
示例7: complex_combination_example
import org.paukov.combinatorics.Factory; //导入依赖的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.Factory; //导入依赖的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.Factory; //导入依赖的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: simpleFiveCompositionRange
import org.paukov.combinatorics.Factory; //导入依赖的package包/类
@Test
public void simpleFiveCompositionRange() {
Generator<Integer> compositionGenerator = Factory
.createCompositionGenerator(5);
System.out.println("Number of compositions is: "
+ compositionGenerator.getNumberOfGeneratedObjects());
assertEquals(16, compositionGenerator.getNumberOfGeneratedObjects());
List<ICombinatoricsVector<Integer>> list = compositionGenerator
.generateObjectsRange(5, 7);
assertEquals(3, list.size());
assertEquals("CombinatoricsVector=([3, 2], size=2)", list.get(0)
.toString());
assertEquals("CombinatoricsVector=([1, 2, 2], size=3)", list.get(1)
.toString());
assertEquals("CombinatoricsVector=([2, 1, 2], size=3)", list.get(2)
.toString());
}
示例11: all_permutations_of_all_combination
import org.paukov.combinatorics.Factory; //导入依赖的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: simpleZeroComposition
import org.paukov.combinatorics.Factory; //导入依赖的package包/类
@Test
public void simpleZeroComposition() {
Generator<Integer> compositionGenerator = Factory
.createCompositionGenerator(0);
Iterator<ICombinatoricsVector<Integer>> compositionIterator = compositionGenerator
.iterator();
System.out.println("Number of compositions is: "
+ compositionGenerator.getNumberOfGeneratedObjects());
assertEquals(1, compositionGenerator.getNumberOfGeneratedObjects());
while (compositionIterator.hasNext()) {
compositionIterator.next();
System.out.println(compositionIterator);
}
List<ICombinatoricsVector<Integer>> list = compositionGenerator
.generateAllObjects();
assertEquals(1, list.size());
assertEquals("CombinatoricsVector=([0], size=1)", list.get(0)
.toString());
}
示例13: PermutationWithRepetitionIterator
import org.paukov.combinatorics.Factory; //导入依赖的package包/类
/**
* Constructor
*
* @param generator
* Generator
*/
PermutationWithRepetitionIterator(
PermutationWithRepetitionGenerator<T> generator) {
_generator = generator;
_n = generator.getOriginalVector().getSize();
_k = generator.getPermutationLength();
List<T> list = new ArrayList<T>(_k);
T defaultValue = generator.getOriginalVector().getValue(0);
for (int i = 0; i < _k; i++) {
list.add(defaultValue);
}
_currentPermutation = Factory.createVector(list);
_bitVector = new int[_k + 2];
init();
}
示例14: next
import org.paukov.combinatorics.Factory; //导入依赖的package包/类
/**
* Moves to the next permutation
*
* @see Iterator#next()
*/
@Override
public ICombinatoricsVector<T> next() {
_currentIndex++;
for (int j = _k - 1; j >= 0; j--) {
int index = _bitVector[j];
_currentPermutation.setValue(j, _generator.getOriginalVector()
.getValue(index));
}
int i = 0;
while (_bitVector[i] == _n - 1) {
if (i < _k + 1)
_bitVector[i] = 0;
else {
_bitVector[_k] = 1;
return Factory.createVector(_currentPermutation);
}
i++;
}
_bitVector[i]++;
return Factory.createVector(_currentPermutation);
}
示例15: next
import org.paukov.combinatorics.Factory; //导入依赖的package包/类
/**
* Returns the next subset if it is available
*
* @see Iterator#next()
*/
@Override
public ICombinatoricsVector<T> next() {
_currentIndex++;
_currentSubSet.clearVector();
for (int index = 1; index <= _length; index++) {
if (_bitVector[index] == 1) {
T value = _generator.getOriginalVector().getValue(index - 1);
_currentSubSet.addValue(value);
}
}
int i = 1;
while (_bitVector[i] == 1) {
_bitVector[i] = 0;
i++;
}
_bitVector[i] = 1;
return Factory.createVector(_currentSubSet);
}