public Formula RegressDet(Action a)
        {
            Formula f = a.RegressDet(Predicate);

            if (f != null)
            {
                return(f);
            }

            CompoundFormula cfAndNot   = new CompoundFormula("and");
            CompoundFormula cfOr       = new CompoundFormula("or");
            int             iCondition = 0;
            Predicate       pNegate    = Predicate.Negate();

            foreach (CompoundFormula cfCondition in a.GetConditions())
            {
                HashSet <Predicate> lEffects = cfCondition.Operands[1].GetAllPredicates();
                if (lEffects.Contains(Predicate))
                {
                    cfOr.AddOperand(cfCondition.Operands[0].CreateRegression(Predicate, -1));
                }
                else if (lEffects.Contains(pNegate))
                {
                    cfAndNot.AddOperand(cfCondition.Operands[0].CreateRegression(pNegate, -1).Negate());
                }
                iCondition++;
            }
            cfOr.AddOperand(this);
            cfAndNot.AddOperand(cfOr);
            return(cfAndNot.Simplify());
        }
        private Formula AddPreconditions(Action a)
        {
            CompoundFormula cfOr  = new CompoundFormula("or");
            CompoundFormula cfAnd = new CompoundFormula("and");

            cfAnd.AddOperand(a.Preconditions);
            cfAnd.AddOperand(Negate());
            cfOr.AddOperand(cfAnd);
            cfOr.AddOperand(this);
            return(cfOr.Simplify());
        }
示例#3
0
        public static void GetJointDomain(List <Domain> lDomains, List <Problem> lProblems, out Domain dJoint, out Problem pJoint)
        {
            dJoint        = lDomains[0].Clone();
            pJoint        = lProblems[0].Clone();
            pJoint.Domain = dJoint;
            CompoundFormula cfAnd = new CompoundFormula("and");

            cfAnd.AddOperand(pJoint.Goal);
            for (int i = 1; i < lDomains.Count; i++)
            {
                dJoint.Actions.AddRange(lDomains[i].Actions);
                dJoint.Predicates.UnionWith(lDomains[i].Predicates);
                dJoint.Constants.UnionWith(lDomains[i].Constants);
                foreach (Predicate pKnown in lProblems[i].Known)
                {
                    pJoint.AddKnown(pKnown);
                }
                cfAnd.AddOperand(lProblems[i].Goal);
            }
            pJoint.Goal = cfAnd.Simplify();
        }
示例#4
0
        public Formula RegressDetII(Action a)
        {
            CompoundFormula cfAndNot = new CompoundFormula("and");
            CompoundFormula cfOr     = new CompoundFormula("or");

            foreach (CompoundFormula cfCondition in a.GetConditions())
            {
                HashSet <Predicate> lEffects = new HashSet <Predicate>();
                cfCondition.Operands[1].GetAllPredicates(lEffects);
                if (lEffects.Contains(Predicate))
                {
                    cfOr.AddOperand(cfCondition.Operands[0]);
                }
                if (lEffects.Contains(Predicate.Negate()))
                {
                    cfAndNot.AddOperand(cfCondition.Operands[0].Negate());
                }
            }
            cfAndNot.AddOperand(this);
            cfOr.AddOperand(cfAndNot);
            return(cfOr.Simplify());
        }
        public Formula RegressII(Action a)
        {
            CompoundFormula cfAndNot = new CompoundFormula("and");
            CompoundFormula cfOr     = new CompoundFormula("or");

            /*
             * if (a.Effects is PredicateFormula)
             * {
             *  if (a.Effects.Equals(this))
             *      return AddPreconditions(a);//assuming that an effect can't be both deterministic and conditional
             * }
             * else
             * {
             *  CompoundFormula cfEffects = (CompoundFormula)a.Effects;
             *  if (cfEffects.Operator != "and")
             *      throw new NotImplementedException();
             *  foreach (Formula f in cfEffects.Operands)
             *      if (f.Equals(this))
             *          return AddPreconditions(a);//assuming that an effect can't be both deterministic and conditional
             * }
             * */
            foreach (CompoundFormula cfCondition in a.GetConditions())
            {
                HashSet <Predicate> lEffects = new HashSet <Predicate>();
                cfCondition.Operands[1].GetAllPredicates(lEffects);
                if (lEffects.Contains(Predicate))
                {
                    cfOr.AddOperand(cfCondition.Operands[0]);
                }
                if (lEffects.Contains(Predicate.Negate()))
                {
                    cfAndNot.AddOperand(cfCondition.Operands[0].Negate());
                }
            }
            cfAndNot.AddOperand(this);
            cfOr.AddOperand(cfAndNot);
            return(cfOr.Simplify());
        }
        public Formula RegressNonDet(Action a)
        {
            CompoundFormula cfAndNot   = new CompoundFormula("and");
            CompoundFormula cfOr       = new CompoundFormula("or");
            int             iCondition = 0;
            Predicate       pNegate    = Predicate.Negate();

            foreach (CompoundFormula cfCondition in a.GetConditions())
            {
                HashSet <Predicate> lEffects         = cfCondition.Operands[1].GetAllPredicates();
                HashSet <Predicate> lOptionalEffects = cfCondition.Operands[1].GetAllOptionalPredicates();
                if (lEffects.Contains(Predicate))
                {
                    int iChoice = cfCondition.GetChoiceIndex(Predicate);
                    cfOr.AddOperand(cfCondition.Operands[0].CreateRegression(Predicate, iChoice));
                    a.SetChoice(iCondition, iChoice);
                }
                else if (lEffects.Contains(pNegate))
                {
                    if (!lOptionalEffects.Contains(pNegate))
                    {
                        cfAndNot.AddOperand(cfCondition.Operands[0].Negate());
                    }
                    else
                    {
                        int iChoice      = cfCondition.GetChoiceIndex(pNegate);
                        int iOtherChoice = cfCondition.GetOtherChoiceIndex(pNegate);
                        cfAndNot.AddOperand(cfCondition.Operands[0].CreateRegression(pNegate, iChoice).Negate());
                        a.SetChoice(iCondition, iOtherChoice);
                    }
                }
                iCondition++;
            }
            cfOr.AddOperand(this);
            cfAndNot.AddOperand(cfOr);
            return(cfAndNot.Simplify());
        }
