Пример #1
0
        public void Test(IAtomContainer mol, int expected)
        {
            AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();
            PermutationGroup             group   = refiner.GetAutomorphismGroup(mol);

            Assert.AreEqual(expected, group.Order());
        }
Пример #2
0
        /// <summary>
        /// Change the base of the group to the new base <paramref name="newBase"/>.
        /// </summary>
        /// <param name="newBase">the new base for the group</param>
        public void ChangeBase(Permutation newBase)
        {
            var h = new PermutationGroup(newBase);

            int firstDiffIndex = basePermutation.FirstIndexOfDifference(newBase);

            for (int j = firstDiffIndex; j < size; j++)
            {
                for (int a = 0; a < size; a++)
                {
                    Permutation g = permutations[j][a];
                    if (g != null)
                    {
                        h.Enter(g);
                    }
                }
            }

            for (int j = 0; j < firstDiffIndex; j++)
            {
                for (int a = 0; a < size; a++)
                {
                    Permutation g = permutations[j][a];
                    if (g != null)
                    {
                        int hj = h.basePermutation[j];
                        int x  = g[hj];
                        h.permutations[j][x] = new Permutation(g);
                    }
                }
            }
            this.basePermutation = new Permutation(h.basePermutation);
            this.permutations    = (Permutation[][])h.permutations.Clone();
        }
Пример #3
0
        public void GetSizeTest()
        {
            int size = 4;
            PermutationGroup group = new PermutationGroup(size);

            Assert.AreEqual(size, group.Count);
        }
Пример #4
0
 void Main()
 {
     IAtomContainer someMolecule = null;
     {
         #region 1
         IAtomContainer ac = someMolecule; // get an atom container somehow
         AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();
         PermutationGroup             autG    = refiner.GetAutomorphismGroup(ac);
         foreach (var automorphism in autG.GenerateAll())
         {
             // do something with the permutation
         }
         #endregion
     }
     {
         #region 2
         IAtomContainer ac = someMolecule; // get an atom container somehow
         AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();
         if (refiner.IsCanonical(ac))
         {
             // do something with the atom container
         }
         #endregion
     }
     {
         IAtomContainer ac = someMolecule;
         #region 3
         AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();
         refiner.Refine(ac);
         bool             isCanon = refiner.IsCanonical();
         PermutationGroup autG    = refiner.GetAutomorphismGroup();
         #endregion
     }
 }
Пример #5
0
        public void GetTest()
        {
            int size = 6;
            // group that could represent a hexagon (numbered clockwise from top)
            // p1 = a flip across the vertical, p2 = flip across the horizontal
            Permutation p1         = new Permutation(0, 5, 4, 3, 2, 1);
            Permutation p2         = new Permutation(3, 2, 1, 0, 5, 4);
            var         generators = new List <Permutation>
            {
                p1,
                p2
            };
            PermutationGroup group = new PermutationGroup(size, generators);

            // the permutations in U0 all have 0 in the orbit of i
            // but fixing 0 cannot fix 1, so there is no such perm
            int         uIndex    = 0;
            int         uSubIndex = 1;
            Permutation u01       = group[uIndex, uSubIndex];

            Assert.IsNull(u01);

            // however, 0 and 3 are in the same orbit by both flips
            uSubIndex = 3;
            Permutation u03   = group[uIndex, uSubIndex];
            var         orbit = u03.GetOrbit(0);

            Assert.IsTrue(orbit.Contains(uSubIndex));
        }
Пример #6
0
        public void OrderTest()
        {
            int size             = 5;
            PermutationGroup sym = PermutationGroup.MakeSymN(size);

            Assert.AreEqual(Factorial(size), sym.Order());
        }
Пример #7
0
        public void GetLeftTransversalTest()
        {
            PermutationGroup group = GetCubeGroup();
            var transversal        = group.GetLeftTransversal(1);

            Assert.AreEqual(3, transversal.Count);
        }
Пример #8
0
        public void TestTransversal()
        {
            int size = 4;
            // Sym(n) : make the total symmetry group
            PermutationGroup group = PermutationGroup.MakeSymN(size);

            // Aut(G) : make the automorphism group for a graph
            Permutation p1         = new Permutation(2, 1, 0, 3);
            Permutation p2         = new Permutation(0, 3, 2, 1);
            var         generators = new List <Permutation>
            {
                p1,
                p2
            };
            PermutationGroup subgroup = new PermutationGroup(size, generators);

            // generate the traversal
            var transversal = group.Transversal(subgroup);

            int subgroupOrder   = (int)subgroup.Order();
            int groupOrder      = (int)group.Order();
            int transversalSize = transversal.Count;

            // check that |Aut(G)| / |Sym(N)| = |Transversal|
            Assert.AreEqual(Factorial(size), groupOrder);
            Assert.AreEqual(groupOrder / subgroupOrder, transversalSize);
        }
Пример #9
0
        public void SizeConstructor()
        {
            int size = 4;
            PermutationGroup group = new PermutationGroup(size);

            Assert.AreEqual(size, group.Count);
        }
Пример #10
0
 public TransversalBacktracker(PermutationGroup parent, PermutationGroup subgroup, long m, IList <Permutation> results)
 {
     this.parent   = parent;
     this.subgroup = subgroup;
     this.m        = m;
     this.results  = results;
 }
 /// <summary>
 /// Setup the group and refiner; it is important to call this method before
 /// calling <see cref="Refine(Partition)"/>  otherwise the refinement process will fail.
 /// </summary>
 /// <param name="group">a group (possibly empty) of automorphisms</param>
 /// <param name="refiner">the equitable refiner</param>
 public void Setup(PermutationGroup group, EquitablePartitionRefiner refiner)
 {
     this.bestExist        = false;
     this.best             = null;
     this.group            = group;
     this.equitableRefiner = refiner;
 }
Пример #12
0
        public void BaseConstructor()
        {
            int              size  = 4;
            Permutation      base_ = new Permutation(size);
            PermutationGroup group = new PermutationGroup(base_);

            Assert.AreEqual(size, group.Count);
        }
Пример #13
0
        public void AllTest()
        {
            int size = 4;
            PermutationGroup group = PermutationGroup.MakeSymN(size);
            var all = group.GenerateAll();

            Assert.AreEqual(Factorial(size), all.Count);
        }
Пример #14
0
        public void EnterTest()
        {
            int size = 4;
            PermutationGroup group = new PermutationGroup(size);

            group.Enter(new Permutation(1, 0, 3, 2));
            Assert.AreEqual(2, group.Order());
        }
Пример #15
0
        public void ApplyTest()
        {
            var all  = new List <Permutation>();
            int size = 4;
            PermutationGroup group = PermutationGroup.MakeSymN(size);

            group.Apply(new NBacktracker(all));
            Assert.AreEqual(Factorial(size), all.Count);
        }
Пример #16
0
        public void Test_SuccessTest()
        {
            PermutationGroup group = GetCubeGroup();
            Permutation      p     = new Permutation(6, 7, 4, 5, 2, 3, 0, 1);
            int position           = group.Test(p);

            // this means p is a member of G
            Assert.IsTrue(position == group.Count);
        }
Пример #17
0
        public void Test_FailureTest()
        {
            PermutationGroup group = GetCubeGroup();
            Permutation      p     = new Permutation(1, 2, 3, 4, 0, 6, 7, 5);
            int position           = group.Test(p);

            // this means p is not in G
            Assert.IsTrue(position < group.Count);
        }
Пример #18
0
        /// <summary>
        /// Generate a transversal of a subgroup in this group.
        /// </summary>
        /// <param name="subgroup">the subgroup to use for the transversal</param>
        /// <returns>a list of permutations</returns>
        public IReadOnlyCollection <Permutation> Transversal(PermutationGroup subgroup)
        {
            long m       = this.Order() / subgroup.Order();
            var  results = new List <Permutation>();
            var  transversalBacktracker = new TransversalBacktracker(this, subgroup, m, results);

            this.Apply(transversalBacktracker);
            return(results);
        }
