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


Java ICombinatoricsVector.addValue方法代码示例

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


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

示例1: DuplicatedPermutationIterator

import org.paukov.combinatorics.ICombinatoricsVector; //导入方法依赖的package包/类
/**
 * Constructor
 * 
 * @param generator
 *            Permutation generator
 */
DuplicatedPermutationIterator(Generator<T> generator) {
	_generator = generator;
	_length = generator.getOriginalVector().getSize();
	_data = new int[_length];

	ICombinatoricsVector<T> originalVector = generator.getOriginalVector();
	ICombinatoricsVector<T> initialPermutation = Factory.createVector();

	// Create a set of the initial data
	Set<T> initialSet = new LinkedHashSet<T>(originalVector.getVector());
	initialSet.addAll(originalVector.getVector());

	// Create internal data
	int dataValue = 0;
	int dataIndex = 0;

	_initialOrderedPermutation = Factory.createVector(initialSet);

	for (int i = 0; i < _initialOrderedPermutation.getSize(); i++) {

		T value = _initialOrderedPermutation.getValue(i);
		dataValue++;

		if (!initialPermutation.contains(value)) {
			// Determine how many duplicates of the value in the original
			// vector
			int count = originalVector.countElements(value);

			for (int countIndex = 0; countIndex < count; countIndex++) {
				_data[dataIndex++] = dataValue;
				initialPermutation.addValue(value);
			}
		}
	}

	init();
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:44,代码来源:DuplicatedPermutationIterator.java

示例2: getOriginalVector

import org.paukov.combinatorics.ICombinatoricsVector; //导入方法依赖的package包/类
/**
 * Returns the original vector wrapped into one more vector.
 * 
 * @return Returns the _originalVector.
 */
public ICombinatoricsVector<ICombinatoricsVector<T>> getOriginalVector() {
	ICombinatoricsVector<ICombinatoricsVector<T>> result = Factory
			.<ICombinatoricsVector<T>> createVector();
	result.addValue(_originalVector);
	return result;
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:12,代码来源:ComplexCombinationGenerator.java

示例3: CompositionIterator

import org.paukov.combinatorics.ICombinatoricsVector; //导入方法依赖的package包/类
/**
 * Constructor of the iterator
 * 
 * @param generator The Composition generator
 */
CompositionIterator(CompositionGenerator generator) {
	super();
	_generator = generator;

	ICombinatoricsVector<Integer> coreSet = Factory.createVector();

	for (int i = 1; i < this._generator._initialValue; i++)
		coreSet.addValue(i);

	_subsetGenerator = Factory.createSubSetGenerator(coreSet);

	_subsetIterator = _subsetGenerator.iterator();
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:19,代码来源:CompositionIterator.java

示例4: simpleObjectsCombinationTest

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

	// create combinatorics vector
	ICombinatoricsVector<Apple> initialVector = Factory.createVector();
	
	// Add 3 apples
	initialVector.addValue(new Apple("red"));
	initialVector.addValue(new Apple("green"));
	initialVector.addValue(new Apple("yellow"));

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

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

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

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

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

	assertEquals(3, list.size());

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

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

示例5: simpleCombinationOfVectorsTest

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

	// create combinatorics vector
	ICombinatoricsVector<String> vectorA = Factory
			.createVector(new String[] { "A1", "A2", "A3" });
	
	ICombinatoricsVector<String> vectorB = Factory
			.createVector(new String[] { "B1", "B2", "B3" });
	
	ICombinatoricsVector<String> vectorC = Factory
			.createVector(new String[] { "C1", "C2", "C3" });
	
	// create combinatorics vector
	ICombinatoricsVector<ICombinatoricsVector<String>> initialVector = Factory.createVector();
	initialVector.addValue(vectorA);
	initialVector.addValue(vectorB);
	initialVector.addValue(vectorC);

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

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

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

	// go through the iterator
	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 = gen.generateAllObjects();

	assertEquals(3, list.size());

	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([B1, B2, B3], size=3)], size=2)", list
			.get(0).toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=2)", list
			.get(1).toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=2)", list
			.get(2).toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:50,代码来源:SimpleCombinationTest.java

示例6: simpleObjectsModifiedCombinationTest

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

	// create combinatorics vector
	ICombinatoricsVector<Apple> initialVector = Factory.createVector();
	
	Apple red = new Apple("red");
	Apple green = new Apple("green");
	Apple yellow = new Apple("yellow");
	
	initialVector.addValue(red);
	initialVector.addValue(green);
	initialVector.addValue(yellow);

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

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

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

	// Print the first combination
	ICombinatoricsVector<Apple> combination = itr.next();
	System.out.println(combination);
	assertEquals("CombinatoricsVector=([(Apple: red), (Apple: green)], size=2)", combination.toString());
	
	// Modify the original red apple
	red.color = "brawn";
	
	// Print the next combination
	combination = itr.next();
	System.out.println(combination);
	assertEquals("CombinatoricsVector=([(Apple: brawn), (Apple: yellow)], size=2)", combination.toString());
	
	// Modify the original green apple
	green.color = "rose";

	// Print the next combination
	combination = itr.next();
	System.out.println(combination);
	assertEquals("CombinatoricsVector=([(Apple: rose), (Apple: yellow)], size=2)", combination.toString());

	// Modify the original yellow apple
	yellow.color = "white";
	
	List<ICombinatoricsVector<Apple>> list = gen.generateAllObjects();

	assertEquals(3, list.size());

	assertEquals("CombinatoricsVector=([(Apple: brawn), (Apple: rose)], size=2)", list.get(0)
			.toString());
	assertEquals("CombinatoricsVector=([(Apple: brawn), (Apple: white)], size=2)", list.get(1)
			.toString());
	assertEquals("CombinatoricsVector=([(Apple: rose), (Apple: white)], size=2)", list.get(2)
			.toString());

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

示例7: multiCombinationVectorsTest

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

	ICombinatoricsVector<String> vectorA = Factory
			.createVector(new String[] { "A1", "A2", "A3" });
	
	ICombinatoricsVector<String> vectorB = Factory
			.createVector(new String[] { "B1", "B2", "B3" });
	
	ICombinatoricsVector<String> vectorC = Factory
			.createVector(new String[] { "C1", "C2", "C3" });
	
	// create combinatorics vector
	ICombinatoricsVector<ICombinatoricsVector<String>> initialVector = Factory.createVector();
	initialVector.addValue(vectorA);
	initialVector.addValue(vectorB);
	initialVector.addValue(vectorC);

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

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

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

	// go through the iterator
	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 = gen.generateAllObjects();

	assertEquals(10, list.size());

	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([A1, A2, A3], size=3)], size=3)", list.get(0)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([B1, B2, B3], size=3)], size=3)", list.get(1)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=3)", list.get(2)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([B1, B2, B3], size=3)], size=3)", list.get(3)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=3)", list.get(4)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([A1, A2, A3], size=3), CombinatoricsVector=([C1, C2, C3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=3)", list.get(5)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([B1, B2, B3], size=3)], size=3)", list.get(6)
			.toString());

	assertEquals("CombinatoricsVector=([CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=3)", list.get(7)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([B1, B2, B3], size=3), CombinatoricsVector=([C1, C2, C3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=3)", list.get(8)
			.toString());
	assertEquals("CombinatoricsVector=([CombinatoricsVector=([C1, C2, C3], size=3), CombinatoricsVector=([C1, C2, C3], size=3), CombinatoricsVector=([C1, C2, C3], size=3)], size=3)", list.get(9)
			.toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:64,代码来源:MultiCombinationsTest.java


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