private bool PubliclyEqualStates(MapsVertex s1, MapsVertex s2)
        {
            HashSet <GroundedPredicate> publicS1 = s1.publicFacts;
            HashSet <GroundedPredicate> publicS2 = s2.publicFacts;

            return(publicS1.SetEquals(publicS2));
        }
コード例 #2
0
        public override void publishState(MapsVertex vertex, MapsAgent senderAgent)
        {
            if (!gotToRealStartState)
            {
                // Only when we got to the real start state, we will start publishing regular states...
                return;
            }
            //int senderID = senderAgent.GetID();
            int        senderID    = -1; //The json of sent state needs to be with senderID of -1...
            int        stateID     = TraceState.GetNextStateID();
            TraceState parentState = vertex.publicParent.traceStateForPublicRevealedState;
            int        iparent     = GetIParent(vertex, senderAgent);
            Dictionary <string, int> newIParents = new Dictionary <string, int>(vertex.publicParent.agent2iparent); //as a sender, I will change the iParents dictionary to be a new dictionary.

            //newIParents[senderAgent.name] = iparent;
            newIParents[senderAgent.name] = stateID;

            string context   = TraceState.SendingMessage;
            int    parentID  = parentState.stateID;
            int    cost      = vertex.g;
            int    heuristic = vertex.h_when_sent;

            iparent = -1; //The json of sent state needs to be with iparent of -1...

            WriteStateToTrace(vertex, senderAgent, context, parentID, iparent, stateID, senderID, cost, heuristic, newIParents);
        }
コード例 #3
0
        public override void PublishGoalState(MapsVertex goalVertex, MapsAgent goalFinder)
        {
            //int senderID = goalFinder.GetID();
            int stateID = TraceState.GetNextStateID();
            Dictionary <string, int> newIParents = new Dictionary <string, int>(goalVertex.publicParent.agent2iparent);

            TraceState parentState = goalVertex.publicParent.traceStateForPublicRevealedState;
            //int parentID = parentState.stateID;
            int    cost      = goalVertex.g;
            int    heuristic = goalVertex.h_when_sent;
            string context   = TraceState.GoalVerifiedMessage;

            foreach (MapsAgent agent in MapsPlanner.name2mapsAgent.Values)
            {
                int parentID = -1;
                if (agent.Equals(goalFinder))
                {
                    parentID = parentState.stateID; //In the json, only the goal finder needs to have a value of the parent of the last state
                }
                int senderID = agent.GetID();
                int iparent  = GetIParent(goalVertex, agent);
                newIParents[agent.name] = iparent;

                iparent = -1; //The json of goal state needs to be with iparent of -1...
                WriteStateToTrace(goalVertex, agent, context, parentID, iparent, stateID, senderID, cost, heuristic, newIParents);
            }
        }
コード例 #4
0
        private List <int> GetPrivateIDs(MapsVertex vertex)
        {
            List <int> privateIDs = new List <int>();

            foreach (Agent agent in agents)
            {
                privateIDs.Add(vertex.stateIndexes[agent.name]);
            }
            return(privateIDs);
        }
コード例 #5
0
        private State GetCorrespondingAgentState(MapsVertex vertex, MapsAgent agent)
        {
            State state = new State(agent.GetPrivateState(vertex.stateIndexes[agent.name]));

            foreach (GroundedPredicate gp in vertex.publicFacts)
            {
                state.AddPredicate(gp);
            }
            return(state);
        }
コード例 #6
0
        private int GetIParent(MapsVertex vertex, MapsAgent agent)
        {
            MapsVertex parentState = vertex.publicParent;
            int        iparent     = parentState.agent2iparent[agent.name];

            if (parentState.traceStateForPublicRevealedState.senderID == agent.GetID())
            {
                iparent = parentState.traceStateForPublicRevealedState.stateID;
            }
            return(iparent);
        }
コード例 #7
0
        public override void publishStartState(MapsAgent agent, MapsVertex startState, int stateID, Dictionary <string, int> iparents)
        {
            int    senderID  = -1;
            int    parentID  = -1;
            int    iparentID = -1;
            int    cost      = 0;
            int    heuristic = -1;
            string context   = TraceState.InitMessage;

            //iparents[agent.name] = 0;
            iparents[agent.name] = iparentID;

            WriteStateToTrace(startState, agent, context, parentID, iparentID, stateID, senderID, cost, heuristic, iparents);
        }