示例#7
0
文件: Problem.cs 项目: Sharpen6/IMAP
        public MemoryStream WriteKnowledgeProblem(HashSet <Predicate> lObserved, HashSet <Predicate> lAllValues)
        {
            MemoryStream msProblem = new MemoryStream();
            StreamWriter sw        = new StreamWriter(msProblem);

            sw.WriteLine("(define (problem K" + Name + ")");
            sw.WriteLine("(:domain K" + Domain.Name + ")");
            sw.WriteLine(";;" + SDRPlanner.Translation);
            sw.WriteLine("(:init"); //ff doesn't like the and (and");


            foreach (GroundedPredicate gp in lObserved)
            {
                if (gp.Name == "Choice")
                {
                    continue;
                }
                sw.WriteLine(gp);
                if (!Domain.AlwaysKnown(gp))
                {
                    Predicate kp = new KnowPredicate(gp);
                    sw.WriteLine(kp);
                }
            }
            HashSet <Predicate> lHidden = new HashSet <Predicate>(lAllValues.Except(lObserved));



            foreach (GroundedPredicate gp in lHidden)
            {
                sw.WriteLine(gp);
            }



            sw.WriteLine(")");

            HashSet <Predicate> lGoalPredicates = Goal.GetAllPredicates();


            CompoundFormula cfGoal = new CompoundFormula("and");

            foreach (Predicate p in lGoalPredicates)
            {
                if (Domain.AlwaysKnown(p))
                {
                    cfGoal.AddOperand(p);
                }
                else
                {
                    cfGoal.AddOperand(new KnowPredicate(p));
                }
            }

            CompoundFormula cfAnd = new CompoundFormula(cfGoal);

            sw.WriteLine("(:goal " + cfAnd.Simplify() + ")");
            //sw.WriteLine("))");

            sw.WriteLine(")");
            sw.Flush();


            return(msProblem);
        }
