PlanOrder() public method

Plan the Order using POP Algorithm
public PlanOrder ( IEnumerable initialState, IEnumerable goalState ) : PartialOrderPlan
initialState IEnumerable Initial Predicates
goalState IEnumerable Goal Predicates
return PartialOrderPlan
        public void PlanOrderTest()
        {
            Action RightShoe = new Action(Predicate.Create("RightShoe"));
            RightShoe.AddPrecondition(Predicate.Create("RightSockOn"));
            RightShoe.AddEffect(Predicate.Create("RightShoeOn"));
            Action RightSock = new Action(Predicate.Create("RightSock"));
            RightSock.AddEffect(Predicate.Create("RightSockOn"));
            Action LeftShoe = new Action(Predicate.Create("LeftShoe"));
            LeftShoe.AddPrecondition(Predicate.Create("LeftSockOn"));
            LeftShoe.AddEffect(Predicate.Create("LeftShoeOn"));
            Action LeftSock = new Action(Predicate.Create("LeftSock"));
            LeftSock.AddEffect(Predicate.Create("LeftSockOn"));

            PartialOrderPlanner target = new PartialOrderPlanner(RightShoe, RightSock, LeftShoe, LeftSock);

            IEnumerable<Predicate> voInitialState = null;
            List<Predicate> voGoalState = new List<Predicate>();
            voGoalState.Add(Predicate.Create("RightShoeOn"));
            voGoalState.Add(Predicate.Create("LeftShoeOn"));

            PartialOrderPlan plan = target.PlanOrder(voInitialState, voGoalState);
            Assert.IsTrue(plan != null);

            List<Action> theActions = plan.SortedActions;
            foreach(Action action in theActions)
            {
                string sOut = string.Format("{0}", action.Identity.Name);
                Console.Out.WriteLine(sOut);
            }
        }
        public void PlanOrderTestTireProblem()
        {
            Action RemoveSpare = new Action(Predicate.Create("Remove", false, new ConstantTerm[] { "Spare", "Trunk" }));
            RemoveSpare.AddPrecondition(Predicate.Create("At", false, new ConstantTerm[] { "Spare", "Trunk" }));
            RemoveSpare.AddEffect(Predicate.Create("At", true, new ConstantTerm[] { "Spare", "Trunk" }));
            RemoveSpare.AddEffect(Predicate.Create("At", false, new ConstantTerm[] { "Spare", "Ground" }));

            Action RemoveFlat = new Action(Predicate.Create("Remove", false, ConstantTerm.Create("Flat"), ConstantTerm.Create("Axle")));
            RemoveFlat.AddPrecondition(Predicate.Create("At", false, ConstantTerm.Create("Flat"), ConstantTerm.Create("Axle")));
            RemoveFlat.AddEffect(Predicate.Create("At", true, ConstantTerm.Create("Flat"), ConstantTerm.Create("Axle")));
            RemoveFlat.AddEffect(Predicate.Create("At", false, ConstantTerm.Create("Flat"), ConstantTerm.Create("Ground")));

            Action PutOnSpare = new Action(Predicate.Create("PutOn", false, ConstantTerm.Create("Spare"), ConstantTerm.Create("Axle")));
            PutOnSpare.AddPrecondition(Predicate.Create("At", false, ConstantTerm.Create("Spare"), ConstantTerm.Create("Ground")));
            PutOnSpare.AddPrecondition(Predicate.Create("At", true, ConstantTerm.Create("Flat"), ConstantTerm.Create("Axle")));
            PutOnSpare.AddEffect(Predicate.Create("At", true, ConstantTerm.Create("Spare"), ConstantTerm.Create("Ground")));
            PutOnSpare.AddEffect(Predicate.Create("At", false, ConstantTerm.Create("Spare"), ConstantTerm.Create("Axle")));

            Action LeaveOvernight = new Action(Predicate.Create("LeaveOvernight"));
            LeaveOvernight.AddEffect(Predicate.Create("At", true, ConstantTerm.Create("Spare"), ConstantTerm.Create("Ground")));
            LeaveOvernight.AddEffect(Predicate.Create("At", true, ConstantTerm.Create("Spare"), ConstantTerm.Create("Axle")));
            LeaveOvernight.AddEffect(Predicate.Create("At", true, ConstantTerm.Create("Spare"), ConstantTerm.Create("Trunk")));
            LeaveOvernight.AddEffect(Predicate.Create("At", true, ConstantTerm.Create("Flat"), ConstantTerm.Create("Ground")));
            LeaveOvernight.AddEffect(Predicate.Create("At", true, ConstantTerm.Create("Flat"), ConstantTerm.Create("Axle")));

            PartialOrderPlanner target = new PartialOrderPlanner(RemoveSpare, RemoveFlat, PutOnSpare, LeaveOvernight);

            List<Predicate> voInitialState = new List<Predicate>();
            voInitialState.Add(Predicate.Create("At", false, ConstantTerm.Create("Flat"), ConstantTerm.Create("Axle")));
            voInitialState.Add(Predicate.Create("At", false, ConstantTerm.Create("Spare"), ConstantTerm.Create("Trunk")));
            List<Predicate> voGoalState = new List<Predicate>();
            voGoalState.Add(Predicate.Create("At", false, ConstantTerm.Create("Spare"), ConstantTerm.Create("Axle")));

            PartialOrderPlan plan = target.PlanOrder(voInitialState, voGoalState);
            Assert.IsTrue(plan != null);

            List<Action> theActions = plan.SortedActions;
            foreach (Action action in theActions)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0}", action.Identity.Name);
                if (action.Identity.Parameters != null && action.Identity.Parameters.Count > 0)
                {
                    sb.Append("(");
                    foreach(Term t in action.Identity.Parameters)
                    {
                        sb.Append(t.Name + ",");
                    }
                    sb.Length--;
                    sb.Append(")");
                }
                Console.Out.WriteLine(sb.ToString());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Decompose this Task into a Partial Order Plan
        /// </summary>
        /// <returns></returns>
        public PartialOrderPlan Decompose()
        {
            //TODO: Unfinished
            PartialOrderPlanner planner = new PartialOrderPlanner(SubTasks.ToArray());

            return planner.PlanOrder(new List<Predicate>(Preconditions), new List<Predicate>(Effects));
        }