コード例 #8
0
        private void WriteStateToTrace(MapsVertex vertex, MapsAgent agent, string context, int parentID, int iparentID, int stateID, int senderID, int cost, int heuristic, Dictionary <string, int> newIParents)
        {
            int        agentID    = agent.GetID();
            List <int> privateIDs = GetPrivateIDs(vertex);
            List <int> values     = GetValues(vertex, agent);

            TraceState writtenTraceState = new TraceState(agentID, senderID, stateID, parentID, iparentID, cost, heuristic, privateIDs, values, context);

            traces[agent.regularAgent].AddState(writtenTraceState);
            vertex.traceStateForPublicRevealedState = writtenTraceState;
            vertex.agent2iparent = newIParents;

            if (TraceState.TimeToFlashStates())
            {
                FlashStates();
            }
        }
コード例 #9
0
        public override void RecieveState(MapsVertex recievedVertex, MapsAgent recievedAgent, MapsVertex sentVertex, MapsAgent senderAgent)
        {
            int        senderID    = senderAgent.GetID();
            int        stateID     = sentVertex.traceStateForPublicRevealedState.stateID;
            TraceState parentState = recievedVertex.publicParent.traceStateForPublicRevealedState;
            int        iparent     = GetIParent(recievedVertex, recievedAgent);
            Dictionary <string, int> newIParents = sentVertex.agent2iparent; //The sender already made a new dictionary, I shall update it and save it to myself too as it should be the same dictionary for this state.

            newIParents[recievedAgent.name] = iparent;

            string context = TraceState.ReceivedMessage;
            //int parentID = parentState.stateID;
            int parentID  = -1; //The json of recieved state needs to be with parentID of -1...
            int cost      = recievedVertex.g;
            int heuristic = recievedVertex.h_when_sent;

            WriteStateToTrace(recievedVertex, recievedAgent, context, parentID, iparent, stateID, senderID, cost, heuristic, newIParents);
        }
        public bool CanPublish(MapsAgent agent, MapsVertex vertex)
        {
            //remember which effects were revealed:
            HashSet <Predicate> effectsRevealed = new HashSet <Predicate>();
            //remember which action revealed this effect:
            Dictionary <Predicate, string> whoRevealed = new Dictionary <Predicate, string>();
            //init with the start state:
            List <Predicate> dependenciesFromStartState = agent.GetDependenciesAtStartState();

            foreach (Predicate p in dependenciesFromStartState)
            {
                effectsRevealed.Add(p);
                whoRevealed[p] = "Start-State";
            }
            //iterate through the plan:
            foreach (Action action in vertex.lplan)
            {
                if (action.agent.Equals(agent.name))
                {
                    if (action.isPublic)
                    {
                        //Check preconditions:
                        foreach (Predicate preCond in agent.GetPredicatesPreconditionsForAction(action.Name))
                        {
                            if (!effectsRevealed.Contains(preCond))
                            {
                                //This is not a revealed effect, so it is a forbidden plan. don't publish this state.
                                return(false);
                            }
                            else
                            {
                                //It is a used dependency.
                                string previousAction = whoRevealed[preCond];
                                agent.AddToUsedDependencies(previousAction, preCond);
                            }
                        }
                        //Reveal:
                        RevealEffects(effectsRevealed, agent.GetPredicatesRevealedByAction(action.Name) /*, agent.GetAllPossibleDependenciesOfAction(action.Name)*/, action, whoRevealed);
                    }
                }
            }

            return(true);
        }
コード例 #11
0
        private List <int> GetValues(MapsVertex vertex, MapsAgent agent)
        {
            Dictionary <Predicate, TraceVariable> agentsVars = TraceVariable.GetVariablesDict(agent.GetID());
            List <int>          values     = new List <int>();
            HashSet <Predicate> predicates = GetCorrespondingAgentState(vertex, agent).m_lPredicates;

            foreach (Predicate p in agentsVars.Keys)
            {
                if (predicates.Contains(p))
                {
                    values.Add(0); //0 == true
                }
                else
                {
                    values.Add(1); //1 == false
                }
            }
            return(values);
        }
