📄 accessibledata.java
字号:
package MRL.Utilities;import yab.agent.*;import yab.agent.object.*;import java.util.*;public class AccessibleData implements ConstantConditions{ private final DisasterSpace world; public AccessibleData(DisasterSpace world){ this.world = world; motionlessObjects = world.motionlessObjects; roads = world.roads; buildings = world.buildings; nodes = world.nodes; } private final List <MotionlessObject> motionlessObjects; private final List <Road> roads; private final List <Node> nodes; private final List <Building>buildings; public final Set toSiteCheck = new HashSet(); private int time(){ return world.time(); } public void updateAccessiblity(){ long st = System.currentTimeMillis(); if(!shouldCheck()) return; checkReachable(); long ed = System.currentTimeMillis(); // System.out.println(world.self + " Updating Accessibility Took : " + (ed - st) + " MilliSeconds."); } private boolean shouldCheck(){ Road road; int time = time(); for(Iterator it = roads.iterator();it.hasNext();){ road = (Road) it.next(); if(time - road.time() < 2 && PASSABLE_C.eval(road) && ! road.isReachable()) return true; } return false; } private void addAccessibleRoad(Road road){ if(road.isReachable()){ return; } Collection tmp; tmp = road.getConnectedBuildings(); setReachable(tmp);// System.out.println(world.self + " Added : " + tmp.size() + " Reachable Buildings In : " + time()); tmp = road.neighborhood(); setReachable(tmp); road.setReachable(true); } private void addAccessible(Collection set){ for(Iterator it = set.iterator();it.hasNext();){ addAccessibleRoad((Road)it.next()); } } private void setReachable(Collection tmp){ MotionlessObject mo; for(Iterator it = tmp.iterator();it.hasNext();){ mo = (MotionlessObject) it.next(); mo.setReachable(true); } } private void checkReachable (Node start) { toSiteCheck.clear(); LinkedList open = new LinkedList(); HashSet hasRoute = new HashSet(); Road road = null,troad; boolean canContinue = false; for(Iterator it= start.getConnectedRoads().iterator();it.hasNext();){ road = (Road) it.next(); if(road.passableLinesFrom(start) > 0) { canContinue = true; break; } } if(! canContinue) return; NRT route = new NRT(road,0),nrt; open.add(route); while (true) { if (open.isEmpty()) return; route = (NRT) open.removeFirst(); road = route.rd; if( route.cost < NOT_SEEN_RD){ if(! road.isReachable()){ addAccessibleRoad(road); } } else{ toSiteCheck.addAll(road.getConnectedBuildings()); } hasRoute.add(road); for(Iterator it=road.getConnectedRoads().iterator();it.hasNext();){ troad = (Road) it.next(); if(hasRoute.add(troad)){ nrt = new NRT(troad, route.cost + getCost(road,troad)); if(nrt.cost < IN_BLOCKS){ open.add(nrt); } } } } } private void checkReachable(){ Node outsidePosition=HumanoidAgent.outsidePosition((MovingObject)world.self); checkReachable(outsidePosition); } private float getCost(Road from, Road to) { Node between = (from.head() == to.head() || from.head() == to.tail()) ? (Node)from.head() : (Node)from.tail(); if (to.passableLinesFrom(between) == 0) return IN_BLOCKS; return to.hasBeenSeen() ? 1 : NOT_SEEN_RD; // Cycle 3+ } private class NRT { public final float cost; public final Road rd; public NRT(Road rd , float cost){ this.cost = cost; this.rd = rd; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -