org.jgrapht.experimental.permutation
Class CompoundPermutationIter

java.lang.Object
  extended by org.jgrapht.experimental.permutation.CompoundPermutationIter
All Implemented Interfaces:
Iterator, ArrayPermutationsIter

public class CompoundPermutationIter
extends Object
implements ArrayPermutationsIter, Iterator

For permutation like this:

  • 1,2 are the same eq.group (numbers)
  • a,b are og the same eq.group (letters)
  • '$' is of its own eq. group (signs) Let the order of the group be (arbitrary): signs,numbers,letters (note that for performance reasons, this arbitrary order is the worst! see Performance section below)

    These are the possible compound perm: [$,1,2,a,b,c]

    [$,1,2,a,c,b]

    [$,1,2,b,a,c]

    [$,1,2,b,c,a]

    [$,1,2,c,a,b]

    [$,1,2,c,b,a]

    [$,2,1,a,b,c]

    [$,2,1,a,c,b]

    [$,2,1,b,a,c]

    [$,2,1,b,c,a]

    [$,2,1,c,a,b]

    [$,2,1,c,b,a]

    The overall number is the product of the factorials of each eq. group size; in our example : (1!)x(2!)x(3!)=1x2x6=12. Using the constructor with eq.group sizes and initial order [1,2,3], the result permutations are retrieved as numbers in an array, where [0,1,2,3,4,5] means [$,1,2,a,b,c]:

    [0,1,2,3,5,4]

    [0,1,2,4,3,5]

    etc. etc., till:

    [0,2,1,5,4,3] means [$,2,1,c,b,a]

    Performance: The implementation tries to advance each time the group zero, if it does not succeed, it tries the next group (1,2 and so on), so: try to put the largest group as the first groups, UNLIKE the example. Performance-wise it is better to do [a,b,c,1,2,$] .The effect is improvement by constant (for example, by 2)

    Since:
    May 30, 2005
    Author:
    Assaf

    Constructor Summary
    CompoundPermutationIter(int[] equalityGroupsSizesArray)
              For the class example, use [1,2,2].
     
    Method Summary
     int getMax()
               
     int[] getNext()
              Iteration may be one of these two: 1.
     int[] getPermAsArray()
              Creates and returns a new array which consists of the eq.
     boolean hasNext()
               
     boolean hasNextPermutaions()
               
     Object next()
               
     int[] nextPermutation()
               
     void remove()
              UNIMPLEMENTED.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    CompoundPermutationIter

    public CompoundPermutationIter(int[] equalityGroupsSizesArray)
    For the class example, use [1,2,2]. order matters! (performance-wise too)

    Parameters:
    equalityGroupsSizesArray -
    Method Detail

    next

    public Object next()
    Specified by:
    next in interface Iterator

    getNext

    public int[] getNext()
    Iteration may be one of these two: 1. the last group advances by one iter, all else stay. 2. the last group cannot advance , so it restarts but telling the group after it to advance (done recursively till some group can advance)


    getPermAsArray

    public int[] getPermAsArray()
    Creates and returns a new array which consists of the eq. group current permutation arrays. For example, in the 10th iter ([$,2,1,b,c,a]) The permutations current statuses is [0] [2,1] [4,5,3] so retrieve [0,2,1,4,5,3]


    hasNext

    public boolean hasNext()
    Specified by:
    hasNext in interface Iterator

    getMax

    public int getMax()

    nextPermutation

    public int[] nextPermutation()
    Specified by:
    nextPermutation in interface ArrayPermutationsIter

    hasNextPermutaions

    public boolean hasNextPermutaions()
    Specified by:
    hasNextPermutaions in interface ArrayPermutationsIter

    remove

    public void remove()
    UNIMPLEMENTED. always throws new UnsupportedOperationException

    Specified by:
    remove in interface Iterator
    See Also:
    Iterator.remove()


    Copyright © 2013. All rights reserved.