private List<Action> RemoveConditions(List<Action> lActions) { List<Action> lNoConditions = new List<Action>(); foreach (Action a in lActions) { HashSet<Predicate> lMandatory = a.GetMandatoryEffects(); List<CompoundFormula> lConditions = a.GetConditions(); if (lConditions.Count == 0) { lNoConditions.Add(a); } else { int iCondition = 0; foreach (CompoundFormula cfCondition in lConditions) { Action aNew = new Action(a.Name + "." + iCondition); CompoundFormula cfPreconditions = new CompoundFormula("and"); cfPreconditions.AddOperand(a.Preconditions); cfPreconditions.AddOperand(cfCondition.Operands[0]); if (!cfPreconditions.IsFalse(null)) { aNew.Preconditions = cfPreconditions; CompoundFormula cfEffects = new CompoundFormula("and"); cfEffects.AddOperand(cfCondition.Operands[1]); foreach (Predicate p in lMandatory) cfEffects.AddOperand(p); aNew.Effects = cfEffects; lNoConditions.Add(aNew); iCondition++; } } } } return lNoConditions; }
public override Formula PartiallyGround(Dictionary<string, Constant> dBindings) { CompoundFormula cfGrounded = new CompoundFormula(Operator); foreach (Formula fSub in Operands) { Formula fGrounded = fSub.PartiallyGround(dBindings); if (fGrounded is PredicateFormula) { Predicate p = ((PredicateFormula)fGrounded).Predicate; if (p.Name == Domain.TRUE_PREDICATE) { if (Operator == "and") continue; else if (Operator == "or") return fGrounded; else throw new NotImplementedException(); } if (p.Name == Domain.FALSE_PREDICATE) { if (Operator == "and") return fGrounded; else if (Operator == "or") continue; else if (Operator == "when") { return null; } else throw new NotImplementedException(); } } cfGrounded.AddOperand(fGrounded); if (cfGrounded.IsFalse(null)) return new PredicateFormula(new GroundedPredicate(Domain.FALSE_PREDICATE)); } return cfGrounded; }