当前位置: 首页>>代码示例>>Java>>正文


Java Generator.iterator方法代码示例

本文整理汇总了Java中org.paukov.combinatorics.Generator.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java Generator.iterator方法的具体用法?Java Generator.iterator怎么用?Java Generator.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.paukov.combinatorics.Generator的用法示例。


在下文中一共展示了Generator.iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:27,代码来源:PermutationsTest.java

示例2: createAllMultiCharCombosExcludingOneTaskChar

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
public SortedSet<TaskCharSet> createAllMultiCharCombosExcludingOneTaskChar(TaskChar excluded, int maxSizeOfCombos) {
	Collection<TaskChar> alphabet = taskCharArchive.getTaskChars();
	Collection<TaskChar> otherChrs = new ArrayList<TaskChar>(alphabet);
	if(excluded != null)
		otherChrs.remove(excluded);

	SortedSet<TaskCharSet> combos = new TreeSet<TaskCharSet>();
	
	if (otherChrs.size() < 1) {
		return combos;
	}
	// Create the initial vector
	ICombinatoricsVector<TaskChar> initialVector = Factory.createVector(otherChrs);
	Generator<TaskChar> gen = null;
	Iterator<ICombinatoricsVector<TaskChar>> combosIterator = null;
	
	if (maxSizeOfCombos < otherChrs.size()) {
		for (int k=1; k <= maxSizeOfCombos; k++) {
			// Create a simple combination generator to generate k-combinations of the initial vector
			gen = Factory.createSimpleCombinationGenerator(initialVector, k);
			combosIterator = gen.iterator();
			while (combosIterator.hasNext()) {
				combos.add(new TaskCharSet(combosIterator.next().getVector()));
			}
		}
	} else {
		Collection<TaskChar> auxComboVector = null;
		// Create an instance of the subset generator
		gen = Factory.createSubSetGenerator(initialVector);
		combosIterator = gen.iterator();
		while (combosIterator.hasNext()) {
			auxComboVector = combosIterator.next().getVector();
			if (	auxComboVector.size() > 0
				&&	auxComboVector.size() <= otherChrs.size()) {
				combos.add(new TaskCharSet(auxComboVector));
			}
		}
	}
	return combos;
}
 
开发者ID:cdc08x,项目名称:MINERful,代码行数:41,代码来源:TaskCharSetFactory.java

示例3: simplePartition

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void simplePartition() {

	Generator<Integer> partitionGenerator = Factory
			.createPartitionGenerator(5);
	Iterator<ICombinatoricsVector<Integer>> partitionIterator = partitionGenerator
			.iterator();

	System.out.println("Number of partition is: "
			+ partitionGenerator.getNumberOfGeneratedObjects());
	assertEquals(8, partitionGenerator.getNumberOfGeneratedObjects());

	while (partitionIterator.hasNext()) {
		partitionIterator.next();
		System.out.println(partitionIterator);
	}

	List<ICombinatoricsVector<Integer>> list = partitionGenerator
			.generateAllObjects();

	assertEquals(7, list.size());

	assertEquals("CombinatoricsVector=([1, 1, 1, 1, 1], size=5)",
			list.get(0).toString());
	assertEquals("CombinatoricsVector=([2, 1, 1, 1], size=4)", list.get(1)
			.toString());
	assertEquals("CombinatoricsVector=([2, 2, 1], size=3)", list.get(2)
			.toString());
	assertEquals("CombinatoricsVector=([3, 1, 1], size=3)", list.get(3)
			.toString());
	assertEquals("CombinatoricsVector=([3, 2], size=2)", list.get(4)
			.toString());
	assertEquals("CombinatoricsVector=([4, 1], size=2)", list.get(5)
			.toString());
	assertEquals("CombinatoricsVector=([5], size=1)", list.get(6)
			.toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:38,代码来源:PartitionsTest.java

示例4: emptySubsetTest

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void emptySubsetTest() {

	// create the empty combinatorics vector
	ICombinatoricsVector<String> initialVector = Factory
			.<String> createVector();

	// create a sub-set generator
	Generator<String> gen = Factory.createSubSetGenerator(initialVector);

	// create an iterator
	Iterator<ICombinatoricsVector<String>> itr = gen.iterator();

	// verify the number of sunsets
	assertEquals(1, gen.getNumberOfGeneratedObjects());

	// go through the iterator
	while (itr.hasNext()) {
		ICombinatoricsVector<String> combination = itr.next();
		System.out.println(combination);
	}

	List<ICombinatoricsVector<String>> list = gen.generateAllObjects();

	assertEquals(1, list.size());

	assertEquals("CombinatoricsVector=([], size=0)", list.get(0).toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:29,代码来源:SubSetsTest.java

示例5: test9

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void test9() {

	// create a combinatorics vector (a, b)
	ICombinatoricsVector<String> initialVector = Factory
			.createVector(new String[] { "a", "b" });

	// Create a complex-combination generator and iterator
	Generator<ICombinatoricsVector<String>> complexGenerator = new ComplexCombinationGenerator<String>(
			initialVector, 1, true, true);

	// Create a complex-combination iterator
	Iterator<ICombinatoricsVector<ICombinatoricsVector<String>>> itr = complexGenerator
			.iterator();

	// Iterate the elements
	while (itr.hasNext()) {
		ICombinatoricsVector<ICombinatoricsVector<String>> combination = itr
				.next();
		String str = ComplexCombinationGenerator
				.<String> convert2String(combination);
		System.out.println(str + " = " + itr);
	}

	List<ICombinatoricsVector<ICombinatoricsVector<String>>> list = complexGenerator
			.generateAllObjects();

	assertEquals(1, list.size());

	assertEquals("([a, b])",
			ComplexCombinationGenerator.convert2String(list.get(0)));
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:33,代码来源:ComplexCombinationTest.java

示例6: simpleOneTwoCombinationTest

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void simpleOneTwoCombinationTest() {

	// create array of initial items
	List<String> array = new ArrayList<String>();
	array.add("red");

	// create combinatorics vector
	ICombinatoricsVector<String> initialVector = Factory
			.createVector(array);

	// create simple combination generator to generate 2-combination of 1
	Generator<String> gen = Factory.createSimpleCombinationGenerator(
			initialVector, 2);

	// create iterator
	Iterator<ICombinatoricsVector<String>> itr = gen.iterator();

	// print the number of combinations
	assertEquals(0, gen.getNumberOfGeneratedObjects());

	// go through the iterator
	assertEquals(false, itr.hasNext());

	List<ICombinatoricsVector<String>> list = gen.generateAllObjects();
	assertEquals(0, list.size());

}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:29,代码来源:SimpleCombinationTest.java

示例7: simpleTwoTwoCombinationTest

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void simpleTwoTwoCombinationTest() {

	// create combinatorics vector
	ICombinatoricsVector<String> initialVector = Factory
			.createVector(new String[] { "red", "green" });

	// create simple combination generator to generate 2-combination of 2
	Generator<String> gen = Factory.createSimpleCombinationGenerator(
			initialVector, 2);

	// create iterator
	Iterator<ICombinatoricsVector<String>> itr = gen.iterator();

	// print the number of combinations
	assertEquals(1, gen.getNumberOfGeneratedObjects());

	// go through the iterator
	while (itr.hasNext()) {
		ICombinatoricsVector<String> combination = itr.next();
		System.out.println(combination);
	}

	List<ICombinatoricsVector<String>> list = gen.generateAllObjects();

	assertEquals(1, list.size());

	assertEquals("CombinatoricsVector=([red, green], size=2)", list.get(0)
			.toString());

}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:32,代码来源:SimpleCombinationTest.java

示例8: test5

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void test5() {

	// create a combinatorics vector (a, a)
	ICombinatoricsVector<String> initialVector = Factory
			.createVector(new String[] { "a", "a" });

	// Create a complex-combination generator and iterator
	Generator<ICombinatoricsVector<String>> complexGenerator = new ComplexCombinationGenerator<String>(
			initialVector, 1, true, true);

	// Create a complex-combination iterator
	Iterator<ICombinatoricsVector<ICombinatoricsVector<String>>> itr = complexGenerator
			.iterator();

	// Iterate the elements
	while (itr.hasNext()) {
		ICombinatoricsVector<ICombinatoricsVector<String>> combination = itr
				.next();
		String str = ComplexCombinationGenerator
				.<String> convert2String(combination);
		System.out.println(str + " = " + itr);
	}

	List<ICombinatoricsVector<ICombinatoricsVector<String>>> list = complexGenerator
			.generateAllObjects();

	assertEquals(1, list.size());

	assertEquals("([a, a])",
			ComplexCombinationGenerator.convert2String(list.get(0)));

}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:34,代码来源:ComplexCombinationTest.java

示例9: multiCombinationOneTest

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void multiCombinationOneTest() {

	// create array of initial items
	List<String> array = new ArrayList<String>();
	array.add("A");

	// create combinatorics vector
	ICombinatoricsVector<String> initialVector = Factory.createVector(
			array);

	// create multi-combination generator to generate 3-combination
	Generator<String> gen = Factory.createMultiCombinationGenerator(
			initialVector, 3);

	// create iterator
	Iterator<ICombinatoricsVector<String>> itr = gen.iterator();

	// print the number of combinations
	assertEquals(1, gen.getNumberOfGeneratedObjects());

	// go through the iterator
	while (itr.hasNext()) {
		ICombinatoricsVector<String> combination = itr.next();
		System.out.println(combination);
	}

	List<ICombinatoricsVector<String>> list = gen.generateAllObjects();

	assertEquals(1, list.size());

	assertEquals("CombinatoricsVector=([A, A, A], size=3)", list.get(0)
			.toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:35,代码来源:MultiCombinationsTest.java

示例10: multiCombinationEmptyTest

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void multiCombinationEmptyTest() {

	// create combinatorics vector
	ICombinatoricsVector<String> initialVector = Factory.createVector(new String[] { "A", "B" });

	// create multi-combination generator to generate 0-combination
	Generator<String> gen = Factory.createMultiCombinationGenerator(
			initialVector, 0);

	// create iterator
	Iterator<ICombinatoricsVector<String>> itr = gen.iterator();

	// print the number of combinations
	assertEquals(1, gen.getNumberOfGeneratedObjects());

	// go through the iterator
	while (itr.hasNext()) {
		ICombinatoricsVector<String> combination = itr.next();
		System.out.println(combination);
	}

	List<ICombinatoricsVector<String>> list = gen.generateAllObjects();

	assertEquals(1, list.size());

	assertEquals("CombinatoricsVector=([], size=0)", list.get(0).toString());

}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:30,代码来源:MultiCombinationsTest.java

示例11: identicalPermutation

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void identicalPermutation() {

	ICombinatoricsVector<String> initialVector = Factory
			.createVector(new String[] { "a", "a", "b" });
	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(3, list.size());

	assertEquals("CombinatoricsVector=([a, a, b], size=3)", list.get(0)
			.toString());
	assertEquals("CombinatoricsVector=([a, b, a], size=3)", list.get(1)
			.toString());
	assertEquals("CombinatoricsVector=([b, a, a], size=3)", list.get(2)
			.toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:28,代码来源:PermutationsTest.java

示例12: multiCombinationEmptyOneTest

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void multiCombinationEmptyOneTest() {

	// create array of initial empty items
	List<String> array = new ArrayList<String>();

	// create combinatorics vector
	ICombinatoricsVector<String> initialVector = Factory.createVector(
			array);

	// create multi-combination generator to generate 1-combination
	Generator<String> gen = Factory.createMultiCombinationGenerator(
			initialVector, 1);

	// create iterator
	Iterator<ICombinatoricsVector<String>> itr = gen.iterator();

	// print the number of combinations
	assertEquals(1, gen.getNumberOfGeneratedObjects());

	// go through the iterator
	while (itr.hasNext()) {
		ICombinatoricsVector<String> combination = itr.next();
		System.out.println(combination);
	}

	List<ICombinatoricsVector<String>> list = gen.generateAllObjects();

	assertEquals(1, list.size());

	assertEquals("CombinatoricsVector=([], size=0)", list.get(0).toString());

}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:34,代码来源:MultiCombinationsTest.java

示例13: simpleThreeZeroPermutationWithRepetition

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void simpleThreeZeroPermutationWithRepetition() {

	ICombinatoricsVector<Integer> coreVector = Factory
			.createVector(new Integer[] { 1, 2, 3 });

	Generator<Integer> permutationWithRepetitionGenerator = Factory.createPermutationWithRepetitionGenerator(
			coreVector, 0);
	Iterator<ICombinatoricsVector<Integer>> permutationWithRepetitionIterator = permutationWithRepetitionGenerator
			.iterator();

	assertEquals(1,
			permutationWithRepetitionGenerator
					.getNumberOfGeneratedObjects());
	System.out.println("Number of permutationWithRepetition is: "
			+ permutationWithRepetitionGenerator
					.getNumberOfGeneratedObjects());

	while (permutationWithRepetitionIterator.hasNext()) {
		permutationWithRepetitionIterator.next();
		System.out.println(permutationWithRepetitionIterator);
	}

	List<ICombinatoricsVector<Integer>> list = permutationWithRepetitionGenerator
			.generateAllObjects();

	assertEquals(1, list.size());
	assertEquals("CombinatoricsVector=([], size=0)", list.get(0).toString());

}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:31,代码来源:PermutationWithRepetitionsTest.java

示例14: simplePermutation

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void simplePermutation() {

	ICombinatoricsVector<Integer> corePermutation = Factory
			.createVector(new Integer[] { 1, 2, 3 });
	Generator<Integer> generator = Factory
			.createPermutationGenerator(corePermutation);

	System.out.println("Number of permutations is: "
			+ generator.getNumberOfGeneratedObjects());
	assertEquals(6, generator.getNumberOfGeneratedObjects());

	Iterator<ICombinatoricsVector<Integer>> iterator = generator.iterator();

	while (iterator.hasNext()) {
		iterator.next();
		System.out.println(iterator);
	}

	List<ICombinatoricsVector<Integer>> list = generator
			.generateAllObjects();

	assertEquals(6, list.size());

	assertEquals("CombinatoricsVector=([1, 2, 3], size=3)", list.get(0)
			.toString());
	assertEquals("CombinatoricsVector=([1, 3, 2], size=3)", list.get(1)
			.toString());
	assertEquals("CombinatoricsVector=([3, 1, 2], size=3)", list.get(2)
			.toString());
	assertEquals("CombinatoricsVector=([3, 2, 1], size=3)", list.get(3)
			.toString());
	assertEquals("CombinatoricsVector=([2, 3, 1], size=3)", list.get(4)
			.toString());
	assertEquals("CombinatoricsVector=([2, 1, 3], size=3)", list.get(5)
			.toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:38,代码来源:PermutationsTest.java

示例15: simpleTreeTwoPermutationWithRepetition

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
@Test
public void simpleTreeTwoPermutationWithRepetition() {

	ICombinatoricsVector<Integer> coreVector = Factory
			.createVector(new Integer[] { 1, 2, 3 });

	Generator<Integer> permutationWithRepetitionGenerator = Factory.createPermutationWithRepetitionGenerator(
			coreVector, 2);
	Iterator<ICombinatoricsVector<Integer>> permutationWithRepetitionIterator = permutationWithRepetitionGenerator
			.iterator();

	assertEquals(9,
			permutationWithRepetitionGenerator
					.getNumberOfGeneratedObjects());
	System.out.println("Number of permutationWithRepetition is: "
			+ permutationWithRepetitionGenerator
					.getNumberOfGeneratedObjects());

	while (permutationWithRepetitionIterator.hasNext()) {
		permutationWithRepetitionIterator.next();
		System.out.println(permutationWithRepetitionIterator);
	}

	List<ICombinatoricsVector<Integer>> list = permutationWithRepetitionGenerator
			.generateAllObjects();

	assertEquals(9, list.size());

	assertEquals("CombinatoricsVector=([1, 1], size=2)", list.get(0)
			.toString());
	assertEquals("CombinatoricsVector=([2, 1], size=2)", list.get(1)
			.toString());
	assertEquals("CombinatoricsVector=([3, 1], size=2)", list.get(2)
			.toString());
	assertEquals("CombinatoricsVector=([1, 2], size=2)", list.get(3)
			.toString());
	assertEquals("CombinatoricsVector=([2, 2], size=2)", list.get(4)
			.toString());
	assertEquals("CombinatoricsVector=([3, 2], size=2)", list.get(5)
			.toString());
	assertEquals("CombinatoricsVector=([1, 3], size=2)", list.get(6)
			.toString());
	assertEquals("CombinatoricsVector=([2, 3], size=2)", list.get(7)
			.toString());
	assertEquals("CombinatoricsVector=([3, 3], size=2)", list.get(8)
			.toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:48,代码来源:PermutationWithRepetitionsTest.java


注:本文中的org.paukov.combinatorics.Generator.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。