📄 disasterspace.java
字号:
buriedAgents.clear(); buriedAgents.addAll(BURIED_C.extract(platoonAgents));// trafficICCPs.clear(); burningBuildings.clear(); burningBuildings.addAll(BURNING_C.extract(buildings)); if (IsUsingPartitioning) { if (pathsIP.isEmpty() && workingPartition != null && !pathsSet) { pathsSet = true; Collection unClearedPathsip = workingPartition.ML_OBJS_IN_PART_CND. and(SHOULD_CHECK_PATH_CND).extract( paths); pathsIP.addAll(unClearedPathsip);// sortedBlockedPathsIP.clear();// sortedBlockedPathsIP.addAll(unClearedPathsip); unClearedPathsip = null; } if (workingPartition != null &&! MRL.MRLConstants.IS_SIMPLE) { if (shouldUpdateAlphas) { if (prevPath != null && prevPath.contains(self.motionlessPosition())) { updateCPScore(); prevPath.updateAlphas(); } } /** * todo : Update Partition's Score : */// if (!sortedBlockedPathsIP.isEmpty()) {// updatePathValues();// sortPathsByValue(); //System.out.println("Total Paths In Partition : " + workingpartition.getID() + " , " + pathsIP.size());// }// } } } } public int burningTime(Building building) { Integer start = (Integer) m_fireSet.get(building); return (start == null) ? -1 : (m_time - start.intValue()); } /** * todo Should Implement A Dynamic Partitioning . MayBe Based On Map Or Something ! */ private void PartitioningInit() { if (Center == null) Center = getCenter(); dynamicPartition();// partitioner = new Partitioner(3, 3, motionlessObjects);// dynamicPartitionWNPFISP(motionlessObjects);// dynamicPartitionWALOPFIEP(motionlessObjects); // WAS THIS// if (MRLConstants.PARTITION_DEBUG_MODE) System.out.println("Center:" + Center);// testPartitions();// int objectspartitioned = partitioner.QuadPartitionFill();// if (MRLConstants.PARTITION_DEBUG_MODE) {// System.out.println(self + "Total Objects : " + m_idObjMap.values().size() +// " , " + objectspartitioned + " Objects Partitioned");// }// testAllObjectsIncluded();// List nodes = partitioner.getPartition(Center).getNodes();// System.out.println("Nodes Count : " + nodes.size());// partitioner.testRoads(); } public void computeTraffic(){ inTraffic.clear(); Path path; MotionlessObject pos = self.motionlessPosition(); for (Iterator it = trafficICCPs.keySet().iterator(); it.hasNext(); ) { path = (Path) it.next(); if(!path.IsContaining(pos) || path.getEdges().contains(pos)) { inTraffic.addAll(path.getContainingObjects()); } inTraffic.add(path); } inTraffic.addAll(curCycleTraffObjs); inTraffic.remove(pos);// System.out.println(self + " , Traffic In Time : " +time()+ " , Is : " + inTraffic); curCycleTraffObjs.clear(); } /** * todo : Must Decide How To Partition */ private void dynamicPartition(){ if(self instanceof PoliceForce || self instanceof PoliceOffice){// dynamicPartitionWALOAIEP(policeForces.size(), motionlessObjects);// staticPartition(3,2,motionlessObjects); int maxPartNum = policeForces.size()/2; int pfCount = policeForces.size(); if(pfCount >= 12) maxPartNum = 9; else if (pfCount >= 8) maxPartNum = 6; else if (pfCount >= 6) maxPartNum = 4; else if (pfCount >= 4) maxPartNum = 2; else maxPartNum = 1; dynamicPartitionWNAISP(maxPartNum,objToPartition); } else if (self instanceof FireBrigade || self instanceof FireStation){ dynamicPartitionWNAISP(fireBrigades.size(), objToPartition); } } private void dynamicPartitionWNAISP(int count,Collection motionlessObjects) { int i = count; double sqrt = Math.sqrt(i); int lB = (int) sqrt, uB = lB + 1; if (((double) lB) == sqrt) { partitioner = new Partitioner(this,lB, lB, motionlessObjects); } else if (lB * uB >= i) {// int rnd = new Random().nextInt(100);// if (rnd <= 50) { partitioner = new Partitioner(this,lB, uB, motionlessObjects);// } else {// partitioner = new Partitioner(this,uB, lB, motionlessObjects);// } } else if (lB * (uB + 1) >= i) {// int rnd = new Random().nextInt(100);// if (rnd <= 50) { partitioner = new Partitioner(this,lB, uB + 1, motionlessObjects);// } else {// partitioner = new Partitioner(this,uB + 1, lB, motionlessObjects);// } } else { partitioner = new Partitioner(this,uB, uB, motionlessObjects); } } private void dynamicPartitionWNPFISPD(Collection motionlessObjects) { int cnt = policeForces.size(); for (int i = 2; i < cnt; i++) { } } private void dynamicPartitionWALOAIEP(int count,Collection motionlessObjects) { int i = count; double sqrt = Math.sqrt(i); int partnum = (int) sqrt; partitioner = new Partitioner(this,partnum, partnum, motionlessObjects); //Ashkan changed it ----------------------------------------// partitioner = new Partitioner(this,count, count, motionlessObjects); } private void staticPartition(int x, int y, Collection motionlessObjects) { partitioner = new Partitioner(this,x, y, motionlessObjects); } public void setPrevPath(Path path) { prevPath = path; } public Path getPrevPath(){ return prevPath; }// public List getLockedBBAgentsIPPos(Collection inp) {// Humanoid hum;// MotionlessObject pos;// List res = new ArrayList();// for (Iterator it = lockedBBAgents.keySet().iterator(); it.hasNext(); ) {// hum = (Humanoid) it.next();// pos = (MotionlessObject) lockedBBAgents.get(hum);// if (inp.contains(hum)) res.add(pos); // && workingpartition!= null && workingpartition.IsContaining(pos)// }// return res;// } public Node getCenter() { if(Center != null) return Center; long x = 0, y = 0; Node result; for (int i = nodes.size() - 1; i >= 0; --i) { Node node = (Node) nodes.get(i); x += node.x(); y += node.y(); } x /= nodes.size(); y /= nodes.size(); result = (Node) nodes.get(0); for (int i = 1; i < nodes.size(); ++i) { Node temp = (Node) nodes.get(i); if (Util.distance((int) x, (int) y, result.x(), result.y()) > Util.distance((int) x, (int) y, temp.x(), temp.y())) { result = temp; } } return result; } public Collection getObjects() { return m_idObjMap.values(); } public List paths = new ArrayList(); private Map m_RoadPathMap = new HashMap(); public void createPath() { Collection usedRoads = new ArrayList(); for (Iterator it = roads.iterator(); it.hasNext(); ) { Road rd = (Road) it.next(); Node h_node = (Node) rd.head(); Node t_node = (Node) rd.tail(); if (!usedRoads.contains(rd)) { if (h_node.getConnectedRoads().size() == 2 && t_node.getConnectedRoads().size() == 2)continue; if (h_node.getConnectedRoads().size() != 2 && t_node.getConnectedRoads().size() != 2) { // path that only consist of one road Path path = new Path(this,paths.size()+1); path.setFirstRoad(rd); path.setLastRoad(rd); path.setFirstNode(h_node); path.setLastNode(t_node); path.add(rd); usedRoads.add(rd); paths.add(path); continue; } if (h_node.getConnectedRoads().size() != 2) { Path path = new Path(this,paths.size()+1); path.setFirstRoad(rd); Node nexNode = t_node; path.setFirstNode(h_node); path.add(rd); usedRoads.add(rd); while (nexNode.getConnectedRoads().size() == 2) { Object[] roadArr = nexNode.getConnectedRoads().toArray(); if (roadArr[0] == rd) rd = (Road) roadArr[1]; else rd = (Road) roadArr[0]; if (nexNode == rd.head()) nexNode = (Node) rd.tail(); else nexNode = (Node) rd.head(); usedRoads.add(rd); path.add(rd); } path.setLastNode(nexNode); path.setLastRoad(rd); paths.add(path); continue; } if (t_node.getConnectedRoads().size() != 2) { Path path = new Path(this,paths.size()+1); path.setFirstRoad(rd); path.setFirstNode(t_node); path.add(rd); usedRoads.add(rd); Node nexNode = h_node; while (nexNode.getConnectedRoads().size() == 2) { Object[] roadArr = nexNode.getConnectedRoads().toArray(); if (roadArr[0] == rd) rd = (Road) roadArr[1]; else rd = (Road) roadArr[0]; if (nexNode == rd.head()) nexNode = (Node) rd.tail(); else nexNode = (Node) rd.head(); path.add(rd); usedRoads.add(rd); } path.setLastRoad(rd); path.setLastNode(nexNode); paths.add(path); continue; } } //end if } //end loop// int i = 1; for (Iterator it = paths.iterator(); it.hasNext(); ) { Path path = (Path) it.next(); for (Iterator it2 = path.iterator(); it2.hasNext(); ) { // set pathId for every road in path Road road = (Road) it2.next(); m_RoadPathMap.put(road, path); if (!path.getRouteFromHeadNodeToTailNode().validate() || !path.getRouteFromTailNodeToHeadNode().validate()) System.out.println("Error In Validating In First Step"); } } for (Iterator it = paths.iterator(); it.hasNext(); ) { Path path = (Path) it.next(); Collection temp; Node f_node = path.getFirstNode(); temp = f_node.getConnectedRoads(); for (Iterator it3 = temp.iterator(); it3.hasNext(); ) { Road road = (Road) it3.next(); Path pth = getContainingPath(road); if (pth != path) { path.addPathToHead(pth); } } Node t_node = path.getLastNode(); temp = t_node.getConnectedRoads(); for (Iterator it3 = temp.iterator(); it3.hasNext(); ) { Road road = (Road) it3.next(); Path pth = getContainingPath(road); if (pth != path) { path.addPathToTail(pth); } } } } private int m_lastTimeCurPathRequested = -1; private Path m_curPath; public Path getCurrentPath() { if(m_lastTimeCurPathRequested != time()){ m_curPath = getContainingPath(self.motionlessPosition()); m_lastTimeCurPathRequested = time(); } return m_curPath; } public void updatePathValues() { if (workingPartition != null) { updatePathValues(pathsIP); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -