Example #1
0
 bool resolveConflicts(CausalLink cl, Affordance act)
 {
     foreach (Condition effect in act.getEffects())
     {
         if (!(cl.act1.getActionInstance().Equals(act.getActionInstance())) &&
             !(cl.act2.getActionInstance().Equals(act.getActionInstance())) &&
             (effect.negation(cl.p)))
         {
             Debug.Log("resolveConflicts : ");
             act.disp();
             cl.disp();
             if (cl.act2.isGoal())
             {
                 constraints.Add(Tuple.New(act, cl.act1));
                 addToOrderingConstraints(act, cl.act1);
             }
             else if (!cl.act1.isStart())
             {
                 constraints.Add(Tuple.New(cl.act2, act));
                 addToOrderingConstraints(cl.act2, act);
             }
         }
     }
     return(true);
 }
Example #2
0
        bool checkActionsForPrecondition(Tuple <Condition, Affordance> g, out Affordance satAct)
        {
            satAct = null;

            //g.First.disp ();

            foreach (Affordance act in allPossibleActions)
            {
                List <Condition> actEffects = act.getEffects();
                foreach (Condition effect in actEffects)
                {
                    //Debug.Log ("allPossibleActions - " + effect.condition);
                    //effect.disp();
                    if (effect.Equals(g.First))
                    {
                        //Debug.LogError ("true that -- " + effect.condition);
                        //effect.disp();
                        satAct = act;
                        allPossibleActions.Remove(act);
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #3
0
 void instantiatePlan(Affordance start, Affordance goal)
 {
     constraints.Add(Tuple.New(start, goal));
     addToOrderingConstraints(start, goal);
     actions.Add(start);
     actions.Add(goal);
     foreach (Condition p in goal.getPreconditions())
     {
         agenda.Push(Tuple.New(p, goal));
     }
     createAllPossibleActions();
 }
Example #4
0
        public bool computePlan(Affordance start, Affordance goal)
        {
            instantiatePlan(start, goal);
            do
            {
                Tuple <Condition, Affordance> subG = agenda.Pop();
                Affordance act;
                if (!preConditionAlreadySatisfied(subG, out act))
                {
                    if (checkActionsForPrecondition(subG, out act))
                    {
                        actions.Add(act);
                        constraints.Add(Tuple.New(start, act));
                        addToOrderingConstraints(start, act);
                        foreach (CausalLink cl in causalLinks)
                        {
                            resolveConflicts(cl, act);
                        }

                        foreach (Condition p in act.getPreconditions())
                        {
                            agenda.Push(Tuple.New(p, act));
                        }
                    }
                    else
                    {
                        Debug.LogError("Plan Failed for condition - ");
                        subG.First.disp();
                        showActions();
                        return(false);
                    }
                }

                constraints.Add(Tuple.New(act, subG.Second));
                addToOrderingConstraints(act, subG.Second);
                CausalLink cLink = new CausalLink(act, subG.First, subG.Second);
                causalLinks.Add(cLink);

                foreach (Affordance a in actions)
                {
                    if (!a.isStart())
                    {
                        resolveConflicts(cLink, a);
                    }
                }

                //Debug.Log("In While loop!!");
            } while (agenda.Count() != 0);

            constraints = Utils.Utils.removeDuplicateConstraints(constraints);
            Debug.LogError("Goal Reached!!");
            return(true);
        }
Example #5
0
 public void addToOrderingConstraints(Affordance key, Affordance value)
 {
     if (orderingConsts.ContainsKey(key))
     {
         if (!orderingConsts[key].Contains(value))
         {
             orderingConsts[key].Add(value);
         }
     }
     else
     {
         List <Affordance> listActions = new List <Affordance> ();
         listActions.Add(value);
         orderingConsts.Add(key, listActions);
     }
 }
Example #6
0
        bool preConditionAlreadySatisfied(Tuple <Condition, Affordance> g, out Affordance satAct)
        {
            satAct = null;

            foreach (Affordance act in actions)
            {
                List <Condition> actEffects = act.getEffects();
                foreach (Condition effect in actEffects)
                {
                    if (effect.Equals(g.First))
                    {
                        satAct = act;
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #7
0
 public bool Equals(Affordance act)
 {
     return(getActionInstance().Equals(act.getActionInstance()));
 }