Пример #19
0
        public void Apply_FinishEarlyTest()
        {
            List <Permutation> all = new List <Permutation>();
            int max  = 5; // stop after this many seen
            int size = 4;
            PermutationGroup group = PermutationGroup.MakeSymN(size);

            group.Apply(new FinishEarlyBacktracker(all, max));
            Assert.AreEqual(max, all.Count);
        }
        public void GetAutomorphismGroup_StartingPartitionTest()
        {
            Partition      partition             = Partition.FromString("0,1|2,3");
            string         acpString             = "C0C1C2C3 0:1(1),0:3(1),1:2(1),2:3(1)";
            IAtomContainer ac                    = AtomContainerPrinter.FromString(acpString, builder);
            AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();
            PermutationGroup             autG    = refiner.GetAutomorphismGroup(ac, partition);

            Assert.AreEqual(2, autG.Order());
        }
        public void SetupTest()
        {
            int n = 5;
            PermutationGroup group   = new PermutationGroup(n);
            Graph            g       = new Graph(n);
            MockRefiner      refiner = new MockRefiner(g);

            Setup(refiner, group, g);
            Assert.AreEqual(group, refiner.GetAutomorphismGroup());
        }
        public void GetAutomorphismGroupTest()
        {
            string         acpString             = "C0C1C2O3 0:1(2),0:2(1),1:3(1),2:3(1)";
            IAtomContainer ac                    = AtomContainerPrinter.FromString(acpString, builder);
            AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();
            PermutationGroup             autG    = refiner.GetAutomorphismGroup(ac);

            Assert.IsNotNull(autG);
            Assert.AreEqual(1, autG.Order());
        }
        public void RefineTest()
        {
            string         acpString             = "C0C1O2O3 0:1(1),0:3(1),1:2(1),2:3(1)";
            IAtomContainer ac                    = AtomContainerPrinter.FromString(acpString, builder);
            AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();

            refiner.Refine(ac);
            PermutationGroup autG = refiner.GetAutomorphismGroup();

            Assert.AreEqual(2, autG.Order());
        }
        public void GetAutomorphismGroup_StartingGroupTest()
        {
            string                       acpString = "C0C1C2C3 0:1(1),0:2(1),1:3(1),2:3(1)";
            IAtomContainer               ac        = AtomContainerPrinter.FromString(acpString, builder);
            Permutation                  flip      = new Permutation(1, 0, 3, 2);
            PermutationGroup             autG      = new PermutationGroup(4, new[] { flip });
            AtomDiscretePartitionRefiner refiner   = new AtomDiscretePartitionRefiner();

            refiner.GetAutomorphismGroup(ac, autG);
            Assert.IsNotNull(autG);
            Assert.AreEqual(8, autG.Order());
        }
Пример #25
0
        public void Refine_IgnoreBondOrderTest()
        {
            string         acpString             = "C0C1C2C3 0:1(2),0:3(1),1:2(1),2:3(2)";
            IAtomContainer ac                    = AtomContainerPrinter.FromString(acpString, builder);
            bool           ignoreBondOrder       = true;
            BondDiscretePartitionRefiner refiner = new BondDiscretePartitionRefiner(ignoreBondOrder);

            refiner.Refine(ac);
            PermutationGroup autG = refiner.GetAutomorphismGroup();

            Assert.AreEqual(8, autG.Order());
        }
        public void GetGroupTest()
        {
            int   n = 3;
            Graph g = new Graph(n)
            {
                connectionTable = new int[][] { new[] { 0, 1, 0 }, new[] { 1, 0, 1 }, new[] { 0, 1, 0 } }
            };
            PermutationGroup group   = new PermutationGroup(n);
            MockRefiner      refiner = new MockRefiner(g);

            Setup(refiner, group, g);
            Assert.IsNotNull(refiner.GetAutomorphismGroup());
        }
        public void RefineTest()
        {
            int   n = 3;
            Graph g = new Graph(n)
            {
                connectionTable = new int[][] { new[] { 0, 1, 1 }, new[] { 1, 0, 0 }, new[] { 1, 0, 0 } }
            };
            PermutationGroup group   = new PermutationGroup(n);
            MockRefiner      refiner = new MockRefiner(g);

            Setup(refiner, group, g);
            refiner.Refine(Partition.Unit(n));
            Assert.IsNotNull(refiner);
        }
Пример #28
0
        public void GeneratorConstructor()
        {
            int         size       = 4;
            Permutation p1         = new Permutation(1, 0, 2, 3);
            Permutation p2         = new Permutation(1, 2, 3, 0);
            var         generators = new List <Permutation>
            {
                p1,
                p2
            };
            PermutationGroup group = new PermutationGroup(size, generators);

            Assert.AreEqual(size, group.Count);
            Assert.AreEqual(Factorial(size), group.Order());
        }
        public void GetFirstHalfMatrixStringTest()
        {
            int   n = 3;
            Graph g = new Graph(n)
            {
                connectionTable = new int[][] { new[] { 0, 0, 1 }, new[] { 0, 0, 1 }, new[] { 1, 1, 0 } }
            };
            PermutationGroup group   = new PermutationGroup(n);
            MockRefiner      refiner = new MockRefiner(g);

            Setup(refiner, group, g);
            refiner.Refine(Partition.Unit(n));
            string hms      = refiner.GetFirstHalfMatrixString();
            string expected = "110";

            Assert.AreEqual(expected, hms);
        }
        public void GetFirstTest()
        {
            int   n = 3;
            Graph g = new Graph(n)
            {
                connectionTable = new int[][] { new[] { 0, 1, 0 }, new[] { 1, 0, 1 }, new[] { 0, 1, 0 } }
            };
            PermutationGroup group   = new PermutationGroup(n);
            MockRefiner      refiner = new MockRefiner(g);

            Setup(refiner, group, g);
            refiner.Refine(Partition.Unit(n));
            Permutation first    = refiner.GetFirst();
            Permutation expected = new Permutation(1, 0, 2);

            Assert.AreEqual(expected, first);
        }