📄 disasterspace.java
字号:
} /** * todo : OM_ASHKAN : CHANGED */ private void updatePathValues(Collection src) { Path path; for (Iterator it = src.iterator(); it.hasNext(); ) { path = (Path) it.next(); if(path.checkPathIsOpen()) continue; path.updateValue(); } //showPathValues(); } public double cpScore; private void updateCPScore() {// Collection humInPart = workingpartition.MO_OBJS_IN_PART_CND.extract(humanoids);// cpScore = workingpartition.getScore(humInPart, time()); // Computes Scores For All Of Humanoids.// humInPart = null; workingPartition.getScore(humanoids, time()); // Computes Scores For All Of Humanoids. if (workingPartition != null) { if (MRL.MRLConstants.PATH_DEBUG_DEEP_MODE) { System.out.println(self + " , Partition : " + workingPartition.getID() + " , Delta Score In : " + time() + " IS : " + workingPartition.getScoreDelta(time()) + " , Score Validation : " + workingPartition.isScoreValid); } } } private void showPathValues() { Path path; for (Iterator it = pathsIP.iterator(); it.hasNext(); ) { path = (Path) it.next(); System.out.println("Path : " + path.hashCode() + " , VALUE : " + path.getValue()); } } private Map m_objPathMap = new HashMap(); public Path getContainingPath(MotionlessObject pos) { // Returns Null For Crossways if(m_objPathMap.containsKey(pos)) return (Path) m_objPathMap.get(pos); List roads; Path path = null; Node node; if (pos instanceof Node || pos instanceof Building) { Node nCheck; if (pos instanceof Building) { nCheck = (Node) ((Building) pos).entrance(); } else { nCheck = (Node) pos; } Road road; for (Iterator it = nCheck.getConnectedRoads().iterator(); it.hasNext(); ) { road = (Road) it.next(); path = getContainingPath(road); if (nCheck == path.getLastNode()) { if (path.getLastNode().getConnectedRoads().size() == 1){ m_objPathMap.put(pos, path); return path; } } else if (nCheck == path.getFirstNode()) { if (path.getFirstNode().getConnectedRoads().size() == 1){ m_objPathMap.put(pos, path); return path; } } else { m_objPathMap.put(pos, path); return path; } } if(pos instanceof Building){ node = (Node)((Building)pos).entrance(); // WILL THROW AN EXCEPTION IF ENTRANCE IS EMPTY. roads =node.getConnectedRoads(); road = (Road)pos.distancePrp.min(roads); path = getContainingPath(road); m_objPathMap.put(pos,path); return path; } } else if (pos instanceof Road) { path = getContainingPath((Road) pos);// m_objPathMap.put(pos,path); return path; } return null; } private void setNeighbourBuildings(Building build) { for (Iterator it = buildings.iterator(); it.hasNext(); ) { Building b = (Building)it.next(); if (b.distance(build) < SimulatorsConstants.EXTINGUISHABLE_DISTANCE) build.neighbourBuildings.add(b); } } public Path getContainingPath(Road road) { Path path; path = (Path) m_RoadPathMap.get(road); if (path == null)throw new Error("Road With No Path"); return path; } public Partition workingPartition = null; public void setWorkingPartition(Partition NewWorkingPartition) { pathsIP.clear(); workingPartition = NewWorkingPartition; } public Partition getWorkingPartition() { return workingPartition; } public Road getRespondingRoad(MotionlessObject pos, MotionlessObject nearTo) { Road res = null; if (pos instanceof Road) { res = (Road) pos; } else { Collection neighbours; int bestmatch = Integer.MAX_VALUE, dist; Node node = null; Road tRoad; if (pos instanceof Building) { node = (Node) ((Building) pos).entrance(); } else if (pos instanceof Node) { node = (Node) pos; } neighbours = node.getConnectedRoads(); for (Iterator it = neighbours.iterator(); it.hasNext(); ) { tRoad = (Road) it.next(); dist = Util.distance(tRoad, nearTo); if (dist < bestmatch) { bestmatch = dist; res = tRoad; } } } return res; } public Path getPath(int path_ID) { Path path; for (Iterator it = paths.iterator(); it.hasNext(); ) { path = (Path) it.next(); if (path.getID() == path_ID)return path; } return null; } public Collection getContainingPaths(Collection moObjects) { Collection contPaths = new HashSet(); MotionlessObject mo; Path path; for (Iterator it = moObjects.iterator(); it.hasNext(); ) { mo = (MotionlessObject) it.next(); path = getContainingPath(mo); if (path != null) contPaths.add(path); } return contPaths; } public List getConnectedBuildings(Collection poses) { // Works For Road And Node Set bldgs = new HashSet(); List tmp; Object obj; for (Iterator it = poses.iterator(); it.hasNext(); ) { obj = it.next(); if (obj instanceof Building){ if (!bldgs.contains(obj)) bldgs.add(obj); } else if (obj instanceof Node) { tmp = new ArrayList( ((Node) obj).getConnectedBuildings()); bldgs.addAll(tmp); } else if (obj instanceof Road) { tmp = new ArrayList(((Road) obj).getConnectedBuildings()); bldgs.addAll(tmp); } else if (obj instanceof Path) { tmp = new ArrayList(((Path) obj).getConnectedBuildings()); bldgs.addAll(tmp); } } List arBldgs = new ArrayList(bldgs); return arBldgs; } public final Set inTraffic = new HashSet(); public final Set curCycleTraffObjs = new HashSet(); public boolean isInTraffic(MotionlessObject mo) { return inTraffic.contains(mo); } public boolean isInTraffic(Path path) { return trafficICCPs.keySet().contains(path); } public void setTraffic(Path path , int time){// trafficICCPs.keySet().remove(path); if(trafficICCPs.containsKey(path)) return; trafficICCPs.put(path,new Integer(time)); } public void clearReportedBlockadesInCycle() { Path path; for (Iterator it = paths.iterator(); it.hasNext(); ) { path = (Path) it.next(); path.clearReportedBlockadesInCycle(); } } public static final Comparator ID_COMP = new Comparator() { final Comparator idComparator = Util.idComparator; public int compare(Object obj1, Object obj2) { if (obj1 instanceof RCRObject && obj2 instanceof RCRObject) { return idComparator.compare(obj1,obj2);// return ((RCRObject) obj1).id - ((RCRObject) obj2).id; } else if (obj1 instanceof Path && obj2 instanceof Path) { return ((Path) obj1).getID() - ((Path) obj2).getID(); } else if (obj1 instanceof Partition && obj2 instanceof Partition){ return ((Partition) obj1).getID() - ((Partition) obj2).getID(); } System.err.println("Invalid Compare : "+ obj1 + " With : "+ obj2); return (obj1.hashCode() - obj2.hashCode()); } }; public int self_MPINDX() { return getMP_INDX(self.motionlessPosition()); } public int self_INDX() { return agents.indexOf(self); } public int getMP_INDX(MotionlessObject mo) { return motionlessObjects.indexOf(mo); } private void doSortings() { sortByID(platoonAgents); sortByID(agents); sortByID(policeForces); sortByID(ambulanceTeams); sortByID(fireBrigades); sortByID(roads); sortByID(buildings); } public static void sortByID(List inp) { Collections.sort(inp, ID_COMP); } private boolean computePrimitiveCalcs(){ Road road; Building bldg; for (Iterator it = roads.iterator(); it.hasNext(); ) { road = (Road) it.next(); road.neighborhood(); road.getConnectedBuildings(); road.getConnectedRoads(); getContainingPath(road); } Node node; for (Iterator it = nodes.iterator(); it.hasNext(); ) { node = (Node) it.next(); node.neighborhood(); node.getConnectedBuildings(); node.getConnectedRoads(); getContainingPath(node); node.getConnectedPaths(); } Path path; for (Iterator it = paths.iterator(); it.hasNext(); ) { path = (Path) it.next(); path.getEdges(); path.getContainingObjects(); path.getConnectedBuildings(); path.getConnectedPaths(); path.checkOneWayPath(); if(path.isOneWayPath()) path.getLastNodeForOneWayPaths(); //path.updateValue(); } for(Iterator it = buildings.iterator();it.hasNext();){ bldg = (Building) it.next(); getContainingPath(bldg); setNeighbourBuildings(bldg); } return true; } public final Map m_objSetKdTreeMap = new HashMap(); public final HashMap m_neighboursMap = new HashMap(); public final Map m_objSetObjNeighboursMapMap = new HashMap(); public final Property FIRE_PRIORITY_PRP = new Property() { public Object eval(Object obj) { return new Double(firePriority((Building) obj)); } }; public double firePriority(Building fire) { for (Iterator it = m_neighboursMap.keySet().iterator(); it.hasNext(); ) { if (((Building) it.next()).isUnburned()) { it.remove(); } } ArrayList neighbours; if (m_neighboursMap.containsKey(fire)) { neighbours = (ArrayList) m_neighboursMap.get(fire); } else { Set bldgs = new HashSet(buildings); neighbours = getAround(fire, bldgs, FireBrigadeConstantsConditions. RADIUS_OF_NEIGHBOURS_FOR_FIRE_PRIORITY); if (neighbours.isEmpty()) { System.err.print("empty\n"); } m_neighboursMap.put(fire, neighbours); } if (fire.buildingAreaGround() > 200000) { return -100; } int noBurned = Utils.size(FireBrigadeConstantsConditions.NOT_BURNING_C, neighbours); int burning = Utils.size(FireBrigadeConstantsConditions.IS_BURNING_C , neighbours); int putOff = Utils.size(FireBrigadeConstantsConditions.IS_PUT_OFF_C , neighbours); int burnedOut = neighbours.size() - noBurned - burning - putOff; double priority = noBurned * FireBrigadeConstantsConditions .PRIORITY_INCREASING_RATE_BY_SURROUNDING_NO_BURNEDS + putOff * FireBrigadeConstantsConditions .PRIORITY_INCREASING_RATE_BY_SURROUNDING_PUT_OFFS - burning * FireBrigadeConstantsConditions .PRIORITY_ATTRITION_RATE_BY_SURROUNDING_FIRES - burnedOut * FireBrigadeConstantsConditions .PRIORITY_ATTRITION_RATE_BY_SURROUNDING_BURNED_OUTS; priority *= (fire.fieryness() < 3) ? 1.2 : 0.8; return priority; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -