本文整理匯總了Python中plan.Plan.getLocalJsonPlan方法的典型用法代碼示例。如果您正苦於以下問題:Python Plan.getLocalJsonPlan方法的具體用法?Python Plan.getLocalJsonPlan怎麽用?Python Plan.getLocalJsonPlan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plan.Plan
的用法示例。
在下文中一共展示了Plan.getLocalJsonPlan方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: receivePlanSyncResponse
# 需要導入模塊: from plan import Plan [as 別名]
# 或者: from plan.Plan import getLocalJsonPlan [as 別名]
def receivePlanSyncResponse(self, sender, otherPlan):
"""callback for the plan synchronisation"""
with self.mutex:
myID = self.plan.ids[-1]
otherID = otherPlan["ID"]["value"]
if myID == otherID:
return
logger.info("I'm executing plan %s. %s is executing %s" % (self.plan.ids, sender, otherPlan["ID"]))
if self.newPlanToImport is not None:
newID = json.loads(self.newPlanToImport)["ID"]["value"]
if newID != otherID:
logger.warning("I'm executing %s. I received a new plan %s and a previous plan %s. Ignoring this one" % (myID,otherID,newID))
else:
logger.info("Ignoring this plan since I have already ask for its use")
return
if myID in otherPlan["ID"]["parents"]:
logger.info("The other has repaired and I was not notified. I need to update my plan")
agents = set([a["agent"] for a in otherPlan["actions"].values() if "agent" in a])
logger.info("List of agents in this plan : %s " % agents)
plansDict = {}
#Prevent the removal of coms time
otherPlan["current-time"] = (time.time() - self.beginDate)
p = Plan(json.dumps(otherPlan), self.agent)
#Check that all my communications are still in the plan
droppedComs = set() #In my current plan
foreignDroppedCom = set() #In the remote plan
for k,a in self.plan.actions.items():
if a["agent"] == self.agent:
if k in p.actions and a["name"] == p.actions[k]["name"]:
continue #Ok, my action is still here
elif k not in p.actions and "communicate" in a["name"]:
#self.dropCommunication(a["name"])
droppedComs.add(a["name"])
else:
logger.error("My action %s (%s) is not in the new plan" % (a["name"],k))
for k,a in p.actions.items():
if a["agent"] == self.agent:
if k in self.plan.actions and a["name"] == self.plan.actions[k]["name"]:
continue #Ok, my action is still here
if "communicate-meta" in a["name"]:
comName = a["name"]
if comName in self.droppedComs or a["name"]:
#I already dropped this com.
logger.warning("They kept a com that I dropped %s (%s)" % (a["name"],k))
foreignDroppedCom.add(k)
else:
logger.error("They added an com action for me %s (%s)" % (a["name"],k))
logger.error("%s not in %s" % (comName, self.droppedComs))
else:
logger.error("They added an action for me %s (%s)" % (a["name"],k))
for k1,a1 in self.plan.actions.items():
if a1["name"] == a["name"]: logger.error("I have this action with key %s" % k1)
for k,a in self.plan.actions.items():
if "communicate-meta" in a["name"] and k not in p.actions:
droppedComs.add(a["name"])
for c in droppedComs:
self.dropCommunication(c)
if foreignDroppedCom:
logger.info("Imported plan before removing a foreign com: %s" % json.dumps(otherPlan))
for c in foreignDroppedCom:
logger.info("Removing action %s (%s)" % (otherPlan["actions"][c], c))
logger.info("Length before %s" % len(otherPlan["actions"]))
otherPlan = Plan.removeAction(otherPlan, c) #remove the com meta for actions that I dropped
logger.info("Length after %s" % len(otherPlan["actions"]))
logger.info("Imported plan after removing a foreign com: %s" % json.dumps(otherPlan))
p = Plan(json.dumps(otherPlan), self.agent)
for a in agents:
if a != self.agent:
plansDict[a] = p.getLocalJsonPlan(a)
plansDict[self.agent] = self.plan.getLocalJsonPlan(self.agent, currentTime=(time.time() - self.beginDate))
p = Plan.mergeJsonPlans(plansDict, idAgent = sender)
p["current-time"] = plansDict[self.agent]["current-time"]
# See if the plan is still temporally valid. It could be a problem if I added a ub for a com
# while the other robot was late : both constraints are problematic. In this case, drop my
# current com or the com of the other robot
try:
_ = Plan(json.dumps(p), self.agent)
except PlanImportError as e:
logger.warning("The fused plan will not be valid. Try to drop a current com")
for action in p["actions"].values():
#for name,_,_ in self.ongoingActions:
name = action["name"]
if self.agent not in name: continue
#if not (action["startTp"] in p["absolute-time"] and not action["endTp"] in p["absolute-time"]):continue
#.........這裏部分代碼省略.........