📄 partition.java
字号:
package MRL.Utilities.Partitioning;import java.util.*;import yab.agent.object.*;import yab.agent.DisasterSpace;import yab.agent.Condition;import yab.agent.Util;import MRL.Utilities.*;public abstract class Partition implements Partitionable , ConstantConditions{ // ---------------------------------------------------------------- OMID private final Collection objects = new HashSet(); private final int ID; protected final DisasterSpace world; protected Partition(DisasterSpace world,int ID) { this.ID = ID; this.world = world; Arrays.fill(numLiving,-1); } protected boolean Add(Partitionable p) { return objects.add(p); } protected boolean Remove(Partitionable p) { return objects.remove(p); } protected Collection getobjects() { return objects; } protected abstract boolean Includes(MovingObject mo); // Returns Wether Object Should Be Included In The Partition Or Not protected abstract boolean Includes(Partitionable p); public abstract int getMaxLength(); public boolean Includes(RealObject ro) { if (ro instanceof MotionlessObject) return IsContaining( (Partitionable) ro); else if (ro instanceof MovingObject) return Includes( (MovingObject) ro); else System.err.println("Invalid Object Type To Check For Including : " + yab.agent.Util.classBaseName(ro)); return false; } public boolean IsContaining(Partitionable p) { // Returns IF Object Is Added To The Partition's Collection return (objects.contains(p)); } public int getID() { return ID; } public String toString() { return "Quad Partition , ID:" + getID(); } public String showContents() { return "Total Objects:" + objects.size() + " , Edge Objects : " + edgeObjects.size(); } public abstract int getDistanceToCenter(Partitionable p); public abstract MovingObject getNearestMovingObject(Collection movingobjs); private final String basepackagename = "yab.agent.object."; private final List m_nodesIP = new ArrayList(); public List getNodes() {// Class type = getClass(basepackagename + "Node");// return type == null ? null : getInstancesFromCollection(objects, type); if (m_nodesIP.isEmpty()) { m_nodesIP.addAll(NODE_C.extract(objects)); } return m_nodesIP; } private final List m_roadsIP = new ArrayList(); public List getRoads() { if(m_roadsIP.isEmpty()){ m_roadsIP.addAll(ROAD_C.extract(objects)); } return m_roadsIP; } private final List m_pathsIP = new ArrayList(); public List getPaths() {// Class type = getClass("MRL.Utilities.Partitioning.Path");// return type == null ? null : getInstancesFromCollection(objects, type); if (m_pathsIP.isEmpty()) { m_pathsIP.addAll(PATH_C.extract(objects)); } return m_pathsIP; } private final List m_bldgsIP = new ArrayList(); public List getBuildings() { if (m_bldgsIP.isEmpty()) { m_bldgsIP.addAll(BUILDING_C.extract(objects)); } return m_bldgsIP; } private Class getClass(String classname) { Class type = null; try { type = Class.forName(classname); } catch (ClassNotFoundException ex) { } return type; } public List getInstancesFromCollection(Collection collection, Class Type) { List result = new ArrayList(); Object object; for (Iterator it = collection.iterator(); it.hasNext(); ) { object = it.next(); if (object.getClass() == Type) result.add(object); } return result; } public Condition ML_OBJS_IN_PART_CND = new Condition() { public boolean eval(Object obj) { if (obj instanceof Partitionable) { return IsContaining( (Partitionable) obj); } else return false; } }; public Condition RO_OBJS_IN_PART_CND = new Condition() { public boolean eval(Object obj) { if (obj instanceof RealObject) return Includes( (RealObject) obj); else return false; } }; public Condition MO_OBJS_IN_PART_CND = new Condition() { public boolean eval(Object obj) { if (obj instanceof MovingObject) { return Includes( (MovingObject) obj); } else return false; } }; public Condition EDGE_OBJS_IN_PART_CND = new Condition() { public boolean eval(Object obj) { if (obj instanceof Partitionable) { return isEdgeObject((Partitionable)obj); } else return false; } }; public abstract double getScore(Collection movingObjects, int time); public abstract double getScoreDelta(int time); public boolean isScoreValid=false; private final Collection edgeObjects = new HashSet(); protected boolean addEdgeObject(Partitionable p){ return edgeObjects.add(p); } public boolean isEdgeObject(Partitionable p){ return edgeObjects.contains(p); } public Collection getEdgeObjects(){ return edgeObjects; } final int [] numLiving = new int[SimulatorsConstants.SIMULATING_TIME + 2]; public int getNumLiving(){ int time = world.time(); if(numLiving[time] == -1){ numLiving[time] = Utils.getConditionCount(world.humanoids, MO_OBJS_IN_PART_CND); } return numLiving[time]; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -