public Object Template() { Axiom clone = Clone() as Axiom; Hashtable newBinds = clone.Bindings; List <string> keys = new List <string>(); foreach (string key in newBinds.Keys) { keys.Add(key); } foreach (string key in keys) { newBinds[key] = ""; } clone.Bindings = newBinds; clone.BindTerms(); return(clone); }
// Checks if two operators are equal. public override bool Equals(Object obj) { // Store the object an axiom Axiom ax = obj as Axiom; // If the number of preconditions are the same... if (ax.Preconditions.Count == Preconditions.Count) { // Loop through the preconditions. foreach (Predicate precondition in Preconditions) { if (!ax.Preconditions.Contains(precondition)) { return(false); } } // If the number of effects are the same... if (ax.Effects.Count == Effects.Count) { // Loop through the effects. foreach (Predicate effect in Effects) { if (!ax.Effects.Contains(effect)) { return(false); } } // Otherwise, return true! return(true); } } // Otherwise, fail. return(false); }
// Find applicable conditional effects. public List <IAxiom> ApplicableConditionals(Operator action, List <IObject> objects) { // Store the conditional axioms that are true in the current state. List <IAxiom> applicableEffects = new List <IAxiom>(); // Loop through the action's conditional effect axioms. foreach (IAxiom conditional in action.Conditionals) { List <Hashtable> bindings = new List <Hashtable>(); if (conditional.Arity == 0) { Hashtable thisBind = action.Bindings.Clone() as Hashtable; bindings.Add(thisBind); } else { for (int i = 0; i < conditional.Arity; i++) { List <Hashtable> lastBindings = new List <Hashtable>(); foreach (Hashtable lastBinding in bindings) { lastBindings.Add(lastBinding.Clone() as Hashtable); } List <Hashtable> newBindings = new List <Hashtable>(); foreach (IObject obj in objects) { List <Hashtable> theseBindings = new List <Hashtable>(); if (lastBindings.Count > 0) { foreach (Hashtable bind in lastBindings) { Hashtable thisBind = bind.Clone() as Hashtable; thisBind.Add(conditional.TermAt(i), obj.Name); theseBindings.Add(thisBind); } } else { Hashtable thisBind = action.Bindings.Clone() as Hashtable; thisBind.Add(conditional.TermAt(i), obj.Name); theseBindings.Add(thisBind); } newBindings.AddRange(theseBindings); } bindings = newBindings; } } foreach (Hashtable bind in bindings) { Axiom boundAxiom = conditional.Clone() as Axiom; boundAxiom.Bindings = bind; applicableEffects.Add(boundAxiom); } } List <IAxiom> removeCond = new List <IAxiom>(); foreach (IAxiom conditional in applicableEffects) { conditional.BindTerms(); if (!Satisfies(conditional.Preconditions)) { removeCond.Add(conditional); } } foreach (Axiom remove in removeCond) { applicableEffects.Remove(remove); } return(applicableEffects); }