AbstractDiscretePartitionRefiner implements DiscretePartitionRefiner { public Partition getAutomorphismPartition() { final int n = group.getSize(); final DisjointSetForest forest = new DisjointSetForest(n); group.apply(new PermutationGroup.Backtracker() { boolean[] inOrbit = new boolean[n]; private int inOrbitCount = 0; private boolean isFinished; @Override public boolean isFinished() { return isFinished; } @Override public void applyTo(Permutation p) { for (int elementX = 0; elementX < n; elementX++) { if (inOrbit[elementX]) { continue; } else { int elementY = p.get(elementX); while (elementY != elementX) { if (!inOrbit[elementY]) { inOrbitCount++; inOrbit[elementY] = true; forest.makeUnion(elementX, elementY); } elementY = p.get(elementY); } } } if (inOrbitCount == n) { isFinished = true; } } }); Partition partition = new Partition(); for (int[] set : forest.getSets()) { partition.addCell(set); } partition.order(); return partition; } AbstractDiscretePartitionRefiner(); void setup(PermutationGroup group, EquitablePartitionRefiner refiner); boolean firstIsIdentity(); Partition getAutomorphismPartition(); String getFirstHalfMatrixString(); String getHalfMatrixString(); PermutationGroup getAutomorphismGroup(); Permutation getBest(); Permutation getFirst(); boolean isCanonical(); void refine(Partition partition);  }
@Test public void getAutomorphismPartitionTest() { int n = 3; Graph g = new Graph(n); g.connectionTable = new int[][]{{0, 1, 1}, {1, 0, 0}, {1, 0, 0}}; PermutationGroup group = new PermutationGroup(n); MockRefiner refiner = new MockRefiner(g); setup(refiner, group, g); refiner.refine(Partition.unit(n)); Partition autPartition = refiner.getAutomorphismPartition(); Partition expected = Partition.fromString("0|1,2"); Assert.assertEquals(expected, autPartition); }