dwdyer/uncommons-maths · PermutationGenerator.java
java logo
public List<T> nextPermutationAsList()
    {
        List<T> permutation = new ArrayList<T>(elements.length);
        return nextPermutationAsList(permutation);
    }
Similar code snippets
1.
dwdyer/uncommons-maths · PermutationGenerator.java
Match rating: 76.5% · See similar code snippets
java logo
@SuppressWarnings("unchecked")
    public T[] nextPermutationAsArray()
    {
        T[] permutation = (T[]) Array.newInstance(elements.getClass().getComponentType(),
                                                  permutationIndices.length);
        return nextPermutationAsArray(permutation);
    }
2.
Match rating: 75.63% · See similar code snippets
java logo
@Override
  public int[] next() {
    if (numLeft == 0) {
      throw new NoSuchElementException();
    }

    if (numLeft == total) {
      numLeft--;
      return ArrayUtils.copyOf(permutation, permutation.length);
    }

    // Find largest index j with a[j] < a[j+1]
    int j = permutation.length - 2;
    while (permutation[j] > permutation[j + 1]) {
      j--;
    }

    // Find index k such that a[k] is smallest integer
    // greater than a[j] to the right of a[j]
    int k = permutation.length - 1;
    while (permutation[j] > permutation[k]) {
      k--;
    }

    // Interchange a[j] and a[k]
    int temp = permutation[k];
    permutation[k] = permutation[j];
    permutation[j] = temp;

    // Put tail end of permutation after jth position in increasing order
    int r = permutation.length - 1;
    int s = j + 1;

    while (r > s) {
      temp = permutation[s];
      permutation[s] = permutation[r];
      permutation[r] = temp;
      r--;
      s++;
    }

    numLeft--;
    return ArrayUtils.copyOf(permutation, permutation.length);
  }
3.
Match rating: 75.01% · See similar code snippets
java logo
public Permutation multiply(Permutation other) {
        Permutation newPermutation = new Permutation(values.length);
        for (int i = 0; i < values.length; i++) {
            newPermutation.values[i] = this.values[other.values[i]];
        }
        return newPermutation;
    }
4.
biojava/biojava · PermutationGroup.java
Match rating: 74.73% · See similar code snippets
java logo
public static int getOrder(List<Integer> permutation) {
		List<Integer> copy = new ArrayList<Integer>(permutation);
		for (int i = 0, n = permutation.size(); i < n; i++) {
			copy = combine(copy, permutation);
			if (copy.equals(permutation)) {
				return i + 1;
			}
		}
		return 0;
	}
5.
biojava/biojava · PermutationGroup.java
Match rating: 74.61% · See similar code snippets
java logo
public static List<Integer> combine(List<Integer> permutation1, List<Integer> permutation2) {
		List<Integer> intermediate = new ArrayList<Integer>(permutation1.size());
		for (int i = 0, n = permutation1.size(); i < n; i++) {
			intermediate.add(permutation2.get(permutation1.get(i)));
		}
		return intermediate;
	}
6.
Match rating: 74.28% · See similar code snippets
java logo
public int test(Permutation permutation) {
        for (int i = 0; i < size; i++) {
            int x = permutation.get(base.get(i));
            Permutation h = permutations[i][x];
            if (h == null) {
                return i;
            } else {
                permutation.setTo(h.invert().multiply(permutation));
            }
        }
        return size;
    }
7.
cdk/cdk · Partition.java
Match rating: 73.24% · See similar code snippets
java logo
public Permutation toPermutation() {
        Permutation p = new Permutation(this.size());
        for (int i = 0; i < this.size(); i++) {
            p.set(i, this.cells.get(i).first());
        }
        return p;
    }
8.
Match rating: 72.64% · See similar code snippets
java logo
public List<Permutation> all() {
        final List<Permutation> permutations = new ArrayList<Permutation>();
        Backtracker counter = new Backtracker() {

            @Override
            public void applyTo(Permutation p) {
                permutations.add(p);
            }

            @Override
            public boolean isFinished() {
                return false;
            }
        };
        this.apply(counter);
        return permutations;
    }
9.
skjolber/3d-bin-container-packing · PermutationRotationIterator.java
Match rating: 72.4% · See similar code snippets
java logo
public boolean nextPermutation() {
		resetRotations();

	    // Find longest non-increasing suffix

	    int i = permutations.length - 1;
	    while (i > 0 && permutations[i - 1] >= permutations[i])
	        i--;
	    // Now i is the head index of the suffix

	    // Are we at the last permutation already?
	    if (i <= 0) {
	        return false;
	    }

	    // Let array[i - 1] be the pivot
	    // Find rightmost element that exceeds the pivot
	    int j = permutations.length - 1;
	    while (permutations[j] <= permutations[i - 1])
	        j--;
	    // Now the value array[j] will become the new pivot
	    // Assertion: j >= i

	    // Swap the pivot with j
	    int temp = permutations[i - 1];
	    permutations[i - 1] = permutations[j];
	    permutations[j] = temp;

	    // Reverse the suffix
	    j = permutations.length - 1;
	    while (i < j) {
	        temp = permutations[i];
	        permutations[i] = permutations[j];
	        permutations[j] = temp;
	        i++;
	        j--;
	    }

	    // Successfully computed the next permutation
	    return true;
	}
10.
biojava/biojava · RotationSolver.java
Match rating: 72.32% · See similar code snippets
java logo
private Rotation isValidPermutation(List<Integer> permutation) {
		if (permutation.size() == 0) {
			return null;
		}

		// cached value
		if (evaluatedPermutations.containsKey(permutation)) {
			return evaluatedPermutations.get(permutation);
		}

		// check if permutation is allowed
		if (! isAllowedPermutation(permutation)) {
			evaluatedPermutations.put(permutation, null);
			return null;
		}

		// check if superimposes
		Rotation rot = superimposePermutation(permutation);
		return rot;
	}