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); }
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); } }
public List <string> PreferablePlan_DirectMessage() { //List<Thread> threads = new List<Thread>(); //begin = DateTime.Now; //return null; countMacro = 0.0; countAvgPerMacro = 0.0; sendedStateCounter = 0; ffMessageCounter = 0; Program.StateExpandedCounter = 0; notSandedStates = 0; MapsPlanner.generateCounter = 0; makeSpanPlanTime = 0.0; List <string> lplan = null; MapsAgent.InitMutex(MapsAgents); List <double> iterationTimes = null; MapsAgent.thereIsPrivate = false; foreach (MapsAgent agent in MapsAgents) { if (agent.privateActions.Count > 0) { MapsAgent.thereIsPrivate = true; } } int x = 0; while (lplan == null) { iterationTimes = new List <double>(); foreach (MapsAgent agent in MapsAgents) { DateTime startTime = DateTime.Now; lplan = agent.BeginPreferablePlanning(); iterationTimes.Add(DateTime.Now.Subtract(startTime).TotalSeconds); if (lplan != null) { break; } } double maxTime = iterationTimes.Max(); makeSpanPlanTime += maxTime; if (lplan != null) { MapsPlanner.stop = true; break; } } return(lplan); }
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); }
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); }
public List <string> PreferableFFPlan() { //List<Thread> threads = new List<Thread>(); //begin = DateTime.Now; countMacro = 0.0; countAvgPerMacro = 0.0; sendedStateCounter = 0; ffMessageCounter = 0; Program.StateExpandedCounter = 0; notSandedStates = 0; makeSpanPlanTime = 0.0; MapsPlanner.generateCounter = 0; List <string> lplan = null; MapsAgent.InitMutex(MapsAgents); List <double> iterationTimes = null; while (lplan == null) { nextGlobalOpenList = new Dictionary <string, HashSet <MapsVertex> >(); foreach (MapsAgent agent in MapsAgents) { nextGlobalOpenList.Add(agent.name, new HashSet <MapsVertex>()); } iterationTimes = new List <double>(); foreach (MapsAgent agent in MapsAgents) { DateTime startTime = DateTime.Now; lplan = agent.BeginPreferableFFPlanning(); iterationTimes.Add(DateTime.Now.Subtract(startTime).TotalSeconds); if (lplan != null) { break; } } double maxTime = iterationTimes.Max(); makeSpanPlanTime += maxTime; if (lplan != null) { MapsPlanner.stop = true; break; } else { foreach (MapsAgent agent in MapsAgents) { agent.SetPublicOpenLists(nextGlobalOpenList); } } } return(lplan); }
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); }
private void CalculateGroundTruth(MapsAgent chosen) { HashSet <Action> gt_init_applicable = new HashSet <Action>(); HashSet <Action> gt_not_init_applicable = new HashSet <Action>(); HashSet <Action> gt_privately_dependent = new HashSet <Action>(); HashSet <Action> gt_privately_independent = new HashSet <Action>(); //HashSet<GroundedPredicate> startState = chosen.startVertexForTrace.GetFullState(); HashSet <GroundedPredicate> startState = chosen.realStartStateVertex.GetFullState(); foreach (Action action in GetActionsWithoutInitActions(chosen.publicActions)) { bool has_private_precondition = false; bool has_non_start_state_precondition = false; foreach (Predicate p in action.HashPrecondition) { if (!chosen.regularAgent.PublicPredicates.Contains(p)) { // this is a private precondition has_private_precondition = true; } if (!startState.Contains(p)) { //this is not a precondition that is available in the start state has_non_start_state_precondition = true; } } if (has_private_precondition) { gt_privately_dependent.Add(action); } else { gt_privately_independent.Add(action); } if (has_non_start_state_precondition) { gt_not_init_applicable.Add(action); } else { gt_init_applicable.Add(action); } } FindActionsWhichArePubliclyEqual(chosen.regularAgent); int i = 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(); } }
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 static Mutex goalChackMutex = null; // public static Dictionary<string, Mutex> globalListMutex = null; public List <string> DistrebutedPreferablePlan() { //List<Thread> threads = new List<Thread>(); //begin = DateTime.Now; // goalChackMutex = new Mutex(); // heursticCalcultionMutex = new Mutex(); //tmpMutex = new Mutex(); MapsAgent.InitMutex(MapsAgents); countMacro = 0.0; ffMessageCounter = 0; countAvgPerMacro = 0.0; sendedStateCounter = 0; Program.StateExpandedCounter = 0; notSandedStates = 0; MapsPlanner.generateCounter = 0; List <string> lplan = null; List <Thread> threads = new List <Thread>(); /* * for(int i=MapsAgents.Count-1;i>-1;i--) * { * MapsAgent agent = MapsAgents.ElementAt(i); * Thread t = new Thread(agent.BeginDistrebutedPreferablePlanning); * threads.Add(t); * t.Start(); * } */ foreach (MapsAgent agent in MapsAgents) { Thread t = new Thread(agent.BeginDistrebutedPreferablePlanning); t.Name = agent.name; threads.Add(t); t.Start(); } foreach (Thread t in threads) { t.Join(); } return(finalPlan); }
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); }
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); }
public static void ResetStaticFields() { nextGlobalOpenList = null; findGoal = false; finalPlan = null; generateCounter = 0; stop = false; massageEffCounter = 0; massagePreCounter = 0; allPublicFacts = null; sendedToAllSign = null; actionMap = null; AgentToInfluActions = null; influencedByAgents = null; recoverActionEffect = null; MAFSPublisher = null; dependenciesSelectionPreperation = null; tracesHandler = null; highLevelPlan = null; name2mapsAgent = null; allProjectionActions = null; MapsAgent.ResetStaticFields(); }
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; }
public abstract void PublishGoalState(MapsVertex goalVertex, MapsAgent goalFinder);
public void CalculateLeakage(List <MapsAgent> adversaries, MapsAgent chosen) { CalculateGroundTruth(chosen); CalculateAdverseriesFoundAttributes(adversaries, chosen); }
public List <string> PreferablePlan_NotdirectMessage() { highLevelPlan = new List <string>(); //List<Thread> threads = new List<Thread>(); //begin = DateTime.Now; //return null; Program.countMacro = 0.0; Program.countAvgPerMacro = 0.0; Program.sendedStateCounter = 0; Program.ffMessageCounter = 0; Program.StateExpendCounter = 0; Program.notSendedStates = 0; MapsPlanner.generateCounter = 0; Program.makeSpanPlanTime = 0.0; List <string> lplan = null; MapsAgent.InitMutex(MapsAgents); List <double> iterationTimes = null; MapsAgent.thereIsPrivate = false; foreach (MapsAgent agent in MapsAgents) { if (agent.privateActions.Count > 0) { MapsAgent.thereIsPrivate = true; } } int x = 0; while (lplan == null) { nextGlobalOpenList = new Dictionary <string, HashSet <MapsVertex> >(); foreach (MapsAgent agent in MapsAgents) { nextGlobalOpenList.Add(agent.name, new HashSet <MapsVertex>()); } iterationTimes = new List <double>(); foreach (MapsAgent agent in MapsAgents) { DateTime startTime = DateTime.Now; lplan = agent.BeginPreferablePlanning(); iterationTimes.Add(DateTime.Now.Subtract(startTime).TotalSeconds); Program.cancellationTokenSource.Token.ThrowIfCancellationRequested(); if (lplan != null) { break; } } /* bool chacking = false; * foreach (MapsAgent agent in MapsAgents) * { * if (agent.GetCountOfPreferableList() > 0) * chacking = true; * * } * foreach(HashSet<MapsVertex> l in nextGlobalOpenList.Values) * { * foreach(MapsVertex mv in l) * { * if (mv.isPreferable) * chacking = true; * } * } * Console.WriteLine(x); * if (!chacking && x != 0) * Console.WriteLine("ddd"); * x++;*/ double maxTime = iterationTimes.Max(); Program.makeSpanPlanTime += maxTime; if (lplan != null) { MapsPlanner.stop = true; break; } else { foreach (MapsAgent agent in MapsAgents) { agent.SetPublicOpenLists(nextGlobalOpenList); } } //Check if all the agents haven't found any plan, and don't have any node in their open list. //If so, end the program - we couldn't find any valid plan. bool allDone = true; foreach (MapsAgent agent in MapsAgents) { if (!agent.openIsEmpty()) { allDone = false; } } if (allDone) { MapsPlanner.stop = true; break; } } int maxAmountOfUsedDependencies = 0; foreach (MapsAgent agent in MapsAgents) { int amountOfUsedDependencies = agent.GetAmountOfUsedDependencies(); if (maxAmountOfUsedDependencies < amountOfUsedDependencies) { maxAmountOfUsedDependencies = amountOfUsedDependencies; } } Program.amountOfDependenciesUsedInPlanningProcess = maxAmountOfUsedDependencies; if (lplan != null) { //calculate amount of dependencies used: Program.amountOfDependenciesUsed = AdvancedLandmarkProjectionPlaner.CalculateAmountOfDependenciesUsedAndSaveGoldenStandardTrace(highLevelPlan, allProjectionActions, agents, null, false); } tracesHandler.FinishPlanning(highLevelPlan); return(lplan); }
public bool CanPublish(MapsAgent agent, MapsVertex vertex) { return(true); }
public override void RecieveState(MapsVertex recievedVertex, MapsAgent recievedAgent, MapsVertex sentVertex, MapsAgent senderAgent) { //don't do anything here... }
public abstract void RecieveState(MapsVertex recievedVertex, MapsAgent recievedAgent, MapsVertex sentVertex, MapsAgent senderAgent);
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...). }
public override void publishState(MapsVertex vertex, MapsAgent agent) { //don't do anything here... }
public abstract void publishState(MapsVertex vertex, MapsAgent agent);
public List <string> PreferablePlan_NotdirectMessage() { //List<Thread> threads = new List<Thread>(); //begin = DateTime.Now; //return null; countMacro = 0.0; countAvgPerMacro = 0.0; sendedStateCounter = 0; ffMessageCounter = 0; Program.StateExpandedCounter = 0; notSandedStates = 0; MapsPlanner.generateCounter = 0; makeSpanPlanTime = 0.0; List <string> lplan = null; MapsAgent.InitMutex(MapsAgents); List <double> iterationTimes = null; MapsAgent.thereIsPrivate = false; foreach (MapsAgent agent in MapsAgents) { if (agent.privateActions.Count > 0) { MapsAgent.thereIsPrivate = true; } } int x = 0; while (lplan == null) { nextGlobalOpenList = new Dictionary <string, HashSet <MapsVertex> >(); foreach (MapsAgent agent in MapsAgents) { nextGlobalOpenList.Add(agent.name, new HashSet <MapsVertex>()); } iterationTimes = new List <double>(); foreach (MapsAgent agent in MapsAgents) { DateTime startTime = DateTime.Now; lplan = agent.BeginPreferablePlanning(); iterationTimes.Add(DateTime.Now.Subtract(startTime).TotalSeconds); if (lplan != null) { break; } } /* bool chacking = false; * foreach (MapsAgent agent in MapsAgents) * { * if (agent.GetCountOfPreferableList() > 0) * chacking = true; * * } * foreach(HashSet<MapsVertex> l in nextGlobalOpenList.Values) * { * foreach(MapsVertex mv in l) * { * if (mv.isPreferable) * chacking = true; * } * } * Console.WriteLine(x); * if (!chacking && x != 0) * Console.WriteLine("ddd"); * x++;*/ double maxTime = iterationTimes.Max(); makeSpanPlanTime += maxTime; if (lplan != null) { MapsPlanner.stop = true; break; } else { foreach (MapsAgent agent in MapsAgents) { agent.SetPublicOpenLists(nextGlobalOpenList); } } } return(lplan); }
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; } } } } }
public override void publishRealStartState(MapsAgent agent, MapsVertex realStartState, int stateID, Dictionary <string, int> iparents) { // don't do anything here... }
/* * Use this class in order to limit the publishing of states that reveal a certain dependency that shouldn't be revealed. * This class shall pick which dependencies should we reveal and which should we not reveal. */ public void PrepareSelection(AAdvancedProjectionActionPublisher publisher, List <MapsAgent> mafsAgents, List <Agent> agents, AHandleTraces tracesHandler, List <Domain> lDomains, List <Problem> lProblems) { //TODO: handle traces later... List <Action> allProjectionAction = new List <Action>(); GroundedPredicate newPrePredicate = null; newPrePredicate = new GroundedPredicate(Domain.ARTIFICIAL_PREDICATE + "StartState"); List <Predicate> predicates = new List <Predicate>(); predicates.Add(newPrePredicate); int index = 0; Dictionary <Agent, List <Action> > agentsProjections = new Dictionary <Agent, List <Action> >(); //Measuring the time for the dependencies generation: List <DateTime> dependenciesProjectionStartTimes = new List <DateTime>(); List <DateTime> dependenciesProjectionEndTimes = new List <DateTime>(); foreach (Agent agent in agents) { agent.initLandmarksDetect(); //this returns all of the projections, we will need to take only some of them and look at how does it affect the solution DateTime startDependenciesGeneration = DateTime.Now; dependenciesProjectionStartTimes.Add(startDependenciesGeneration); List <Action> currentlProjAction = agent.getAdvancedProjectionPublicAction(index, predicates); DateTime endDependenciesGeneration = DateTime.Now; dependenciesProjectionEndTimes.Add(endDependenciesGeneration); //Save the dependencies for later usage: agentsProjections.Add(agent, currentlProjAction); foreach (Action act in currentlProjAction) { act.agent = agent.name; } index += 1000; } Program.SaveTimeMeasurmentsForCreatingDependencies(dependenciesProjectionStartTimes, dependenciesProjectionEndTimes); /* * LeakageTrace.setAgents(agents); * Dictionary<Agent, LeakageTrace> traces = new Dictionary<Agent, LeakageTrace>(); * List<Action> publicActionsForTraces = new List<Action>(); * foreach (Agent agent in agents) * { * LeakageTrace trace = new LeakageTrace(agent); * traces.Add(agent, trace); * publicActionsForTraces.AddRange(agentsProjections[agent]); * } * AdvancedLandmarkProjectionPlaner.firstTimeWritenStates = new Dictionary<Agent, bool>(); * foreach (Agent agent in agents) * { * traces[agent].initializeOperators(publicActionsForTraces, agent.privateActions); * AdvancedLandmarkProjectionPlaner.writeFirstHalfOfJsonToFile(agent, traces[agent]); * AdvancedLandmarkProjectionPlaner.firstTimeWritenStates.Add(agent, true); * } * * tracesHandler.setAgents(agents); * tracesHandler.setTraces(traces); */ //clear the actions affected dictionary: AdvancedLandmarkProjectionPlaner.actionsAffectedForAgent = new Dictionary <Agent, Dictionary <Predicate, List <Action> > >(); //publish all of the chosen projections, by the chosen policy: Console.WriteLine("Choosing which dependencies to publish"); publisher.setAgents(agents); DateTime dependenciesSelectionStartTime = DateTime.Now; publisher.publishActions(allProjectionAction, agentsProjections); DateTime dependenciesSelectionEndTime = DateTime.Now; Program.SaveTimeMeasurmentForSelectingDependencies(dependenciesSelectionStartTime, dependenciesSelectionEndTime); Dictionary <string, MapsAgent> name2mafsAgent = new Dictionary <string, MapsAgent>(); foreach (MapsAgent mapsAgent in mafsAgents) { name2mafsAgent.Add(mapsAgent.name, mapsAgent); } Dictionary <string, Agent> name2agent = new Dictionary <string, Agent>(); Dictionary <string, List <Action> > agentName2agentProjActions = new Dictionary <string, List <Action> >(); foreach (Agent agent in agents) { name2agent.Add(agent.name, agent); //Set start state dependencies: MapsAgent mapsAgent = name2mafsAgent[agent.name]; List <Predicate> startStatePredicates = agent.GetPrivateStartState().Cast <Predicate>().ToList(); //List<Predicate> startState = GetTransformedArtificialPredicates(agent, startStatePredicates); mapsAgent.SetDependenciesAtStartState(startStatePredicates); agentName2agentProjActions[agent.name] = new List <Action>(); } foreach (Action action in allProjectionAction) { MapsAgent mafsAgent = name2mafsAgent[action.agent]; Agent agent = name2agent[action.agent]; List <Predicate> effects = GetTransformedArtificialPredicates(agent, action.HashEffects); mafsAgent.AddToEffectsActionsAndDependencies(action.Name, effects); List <Predicate> preconditions = GetTransformedArtificialPredicates(agent, action.HashPrecondition); mafsAgent.AddToPreconditionActionsAndDependencies(action.Name, preconditions); agentName2agentProjActions[agent.name].Add(action); } MapsPlanner.allProjectionActions = allProjectionAction; foreach (Agent a in agents) { MapsAgent mAgent = name2mafsAgent[a.name]; //Create a new projection hueristics, based on only the selected dependencies: mAgent.projectionHeuristic = new AdvancedProjectionHeuristic(a, agents, lDomains, lProblems, agentName2agentProjActions, predicates); } }
public override void PublishGoalState(MapsVertex goalVertex, MapsAgent goalFinder) { //don't do anything here... }
public abstract void publishRealStartState(MapsAgent agent, MapsVertex realStartState, int stateID, Dictionary <string, int> iparents);