wenxiangtune / combinatoricslib

Automatically exported from code.google.com/p/combinatoricslib
0 stars 0 forks source link

Runtime exception in getNumberOfGeneratedObjects when using createPermutationGenerator with treatAsIdentical=false #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
I run the following code:
org.paukov.combinatorics.ICombinatoricsVector<String> originalVector =
    org.paukov.combinatorics.Factory.createVector(new String[]{"apple","orange", "apple", "orange"});
org.paukov.combinatorics.Generator<String> permutations =
    org.paukov.combinatorics.Factory.createPermutationGenerator(
        originalVector,false);
System.out.println("size "+permutations.getNumberOfGeneratedObjects());
for (org.paukov.combinatorics.ICombinatoricsVector<String> permutation : 
permutations)
{
    System.out.println(permutation.toString());  
}

What is the expected output? What do you see instead?
An exception occurred during evaluation:  java.lang.RuntimeException
But if I remove the first println with the getNumberOfGeneratedObjects()

the output is ok:
CombinatoricsVector=([apple, apple, orange, orange], size=4)
CombinatoricsVector=([apple, orange, apple, orange], size=4)
CombinatoricsVector=([apple, orange, orange, apple], size=4)
CombinatoricsVector=([orange, apple, apple, orange], size=4)
CombinatoricsVector=([orange, apple, orange, apple], size=4)
CombinatoricsVector=([orange, orange, apple, apple], size=4)

What version of the product are you using? On what operating system?
it was on r174 v2.1 in eclipse kepler sp1 scrapbook with java 1.7_51 on win7

Original issue reported on code.google.com by ferenc.l...@gmail.com on 8 Mar 2014 at 9:17

GoogleCodeExporter commented 8 years ago
This is not an issue, this is expected behavior as the exception says that the 
initial vector has duplicates: CombinatoricsVector=([apple, orange, apple, 
orange], size=4). 

The method getNumberOfGeneratedObjects() can't calculate a number of the 
generated objects if the initial vector has duplicates and the generator should 
treat the vector as identical. In this case it throws a Runtime exception 
notifying the caller that number of the generated objects has to be calculated 
by another way. The permutation generator works correctly as it generates the 
correct objects.

Original comment by d.pau...@gmail.com on 10 Mar 2014 at 12:08

GoogleCodeExporter commented 8 years ago

Original comment by d.pau...@gmail.com on 10 Mar 2014 at 12:09

GoogleCodeExporter commented 8 years ago

Original comment by d.pau...@gmail.com on 18 Mar 2014 at 9:51

GoogleCodeExporter commented 8 years ago
Works per design

Original comment by d.pau...@gmail.com on 19 Jun 2014 at 12:18