📄 blockdata.java
字号:
package MRL.Police;import yab.agent.DisasterSpace;import yab.agent.object.*;import java.util.*;import MRL.Utilities.Partitioning.*;public class BlockData implements PoliceConstantsAndConditions{ private DisasterSpace world; private RealObject self; public BlockData(RealObject self){ this.world = self.world; this.self = self; agents = world.platoonAgents; paths = world.paths; motionlessObjects = world.motionlessObjects; } private final int SIM_TIME = yab.agent.Constants.SIMULATING_TIME; private final Map <Humanoid,ArrayList[]> agentPathsTimeMap = new HashMap(); private final Map <Humanoid,ArrayList[]> agentMOTimeMap = new HashMap(); private final Map <Humanoid,Path> currentAgentPathMap = new HashMap(); private final List agents; private final List motionlessObjects ; private final List paths; private RealObject self(){ return self; } private int time() { return world.time(); } public void setLockedByBlockade(Humanoid agent,MotionlessObject mo){ int time = time(); if(!updateMoTime(agent,mo,time)) return; Path path = world.getContainingPath(mo); if(path != null){ updatePathTime(agent,path,time); } } private boolean updateMoTime(Humanoid agent,MotionlessObject mo , int time){ Integer timeInt = new Integer(time); ArrayList[] moTime; ArrayList mos , times; if(agentMOTimeMap.containsKey(agent)){ moTime= agentMOTimeMap.get(agent); } else{ moTime=new ArrayList[2]; moTime[0] = new ArrayList(); moTime[1] = new ArrayList(); agentMOTimeMap.put(agent,moTime); } mos = moTime[0]; times = moTime[1]; int lastMoIndx = mos.lastIndexOf(mo); if(lastMoIndx == -1 || ((Integer)times.get(lastMoIndx)).intValue() < time){ mos.add(mo); times.add(timeInt); return true; } else {// System.err.println(self() + " , Error , Duplicate Value For : " + mo + " , " + time); return false; } } private boolean updatePathTime(Humanoid agent,Path path,int time){ Integer timeInt = new Integer(time); ArrayList[] pathTime; ArrayList paths,times; if(agentPathsTimeMap.containsKey(agent)){ pathTime = agentPathsTimeMap.get(agent); } else{ pathTime= new ArrayList[2]; pathTime[0]= new ArrayList(); pathTime[1] = new ArrayList(); agentPathsTimeMap.put(agent,pathTime); } paths = pathTime[0]; times=pathTime[1]; int lastPathIndx = paths.lastIndexOf(path); if(lastPathIndx == -1 || ((Integer)times.get(lastPathIndx)).intValue() < time){ paths.add(path); times.add(timeInt); return true; } else {// System.err.println(self() + " , Error , Duplicate Value For : " + path.getID() + " , " + time); return false; } } public void updateLockedByBlockade(){ Humanoid hum; ArrayList [] pathTime; ArrayList paths,times; Path path; int time; for(Iterator it =agentPathsTimeMap.keySet().iterator();it.hasNext();){ hum = (Humanoid)it.next(); pathTime = agentPathsTimeMap.get(hum); paths = pathTime[0]; times = pathTime[1]; path = (Path) paths.get(paths.size()-1); time = ((Integer) times.get(times.size() -1)).intValue(); currentAgentPathMap.remove(hum); if(time() - time > LOCKED_BB_TIMEOUT) continue; if(!path.checkPathIsOpen()){ currentAgentPathMap.put(hum,path);// System.out.println(self() + " , Detected LBB : " + hum + " In : " + path.getID()); } } } public int getLockedAgentsCountInPart(Partition part){ int res = 0; Humanoid hum; Path path; for(Iterator it=currentAgentPathMap.keySet().iterator();it.hasNext();){ hum = (Humanoid) it.next(); path = currentAgentPathMap.get(hum); if(part.ML_OBJS_IN_PART_CND.eval(path)) res++; } return res; } public int getAgentsLockedInPathCount(Path path){ int res = 0; Humanoid hum; for(Iterator it = currentAgentPathMap.keySet().iterator();it.hasNext();){ hum = (Humanoid) it.next(); if(currentAgentPathMap.get(hum) == path) res ++; } return res; } public List getAgentsLockedInPath(Path path){ List res = new ArrayList(); Humanoid hum; for(Iterator it = currentAgentPathMap.keySet().iterator();it.hasNext();){ hum = (Humanoid) it.next(); if(currentAgentPathMap.get(hum) == path) res.add(hum); } return res; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -