RandomKey extends AbstractListChromosome<Double> implements PermutationChromosome<T> { public static <S> List<Double> inducedPermutation(final List<S> originalData, final List<S> permutedData) throws DimensionMismatchException, MathIllegalArgumentException { if (originalData.size() != permutedData.size()) { throw new DimensionMismatchException(permutedData.size(), originalData.size()); } int l = originalData.size(); List<S> origDataCopy = new ArrayList<S> (originalData); Double[] res = new Double[l]; for (int i=0; i<l; i++) { int index = origDataCopy.indexOf(permutedData.get(i)); if (index == -1) { throw new MathIllegalArgumentException(LocalizedFormats.DIFFERENT_ORIG_AND_PERMUTED_DATA); } res[index] = (double) i / l; origDataCopy.set(index, null); } return Arrays.asList(res); } RandomKey(final List<Double> representation);  RandomKey(final Double[] representation); List<T> decode(final List<T> sequence); static final List<Double> randomPermutation(final int l); static final List<Double> identityPermutation(final int l); static List<Double> comparatorPermutation(final List<S> data,
                                                         final Comparator<S> comparator); static List<Double> inducedPermutation(final List<S> originalData,
                                                      final List<S> permutedData); @Override String toString();  }
@Test public void testInducedPermutation() { List<String> origData = Arrays.asList(new String[] {"a", "b", "c", "d", "d"}); List<String> permutedData = Arrays.asList(new String[] {"d", "b", "c", "a", "d"}); DummyRandomKey drk = new DummyRandomKey(RandomKey.inducedPermutation(origData, permutedData)); List<String> decoded = drk.decode(origData); Assert.assertEquals("d", decoded.get(0)); Assert.assertEquals("b", decoded.get(1)); Assert.assertEquals("c", decoded.get(2)); Assert.assertEquals("a", decoded.get(3)); Assert.assertEquals("d", decoded.get(4)); try { RandomKey.inducedPermutation( Arrays.asList(new String[] {"a", "b", "c", "d", "d"}), Arrays.asList(new String[] {"a", "b", "c", "d"}) ); Assert.fail("Uncaught exception"); } catch (IllegalArgumentException e) { } try { RandomKey.inducedPermutation( Arrays.asList(new String[] {"a", "b", "c", "d", "d"}), Arrays.asList(new String[] {"a", "b", "c", "d", "f"}) ); Assert.fail("Uncaught exception"); } catch (IllegalArgumentException e) { } }