本文整理汇总了Java中org.paukov.combinatorics.Factory.createPartitionGenerator方法的典型用法代码示例。如果您正苦于以下问题:Java Factory.createPartitionGenerator方法的具体用法?Java Factory.createPartitionGenerator怎么用?Java Factory.createPartitionGenerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.paukov.combinatorics.Factory
的用法示例。
在下文中一共展示了Factory.createPartitionGenerator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: simpleOnePartition
import org.paukov.combinatorics.Factory; //导入方法依赖的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());
}
示例2: simpleEmptyPartition
import org.paukov.combinatorics.Factory; //导入方法依赖的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());
}
示例3: integer_partition
import org.paukov.combinatorics.Factory; //导入方法依赖的package包/类
static void integer_partition() {
System.out.println("===== All integer partitions of 5: =====");
// Create an instance of the partition generator to generate all
// possible partitions of 5
Generator<Integer> gen = Factory.createPartitionGenerator(5);
// Print the partitions
for (ICombinatoricsVector<Integer> p : gen) {
System.out.println(p);
}
}
示例4: simplePartition
import org.paukov.combinatorics.Factory; //导入方法依赖的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());
}
示例5: simpleTwoPartition
import org.paukov.combinatorics.Factory; //导入方法依赖的package包/类
@Test
public void simpleTwoPartition() {
Generator<Integer> partitionGenerator = Factory
.createPartitionGenerator(2);
Iterator<ICombinatoricsVector<Integer>> partitionIterator = partitionGenerator
.iterator();
System.out.println("Number of partition is: "
+ partitionGenerator.getNumberOfGeneratedObjects());
assertEquals(2, partitionGenerator.getNumberOfGeneratedObjects());
while (partitionIterator.hasNext()) {
partitionIterator.next();
System.out.println(partitionIterator);
}
List<ICombinatoricsVector<Integer>> list = partitionGenerator
.generateAllObjects();
assertEquals(2, list.size());
assertEquals("CombinatoricsVector=([1, 1], size=2)", list.get(0)
.toString());
assertEquals("CombinatoricsVector=([2], size=1)", list.get(1)
.toString());
}
示例6: mostThreeIntegersPartition
import org.paukov.combinatorics.Factory; //导入方法依赖的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());
}
示例7: exactlyThreeIntegersPartition
import org.paukov.combinatorics.Factory; //导入方法依赖的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());
}