示例#1
0
        private static bool UpdateTrigger(SymValue sv, MultiEdge <TFunc, TADomain> edge, ref IImmutableMap <SymValue, int> triggers)
        {
            int val = triggers [sv] + 1;

            triggers = triggers.Add(sv, val);
            return(val == edge.Arity);
        }
示例#2
0
        private SymValue FindCandidate(SymValue[] args, TFunc function)
        {
            int length    = args.Length;
            var multiEdge = new MultiEdge <TFunc, TADomain> (function, 0, length);

            for (LispList <SymValue> list = MultiEdgeMap [args [0], multiEdge]; list != null; list = list.Tail)
            {
                SymGraphTerm <TFunc> term = EqualMultiTermsMap [list.Head];
                if (term.Args.Length == length)
                {
                    bool found = true;

                    for (int i = 0; i < length; ++i)
                    {
                        if (Find(term.Args [i]) != args [i])
                        {
                            found = false;
                            break;
                        }
                    }

                    if (found)
                    {
                        return(list.Head);
                    }
                }
            }
            return(null);
        }
示例#3
0
        public void JoinMultiEdge(SymValue sv1, SymValue sv2, MultiEdge <TFunc, TADomain> edge)
        {
            var key = new Tuple <SymValue, SymValue, MultiEdge <TFunc, TADomain> > (sv1, sv2, edge);

            if (!this.visited_multi_edges.Add(key))
            {
                return;
            }

            Sequence <SymValue> list1 = this.Graph1.MultiEdgeMap [sv1, edge];
            Sequence <SymValue> list2 = this.Graph2.MultiEdgeMap [sv2, edge];

            if (list2.IsEmpty())
            {
                return;
            }
            foreach (SymValue v1 in list1.AsEnumerable())
            {
                foreach (SymValue v2 in list2.AsEnumerable())
                {
                    if (UpdatePendingCount(v1, v2, edge.Arity))
                    {
                        SymGraphTerm <TFunc> term1 = this.Graph1.EqualMultiTermsMap [v1];
                        SymGraphTerm <TFunc> term2 = this.Graph2.EqualMultiTermsMap [v2];
                        if (term1.Args != null && term2.Args != null)
                        {
                            var resultRoots = new SymValue[term1.Args.Length];
                            for (int i = 0; i < resultRoots.Length; i++)
                            {
                                resultRoots [i] = this.mappings [term1.Args [i], term2.Args [i]];
                            }
                            SymValue r = AddJointEdge(v1, v2, edge.Function, resultRoots);
                            if (r != null)
                            {
                                JoinSymbolicValue(sv1, sv2, r);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
示例#4
0
        public SymValue this [SymValue[] args, TFunc function]
        {
            get
            {
                int len = args.Length;
                for (int i = 0; i < len; i++)
                {
                    args [i] = Find(args [i]);
                }

                SymValue candidate = FindCandidate(args, function);
                if (candidate != null)
                {
                    return(candidate);
                }
                candidate = FreshSymbol();
                for (int i = 0; i < len; i++)
                {
                    var edge = new MultiEdge <TFunc, TADomain> (function, i, len);
                    MultiEdgeMap = MultiEdgeMap.Add(args [i], edge, MultiEdgeMap [args [i], edge].Cons(candidate));
                }
                EqualMultiTermsMap = EqualMultiTermsMap.Add(candidate, new SymGraphTerm <TFunc> (function, args));
                AddMultiEdgeUpdate(args, function);
                return(candidate);
            }
            set
            {
                int len = args.Length;
                for (int i = 0; i < len; i++)
                {
                    args [i] = Find(args [i]);
                }

                bool isTermEqual          = true;
                SymGraphTerm <TFunc> term = EqualMultiTermsMap [value];
                if (term.Args != null)
                {
                    for (int i = 0; i < len; i++)
                    {
                        if (term.Args [i] != args [i])
                        {
                            isTermEqual = false;
                            break;
                        }
                    }
                }

                for (int i = 0; i < len; i++)
                {
                    var edge = new MultiEdge <TFunc, TADomain> (function, i, len);
                    Sequence <SymValue> list = MultiEdgeMap [args [i], edge];
                    if (isTermEqual && !Sequence <SymValue> .Contains(list, value))
                    {
                        isTermEqual = false;
                    }
                    if (!isTermEqual)
                    {
                        MultiEdgeMap = MultiEdgeMap.Add(args [i], edge, list.Cons(value));
                    }
                }
                if (isTermEqual)
                {
                    return;
                }
                EqualMultiTermsMap = EqualMultiTermsMap.Add(value, new SymGraphTerm <TFunc> (function, args));
                AddMultiEdgeUpdate(args, function);
            }
        }
示例#5
0
 public bool Equals(MultiEdge <TFunc, TAbstractDomain> other)
 {
     return(this.Index == other.Index && this.Arity == other.Arity && this.Function.Equals(other.Function));
 }