Ejemplo n.º 1
0
 public void OperatorAddBindingTest()
 {
     testOperator.AddBinding("?taker", "frodo");
     testOperator.AddBinding("?thing", "ring");
     Assert.AreEqual("frodo", testOperator.TermAt(0));
     Assert.AreEqual("ring", testOperator.TermAt(1));
     Assert.AreEqual(testOperator.Bindings["?taker"], "frodo");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Given an event revision plan, along with its original domain and problem, returns an equivalent regular plan.
        /// </summary>
        /// <param name="plan">A plan with event revision steps.</param>
        /// <param name="domain">The original domain used to build the event revision.</param>
        /// <param name="problem">The original problem used to build the mediation tree.</param>
        /// <returns>A regular plan, equivalent to the output of event revision.</returns>
        public static Plan ReformatPlan(Plan plan, Domain domain, Problem problem)
        {
            // Create a list to hold the new plan steps.
            List <IOperator> newSteps = new List <IOperator>();

            // Loop through the steps in the event revision plan.
            foreach (IOperator step in plan.Steps)
            {
                // Split the title according to the * token placeholder.
                string[] title = step.Name.Split('*');

                // Find the operator template in the original domain that matches the event revision action.
                Operator template = new Operator("do-nothing");
                if (!title[0].Equals("do-nothing"))
                {
                    template = domain.Operators.Find(x => x.Name.Equals(title[0])).Template() as Operator;
                }

                // If this is a proper event revision action...
                if (title.Length > 1)
                {
                    // If this was an observed action...
                    if (title.Length - 1 == template.Arity)
                    {
                        // Loop through each of the template's terms...
                        for (int i = 0; i < template.Arity; i++)
                        {
                            // And bind the variable to the constant listed in the title.
                            template.AddBinding(template.TermAt(i), title[i + 1]);
                        }
                    }
                    // If this was an unobserved action...
                    else
                    {
                        // Bind the action's actor using the title.
                        template.AddBinding(template.TermAt(0), title[1]);

                        // Then loop through each of the template's terms...
                        for (int i = 1; i < template.Arity; i++)
                        {
                            // And bind the variable using the corresponding constant in the action.
                            template.AddBinding(template.TermAt(i), step.TermAt(i));
                        }
                    }
                }
                // If this is not an event revision action, just clone it.
                else
                {
                    template = step.Clone() as Operator;
                }

                // Add the translated action to the set of actions.
                newSteps.Add(template);
            }

            // Create a new plan object using the new set of actions and return it.
            return(new Plan(domain, problem, newSteps));
        }
Ejemplo n.º 3
0
        // The plan already has this step.
        public List <IPlan> Process(IPlan planToBuildOn)
        {
            //
            Operator step = planToBuildOn.Find(HasTerm).Action as Operator;

            // Check if
            if (step.TermAt(PositionOfTerm).Equals(TermToHave))
            {
                return(new List <IPlan>()
                {
                    planToBuildOn
                });
            }
            else
            {
                var t = step.TermAt(PositionOfTerm);
                step.AddBinding(t, TermToHave.Constant);
            }
            var newPlans = new List <IPlan>();

            //foreach (var precon in thisConstraint.Second.Preconditions)
            //{
            //    if (CacheMaps.IsCndt(precon, thisConstraint.First))
            //    {
            //        var planClone = planToBuildOn.Clone() as IPlan;
            //        planClone.CausalLinks.Add(new CausalLink<IPlanStep>(precon, thisConstraint.First, thisConstraint.Second));
            //        newPlans.Add(planClone);
            //    }
            //}
            return(newPlans);
        }
Ejemplo n.º 4
0
        public static IOperator AddPreconditionsAndEffects(Operator opToken, Domain domain)
        {
            foreach (var op in domain.Operators)
            {
                if (!opToken.Name.Equals(op.Name))
                {
                    continue;
                }

                for (int i = 0; i < op.Terms.Count; i++)
                {
                    var term = opToken.Terms[i];
                    term.Variable = op.Terms[i].Variable;
                    opToken.AddBinding(term.Variable, term.Constant);
                }

                var groundOperator = new Operator(opToken.Name, opToken.Terms, opToken.Bindings, op.Preconditions.ToList(), op.Effects.ToList());
                groundOperator.UpdateBindings();
                // Check to see if bindings are propagated to preconditiosn and effects
                Console.Write(groundOperator);
                return(groundOperator as IOperator);
            }
            return(null);
        }