Ejemplo n.º 1
0
        private bool? EquationLaws(Equation rootEq, bool withEqRule, out object outputEq,
            bool lineCheck = false)
        {
/*            Equation currentEq;
            if (Traces.Count == 0)
            {
                currentEq = this;
            }
            else
            {
                var tuple = Traces[Traces.Count - 1];
                var lst = tuple.Item2 as List<TraceStep>;
                Debug.Assert(lst != null);
                currentEq = lst[lst.Count - 1].Target as Equation;
            }*/
            Equation currentEq = FindCurrentEq(rootEq);
            outputEq = currentEq;

            Debug.Assert(currentEq != null);
            bool hasChange;
            do
            {
                hasChange = false;

                Equation localEq00 = currentEq.EvalTermInEquation(rootEq, true);
                if (!localEq00.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq00;
                }
                Equation localEq0 = currentEq.EvalTermInEquation(rootEq, false);
                if (!localEq0.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq0;
                }

                bool? satisfiable = Satisfy(currentEq);
                if (satisfiable != null)
                {
                    if (rootEq._innerLoop.Count != 0)
                    {
                        rootEq.GenerateATrace(EquationsRule.EqStrategy);
                    }
                    outputEq = currentEq;
                    return satisfiable.Value;
                }

                var localEq000 = currentEq.ApplyTransitive2(rootEq, withEqRule, lineCheck);
                if (!localEq000.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq000 as Equation;
                }

                var localObj1 = currentEq.ApplyTransitive(rootEq, withEqRule, lineCheck);

                var localEq1 = localObj1 as Equation;
                var localEqLst = localObj1 as List<Equation>;
                if (localEqLst != null)
                {
                    if (rootEq._innerLoop.Count != 0)
                    {
                        rootEq.GenerateATrace(EquationsRule.EqStrategy);
                    }
                    outputEq = localEqLst;
                    return null;
                }

                if (localEq1 != null && !localEq1.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq1;
                }

                var localEq2 = localEq1.ApplySymmetric(rootEq);
                if (!localEq2.Equals(localEq1))
                {
                    hasChange = true;
                    currentEq = localEq2;
                }

            } while (hasChange);

            if (rootEq._innerLoop.Count != 0)
            {
                rootEq.GenerateATrace(EquationsRule.EqStrategy);
            }

            outputEq = currentEq;
            return null;
        }
Ejemplo n.º 2
0
        private bool?EquationLaws(Equation rootEq, bool withEqRule, out object outputEq,
                                  bool lineCheck = false)
        {
/*            Equation currentEq;
 *          if (Traces.Count == 0)
 *          {
 *              currentEq = this;
 *          }
 *          else
 *          {
 *              var tuple = Traces[Traces.Count - 1];
 *              var lst = tuple.Item2 as List<TraceStep>;
 *              Debug.Assert(lst != null);
 *              currentEq = lst[lst.Count - 1].Target as Equation;
 *          }*/
            Equation currentEq = FindCurrentEq(rootEq);

            outputEq = currentEq;

            Debug.Assert(currentEq != null);
            bool hasChange;

            do
            {
                hasChange = false;

                Equation localEq00 = currentEq.EvalTermInEquation(rootEq, true);
                if (!localEq00.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq00;
                }
                Equation localEq0 = currentEq.EvalTermInEquation(rootEq, false);
                if (!localEq0.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq0;
                }

                bool?satisfiable = Satisfy(currentEq);
                if (satisfiable != null)
                {
                    if (rootEq._innerLoop.Count != 0)
                    {
                        rootEq.GenerateATrace(EquationsRule.EqStrategy);
                    }
                    outputEq = currentEq;
                    return(satisfiable.Value);
                }

                var localEq000 = currentEq.ApplyTransitive2(rootEq, withEqRule, lineCheck);
                if (!localEq000.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq000 as Equation;
                }

                var localObj1 = currentEq.ApplyTransitive(rootEq, withEqRule, lineCheck);

                var localEq1   = localObj1 as Equation;
                var localEqLst = localObj1 as List <Equation>;
                if (localEqLst != null)
                {
                    if (rootEq._innerLoop.Count != 0)
                    {
                        rootEq.GenerateATrace(EquationsRule.EqStrategy);
                    }
                    outputEq = localEqLst;
                    return(null);
                }

                if (localEq1 != null && !localEq1.Equals(currentEq))
                {
                    hasChange = true;
                    currentEq = localEq1;
                }

                var localEq2 = localEq1.ApplySymmetric(rootEq);
                if (!localEq2.Equals(localEq1))
                {
                    hasChange = true;
                    currentEq = localEq2;
                }
            } while (hasChange);

            if (rootEq._innerLoop.Count != 0)
            {
                rootEq.GenerateATrace(EquationsRule.EqStrategy);
            }

            outputEq = currentEq;
            return(null);
        }