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);
            }
        }
예제 #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
        private List <TraceState> getRevealerSentStates(Agent agent, List <Action> actionsAffected, int val, int recievedStateID)
        {
            int diff = 1;
            List <TraceState> sentStates = new List <TraceState>();

            foreach (Action action in actionsAffected)
            {
                Dictionary <Predicate, int> publicEffectsOfAffected = getPublicEffects(action.HashEffects);
                List <int> sentStateVals  = GetVals(null, agent, val, publicEffectsOfAffected);
                int        sentSenderID   = agent.getID();
                int        sentStateID    = TraceState.GetNextStateID();
                int        sentParentID   = recievedStateID;
                int        sentIParentID  = -1;
                int        sentCost       = 1;
                int        sentHeuristic  = 1;
                List <int> sentPrivateIDs = GetIDs(recievedStateID, agents, agent, diff);
                string     sentContext    = "sending";
                TraceState sentState      = new TraceState(agent.getID(), sentSenderID, sentStateID, sentParentID, sentIParentID, sentCost, sentHeuristic, sentPrivateIDs, sentStateVals, sentContext);

                sentStates.Add(sentState);

                diff++;
            }

            return(sentStates);
        }
예제 #4
0
        public void PublishStartStatesForTraces()
        {
            if (tracesHandler.usesRealStartState())
            {
                // if we use the real start state, we don't need this function to run (as we do not record the "fake" start state...)
                return;
            }
            int startStateID = TraceState.GetNextStateID();
            Dictionary <string, int> iparents = new Dictionary <string, int>();

            foreach (MapsAgent agent in MapsAgents)
            {
                tracesHandler.publishStartState(agent, agent.startVertexForTrace, startStateID, iparents);
            }
        }
예제 #5
0
        public void EnterDependenciesToTrace(Agent agent, Tuple <Action, Predicate> chosen, List <Action> actionsAffected)
        {
            if (!Program.creatingTracesAfterSolutionWasFound)
            {
                return;
            }
            //if (Program.alreadySolved[Program.currentProblemName])
            //    return;
            if (actionsAffected.Count == 0)
            {
                return;
            }
            Predicate predicate;
            bool      negation = false;
            int       val      = 0;

            if (chosen.Item2.Negation)
            {
                //if it is a "not Predicate"
                predicate = chosen.Item2.Negate();
                negation  = true;
                val       = 1;
                return;
            }
            else
            {
                predicate = chosen.Item2;
            }
            Predicate privatePredicate = agent.ArtificialToPrivate[(GroundedPredicate)predicate];

            Dictionary <Predicate, int> publicEffectsOfChosen = getPublicEffects(chosen.Item1.HashEffects);
            int recievedStateID = TraceState.GetNextStateID();

            TraceState recievedState = getRevealerRecievedState(agent, privatePredicate, val, publicEffectsOfChosen, recievedStateID);

            List <TraceState> sentStates = getRevealerSentStates(agent, actionsAffected, val, recievedStateID);

            traces[agent].AddStates(recievedState, sentStates);

            CopyTraceStatesForAllAgents(agents, agent, recievedState, sentStates, val);

            if (TraceState.TimeToFlashStates())
            {
                FlashStates();
            }
        }