コード例 #12
0
        public override void publishRealStartState(MapsAgent agent, MapsVertex realStartState, int stateID, Dictionary <string, int> iparents)
        {
            if (gotToRealStartState)
            {
                // Someone else published the real start state already, this is the recieved state...
                stateID  = realStartStateTraceID;
                iparents = realStartState_iparents;
            }
            int    senderID  = -1;
            int    parentID  = -1;
            int    iparentID = -1;
            int    cost      = 0;
            int    heuristic = -1;
            string context   = TraceState.InitMessage;

            //iparents[agent.name] = 0;
            iparents[agent.name] = iparentID;

            WriteStateToTrace(realStartState, agent, context, parentID, iparentID, stateID, senderID, cost, heuristic, iparents);

            realStartStateTraceID   = stateID;
            realStartState_iparents = iparents;
            gotToRealStartState     = true;
        }
コード例 #13
0
ファイル: MapsPlanner.cs プロジェクト: ronistern/ma-strips
        public MapsPlanner(List <Agent> agents, List <Domain> lDomains, List <Problem> lProblems)
        {
            agentsPublicPreconditions = new Dictionary <Agent, HashSet <GroundedPredicate> >();
            agentsPublicEffects       = new Dictionary <Agent, HashSet <GroundedPredicate> >();
            recoverActionEffect       = new Dictionary <string, Dictionary <string, HashSet <string> > >();
            List <GroundedPredicate> allGoals = new List <GroundedPredicate>();

            sendedToAllSign     = new HashSet <string>();
            actionMap           = new Dictionary <string, HashSet <string> >();
            AgentToInfluActions = new Dictionary <string, Dictionary <string, HashSet <Action> > >();
            influencedByAgents  = new Dictionary <string, List <string> >();
            stop = false;
            MacroAction.counter = 1;
            receivedStates      = new Dictionary <string, HashSet <MapsVertex> >();
            openLists           = new Dictionary <string, HashSet <MapsVertex> >();
            mutexs              = new Dictionary <string, Mutex>();
            countOfLandmarks    = new Dictionary <string, int>();
            countOfReasenOrders = new Dictionary <string, int>();
            Dictionary <string, int> indexStates = new Dictionary <string, int>();

            allPublicFacts = new HashSet <GroundedPredicate>();
            foreach (Agent a in agents)
            {
                allGoals = allGoals.Union(a.goal).ToList();
                sendedToAllSign.Add(a.name);
            }
            HashSet <GroundedPredicate> allG = new HashSet <GroundedPredicate>(allGoals);

            foreach (Agent a in agents)
            {
                a.initPlaner();
                for (int i = 0; i < a.publicActions.Count; i++)
                {
                    Action act = a.publicActions[i];
                    foreach (GroundedPredicate gp in act.HashEffects)
                    {
                        if ((a.PublicPredicates.Contains(gp) || a.PublicPredicates.Contains((GroundedPredicate)gp.Negate())) && gp.Negation)
                        {
                            act.isDeletePublic = true;
                            break;
                        }
                    }
                    foreach (GroundedPredicate gp in act.HashPrecondition)
                    {
                        if (a.PublicPredicates.Contains(gp))
                        {
                            if (act.HashEffects.Contains((GroundedPredicate)gp.Negate()))
                            {
                                continue;
                            }
                            ((CompoundFormula)act.Effects).AddOperand(gp);
                            act.HashEffects.Add(gp);
                        }
                    }
                }
                HashSet <GroundedPredicate> preconditions = a.GetAllPublicPreconditions();
                //preconditions.UnionWith(allGoals);
                agentsPublicPreconditions.Add(a, preconditions);
                agentsPublicEffects.Add(a, a.GetAllPublicEffects());
                indexStates.Add(a.name, 0);

                receivedStates.Add(a.name, new HashSet <MapsVertex>());
                openLists.Add(a.name, new HashSet <MapsVertex>());
                mutexs.Add(a.name, new Mutex());
                countOfLandmarks.Add(a.name, a.publicRelevantLandmark.Count);
                countOfReasenOrders.Add(a.name, a.ReasonableOrdering.Count);

                foreach (GroundedPredicate pGp in a.PublicPredicates)
                {
                    allPublicFacts.Add(pGp);
                }

                /* foreach (GroundedPredicate pGp in a.goal)
                 * {
                 *   GroundedPredicate ngp = (GroundedPredicate)pGp.Negate();
                 *   allPublicFacts.Add(ngp);
                 *   allPublicFacts.Add(pGp);
                 * }*/
            }
            MapsVertex.init(agents);
            List <GroundedPredicate> fullStart = new List <GroundedPredicate>();

            foreach (Agent a in agents)
            {
                foreach (GroundedPredicate gp in a.startState.m_lPredicates)
                {
                    fullStart.Add(gp);
                }
            }
            HashSet <GroundedPredicate> publicStartState = new HashSet <GroundedPredicate>();
            Dictionary <string, State>  agPriv           = new Dictionary <string, State>();

            foreach (Agent a in agents)
            {
                State privateStartState = new State((Problem)null);

                foreach (GroundedPredicate gp in a.startState.m_lPredicates)
                {
                    if (!a.PublicPredicates.Contains(gp))
                    {
                        privateStartState.AddPredicate(gp);
                    }
                    else
                    {
                        publicStartState.Add(gp);
                    }
                }
                agPriv.Add(a.name, privateStartState);
            }
            List <MapsVertex> lVertexes = new List <MapsVertex>();
            Dictionary <string, MapsAgent> MapsAgents = new Dictionary <string, MapsAgent>();

            this.MapsAgents = new List <MapsAgent>();
            foreach (Agent a in agents)
            {
                MapsVertex agentStartVertex = new MapsVertex(publicStartState, agPriv[a.name], indexStates, countOfLandmarks, countOfLandmarks.Keys.ToArray(), a.name, a.allGoals.Count, countOfReasenOrders);
                MapsAgent  mAgent           = new MapsAgent(agentStartVertex, a, a.allGoals, countOfLandmarks, openLists, receivedStates, mutexs, countOfReasenOrders, fullStart);
                mAgent.projectionHeuristic = new AdvancedProjectionHeuristic(a, agents, lDomains, lProblems);
                mAgent.SetPrivateState(agPriv[a.name]);
                MapsAgents.Add(mAgent.name, mAgent);
                this.MapsAgents.Add(mAgent);
                lVertexes.Add(agentStartVertex);
            }
            MapsVertex.UpDateAgents(MapsAgents);
            foreach (MapsVertex v in lVertexes)
            {
                v.PreaperFirstVertex();
            }
            foreach (Agent a in agents.ToList())
            {
                recoverActionEffect.Add(a.name, new Dictionary <string, HashSet <string> >());
                foreach (Action act in a.publicActions)
                {
                    recoverActionEffect[a.name].Add(act.Name, new HashSet <string>());
                    bool breaking = false;
                    foreach (GroundedPredicate eff in act.HashEffects)
                    {
                        if (eff.Negation)
                        {
                            foreach (Agent a2 in agents.ToList())
                            {
                                if (a2.name.Equals(a.name))
                                {
                                    continue;
                                }
                                HashSet <GroundedPredicate> agentEff = agentsPublicEffects[a2];
                                if (agentEff.Contains((GroundedPredicate)eff.Negate()))
                                {
                                    recoverActionEffect[a.name][act.Name].Add(a2.name);
                                    breaking = true;
                                    break;
                                }
                            }
                            if (breaking)
                            {
                                break;
                            }
                        }
                    }
                }
                AgentToInfluActions.Add(a.name, new Dictionary <string, HashSet <Action> >());
                foreach (Action act in a.publicActions)
                {
                    if (!actionMap.ContainsKey(act.Name))
                    {
                        actionMap.Add(act.Name, new HashSet <string>());
                    }
                    foreach (var pair in agentsPublicPreconditions)
                    {
                        //  if (a.Equals(pair.Key))
                        //    continue;
                        bool flag = false;
                        foreach (GroundedPredicate eff in act.HashEffects)
                        {
                            if (pair.Value.Contains(eff))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                        {
                            actionMap[act.Name].Add(pair.Key.name);
                        }
                    }
                }
                influencedByAgents.Add(a.name, new List <string>());
                foreach (Agent a2 in agents.ToList())
                {
                    AgentToInfluActions[a.name].Add(a2.name, new HashSet <Action>());
                    foreach (Action act in a.publicActions)
                    {
                        bool effFlag = false;
                        foreach (GroundedPredicate eff in act.HashEffects)
                        {
                            if (agentsPublicPreconditions[a2].Contains(eff))
                            {
                                effFlag = true;
                                break;
                            }
                        }

                        if (effFlag)
                        {
                            AgentToInfluActions[a.name][a2.name].Add(act);
                        }
                    }


                    if (a.name.Equals(a2.name))
                    {
                        continue;
                    }
                    bool flag = false;
                    foreach (GroundedPredicate pre in agentsPublicPreconditions[a])
                    {
                        if (agentsPublicEffects[a2].Contains(pre))
                        {
                            influencedByAgents[a.name].Add(a2.name);
                            break;
                        }
                    }
                }
            }
        }
コード例 #14
0
 public override void publishRealStartState(MapsAgent agent, MapsVertex realStartState, int stateID, Dictionary <string, int> iparents)
 {
     // don't do anything here...
 }
コード例 #15
0
 public override void RecieveState(MapsVertex recievedVertex, MapsAgent recievedAgent, MapsVertex sentVertex, MapsAgent senderAgent)
 {
     //don't do anything here...
 }
 private bool ArePubliclySameStates(MapsVertex s1, MapsVertex s2)
 {
     //return EqualDictionaries(s1.stateIndexes, s2.stateIndexes) && PubliclyEqualStates(s1, s2);
     return(PubliclyEqualStates(s1, s2) && !PrivatlyDifferentStates(s1, s2));
 }
 private bool PubliclyEqualButPrivatlyDifferentStates(MapsVertex s1, MapsVertex s2)
 {
     return(PubliclyEqualStates(s1, s2) && PrivatlyDifferentStates(s1, s2));
 }
 private bool PrivatlyDifferentStates(MapsVertex s1, MapsVertex s2)
 {
     return(!EqualDictionaries(s1.stateIndexes, s2.stateIndexes) || s1.g != s2.g || s1.h_when_sent != s2.h_when_sent);
 }
        private void CalculateAdverseriesFoundAttributes(List <MapsAgent> adversaries, MapsAgent chosen)
        {
            Srec = new List <MapsVertex>();
            Ssen = new List <MapsVertex>();
            foreach (MapsAgent currAdversery in adversaries)
            {
                HandleSrecAndSsen(currAdversery.allStates, chosen.name);
            }
            HandleSrecAndSsen(chosen.allStates, chosen.name);
            Dictionary <MapsVertex, HashSet <Action> > state2Os = new Dictionary <MapsVertex, HashSet <Action> >();

            foreach (MapsVertex state in Srec)
            {
                HashSet <Action> Os = new HashSet <Action>();
                state2Os[state] = Os;

                HashSet <GroundedPredicate> publicState = state.publicFacts;
                //MapsVertex i_par = state.agent2iparentVertex[chosen.name];
                MapsVertex i_par = state.publicParent; // This works great, but not sure if it is ok with the definitions of the paper... Guy will check with the authors...
                HashSet <GroundedPredicate> public_i_par = i_par.publicFacts;


                // get only the predicates we need to create with the action:
                HashSet <GroundedPredicate> difference = new HashSet <GroundedPredicate>(publicState);
                difference.ExceptWith(public_i_par);

                foreach (Action action in GetActionsWithoutInitActions(chosen.publicActions))
                {
                    bool canApply = true;
                    HashSet <Predicate> publicPreconditions = GetPublicPredicates(chosen.regularAgent, action.HashPrecondition);
                    HashSet <Predicate> publicEffects       = GetPublicPredicates(chosen.regularAgent, action.HashEffects);

                    foreach (Predicate pre in publicPreconditions)
                    {
                        if (!public_i_par.Contains(pre))
                        {
                            canApply = false;
                            break;
                        }
                    }
                    if (!canApply)
                    {
                        continue;
                    }

                    // can apply the action, check if it leads to the public state:
                    bool achievesDiff = true;
                    foreach (Predicate wanted in difference)
                    {
                        if (!publicEffects.Contains(wanted))
                        {
                            achievesDiff = false;
                            break;
                        }
                    }
                    if (!achievesDiff)
                    {
                        continue;
                    }
                    // can apply the action, and it achieves the wanted state, so add it to the Os set:
                    Os.Add(action);
                }
            }
            List <HashSet <Action> > possible_init_applicable_actions = new List <HashSet <Action> >();

            foreach (MapsVertex s in Srec)
            {
                MapsVertex i_par = s.agent2iparentVertex[chosen.name];
                //if (i_par == chosen.startVertexForTrace)
                if (i_par == chosen.realStartStateVertex)
                {
                    HashSet <Action> Os = state2Os[s];
                    possible_init_applicable_actions.Add(Os);
                }
            }

            HashSet <Action> privately_independent_actions = new HashSet <Action>();

            foreach (MapsVertex s in Srec)
            {
                MapsVertex s_i_par = s.agent2iparentVertex[chosen.name];
                if (s_i_par == null)
                {
                    continue;
                }
                foreach (MapsVertex s_tag in Ssen)
                {
                    if (!PubliclyEqualButPrivatlyDifferentStates(s_i_par, s_tag))
                    {
                        continue;
                    }
                    foreach (MapsVertex s_double_tag in Srec)
                    {
                        if (ArePubliclySameStates(s_tag, s_double_tag.agent2iparentVertex[chosen.name]))
                        {
                            HashSet <Action> Os            = state2Os[s];
                            HashSet <Action> Os_double_tag = state2Os[s_double_tag];
                            HashSet <Action> intersection  = new HashSet <Action>(Os);
                            intersection.IntersectWith(Os_double_tag);
                            privately_independent_actions.UnionWith(intersection);
                        }
                    }
                }
            }
            int i = 0; //need to check if the Srec and Ssen were calculated correctly (using the debugger...).
        }
コード例 #20
0
 public abstract void publishState(MapsVertex vertex, MapsAgent agent);
コード例 #21
0
 public bool CanPublish(MapsAgent agent, MapsVertex vertex)
 {
     return(true);
 }
コード例 #22
0
 public override void publishState(MapsVertex vertex, MapsAgent agent)
 {
     //don't do anything here...
 }
コード例 #23
0
 public abstract void publishRealStartState(MapsAgent agent, MapsVertex realStartState, int stateID, Dictionary <string, int> iparents);
コード例 #24
0
 public abstract void PublishGoalState(MapsVertex goalVertex, MapsAgent goalFinder);
コード例 #25
0
 public abstract void RecieveState(MapsVertex recievedVertex, MapsAgent recievedAgent, MapsVertex sentVertex, MapsAgent senderAgent);
コード例 #26
0
        //public string name = "";

        /* public MacroAction()
         *   : base("MacroAction"+counter)
         * {
         *   counter++;
         * }*/

        public MacroAction(MapsVertex parentVertex, MapsVertex childVertex)
            : base("MacroAction" + counter)
        {
            // if (Name.Equals("MacroAction46"))
            //    Console.WriteLine("ss");
            lastpreIndex = new List <string>();
            preIndex     = new List <string>();
            parentIndex  = new Dictionary <string, int>(parentVertex.stateIndexes);
            childIndex   = new Dictionary <string, int>(childVertex.stateIndexes);
            counter++;
            isPublic = false;
            Action lastPublicAction = childVertex.lplan[childVertex.lplan.Count - 1];

            //if (lastPublicAction == null)
            //    Console.WriteLine("ss");
            agent = lastPublicAction.agent;
            int k = 0;

            foreach (var indexItem in parentVertex.stateIndexes)
            {
                //parentIndex[k]=indexItem.Value;
                //childIndex[k] = childVertex.stateIndexes[indexItem.Key];
                if (!indexItem.Value.Equals(childVertex.stateIndexes[indexItem.Key]))
                {
                    lastpreIndex.Add(indexItem.Key);
                }
                k++;
            }
            cost         = 0;
            microActions = new List <Action>();
            List <Action> pubActions = new List <Action>();

            for (int i = parentVertex.lplan.Count; i < childVertex.lplan.Count; i++)
            {
                microActions.Add(childVertex.lplan[i]);
                if (childVertex.lplan[i] is MacroAction)
                {
                    foreach (string a in ((MacroAction)childVertex.lplan[i]).preIndex)
                    {
                        if (!preIndex.Contains(a))
                        {
                            preIndex.Add(a);
                        }
                    }
                    cost += ((MacroAction)childVertex.lplan[i]).cost;
                }
                else
                {
                    if (!preIndex.Contains(childVertex.lplan[i].agent))
                    {
                        preIndex.Add(childVertex.lplan[i].agent);
                    }
                    cost += 1;
                }
                if (childVertex.lplan[i].isPublic || childVertex.lplan[i] is MacroAction)
                {
                    pubActions.Add(childVertex.lplan[i]);
                }
            }


            HashEffects      = new List <Predicate>();
            HashPrecondition = new List <Predicate>();
            // if (parentVertex.isComplex)
            //   Console.WriteLine("**");
            foreach (Action pAct in pubActions)
            {
                foreach (GroundedPredicate pre in pAct.HashPrecondition)
                {
                    if (MapsPlanner.allPublicFacts.Contains(pre))
                    {
                        if (!HashEffects.Contains(pre) && !HashPrecondition.Contains(pre))
                        {
                            HashPrecondition.Add(pre);
                        }
                    }
                }
                foreach (GroundedPredicate eff in pAct.HashEffects)
                {
                    if (MapsPlanner.allPublicFacts.Contains(eff))
                    {
                        if (!HashEffects.Contains(eff))
                        {
                            if (HashEffects.Contains(eff.Negate()))
                            {
                                HashEffects.Remove(eff.Negate());
                            }

                            HashEffects.Add(eff);
                        }
                    }
                }
            }
            CompoundFormula prec = new CompoundFormula("and");

            foreach (GroundedPredicate precGp in HashPrecondition)
            {
                prec.AddOperand(precGp);
            }
            Preconditions = prec;

            CompoundFormula effe = new CompoundFormula("and");

            foreach (GroundedPredicate effeGp in HashEffects)
            {
                effe.AddOperand(effeGp);
            }
            Effects = effe;

            if (Program.highLevelPlanerType == Program.HighLevelPlanerType.MafsLandmark)
            {
                heuristicDelta    = parentVertex.h - childVertex.h;
                landmarkVector    = new bool[parentVertex.SatisfactionLandmarks.Length];
                NeglandmarkVector = new bool[parentVertex.SatisfactionLandmarks.Length];
                for (int i = 0; i < parentVertex.SatisfactionLandmarks.Length; i++)
                {
                    if (!parentVertex.SatisfactionLandmarks[i] && childVertex.SatisfactionLandmarks[i])
                    {
                        landmarkVector[i] = true;
                    }
                }
                for (int i = 0; i < parentVertex.SatisfactionLandmarks.Length; i++)
                {
                    if (parentVertex.SatisfactionLandmarks[i] && !childVertex.SatisfactionLandmarks[i])
                    {
                        NeglandmarkVector[i] = true;
                        dellLandmarkCounter++;
                    }
                }
                //if (microActions.Count > 1)
                //   Console.WriteLine("GnGaa");
                rOrder = new bool[parentVertex.vectors[agent][1].Length];
                foreach (string agnt in preIndex)
                {
                    for (int i = 0; i < parentVertex.vectors[agnt][1].Length; i++)
                    {
                        if (!parentVertex.vectors[agnt][1][i] && childVertex.vectors[agnt][1][i])
                        {
                            rOrder[i] = true;
                        }
                    }
                }
                anyTimeVector = new bool[parentVertex.anyTimeSatisfactionLandmarks.Length];
                for (int i = 0; i < parentVertex.SatisfactionLandmarks.Length; i++)
                {
                    if (!parentVertex.anyTimeSatisfactionLandmarks[i] && childVertex.anyTimeSatisfactionLandmarks[i])
                    {
                        anyTimeVector[i] = true;
                    }
                }


                /*satNowVectors = new Dictionary<string, bool[]>();
                 * negSatNowVectors=new Dictionary<string, bool[]>();
                 * foreach (string agnt in preIndex)
                 * {
                 *  satNowVectors.Add(agnt, new bool[childVertex.satisfiedVector[agnt].Length]);
                 *  negSatNowVectors.Add(agnt, new bool[childVertex.satisfiedVector[agnt].Length]);
                 *  for (int i = 0; i < childVertex.satisfiedVector[agnt].Length; i++)
                 *  {
                 *      if (childVertex.satisfiedVector[agnt][i] == true && parentVertex.satisfiedVector[agnt][i] == false)
                 *      {
                 *          satNowVectors[agnt][i] = true;
                 *      }
                 *      if (childVertex.satisfiedVector[agnt][i] == false && parentVertex.satisfiedVector[agnt][i] == true)
                 *      {
                 *          negSatNowVectors[agnt][i] = true;
                 *      }
                 *  }
                 * }*/
            }
        }
コード例 #27
0
 public override void PublishGoalState(MapsVertex goalVertex, MapsAgent goalFinder)
 {
     //don't do anything here...
 }