public void addUniqueVariables(List <Variable> variableSet)
 {
     for (int i = 0; i < _args.Length; ++i)
     {
         YP.addUniqueVariables(_args[i], variableSet);
     }
 }
Example #2
0
 /// <summary>
 /// If bound, call YP.addUniqueVariables on the value.  Otherwise, if this unbound
 /// variable is not already in variableSet, add it.
 /// </summary>
 /// <param name="variableSet"></param>
 public void addUniqueVariables(List <Variable> variableSet)
 {
     if (_isBound)
     {
         YP.addUniqueVariables(getValue(), variableSet);
     }
     else
     {
         if (variableSet.IndexOf(this) < 0)
         {
             variableSet.Add(this);
         }
     }
 }
Example #3
0
        /// <summary>
        /// To get the free variables, split off any existential qualifiers from Goal such as the X in
        /// "X ^ f(Y)", get the set of unbound variables in Goal that are not qualifiers, then remove
        /// the unbound variables that are qualifiers as well as the unbound variables in Template.
        /// </summary>
        /// <param name="Template"></param>
        /// <param name="Goal"></param>
        public BagofAnswers(object Template, object Goal)
        {
            _template = Template;

            // First get the set of variables that are not free variables.
            List <Variable> variableSet = new List <Variable>();

            YP.addUniqueVariables(Template, variableSet);
            object UnqualifiedGoal = YP.getValue(Goal);

            while (UnqualifiedGoal is Functor2 && ((Functor2)UnqualifiedGoal)._name == Atom.HAT)
            {
                YP.addUniqueVariables(((Functor2)UnqualifiedGoal)._arg1, variableSet);
                UnqualifiedGoal = YP.getValue(((Functor2)UnqualifiedGoal)._arg2);
            }

            // Remember how many non-free variables there are so we can find the unique free variables
            //   that are added.
            int nNonFreeVariables = variableSet.Count;

            YP.addUniqueVariables(UnqualifiedGoal, variableSet);
            int nFreeVariables = variableSet.Count - nNonFreeVariables;

            if (nFreeVariables == 0)
            {
                // There were no free variables added, so we won't waste time with _bagForFreeVariables.
                _freeVariables   = null;
                _findallBagArray = new List <object>();
            }
            else
            {
                // Copy the free variables.
                _freeVariables = new Variable[nFreeVariables];
                for (int i = 0; i < nFreeVariables; ++i)
                {
                    _freeVariables[i] = variableSet[i + nNonFreeVariables];
                }

                _bagForFreeVariables = new Dictionary <object[], List <object> >(_termArrayEqualityComparer);
            }
        }
Example #4
0
 public void addUniqueVariables(List <Variable> variableSet)
 {
     YP.addUniqueVariables(_arg1, variableSet);
     YP.addUniqueVariables(_arg2, variableSet);
 }