예제 #1
0
        public bool Reify(Dictionary <object, object> substitutions)
        {
            Lhs = LogicSharp.Reify(Lhs, substitutions);
            Rhs = LogicSharp.Reify(Rhs, substitutions);

            if (Var.ContainsVar(Lhs) || Var.ContainsVar(Rhs))
            {
                return(true);
            }
            else
            {
                return(Lhs.Equals(Rhs));
            }
        }
예제 #2
0
        public object EvalGoal(object field, EqGoal goal)
        {
            var    substitute = goal.ToDict();
            object result     = null;

            if (Var.ContainsVar(field))
            {
                result = LogicSharp.Reify(field, substitute);
            }
            else
            {
                result = field;
            }
            return(result);
        }
예제 #3
0
        public bool Reify(EqGoal goal)
        {
            var lhsTerm = Lhs as Term;
            var rhsTerm = Rhs as Term;
            var lhsVar  = Lhs as Var;
            var rhsVar  = Rhs as Var;

            string strategy = "Reify equation's internal variable by substituing a given fact.";

            if (lhsVar != null)
            {
                var lhsNum = LogicSharp.Reify(lhsVar, goal.ToDict());
                if (lhsNum != null && !lhsNum.Equals(lhsVar))
                {
                    var cloneEq = Clone();
                    cloneEq.Lhs = lhsNum;

                    string rule        = SubstitutionRule.ApplySubstitute();
                    string appliedRule = SubstitutionRule.ApplySubstitute(this, cloneEq);
                    var    ts          = new TraceStep(this, cloneEq, SubstitutionRule.SubstituteKC(), rule, appliedRule);
                    cloneEq._innerLoop.Add(ts);
                    cloneEq.GenerateATrace(strategy);
                    CachedEntities.Add(cloneEq);
                    return(true);
                }
            }

            if (rhsVar != null)
            {
                var rhsNum = LogicSharp.Reify(rhsVar, goal.ToDict());
                if (rhsNum != null && !rhsNum.Equals(lhsVar))
                {
                    var cloneEq = Clone();
                    cloneEq.Rhs = rhsNum;
                    string rule        = SubstitutionRule.ApplySubstitute();
                    string appliedRule = SubstitutionRule.ApplySubstitute(this, goal);
                    var    ts          = new TraceStep(this, cloneEq, SubstitutionRule.SubstituteKC(), rule, appliedRule);
                    cloneEq._innerLoop.Add(ts);
                    cloneEq.GenerateATrace(strategy);
                    CachedEntities.Add(cloneEq);
                    return(true);
                }
            }

            if (lhsTerm != null)
            {
                var term1 = lhsTerm.Reify(goal) as Term;
                if (lhsTerm.Equals(term1) || term1 == null)
                {
                    return(false);
                }
                var obj = term1.Eval();

                var cloneEq = Clone();
                cloneEq.Lhs = obj;
                string rule        = SubstitutionRule.ApplySubstitute();
                string appliedRule = SubstitutionRule.ApplySubstitute(this, goal);
                var    ts          = new TraceStep(this, cloneEq, SubstitutionRule.SubstituteKC(), rule, appliedRule);
                cloneEq._innerLoop.Add(ts);
                cloneEq.GenerateATrace(strategy);
                CachedEntities.Add(cloneEq);

                return(true);
            }

            if (rhsTerm != null)
            {
                object obj = rhsTerm.Reify(goal);
                if (rhsTerm.Equals(obj))
                {
                    return(false);
                }
                var cloneEq = Clone();
                cloneEq.Rhs = obj;
                string rule        = SubstitutionRule.ApplySubstitute();
                string appliedRule = SubstitutionRule.ApplySubstitute(this, goal);
                var    ts          = new TraceStep(this, cloneEq, SubstitutionRule.SubstituteKC(), rule, appliedRule);
                cloneEq._innerLoop.Add(ts);
                cloneEq.GenerateATrace(strategy);

                CachedEntities.Add(cloneEq);
                return(true);
            }
            return(false);
        }