⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    return maxDist;  }  private int roundToMVD(int num) {    String snum = Integer.toString(num);    return Integer.parseInt(snum.substring(0, 1)) *        (int) Math.pow(10, snum.length() - 1);  }  private void setNormFactors() {    /*        nViFact[DTOREF] = (float) roundToMVD(maxDistToRef());        nViFact[ATCOUNT] = 1;        nViFact[PFCOUNT] = 1;        nViFact[FBCOUNT] = 1;        nViFact[CIVCOUNT] = 1;     nViFact[DTOSELF] = (float) roundToMVD(world.workingpartition.getMaxLength());        nViFact[DTOREF] = nViFact[DTOSELF];        nViFact[DTOFIRE] = nViFact[DTOREF];     *///    for (int i = 0; i < valCount; i++) nViFact[i] = 1f;    nViFact[ATCOUNT] = 1f;    nViFact[BLOCKREP] = 1f;    nViFact[PFCOUNT] = 1f;    nViFact[FBCOUNT] = 1f;    nViFact[CIVCOUNT] = 1f;//    nViFact[DTOSELF] = (float) roundToMVD(world.workingPartition.getMaxLength());    nViFact[DTOSELF] = 1f;    nViFact[DTOREF] = 1f;    nViFact[DTOFIRE] = 1f;    nViFact[CONPATH] = 6f;    nViFact[EDGEPATH] = 0.1f;  }  private void showNFs() {    for (int i = 0; i < valCount; i++)      System.out.println("NVIFACT[" + i + "] = " + nViFact[i]);  }  private static int pathtoTest;  private boolean testing = false;  public void testBlock() {    pathtoTest = this.hashCode();    testing = true;    if (getPathIsOpen()) {      System.out.println("Path : " + hashCode() + " Has No Blocks");    }    else System.out.println("Path : " + hashCode() + " Has Blocks");    testing = false;  }  private void initStatVals() {    for (int i = 0; i < valCount; i++) {      avgvals[i] = 0f;      avgvis[i] = 0f;      maxvals[i] = 0f;      minvals[i] = Float.MAX_VALUE;      maxvis[i] = 0f;      minvis[i] = Float.MAX_VALUE;    }  }  public void addReportedBIC() {    reportedBlockadesIS++;  }  private Partition firstWorkingPartition = null;  private Partition workingpartition;  private static final float gamma = .9f;  private static final float mulCoef = 2f;  public void updateAlphas() {    workingpartition = world.workingPartition;    if(workingpartition == null) return;    else if (firstWorkingPartition == null) firstWorkingPartition= workingpartition;    else if (workingpartition != firstWorkingPartition) return; // Not Computing Alphas When Working Partition Is Changed    float olds[] = new float[valCount];    if(absValue == 0 ) {      if(MRL.MRLConstants.PATH_DEBUG_MODE) System.out.println("Error For Path : " + getID() + " , In Time : " + world.time() + " , ABS Value = 0 ");      return ;    }    if(! world.workingPartition.isScoreValid) return;    for (int i = 0; i < valCount; i++) {      olds[i] = ai[i];      ai[i] += ( (float) world.workingPartition.getScoreDelta(world.time()) * mulCoef) *          (vali[i] / absValue) * ( (float) 1 - gamma);      if(ai[i] < 0 ) ai[i] = 0; // Ke Zarib Manfi Nashe ??      if(MRL.MRLConstants.PATH_DEBUG_MODE) System.out.println("Old Alpha : " + olds[i] + " , New Alpha : " + ai[i]);    }  }  private float repBlockDif =0;  private int connectedPaths = 0;  private int visibleHums = 0;  private float tvi;  private int m_nearestRefDist;  private float absValue;  private int m_time = -1;  public void updateValue() {    m_time = world.time();    if(MRL.MRLConstants.PATH_DEBUG_MODE){      if (firstTime) {        firstTime = false;        firstID = world.self.id;        initStatVals();        setNormFactors();//        System.out.println(getNormFactors());//        System.out.println(getAlphas());        printNormFactors(m_time);      }    }    if(m_firstTime){        setNormFactors();      m_firstTime=false;      m_nearestRefDist = getMinDist(world.refuges);//      if(m_nearestRefDist < 10 ) m_nearestRefDist = 10;      printAlphas(world.time());      connectedPaths = getConnectedPaths().size();    }//    if(world.time()>6) updateAlphas();    resetVals();    Collection col;    tvi = getDistToSelf();    tvi = normTvi(tvi);    vi[DTOSELF] = tvi;//    col = world.refuges;//    vi[DTOREF] = getMinDist(col);    tvi = m_nearestRefDist;    tvi = normTvi(tvi);    vi[DTOREF] = tvi;    col = world.burningBuildings;    tvi = getDistToFire(col); // Distance Of Center Of Path To Entrance Of The Nearest Burning Building To The Path    tvi = normTvi(tvi);    vi[DTOFIRE] = tvi;//    vi[ATCOUNT] = getLockedAgentsCount(world.lockedATIP);    vi[ATCOUNT] =getLockedAgentsCnt(2);//    vi[FBCOUNT] = getLockedAgentsCount(world.lockedFBIP);    vi[FBCOUNT] =getLockedAgentsCnt(3);//    vi[PFCOUNT] = getLockedAgentsCount(world.lockedPFIP);    vi[PFCOUNT] =getLockedAgentsCnt(4);//    vi[CIVCOUNT] = getLockedAgentsCount(world.needRescueCivsIP) + col.size();    vi[CIVCOUNT]=getLockedAgentsCnt(5);//    vi[BLOCKREP] = reportedBlockadesIS;    repBlockDif = prevCycReportedBlockCoef * repBlockDif + curCycReportedBlockCoef *  (float)reportedBlockadesIS ;//    vi[BLOCKREP] = curCycReportedBlockCoef*(float) reportedBlockadesIS + prevCycReportedBlockCoef * (float)reportedBlockades;    vi[BLOCKREP] = repBlockDif;    vi[CONPATH]= connectedPaths;    if(isEdgePath){        tvi = Util.distance(position(),world.getCenter());        tvi = normTvi(tvi);        vi[EDGEPATH] = tvi;    }    /**     * todo : Check This , Visible Humanoids .     *     *///    visibleHums = Utils.getConditionCount(world.updatedmovingobjects,AGENT_C.and(IS_IN_PATH_C)) -1 ;//    if(visibleHums > 0 )//      vi[BLOCKREP] += visHumansCoef * visibleHums;    for (int i = 0; i < valCount; i++) {      vali[i] = ai[i] *  vi[i]  / nViFact[i] ;      absValue += Math.abs(vali[i]);      value += vali[i];    }    checkPathIsOpen();    if (MRL.MRLConstants.PATH_DEBUG_DEEP_MODE) {      compVals(m_time);      compAvgMax();      if (world.self.id == firstID) {        if (MRL.MRLConstants.PATH_DEBUG_MODE) {          //        System.out.println(getVis());          //        System.out.println("VALUE : " + value);        }      }    }  }  private float normTvi(float tvi){      if(tvi < 1000) tvi = 1000f;      tvi /= 1000f; // Changed To Meter .      tvi = 1/tvi + 0.001f;      return tvi;  }  private int time(){    return world.time();  }  public int getMinDist(Collection targets){    if(Utils.getConditionCount(targets,IS_CONTAINING_C) > 0) return 0;    int res = Integer.MAX_VALUE , dist;    Road road;    RealObject ro;    for(Iterator it = this.iterator();it.hasNext();){      road = (Road) it.next();      for(Iterator it2 = targets.iterator();it2.hasNext();){        ro = (RealObject) it2.next();        dist = road.distance(ro)        ;        if(dist < res ) res = dist;      }    }    return res;  }  public boolean checkPathIsOpen(){ // Returns true If Path IS Open      if (hasBlocks && getPathIsOpen()) {        hasBlocks = false;      }    return ! hasBlocks;  }  public void clearReportedBlockadesInCycle(){    reportedBlockadesIS =0;  }  // NOW Uses The COORDINATIVE Distance  private int getDistToSelf(){//    if(world.IS_HEAVY){//      return world.self.distance(position());//    }//    else{//      MotionlessObject mo = world.self.motionlessPosition();//      Route rt = Router.get(mo, Collections.singleton(position()),//                            HumanoidAgent.RELIABILITY_COST_FUNCTION);//      return rt.getLength();//    }      return getMinDist(Collections.singleton(world.self.motionlessPosition()));  }  private int getDistToFire(Collection fires) {//    if (world.IS_HEAVY) {//      Node node;//      int bM = Integer.MAX_VALUE, dist;//      for (Iterator it = fires.iterator(); it.hasNext(); ) {//        node = (Node) ((Building) it.next()).entrance();//        dist = Util.distance(position(), node);//        if (dist < bM) {//          bM = dist;//        }//      }//      return bM;//    }//    else return getMinDist(world.burningBuildings);      return getMinDist(fires);  }  /*  private int getLockedAgentsCount(Collection lockedAgentCol){    Humanoid hum;    int res = 0;    for(Iterator it = lockedAgentCol.iterator();it.hasNext();){      hum = (Humanoid) it.next();      if(world.getContainingPath(hum.motionlessPosition()) == this) res++;    }    return res;  }*/  public int getMinDistUsingPathPosition(Collection col) {    int bestmatch = Integer.MAX_VALUE, dist;    for (Iterator it = col.iterator(); it.hasNext(); ) {     Object obj =  it.next();     if(obj instanceof Path){       dist = Util.distance(position(),((Path)obj).position());     }     else {      dist = Util.distance(position(),(RealObject)obj);     }      if (dist < bestmatch) {        bestmatch = dist;      }    }    return bestmatch;  }  public int getLockedAgentsCnt(int type) { // 2 : AT , 3 : FB , 4 : PF , 5 : CIV    int lBBC=0 , bA=0;    switch (type) {      case 2:        bA = Utils.getConditionCount(world.ambulanceTeams, NEED_RESCUE_C.and(IS_IN_PATH_C));//        lBBC = Utils.getConditionCount(world.getLockedBBAgentsIPPos(world.ambulanceTeams) , IS_CONTAINING_C);          lBBC = Utils.getConditionCount(world.blockData.getAgentsLockedInPath(this),AMBULANCE_TEAM_C);        break;      case 3:        bA = Utils.getConditionCount(world.fireBrigades,NEED_RESCUE_C.and(IS_IN_PATH_C));//        lBBC = Utils.getConditionCount(world.getLockedBBAgentsIPPos(world.fireBrigades),IS_CONTAINING_C);        lBBC = Utils.getConditionCount(world.blockData.getAgentsLockedInPath(this),FIRE_BRIGADE_C);        break;      case 4:        bA = Utils.getConditionCount(world.policeForces, NEED_RESCUE_C.and(IS_IN_PATH_C));        break;      case 5 ://        int possPosCnt = Utils.getConditionCount(world.m_HearedCivPossPosMap.values(),IS_CONTAINING_C);        int possPosCnt = world.hearData.getPossibleNearCiviliansCount(this);        int needRescCnt = Utils.getConditionCount(world.needRescueCivs,IS_IN_PATH_C);        int needLoadCnt =Utils.getConditionCount(world.needLoadCivs,IS_IN_PATH_C);//        int lbbCivs = Utils.getConditionCount(world.m_lockedCivPos_Map.values(),IS_CONTAINING_C);        int res = possPosCnt + needRescCnt + needLoadCnt ; // + lbbCivs//        if(res > 6 ) System.out.println("possPosCnt : " + possPosCnt + " , needRescCnt  : " + needRescCnt + " , lbbCivs : " + lbbCivs);        return res;    }    return lBBC+ bA;  }  public Collection getVisibleHumanoids() {//    int res = 0;//    Collection humsPos = IS_CONTAINING_C.extract() ROAD_C.extract(POSITION_PRP.collect(MO_POS_SET_C.//        extract(world.humanoids)));    Collection hums = VISIBLE_C.and(IS_IN_PATH_C).extract(world.updatedmovingobjects);    return hums;  }  public boolean isPosLockedByBlockade(Road pos){    int fBI = -1, posI = this.indexOf(pos);      if (posI == -1) {        return false;      }      Road cRoad;      for (int i = 0; i < this.size(); i++) {        cRoad = (Road)this.get(i);        if (NOT_PASSABLE_C.eval(cRoad)) {          if (fBI == -1) {            if (i > posI) { // Or >= ? There's At Least One Blockade After Pos Index              if ( ( (Road)this.get(0)).getConnectedRoads().size() > 1)return false;              else return true; // Locked In A Path Where There's Only One Way Out n It's Blocked            }            else {              fBI = i;            }          }          else if (i > posI) { // There's Already A Blockade Before This Index And Before Pos Index            return true;          }          else if (i == posI) { // Some Other Road Before This Road Is Blocked And Current Road Is Blocked            // Fekr Konam Bayad True Bargardoonim            return true;          }        }      }      // Theres At Least One Blockade Before Or At Pos Index      if ( ( (Road)this.get(this.size() - 1)).getConnectedRoads().size() > 1) {        return false;      }      else {        return true;      }    }    /*      public boolean isLockedByBlockade(MotionlessObject pos){        if (passableLines() > 0)return false;        if (pos instanceof Road) {          return isPosLockedByBlockade( (Road) pos);        }        else {     if (pos == this.getFirstNode() || pos == this.getLastNode())return false;          Node node;     if (pos instanceof Building) node = (Node) ( (Building) pos).entrance();          else node = (Node) pos;          Iterator it = node.getConnectedRoads().iterator();          Road troad = (Road) it.next(), troad2 = (Road) it.next();          return (isPosLockedByBlockade(troad) && isPosLockedByBlockade(troad2));        }      }     */    public boolean isLockedByBlockade(Node op) {      if(op == getFirstNode() || op == getLastNode())        return isEndNodeLockedInBlockades(op);      Collection cr = op.getConnectedRoads();      if(cr.size() < 2) throw new Error ("Error In Connected Roads : " + cr + "\nHEAD : " + getFirstNode() + " , TAIL : "+ getLastNode() + " , OP : " + op + "\n Path : " + this);      Iterator it = cr.iterator(); // In The Middle Of The Path , 2 Roads.      Road troad = (Road) it.next(), troad2 = (Road) it.next();      if(troad == getFirstRoad() || troad == getLastRoad()){      }//      return (isPosLockedByBlockade(troad) && isPosLockedByBlockade(troad2));//      return troad.passableLines() == 0 && troad2.passableLines() ==0;      Collection targets = new ArrayList(getEdges());      if(isPathWithOneJunction()){        if(getFirstNode().getConnectedRoads().size() == 1 )          targets.remove(getFirstNode());        else targets.remove(getLastNode());      }      Route rt = Router.get(op,targets,HumanoidAgent.RELIABILITY_COST_FUNCTION);      return rt.cost >= IN_BLOCKS;    }    protected boolean isEndNodeLockedInBlockades(Node node) {      if(node != getLastNode() && node != getFirstNode())        throw new Error ("This Must Be END Points Of Path");      Path path;      Road road;      Collection col = node.getConnectedRoads();      if(col.size() == 1 ) {        return NOT_PASSABLE_C.eval(this);      }      for (Iterator it = col.iterator(); it.hasNext(); ) {        road = (Road) it.next();        path = world.getContainingPath(road);        if (PASSABLE_C.eval(path) && ! path.isPathWithOneJunction())return false;      }      return true;    }  private String getVis() {    String str = world.self + " , Time : " + world.time();    for (int i = 0; i < valCount; i++) {      str +=          (" - VI[" + i + "] = " + vi[i]);    }    return str;  }  protected String getNormFactors() {    String str = "Normalization Factors : \nDistanceToRefugee (0) : " +        nViFact[DTOREF] + "\nDistanceToFire (1): " + nViFact[DTOFIRE] +        "\nLockedAmbulanceTeam (2): " +        nViFact[ATCOUNT] + "\nLockedFireBridage (3): " +        nViFact[FBCOUNT] + "\nLockedPoliceForce (4): " + nViFact[PFCOUNT] +        "\nLockedCivilians (5): " + nViFact[CIVCOUNT] +        "\nDistanceToSelf (6): " + nViFact[DTOSELF] +        "\nBlocksReported (7) : " + nViFact[BLOCKREP] +            "\nConnectedPaths (8) : " + nViFact[CONPATH] +            "\nEdgePath (9) : " + nViFact[EDGEPATH] +        "\nEnd Of Normalization Factors";    return str;  }  protected String getAlphas() {    String str = "Alpha Factors : \nDistanceToRefugee : " + ai[DTOREF] +        "\nDistanceToFire : " + ai[DTOFIRE] +        "\nDistanceToSelf : " + ai[DTOSELF] + "\nLockedAmbulanceTeam : " +        ai[ATCOUNT] + "\nLockedFireBridage : " +        ai[FBCOUNT] + "\nLockedPoliceForce : " + ai[PFCOUNT] +        "\nLockedCivilians : " + ai[CIVCOUNT] + "\nBlocksReported : " + ai[BLOCKREP] +            "\nConnectedPaths : " + ai[CONPATH] + "\nEdgePath : " + ai[EDGEPATH]+            "\nEnd Of Alpha Factors";    return str;  }  private int prTime = 0;  public void addReportedBICTRB(){    if(world.time() <= prTime) return;    prTime = world.time();    reportedBlockades += reportedBlockadesIS;  }  private static int m_prTime = 0;  private void compVals(int time) {//    printAlphas(time);    if (time <= m_prTime)return;    m_prTime = time;    switch (time) {      case 2 - 5:      case 10:      case 20:      case 25:      case 50:      case 100:      case 150:      case 200:      case 250:        printAvgMax(world.self.id, time);        printPathValues(time);      default:    }  }  private boolean getObjectIsStuckInPath(MotionlessObject pos) { // WE NEED THIS    Collection roads;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -