Esempio n. 1
0
        /// <summary>
        /// Find the minimal signature string by trying all colors.
        /// </summary>
        /// <param name="color">the current color to use</param>
        /// <param name="canonicalVertexSignature">the buffer to fill</param>
        public void Canonize(int color, StringBuilder canonicalVertexSignature)
        {
            // assume that the atom invariants have been initialized
            if (this.GetVertexCount() == 0)
            {
                return;
            }

            this.dag.UpdateVertexInvariants();
            int[]      parents = dag.GetParentsInFinalString();
            List <int> orbit   = this.dag.CreateOrbit(parents);

            if (orbit.Count < 2)
            {
                // Color all uncolored atoms having two parents
                // or more according to their invariant.
                List <InvariantInt> pairs = dag.GetInvariantPairs(parents);
                foreach (var pair in pairs)
                {
                    this.dag.SetColor(pair.index, color);
                    color++;
                }

                TMP_COLORING_COUNT++;

                // Creating the root signature string.
                string signature = this.ToString();
                int    cmp       = string.Compare(signature, canonicalVertexSignature.ToString(), StringComparison.Ordinal);
                int    l         = canonicalVertexSignature.Length;
                if (cmp > 0)
                {
                    var temp = signature + canonicalVertexSignature.ToString().Substring(l);
                    canonicalVertexSignature.Clear();
                    canonicalVertexSignature.Append(temp);
                }
                else
                {
                }
                return;
            }
            else
            {
                foreach (var o in orbit)
                {
                    this.dag.SetColor(o, color);
                    Invariants invariantsCopy = this.dag.CopyInvariants();
                    this.Canonize(color + 1, canonicalVertexSignature);
                    this.dag.SetInvariants(invariantsCopy);
                    this.dag.SetColor(o, -1);
                }
            }
        }