Esempio n. 1
0
 public void SetInvariants(Invariants invariants)
 {
     //        this.invariants = invariants;
     this.invariants.colors           = (int[])invariants.colors.Clone();
     this.invariants.nodeInvariants   = (int[])invariants.nodeInvariants.Clone();
     this.invariants.vertexInvariants = (int[])invariants.vertexInvariants.Clone();
 }
Esempio n. 2
0
 public void TestInvariants(
     int[] nodeInv, int[] vertexInv, Invariants invariants)
 {
     // TODO
     //        Assert.AssertArrayEquals(nodeInv, invariants.nodeInvariants);
     //        Assert.AssertArrayEquals(vertexInv, invariants.vertexInvariants);
 }
Esempio n. 3
0
        public virtual Invariants Clone()
        {
            Invariants copy = new Invariants(colors.Length, vertexInvariants.Length)
            {
                colors           = (int[])colors.Clone(),
                nodeInvariants   = (int[])nodeInvariants.Clone(),
                vertexInvariants = (int[])vertexInvariants.Clone()
            };

            return(copy);
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
0
        public void InitializeWithIntLabels(int[] vertexLabels)
        {
            vertexCount     = vertexLabels.Length;
            this.invariants = new Invariants(vertexCount, nodes.Count);

            List <InvariantIntIntPair> pairs = new List <InvariantIntIntPair>();

            for (int i = 0; i < vertexCount; i++)
            {
                int l = vertexLabels[i];
                int p = parentCounts[i];
                pairs.Add(new InvariantIntIntPair(l, p, i));
            }
            pairs.Sort();

            if (pairs.Count == 0)
            {
                return;
            }

            nodeComparator = new NodeIntegerLabelComparator(vertexLabels);
            int order = 1;
            InvariantIntIntPair first = pairs[0];

            invariants.SetVertexInvariant(first.GetOriginalIndex(), order);
            for (int i = 1; i < pairs.Count; i++)
            {
                InvariantIntIntPair a = pairs[i - 1];
                InvariantIntIntPair b = pairs[i];
                if (!a.Equals(b))
                {
                    order++;
                }
                invariants.SetVertexInvariant(b.GetOriginalIndex(), order);
            }
        }