public void OrderTest() { Partition p = new Partition(new int[][] { new[] { 1, 3 }, new[] { 0, 2 } }); p.Order(); SortedSet <int> cell0 = p.GetCell(0); SortedSet <int> cell1 = p.GetCell(1); Assert.IsTrue(cell0.First() < cell1.First()); Assert.IsTrue(cell0.Last() < cell1.Last()); }
/// <summary> /// The automorphism partition is a partition of the elements of the group. /// /// <returns>a partition of the elements of group</returns> /// </summary> public Partition GetAutomorphismPartition() { int n = group.Count; DisjointSetForest forest = new DisjointSetForest(n); group.Apply(new AutomorphismPartitionBacktracker(n, forest)); // convert to a partition Partition partition = new Partition(); foreach (var set in forest.GetSets()) { partition.AddCell(set); } // necessary for comparison by string partition.Order(); return(partition); }
/// <summary> /// Get the bond partition, based on the element types of the atoms at either end /// of the bond, and the bond order. /// </summary> /// <returns>a partition of the bonds based on the element types and bond order</returns> public Partition GetInitialPartition() { var bondCount = atomContainer.Bonds.Count; var cellMap = new Dictionary <string, SortedSet <int> >(); // make mini-'descriptors' for bonds like "C=O" or "C#N" etc for (int bondIndex = 0; bondIndex < bondCount; bondIndex++) { var bond = atomContainer.Bonds[bondIndex]; var el0 = bond.Atoms[0].Symbol; var el1 = bond.Atoms[1].Symbol; string boS; if (ignoreBondOrders) { // doesn't matter what it is, so long as it's constant boS = "1"; } else { var isArom = bond.IsAromatic; var orderNumber = isArom ? 5 : bond.Order.Numeric(); boS = orderNumber.ToString(NumberFormatInfo.InvariantInfo); } string bondString; if (string.CompareOrdinal(el0, el1) < 0) { bondString = el0 + boS + el1; } else { bondString = el1 + boS + el0; } SortedSet <int> cell; if (cellMap.ContainsKey(bondString)) { cell = cellMap[bondString]; } else { cell = new SortedSet <int>(); cellMap[bondString] = cell; } cell.Add(bondIndex); } // sorting is necessary to get cells in order var bondStrings = new List <string>(cellMap.Keys); bondStrings.Sort(); // the partition of the bonds by these 'descriptors' var bondPartition = new Partition(); foreach (string key in bondStrings) { var cell = cellMap[key]; bondPartition.AddCell(cell); } bondPartition.Order(); return(bondPartition); }