示例#8
0
文件: Problem.cs 项目: Sharpen6/IMAP
        public MemoryStream WriteKnowledgeProblem(HashSet <Predicate> lObserved, HashSet <Predicate> lHidden, int cMinMishaps, int cMishaps, bool bRemoveNegativePreconditions)
        {
            MemoryStream msProblem = new MemoryStream();
            StreamWriter sw        = new StreamWriter(msProblem);

            sw.WriteLine("(define (problem K" + Name + ")");
            sw.WriteLine("(:domain K" + Domain.Name + ")");
            sw.WriteLine(";;" + SDRPlanner.Translation);
            sw.WriteLine("(:init"); //ff doesn't like the and (and");

            string sKP = "", sP = "";

            HashSet <string> lNegativePreconditons = new HashSet <string>();

            if (bRemoveNegativePreconditions)
            {
                foreach (Predicate p in Domain.IdentifyNegativePreconditions())
                {
                    lNegativePreconditons.Add(p.Name);
                }
            }

            foreach (GroundedPredicate gp in lObserved)
            {
                if (gp.Name == "Choice")
                {
                    continue;
                }
                if (Domain.AlwaysKnown(gp))
                {
                    sw.WriteLine(gp);
                }
                if (!Domain.AlwaysKnown(gp))
                {
                    Predicate kp = new KnowPredicate(gp);
                    sw.WriteLine(kp);
                }
                if (gp.Negation && bRemoveNegativePreconditions && lNegativePreconditons.Contains(gp.Name))
                {
                    Predicate np = gp.Negate().Clone();
                    np.Name = "Not" + gp.Name;
                    sw.WriteLine(np);
                }
            }
            if (bRemoveNegativePreconditions)
            {
                foreach (GroundedPredicate gp in lHidden)
                {
                    Predicate nkp = gp.Clone();
                    nkp.Name = "NotK" + gp.Name;
                    sw.WriteLine(nkp);
                    Predicate nknp = gp.Clone();
                    nknp.Name = "NotKN" + gp.Name;
                    sw.WriteLine(nknp);
                }
            }

            if (cMinMishaps > cMishaps)
            {
                sw.WriteLine("(MishapCount m" + cMishaps + ")");
            }

            if (SDRPlanner.AddActionCosts)
            {
                sw.WriteLine("(= (total-cost) 0)");
            }

            sw.WriteLine(")");

            HashSet <Predicate> lGoalPredicates    = Goal.GetAllPredicates();


            CompoundFormula cfGoal = new CompoundFormula("and");

            foreach (Predicate p in lGoalPredicates)
            {
                if (Domain.AlwaysKnown(p))
                {
                    cfGoal.AddOperand(p);
                }
                else
                {
                    cfGoal.AddOperand(new KnowPredicate(p));
                }
            }

            CompoundFormula cfAnd = new CompoundFormula(cfGoal);

            if (cMinMishaps > cMishaps && SDRPlanner.Translation != SDRPlanner.Translations.Conformant)
            {
                GroundedPredicate gp = new GroundedPredicate("MishapCount");
                gp.AddConstant(new Constant("mishaps", "m" + cMinMishaps));
                cfAnd.AddOperand(gp);
            }

            sw.WriteLine("(:goal " + cfAnd.Simplify() + ")");
            if (MetricStatement != null)
            {
                sw.WriteLine(MetricStatement);
            }

            sw.WriteLine(")");
            sw.Flush();


            return(msProblem);
        }
示例#9
0
        public MemoryStream WriteKnowledgeProblem(HashSet <Predicate> lObserved, HashSet <Predicate> lHidden, int cMinMishaps, int cMishaps)
        {
            MemoryStream msProblem = new MemoryStream();
            StreamWriter sw        = new StreamWriter(msProblem);

            sw.WriteLine("(define (problem K" + Name + ")");
            sw.WriteLine("(:domain K" + Domain.Name + ")");
            sw.WriteLine(";;" + SDRPlanner.Translation);
            sw.WriteLine("(:init"); //ff doesn't like the and (and");

            string sKP = "", sP = "";

            foreach (GroundedPredicate gp in lObserved)
            {
                if (gp.Name == "Choice")
                {
                    continue;
                }
                if (Domain.AlwaysKnown(gp))
                {
                    sw.WriteLine(gp);
                }
                if (!Domain.AlwaysKnown(gp))
                {
                    Predicate kp = new KnowPredicate(gp);
                    sw.WriteLine(kp);
                }
            }
            foreach (GroundedPredicate gp in lHidden)
            {
                //GroundedPredicate kp = new GroundedPredicate(gp);
                //kp.Name = "NotK" + kp.Name;
                //sw.WriteLine(kp);
            }

            if (cMinMishaps > cMishaps)
            {
                sw.WriteLine("(MishapCount m" + cMishaps + ")");
            }

            sw.WriteLine(")");

            HashSet <Predicate> lGoalPredicates = Goal.GetAllPredicates();


            CompoundFormula cfGoal = new CompoundFormula("and");

            foreach (Predicate p in lGoalPredicates)
            {
                if (Domain.AlwaysKnown(p))
                {
                    cfGoal.AddOperand(p);
                }
                else
                {
                    cfGoal.AddOperand(new KnowPredicate(p));
                }
            }

            CompoundFormula cfAnd = new CompoundFormula(cfGoal);

            if (cMinMishaps > cMishaps && SDRPlanner.Translation != SDRPlanner.Translations.Conformant)
            {
                GroundedPredicate gp = new GroundedPredicate("MishapCount");
                gp.AddConstant(new Constant("mishaps", "m" + cMinMishaps));
                cfAnd.AddOperand(gp);
            }

            sw.WriteLine("(:goal " + cfAnd.Simplify() + ")");
            //sw.WriteLine("))");

            sw.WriteLine(")");
            sw.Flush();


            return(msProblem);
        }