private void AddReasoningAction(HashSet <Predicate> lPreconditions, HashSet <Predicate> lEffects, Dictionary <List <Predicate>, List <Predicate> > dActions) { List <Predicate> lKnowPreconditions = new List <Predicate>(); foreach (GroundedPredicate p in lPreconditions) { KnowPredicate pKnow = new KnowPredicate(p); lKnowPreconditions.Add(pKnow); lKnowPreconditions.Add(p); } List <Predicate> lKnowEffects = new List <Predicate>(); foreach (GroundedPredicate p in lEffects) { KnowPredicate pKnow = new KnowPredicate(p); lKnowEffects.Add(pKnow); } if (dActions.ContainsKey(lKnowPreconditions)) { if (dActions.Comparer.Equals(lKnowEffects, dActions[lKnowPreconditions])) { return; } throw new NotImplementedException(); } dActions[lKnowPreconditions] = lKnowEffects; }
private Action CreateReasoningAction(Predicate pEffect, HashSet <Predicate> lPredicates) { KnowPredicate kpEffect = new KnowPredicate(pEffect); if (Predicates.Contains(kpEffect)) { return(null); } Action a = new KnowledgeAction("Reasoning_" + pEffect.ToString()); a.Preconditions = new CompoundFormula("and"); foreach (Predicate pOther in lPredicates) { if (pOther != pEffect) { KnowPredicate kp = new KnowPredicate(pOther); if (!Predicates.Contains(kp)) { return(null); } ((CompoundFormula)a.Preconditions).AddOperand(new PredicateFormula(kp)); } } CompoundFormula cfEffects = new CompoundFormula("and"); cfEffects.AddOperand(new PredicateFormula(kpEffect)); a.SetEffects(cfEffects); return(a); }
private CompoundFormula AddKnowledgePredicatesToFormula(Formula f, HashSet <Predicate> lKnowPredicates) { CompoundFormula cf = new CompoundFormula("and"); HashSet <Predicate> lPredicates = new HashSet <Predicate>(); f.GetAllPredicates(lPredicates); foreach (Predicate p in lPredicates) { if (lKnowPredicates.Contains(p)) { KnowPredicate kp = new KnowPredicate(p); cf.AddOperand(new PredicateFormula(kp)); } } if (f is CompoundFormula && ((CompoundFormula)f).Operator == "and") { foreach (Formula fSub in ((CompoundFormula)f).Operands) { cf.AddOperand(fSub); } } else { cf.AddOperand(f); } return(cf); }
public override bool Equals(object obj) { if (obj is KnowPredicate) { KnowPredicate kp = (KnowPredicate)obj; if (Value == kp.Value && Negation == kp.Negation) { return(Knowledge.Equals(kp.Knowledge)); } } return(false); }
public override Predicate Negate() { /* * KnowPredicate kpNegate = new KnowPredicate(Knowledge, Value, Parametrized); * kpNegate.Negation = !Negation; * return kpNegate; */ KnowPredicate kpNegate = new KnowPredicate(this); kpNegate.Negation = !Negation; return(kpNegate); }
public override Predicate ToTag() { KnowPredicate ppNew = new KnowPredicate(this); if (Negation) { ppNew.Name = ppNew.Name + "-Remove"; } else { ppNew.Name = ppNew.Name + "-Add"; } ppNew.Negation = false; return(ppNew); }
private void WriteResoningAction(StreamWriter sw, List <Predicate> lPreconditions, List <Predicate> lEffects, int iNumber) { sw.WriteLine("(:action R" + iNumber); sw.Write(":precondition (and"); foreach (Predicate pPrecondition in lPreconditions) { if (pPrecondition is GroundedPredicate) { if (pPrecondition.Negation) { sw.Write(" (not"); } sw.Write(" (" + pPrecondition.Name); foreach (Constant c in ((GroundedPredicate)pPrecondition).Constants) { sw.Write(" " + c.Name); } sw.Write(")"); if (pPrecondition.Negation) { sw.Write(")"); } } else if (pPrecondition is KnowPredicate) { KnowPredicate kp = (KnowPredicate)pPrecondition; sw.Write(" (K" + kp.Knowledge.Name); foreach (Constant c in ((GroundedPredicate)kp.Knowledge).Constants) { sw.Write(" " + c.Name); } sw.Write(")"); } } sw.WriteLine(")"); sw.Write(":effect (and"); foreach (KnowPredicate pEffect in lEffects) { sw.Write(" (K" + pEffect.Knowledge.Name); foreach (Constant c in ((GroundedPredicate)pEffect.Knowledge).Constants) { sw.Write(" " + c.Name); } sw.Write(")"); } sw.WriteLine(")"); sw.WriteLine(")"); }
public override Formula Ground(Dictionary <string, Constant> dBindings) { if (Predicate is ParametrizedPredicate) { ParametrizedPredicate ppred = (ParametrizedPredicate)Predicate; GroundedPredicate gpred = ppred.Ground(dBindings); return(new PredicateFormula(gpred)); } if (Predicate is KnowPredicate) { KnowPredicate kp = (KnowPredicate)Predicate; GroundedPredicate gpred = kp.Ground(dBindings); return(new PredicateFormula(gpred)); } if (Predicate is KnowGivenPredicate) { throw new NotImplementedException(); } return(this); }
public KnowPredicate(KnowPredicate kp) : base(kp.Name) { Knowledge = kp.Knowledge; Value = kp.Value; Parametrized = kp.Parametrized; }