/// <summary> /// Extracts the parameters from the given atom. /// </summary> /// <param name="atom">Atom.</param> private void ExtractParameters(IAtom atom) { foreach (var term in atom.GetTerms()) { ExtractParameters(term); } }
/// <summary> /// Grounds the atom. The "deep" version of terms grounding is used. /// </summary> /// <param name="atom">Function or predicate atom.</param> /// <param name="substitution">Variables substitution.</param> /// <param name="referenceState">Reference state.</param> /// <returns>Grounded atom.</returns> public IAtom GroundAtomDeep(IAtom atom, ISubstitution substitution, IState referenceState) { List <ITerm> groundedTerms = new List <ITerm>(); atom.GetTerms().ForEach(term => groundedTerms.Add(GroundTermDeep(term, substitution, referenceState))); return(new Atom(atom.GetNameId(), groundedTerms)); }
/// <summary> /// Grounds the atom. /// </summary> /// <param name="atom">Function or predicate atom.</param> /// <param name="substitution">Variables substitution.</param> /// <returns>Grounded atom.</returns> public IAtom GroundAtom(IAtom atom, ISubstitution substitution) { List <ITerm> groundedTerms = new List <ITerm>(); atom.GetTerms().ForEach(term => groundedTerms.Add(GroundTerm(term, substitution))); return(new Atom(atom.GetNameId(), groundedTerms)); }
/// <summary> /// Checks whether the atom terms need a rename of any parameter and performs the rename. /// </summary> /// <param name="atom">Predicate or function atom.</param> private void CheckAndRenameAtom(IAtom atom) { foreach (var term in atom.GetTerms()) { CheckAndRenameTerm(term); } }
public static IGroundedAtom GroundAtom(IAtom atom, ISubstitution substitution, State referenceState) { List <int> argumentsList = new List <int>(); foreach (var term in atom.GetTerms()) { argumentsList.Add(TermGrounder.Ground(term, substitution, referenceState)); } return(new GroundedAtom(atom.GetNameID(), argumentsList)); }
/// <summary> /// Gets the unification with the specified atom, i.e. calculates the variable substitution required to ground variable terms of the /// current atom with the grounded terms (i.e. constants) of the other atom. /// </summary> /// <param name="referenceAtom">Reference atom.</param> /// <returns>Unification in the form of variable substitution.</returns> public ISubstitution GetUnificationWith(IAtom referenceAtom) { Debug.Assert(GetNameId() == referenceAtom.GetNameId() && GetTerms().Count == referenceAtom.GetTerms().Count, "Unification of incompatible atoms!"); ISubstitution unification = new Substitution(); int termIndex = 0; foreach (var term in GetTerms()) { VariableTerm variableTerm = term as VariableTerm; if (variableTerm != null) { ConstantTerm valueTerm = referenceAtom.GetTerms()[termIndex] as ConstantTerm; if (valueTerm != null) { unification.Add(variableTerm.NameId, valueTerm.NameId); } } ++termIndex; } return(unification); }