Beispiel #1
0
        public void ComputeVertexInvariants()
        {
            var layerInvariants = new Dictionary <int, int[]>();

            for (int i = 0; i < this.nodes.Count; i++)
            {
                DAG.Node node = this.nodes[i];
                int      j    = node.vertexIndex;
                int[]    layerInvariantsJ;
                if (layerInvariants.ContainsKey(j))
                {
                    layerInvariantsJ = layerInvariants[j];
                }
                else
                {
                    layerInvariantsJ   = new int[this.layers.Count];
                    layerInvariants[j] = layerInvariantsJ;
                }
                layerInvariantsJ[node.layer] = invariants.GetNodeInvariant(i);
            }

            var invariantLists = new List <InvariantArray>();

            foreach (var i in layerInvariants.Keys)
            {
                InvariantArray invArr = new InvariantArray(layerInvariants[i], i);
                invariantLists.Add(invArr);
            }
            invariantLists.Sort();

            int order = 1;
            int first = invariantLists[0].originalIndex;

            invariants.SetVertexInvariant(first, 1);
            for (int i = 1; i < invariantLists.Count; i++)
            {
                InvariantArray a = invariantLists[i - 1];
                InvariantArray b = invariantLists[i];
                if (!a.Equals(b))
                {
                    order++;
                }
                invariants.SetVertexInvariant(b.originalIndex, order);
            }
        }
Beispiel #2
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);
            }
        }