📄 quadpartition.java
字号:
package MRL.Utilities.Partitioning;import yab.agent.DisasterSpace;import yab.agent.object.MovingObject;import yab.agent.object.Humanoid;import yab.agent.object.Building;import java.util.Collection;import java.util.Iterator;class QuadPartition extends Partition { // Can Change Coordinates To PointObjects , MayB It Would Be Usefull For Finding Boundry Points . private final int starting_x, ending_x, starting_y, ending_y, center_x, center_y; public QuadPartition(DisasterSpace world,int ID, int Starting_X, int Starting_Y, int Width, int Height) { super(world,ID); starting_x = Starting_X; starting_y = Starting_Y; ending_x = Starting_X + Width; ending_y = Starting_Y + Height; center_x = (int) (starting_x + ending_x) / 2; center_y = (int) (starting_y + ending_y) / 2; } /* public boolean Includes(RealObject ro) { boolean res = false; if (ro instanceof MovingObject && ( (MovingObject) ro).position() == null) { if (MRL.MRLConstants.PARTITION_DEBUG_MODE) { System.out.println("OBJECT : " + ro.id + " , TYPE : " + yab.agent.Util.classBaseName(ro) + " , Position Not Set So It Cannot Be Checked In Partition"); return false; } } int px = p.x(), py = p.y(); if (px >= starting_x && px <= ending_x && py >= starting_y && py <= ending_y)return true; else return false; } */ public boolean Includes(MovingObject mo) { boolean res = false; if (mo.position() == null) { if (MRL.MRLConstants.PARTITION_DEBUG_DEEP_MODE) { System.out.println("OBJECT : " + mo.id + " , TYPE : " + yab.agent.Util.classBaseName(mo) + " , Position Not Set So It Cannot Be Checked In Partition"); } return false; } return Includes((Partitionable)mo.motionlessPosition());// int mox = mo.x(), moy = mo.y();// if (mox >= starting_x && mox <= ending_x && moy >= starting_y &&// moy <= ending_y)return true;// else return false; } protected boolean Includes(Partitionable p) { int px = p.x(), py = p.y(); if (px >= starting_x && px <= ending_x && py >= starting_y && py <= ending_y)return true; else return false; } public String toString() { return super.toString() + ",Starting:[" + starting_x + "," + starting_y + "],Ending:[" + ending_x + "," + ending_y + "]"; } public boolean Remove(Partitionable p) { return super.Remove(p); } public boolean Add(Partitionable p) { return super.Add(p); } public int getDistanceToCenter(Partitionable p) { if (!Includes(p))return -1; int px = p.x(), py = p.y(); return yab.agent.Util.distance(px, py, center_x, center_y); } public int getDistanceToCenter(MovingObject mo) { if (mo.position() == null) { if (MRL.MRLConstants.PARTITION_DEBUG_MODE) { System.err.println("Moving Object's Position Not Set , Cannot Determine Distance To Center : " + mo.id); } return Integer.MAX_VALUE; } // if (!Includes((Partitionable)mo.motionlessPosition()))return Integer.MAX_VALUE; int mox = mo.motionlessPosition().x(), moy = mo.motionlessPosition().y(); return yab.agent.Util.distance(mox, moy, center_x, center_y); } public MovingObject getNearestMovingObject(Collection movingobjs) { MovingObject res = null, temp; int bestmatch = Integer.MAX_VALUE, distance; for (Iterator it = movingobjs.iterator(); it.hasNext(); ) { temp = (MovingObject) it.next(); distance = getDistanceToCenter(temp); if (distance < bestmatch) { res = temp; bestmatch = distance; } } return res; } private int maxLen = -1; public int getMaxLength() { if (maxLen == -1) { maxLen = yab.agent.Util.distance(starting_x, starting_y, ending_x, ending_y); } return maxLen; } /** * @todo : AGHAZADEH : SHARBAFI : Formula Change ? */ private int m_time = 0; private double m_score; private double m_prevScore; private double m_initialTotalHP; private final double scAlph = .1; private double prevPB = 0; private final double scBet = .9; private final double scGam = 1; private double m_totalScore = 0; private double m_prevTotalScore = 0; private double lockedAgentCoef = 0.5; public double getScore(Collection movingObjects, int time) { if (time == m_time)return m_score; m_prevScore = m_score; m_prevTotalScore = m_totalScore; Collection movingobjs = MO_OBJS_IN_PART_CND.extract(movingObjects); Collection buildings = getBuildings(); double totalHp = 0; int numLiving = 0; int hp; for (Iterator it = movingobjs.iterator(); it.hasNext(); ) { hp = ( (Humanoid) it.next()).hp(); totalHp += hp; if (hp > 0) numLiving++; } m_initialTotalHP = (double)movingObjects.size() * MRL.Utilities.SimulatorsConstants.INITIAL_HP; // THIS IS Why Score Is Limited But It Cannot Be Changed Cuz If Everyone Leaves Partition , Score Is NAN! double totalBldgArea = 0; double totalNonburnedBldgArea = 0; for (Iterator it = buildings.iterator(); it.hasNext(); ) { Building b = (Building) it.next(); int area = b.buildingAreaTotal(); totalBldgArea += area; double factor = 1.0; switch (b.fieryness()) { case 0: break; case 1: case 4: case 5: factor = 0.666666; break; case 2: case 6: factor = 0.333333; break; default: factor = 0; break; } totalNonburnedBldgArea += (factor * area); } Path path; int totalPrevPathBlocks = 0,totalPathCSBlocks = 0; for(Iterator it = getPaths().iterator();it.hasNext();){ path = (Path) it.next(); totalPrevPathBlocks += path.getTotalReportedBlockades(); totalPathCSBlocks += path.getReportedBlockadesInCycle(); } if(m_initialTotalHP == 0) return m_prevScore; // Total HP IS 0 , Result Would Be NAN. double pScore = (numLiving + totalHp / m_initialTotalHP) * Math.sqrt(totalNonburnedBldgArea / totalBldgArea); m_score = pScore; if(m_score > m_prevScore ){ isScoreValid = false; } else isScoreValid = true; if(MRL.MRLConstants.PATH_DEBUG_DEEP_MODE) System.out.print("Prev PB For : " + getID() + " : " + prevPB + " , Total CS BLOCK : " + totalPathCSBlocks + "\n"); prevPB = scBet * prevPB + scGam * totalPathCSBlocks; m_totalScore = scAlph*m_score - prevPB; // HEREEEEEEEEEEEE int lockedAgentCount = world.blockData.getLockedAgentsCountInPart(this); double lockedAgentVal = lockedAgentCoef * lockedAgentCount; if(m_totalScore > lockedAgentVal ) m_totalScore -= lockedAgentVal; // HEREEEEEEEEEEEE if(MRL.MRLConstants.PATH_DEBUG_DEEP_MODE)System.out.println("Score For : " + getID() + " : [Score] - [prevPB] = [Total] : " + m_score + " - " + prevPB + " = " + m_totalScore + " , Prev Total Score : " + m_prevTotalScore); return m_totalScore; } private double m_scoreDelta=0; private double m_prevScoreDelta=0; private double m_resDelta=0; private int m_lpT = 0; public double getScoreDelta(int time){ if(m_lpT < time){ m_prevScoreDelta = m_scoreDelta; m_scoreDelta = m_totalScore - m_prevTotalScore; m_resDelta = m_scoreDelta - m_prevScoreDelta; m_lpT = time; } return m_resDelta ; } public int x(){ return center_x; } public int y(){ return center_y; } // ---------------------------------------------------------------- OMID}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -