Exemplo n.º 1
0
        public void Update(CFKRNode x, CFKRNode y)
        {
            var LCPAndZeta = GetLCP(x, y);

            y.Label.Clear();
            foreach (var l in LCPAndZeta.Item1)
            {
                y.Label.Add(l);
            }
            foreach (var l in LCPAndZeta.Item2)
            {
                y.Label.Add(l);
            }

            if (y.Rank != Infinity)
            {
                y.Label.Add(y);    
            }

            // TODO If `(y) was updated then for all arcs (y, w) ∈ E, recursively apply update(y, w).

            foreach (var node in y.Outgoing)
            {
                Update(y, node);
            }
        }
Exemplo n.º 2
0
 public Message(CFKRNode v, List<CFKRNode> label)
 {
     V = v;
     Label = label;
 }
Exemplo n.º 3
0
        public ReturnMessage BVisit(CFKRNode w, Message msg)
        {
            if(w.Index == msg.V.Index)
                return ReturnMessage.Cycle;

            if (Equals(w, msg.V) && !w.Visited(visitedCurrentRound))
            {
                foreach (var inNode in w.Incoming)
                {
                    if(BVisit(inNode, msg) == ReturnMessage.Cycle)
                        return ReturnMessage.Cycle;
                }
            }
            return ReturnMessage.NoCycle;
        }
Exemplo n.º 4
0
        public ReturnMessage FVisit(CFKRNode w, CFKRNode u)
        {
            if(w.Visited(visitedCurrentRound) || u.Index == w.Index)
                return ReturnMessage.Cycle;

            if (GreaterThan(u, w) && !w.VisitedForward(visitedCurrentRound))
            {
                foreach (var outNode in w.Outgoing)
                {
                    if(FVisit(outNode, u) == ReturnMessage.Cycle)
                        return ReturnMessage.Cycle;
                }
            }

            return ReturnMessage.NoCycle;
        }
Exemplo n.º 5
0
        public bool CycleDetect(CFKRNode u, CFKRNode v)
        {
            var backMessage = BVisit(u, new Message(v, u.Label));
            if (backMessage == ReturnMessage.Cycle)
                return true;

            var forwardMessage = FVisit(v, u);
            if (forwardMessage == ReturnMessage.Cycle)
                return true;

            return false;
        }
Exemplo n.º 6
0
        // Item1 = LCP
        // Item2 = Zeta
        public Tuple<List<CFKRNode>, List<CFKRNode>> GetLCP(CFKRNode x, CFKRNode y)
        {
            int i = 0;
            while (x.Label.Count > i && y.Label.Count > i && x.Label[i].Index == y.Label[i].Index)
            {
                i++;
            }

            var lcp = new List<CFKRNode>(i+1);
            for (int b = 0; b < i; b++)
            {
                lcp.Add(x.Label[b]);
            }
            var zeta = new List<CFKRNode>();
            for (int b = i; b < x.Label.Count; b++)
            {
                zeta.Add(x.Label[b]);
            }
            var zetaPrime = new List<CFKRNode>();
            if(zeta.Count > 0)
                zetaPrime.Add(zeta[0]);
            for (int b = 1; b < zeta.Count; b++)
            {
                if(zeta[b].Rank < y.Rank)
                    zetaPrime.Add(zeta[b]);
                else
                    break;
            }

            return new Tuple<List<CFKRNode>, List<CFKRNode>>(lcp, zetaPrime);
        }