Ejemplo n.º 1
0
        private void AddCollabActionReq(out List <Action> exctractedActions)
        {
            exctractedActions = new List <Action>();
            if (m_ReqCollabActions == null || m_ReqCollabActions.Count == 0)
            {
                return;
            }

            // If there are collaborative constraints - remove the general action of join push.
            // TODO in future work - consider the case if you allow a general joint action push - the agent will be able to
            // activate new joint pushes before the constraint joint push from other agent - and by that he might create for
            //himself the ability to use the artifitial joint push by pushing earlier the big box
            //
            // For example - constraint joint push send to be activated at t4
            // +------------+
            // | B0, a0, a1 | B0 is an heavy box
            // +------------+
            //
            // Iteration 1:
            // a1 plan : 1. Observe big box -->(t) 2. No-op               --> 3. No-op --> 4. Joint-Push (with a1, new)
            //
            // Iteration 2:
            // a2 plan : 1. Observe big box -->(t) 2. Joint-Push t2 (new) --> 3. No-op --> 4. Art-Joint-Push
            //                                 (f) 2. No-op               --> 3. No-op --> 4. Art-Joint-Push

            // Until then -- > remove general collaborative action
            HashSet <string> JointActionsUsed = new HashSet <string>();

            foreach (var reqAction in m_ReqCollabActions)
            {
                JointActionsUsed.Add(reqAction.GetOperationName());
            }
            if (JointActionsUsed.Count > 1)
            {
                // Multiple joint actions type is not yet supported!
                throw new Exception();
            }
            else
            {
                if (JointActionsUsed.Count == 1)
                {
                    // Remove general joint action of the same name
                    string jointActionName       = JointActionsUsed.ElementAt(0);
                    Action generalActionToRemove = null;
                    foreach (var item in m_AgentDomain.Actions)
                    {
                        if (item.GetOperationName() == jointActionName)
                        {
                            generalActionToRemove = item;
                        }
                    }
                    if (generalActionToRemove != null)
                    {
                        m_AgentDomain.Actions.Remove(generalActionToRemove);
                        exctractedActions.Add(generalActionToRemove);
                    }
                }
            }


            // Add the notion of sub goals to the domain.
            m_AgentDomain.AddPredicate("sub-goal", "?g", "aGoal");

            // Count the number of artifitial goals.
            int artGoals = 0;

            // For each required action that needs attention:
            foreach (var reqAction in m_ReqCollabActions)
            {
                // Create sub-goal for this action
                string            predicateName = "sub-goal" + (artGoals++);
                GroundedPredicate gp            = new GroundedPredicate("sub-goal");
                gp.AddConstant(new Constant("aGoal", predicateName));
                m_AgentDomain.AddConstant("aGoal", predicateName);
                // Update this goal to the domain and problem;
                m_ActiveGoals.Add(gp);
                // Let it be known that this goal has not been achieved yet
                m_AgentProblem.AddKnown(gp.Negate());
                // This action now achieves this goal
                reqAction.AddEffect(gp);
                // OK, action is ready. add it to the set of actions
                m_AgentDomain.AddAction(reqAction);

                // We also need to create a counter-action that can be used in cases in which the previous action
                // cannot be used. - only when the agent observes that

                Action counterAction = new Action("art-" + reqAction.Name);

                Formula cgf = reqAction.Preconditions.GetUnknownPredicates(m_AgentDomain.m_lObservable);
                counterAction.Preconditions = cgf.Negate(true);
                //counterAction.Preconditions.AddTime
                //counterAction.Preconditions = counterAction.Preconditions.AddTime(reqAction.GetTime());
                counterAction.AddEffect(gp);
                //Formula cf = reqAction.Effects.Clone();
                //cf.RemoveTime();
                //counterAction.Effects = cf;
                //counterAction.AddEffect(reqAction.Effects);
                m_AgentDomain.AddAction(counterAction);
            }
        }