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


Java Generator.generateFilteredObjects方法代码示例

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


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

示例1: filtered_combinations

import org.paukov.combinatorics.Generator; //导入方法依赖的package包/类
/**
 * Print all 3-combinations of the set (apple, orange, cherry, melon) which
 * contains orange
 */
static void filtered_combinations() {

    System.out.println("===== Filtered Combinations: =====");

    // Create the initial set/vector of 3 elements (apple, orange, cherry,
    // melon)
    ICombinatoricsVector<String> originalVector = Factory
            .createVector(new String[]{"apple", "orange", "cherry",
                    "melon"});

    // Create the combination generator by calling the appropriate method in
    // the Factory class
    Generator<String> gen = Factory.createSimpleCombinationGenerator(
            originalVector, 3);

    // Create a filter and generate the results
    List<ICombinatoricsVector<String>> result = gen
            .generateFilteredObjects(new IFilter<ICombinatoricsVector<String>>() {

                // returns true if the value is accepted
                public boolean accepted(long index,
                                        ICombinatoricsVector<String> value) {
                    return value.contains("orange");
                }

            });

    // Print the result
    for (ICombinatoricsVector<String> perm : result)
        System.out.println(perm);

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

示例2: mostThreeIntegersPartition

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

	Generator<Integer> partitionGenerator = Factory
			.createPartitionGenerator(8);

	List<ICombinatoricsVector<Integer>> list = partitionGenerator
			.generateFilteredObjects(new IFilter<ICombinatoricsVector<Integer>>() {

				@Override
				public boolean accepted(long index,
						ICombinatoricsVector<Integer> value) {
					return value.getSize() <= 3;
				}
			});

	assertEquals(10, list.size());

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

示例3: exactlyThreeIntegersPartition

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

	Generator<Integer> partitionGenerator = Factory
			.createPartitionGenerator(8);

	List<ICombinatoricsVector<Integer>> list = partitionGenerator
			.generateFilteredObjects(new IFilter<ICombinatoricsVector<Integer>>() {

				@Override
				public boolean accepted(long index,
						ICombinatoricsVector<Integer> value) {
					return value.getSize() == 3;
				}
			});

	assertEquals(5, list.size());

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

示例4: exactlyTwoElementsSubsetTest

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

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

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

	List<ICombinatoricsVector<String>> list = gen.generateFilteredObjects(new IFilter<ICombinatoricsVector<String>>() {
		
		@Override
		public boolean accepted(long index, ICombinatoricsVector<String> value) {
			return value.getSize() == 2;
		}
	});

	assertEquals(6, list.size());

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

示例5: sizeofThreePermutations

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

	ICombinatoricsVector<String> originalVector = Factory
			.createVector(new String[] { "a", "b", "c", "d" });
	Generator<String> generator = Factory.createPermutationWithRepetitionGenerator(
			originalVector, 3);

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

	for (ICombinatoricsVector<String> perm : generator)	{
			System.out.println("sizeofThreePermutations " + perm);
	}

	List<ICombinatoricsVector<String>> list = generator
			.generateFilteredObjects(new IFilter<ICombinatoricsVector<String>>() {
				@Override
				public boolean accepted(long index, ICombinatoricsVector<String> value) {
					return (!value.hasDuplicates());
				}
			});

	assertEquals(24, list.size());
	
	assertEquals("CombinatoricsVector=([c, b, a], size=3)", list.get(0)
			.toString());
	assertEquals("CombinatoricsVector=([d, b, a], size=3)", list.get(1)
			.toString());
	assertEquals("CombinatoricsVector=([b, c, a], size=3)", list.get(2)
			.toString());
	assertEquals("CombinatoricsVector=([d, c, a], size=3)", list.get(3)
			.toString());
	assertEquals("CombinatoricsVector=([b, d, a], size=3)", list.get(4)
			.toString());
	assertEquals("CombinatoricsVector=([c, d, a], size=3)", list.get(5)
			.toString());
	assertEquals("CombinatoricsVector=([c, a, b], size=3)", list.get(6)
			.toString());
	assertEquals("CombinatoricsVector=([d, a, b], size=3)", list.get(7)
			.toString());
	assertEquals("CombinatoricsVector=([a, c, b], size=3)", list.get(8)
			.toString());
	assertEquals("CombinatoricsVector=([d, c, b], size=3)", list.get(9)
			.toString());
	assertEquals("CombinatoricsVector=([a, d, b], size=3)", list.get(10)
			.toString());
	assertEquals("CombinatoricsVector=([c, d, b], size=3)", list.get(11)
			.toString());
	assertEquals("CombinatoricsVector=([b, a, c], size=3)", list.get(12)
			.toString());
	assertEquals("CombinatoricsVector=([d, a, c], size=3)", list.get(13)
			.toString());
	assertEquals("CombinatoricsVector=([a, b, c], size=3)", list.get(14)
			.toString());
	assertEquals("CombinatoricsVector=([d, b, c], size=3)", list.get(15)
			.toString());
	assertEquals("CombinatoricsVector=([a, d, c], size=3)", list.get(16)
			.toString());
	assertEquals("CombinatoricsVector=([b, d, c], size=3)", list.get(17)
			.toString());
	assertEquals("CombinatoricsVector=([b, a, d], size=3)", list.get(18)
			.toString());
	assertEquals("CombinatoricsVector=([c, a, d], size=3)", list.get(19)
			.toString());
	assertEquals("CombinatoricsVector=([a, b, d], size=3)", list.get(20)
			.toString());
	assertEquals("CombinatoricsVector=([c, b, d], size=3)", list.get(21)
			.toString());
	assertEquals("CombinatoricsVector=([a, c, d], size=3)", list.get(22)
			.toString());
	assertEquals("CombinatoricsVector=([b, c, d], size=3)", list.get(23)
			.toString());
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:76,代码来源:PermutationWithRepetitionsTest.java

示例6: upToTwoElementsSubsetTest

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

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

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

	List<ICombinatoricsVector<String>> list = gen.generateFilteredObjects(new IFilter<ICombinatoricsVector<String>>() {
		
		@Override
		public boolean accepted(long index, ICombinatoricsVector<String> value) {
			return value.getSize() <= 2;
		}
	});

	assertEquals(11, list.size());

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

示例7: subSetPartition

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

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

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

	for (ICombinatoricsVector<ICombinatoricsVector<String>> element : complexGenerator)
		System.out.println("subSetPartition: " + element);

	List<ICombinatoricsVector<ICombinatoricsVector<String>>> list = complexGenerator
			.generateFilteredObjects(new IFilter<ICombinatoricsVector<ICombinatoricsVector<String>>>() {

				@Override
				public boolean accepted(
						long index,
						ICombinatoricsVector<ICombinatoricsVector<String>> value) {
					ICombinatoricsVector<Integer> sizes = Factory
							.createVector();

					for (ICombinatoricsVector<String> elements : value
							.getVector())
						sizes.addValue(elements.getSize());

					return sizes.isAllElementsEqual()
							&& sizes.getValue(0) == 2;
				}
			});

	assertEquals(15, list.size());

	assertEquals("([a, b],[c, d],[e, f])",
			ComplexCombinationGenerator.convert2String(list.get(0)));
	assertEquals("([a, b],[c, e],[d, f])",
			ComplexCombinationGenerator.convert2String(list.get(1)));
	assertEquals("([a, b],[d, e],[c, f])",
			ComplexCombinationGenerator.convert2String(list.get(2)));
	assertEquals("([a, c],[b, d],[e, f])",
			ComplexCombinationGenerator.convert2String(list.get(3)));
	assertEquals("([a, c],[b, e],[d, f])",
			ComplexCombinationGenerator.convert2String(list.get(4)));
	assertEquals("([a, c],[d, e],[b, f])",
			ComplexCombinationGenerator.convert2String(list.get(5)));
	assertEquals("([b, c],[a, d],[e, f])",
			ComplexCombinationGenerator.convert2String(list.get(6)));
	assertEquals("([b, c],[a, e],[d, f])",
			ComplexCombinationGenerator.convert2String(list.get(7)));
	assertEquals("([b, c],[d, e],[a, f])",
			ComplexCombinationGenerator.convert2String(list.get(8)));
	assertEquals("([a, d],[b, e],[c, f])",
			ComplexCombinationGenerator.convert2String(list.get(9)));
	assertEquals("([a, d],[c, e],[b, f])",
			ComplexCombinationGenerator.convert2String(list.get(10)));
	assertEquals("([b, d],[a, e],[c, f])",
			ComplexCombinationGenerator.convert2String(list.get(11)));
	assertEquals("([b, d],[c, e],[a, f])",
			ComplexCombinationGenerator.convert2String(list.get(12)));
	assertEquals("([c, d],[a, e],[b, f])",
			ComplexCombinationGenerator.convert2String(list.get(13)));
	assertEquals("([c, d],[b, e],[a, f])",
			ComplexCombinationGenerator.convert2String(list.get(14)));
	
}
 
开发者ID:dpaukov,项目名称:combinatoricslib,代码行数:68,代码来源:ComplexCombinationTest.java


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