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

📄 path.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    if (pos instanceof Road) {      roads = ( (Road) pos).getConnectedRoads();    }    else if (pos instanceof Node) {    }    return false;  }  private int getBlocksCount() {    int blocksInPath = 0;    Road road;    for (Iterator it = this.iterator(); it.hasNext(); ) {      road = (Road) it.next();      blocksInPath += road.block();    }    return getBlocksCount();  }  private boolean getPathIsOpen() {    for(Iterator it = this.iterator();it.hasNext();){      if(SHOULD_CHECK_ROAD_CND.eval(it.next())) return false;    }    return true;    /*    Collection col = SHOULD_CHECK_ROAD_CND.extract(this);    boolean res = col.size() == 0;    col = null;    return res;    /*        boolean res = true;        Road road;        for (Iterator it = this.iterator(); it.hasNext(); ) {          road = (Road) it.next();          if (testing) {     System.out.println("Path : " + hashCode() + " , Road : " + road.id +                               " , POS : " + road.x() + " , " + road.y());          }          if (!road.hasBeenSeen() ||              (road.hasBeenSeen() && road.passableLines() == 0)) {            if (this.hashCode() == pathtoTest) {     System.out.println("Path : " + hashCode() + " POS : " + position().x() +                                 " , " + position().y() + " , Total Roads : " +                                 this.size() + " , Road : " + road.id + " , " +                                 (road.hasBeenSeen() ? " HAS BEEN SEEN " :     " HAS NOT BEEN SEEN ") + " , Passable Lines : " +                                 road.passableLines());            }            res = false;            break;          }        }        return res;     */  }  int m_minRoadLines = -1;  public int minRoadLines(){    if(m_minRoadLines == -1){      Road road;      int res=0;      for (Iterator it = this.iterator(); it.hasNext(); ) {        road = (Road) it.next();        res = Util.min(res, road.minLines());      }      m_minRoadLines = res;    }    return m_minRoadLines;  }  public int passableLines() {    Road road;    int res = Integer.MAX_VALUE;    for (Iterator it = this.iterator(); it.hasNext(); ) {      road = (Road) it.next();      res = Util.min(res, road.passableLines());      if (res == 0)break;    }    return res;  }  public int passableLinesToFirstNode() {    return passableLinesFromStart(getLastNode());  }    public int passableLinesToLastNode() {        return passableLinesFromStart(getFirstNode());      }  public int passableLinesFromStart(Node start){    MotionlessObject mo;    int res = Integer.MAX_VALUE;    Node prevNode = start;    Road road;    for(Route rt = goToEndFromStart(start);rt != null ; rt = rt.previous()){        mo = rt.end;        if(mo instanceof Road){            road = (Road) mo;            res = Util.min(res,road.passableLinesFrom(prevNode));        }        else {            prevNode = (Node)mo;        }        if(res == 0) break;    }    return res;  }  private boolean junction_set =false;  private boolean isPathWithOneJunction = false;  public boolean isPathWithOneJunction(){    if(!junction_set){        isPathWithOneJunction = (getFirstNode().getConnectedRoads().size() == 1 || getLastNode().getConnectedRoads().size() == 1);    }    return isPathWithOneJunction;  }  public int getTotalReportedBlockades(){    return reportedBlockades;  }  public int getReportedBlockadesInCycle(){    return reportedBlockadesIS;  }  private static Road getNearestRoad(Collection col, MotionlessObject mo) {    Road res = null, road;    int bestmatch = Integer.MAX_VALUE, dist;    for (Iterator it = col.iterator(); it.hasNext(); ) {      road = (Road) it.next();      dist = Util.distance(road, mo);      if (dist < bestmatch) {        bestmatch = dist;        res = road;      }    }    return res;  }  private static Road getFarestRoad(Collection col, MotionlessObject mo) {    Road res = null, road;    int bestmatch = -1, dist;    for (Iterator it = col.iterator(); it.hasNext(); ) {      road = (Road) it.next();      //dist = Util.distance(road, mo);      Route rt = Router.get(mo,Collections.singleton(road),HumanoidAgent.CLEARING_COST_FUNCTION);      dist = rt.getLength();      if (dist > bestmatch) {        bestmatch = dist;        res = road;      }    }    return res;  }  public Road getFarestBlockedRoad(MotionlessObject mo) {    Collection col = NOT_PASSABLE_C.extract(this);    return getFarestRoad(col, mo);  }  public Road getFarestUncheckedRoad(MotionlessObject mo) {  Collection col = HAS_NOT_BEEN_SEEN_CND.extract(this);  return getFarestRoad(col, mo);}  public Road getNearestBlockedRoad(MotionlessObject mo) {    Collection col = NOT_PASSABLE_C.extract(this);    return getNearestRoad(col, mo);  }  public Road getNearestUncheckedRoad(MotionlessObject mo) {    Collection col = HAS_NOT_BEEN_SEEN_CND.extract(this);    return getNearestRoad(col, mo);  }  public Road getNearestUncheckedOrBlockedRoad(MotionlessObject mo) {    Collection col = HAS_NOT_BEEN_SEEN_CND.or(NOT_PASSABLE_C).extract(this);    return getNearestRoad(col, mo);  }  public Road getFarestUncheckedOrBlockedRoad(MotionlessObject mo) {    Collection col = HAS_NOT_BEEN_SEEN_CND.or(NOT_PASSABLE_C).extract(this);    return getFarestRoad(col, mo);  }  public Road getNearestRoad(MotionlessObject mo) {    return getNearestRoad(this, mo);  }  public int[] toArrayofId() {    int[] arrofId = new int[this.size()];    int count = 0;    for (Iterator it = this.iterator(); it.hasNext(); ) {      arrofId[count++] = ( (Road) it.next()).id;    }    return arrofId;  }  private Route m_rfhtt = null;  public Route getRouteFromHeadNodeToTailNode() {    if (m_rfhtt == null) {      m_rfhtt = getCompleteRoute(getFirstNode());    }    return m_rfhtt;  }  private Route m_rftth = null;  public Route getRouteFromTailNodeToHeadNode() {    if (m_rftth == null) {      m_rftth = getCompleteRoute(getLastNode());    }    return m_rftth;  }  public Route goToEndFromStart(Node start) { // Start Should Be HEAD Or Tail Of The Map    if (start == getFirstNode())return getRouteFromHeadNodeToTailNode();    else if (start == getLastNode())return getRouteFromTailNodeToHeadNode();    throw new Error("Error Start Should Be Head Or Tail Of The Path");  }  private Route getCompleteRoute(Node start) {    Road road = null;    Node hN, tN, next, end;    Collection col= new HashSet();    Route res = new Route(start);    end = (start == getFirstNode() ? getLastNode() : getFirstNode());    next = start;    while (next != end) {      col.clear();      col.addAll(IS_CONTAINING_C.extract(next.getConnectedRoads()));      col.remove(road);      if (col.isEmpty()) {        break;      }      road = (Road) col.iterator().next();//      if (next != start)      res = res.expandedRoute(road, HumanoidAgent.CLEARING_COST_FUNCTION);      hN = (Node) road.head();      tN = (Node) road.tail();      next = next == hN ? tN : hN;      res = res.expandedRoute(next,                              HumanoidAgent.                              CLEARING_COST_FUNCTION);    }    return res;  }  public Route getRouteToHeadFromNode(Node node) {    if (!IsContaining(node))throw new Error("Error , Object Not In Path");    return getRouteFromNode(node,                            getRouteFromTailNodeToHeadNode());  }  public Route getRouteToTailFromNode(Node node) {    if (!IsContaining(node))throw new Error("Error , Object Not In Path");    return getRouteFromNode(node,                            getRouteFromHeadNodeToTailNode());  }  public Node getRespondingNode(MotionlessObject mo,MotionlessObject nearTo) {    Node start = null;    if (mo instanceof Road) {      Road road = (Road) mo;      start = (Util.distance(road.head(), nearTo) < Util.distance(road.tail(), nearTo) ?               (Node) road.head() : (Node) road.tail());    }    else if (mo instanceof Node) {      start = (Node) mo;    }    else if (mo instanceof Building) {      start = (Node) ( (Building) mo).entrance();    }    else {      throw new Error("Unknown Motionless Object : " + mo);    }    return start;  }  private Route getRouteFromNode(Node start, Route res) {    Route result = new Route(start), tmp = res;    int[] tArr = tmp.toIDs();    int sIndex = -1, nIndex = start.id;    for (int i = 0; i < tArr.length; i++) {      if (tArr[i] == nIndex) {        sIndex = i;        break;      }    }    /*        if(sIndex == -1 ){          System.out.println("Error , Exiting , INFO : ");          System.out.println("Orig Route : " + res);          System.out.println("Path : " + this);          System.out.println("Start : " + start);          throw new Error("Couldn't Find Index For Route");        }     */    if (sIndex == -1 || sIndex == tArr.length - 1) {      return getCompleteRoute(start);    }    sIndex++;    MotionlessObject mo;    for (int i = sIndex; i < tArr.length; i++) {      mo = (MotionlessObject) world.get(tArr[i]);      result = result.expandedRoute(mo,                                    HumanoidAgent.CLEARING_COST_FUNCTION);    }    if (!result.validate())throw new Error("ERROR IN RESULT ROUTE !!!! AC");    return result;  }  public Road getFirstRoadToCheck(MotionlessObject pos) {    Collection unchecked = HAS_NOT_BEEN_SEEN_CND.or(NOT_PASSABLE_C).extract(this);//    Road farestRoad = getFarestRoad(unchecked, pos);    Road nearestRoad = getNearestRoad(unchecked, pos);    Road res;    Node node = (Util.distance(nearestRoad, m_firstNode) >                 Util.distance(nearestRoad, m_lastNode) ? m_lastNode :                 m_firstNode);    res = getNearestRoad(unchecked, node);    /*            int dToF = Util.distance(farestRoad, pos),                dToN = Util.distance(nearestRoad, pos),                dNToF = Util.distance(nearestRoad, farestRoad);          if (dNToF > dToF) { // Dar DO Tarafan        }        else res = nearestRoad; // Dar YE Tarafan     */    return res;  }  private int m_lastTimeComputedTimeAgentHaveBeenInPath = -1;  private int m_durAgentHaveBeenInPath = 0;  public int getTimeAgentHaveBeenInPath(){ // Ba Taghribe 1 Cycle Khata .      int time = time();      if(time == m_lastTimeComputedTimeAgentHaveBeenInPath)        return m_durAgentHaveBeenInPath;      m_lastTimeComputedTimeAgentHaveBeenInPath = time;      MovingObject mo = (MovingObject) world.self;      if(!(IsContaining(mo.motionlessPosition()))) return -1;      Node node;      int ph[] , dur = 0;      boolean wereInPath = false;      for(int i = time -1 ; i > TIME_STARTING_ACTION ; i--){          ph = mo.getPositionHistory(i);          if(ph.length == 0){            dur++;            continue;          }          wereInPath = true;          node = (Node) world.get(ph[ph.length-1]);          if(!IsContaining(node)){            for(int j = i+1 ; j < time  ; j++){                ph = mo.getPositionHistory(j);                if(ph.length==0)                    dur--;                else break;            }            break;          }          dur ++;      }      m_durAgentHaveBeenInPath =dur;      return dur;  }  public String toString() {    String str = "Path , ID : " + getID()+ " , Hash Code : " + hashCode() + ", Road Count : " + this.size();    if(MRL.MRLConstants.PATH_DEBUG_MODE){        Road road;        Node hn, tn;        for (Iterator it = this.iterator(); it.hasNext(); ) {          road = (Road) it.next();          hn = (Node) road.head();          tn = (Node) road.tail();          str += " , " + road + "/H:" + hn + "/T:" + tn;        }    }    return str;  }  //// VALUES And Print  private void printPathValues(int time) {    String str = "Path Values  : " + "\n" +        getVis() + "\nEnd Of Path Values " +"\n";    printInFile(Utils.pathfileName, str);  }  private void printInFile(String fname , String str){    if(! MRL.MRLConstants.PATH_WRITE_MODE) return;    Utils.printInFile(fname,str);  }  private static int counter = 0;  private void compAvgMax() {    for (int i = 0; i < valCount; i++) {      avgvis[i] += vi[i];      avgvals[i] += vali[i];      minvis[i] = min(minvis[i], vi[i]);      maxvis[i] = max(maxvis[i], vi[i]);      minvals[i] = min(minvals[i], vali[i]);      maxvals[i] = max(maxvals[i], vali[i]);    }    counter++;  }  private void printAvgMax(int ID, int time) {    String res =        "------------------  ID : " + ID + " , TIME : " + time + "\n";    for (int i = 0; i < valCount; i++) {      res += "Min V[" + i + "] : " + minvis[i] + "\n" +          "Max V[" + i + "] : " + maxvis[i] + "\n" +          ("Avg V[" + i + "] : " + avgvis[i] / (float) counter + "\n") +          ("Min Val[" + i + "] : " + minvals[i] + "\n") +          ("Max Val[" + i + "] : " + maxvals[i] + "\n") +          ("Avg Val[" + i + "] : " + avgvals[i] / (float) counter + "\n");    }    res += "Total Computations : " + counter+ "\n";    res += ("------------------  END OF ID : " + ID + " , TIME : " + time +            "\n");    printInFile(Utils.vivalfileName, res);  }  private void printNormFactors(int time) {    String str = "Normalization Factors For Time : " + time + "\n" +        getNormFactors() + "\nEnd Of Normalization Factors For Time : " + time+"\n";    printInFile(Utils.vivalfileName, str);  }  private void printAlphas(int time) {    if(! MRL.MRLConstants.PATH_WRITE_MODE) return;    String str = "Alpha Values For : " + world.self+ " For Time : " + time + "\n" + getAlphas() +        "\nEnd Of Alpha Values For : " + world.self +" For Time : " + time+"\n";    printInFile(Utils.alphafileName, str);  }  public static float max(float x, float y) {    return x >= y ? x : y;  }  public static float min(float x, float y) {    return x <= y ? x : y;  }//  private float[] vis = new float[valCount];  private static float[] avgvis = new float[valCount];  private static float[] minvis = new float[valCount];  private static float[] maxvis = new float[valCount];  private static float[] minvals = new float[valCount];  private static float[] maxvals = new float[valCount];  private static float[] avgvals = new float[valCount];  private int m_totalFieryBuildings = 0;  private int m_lastTotalFieryComputed = 0;  public int getTotalFieryBuildings(){      if(time() != m_lastTotalFieryComputed){          m_lastTotalFieryComputed = time();          m_totalFieryBuildings = 0;          Building bldg;          for(Iterator it = this.getConnectedBuildings().iterator();it.hasNext();){              bldg = (Building) it.next();              if(bldg.isBurning()) m_totalFieryBuildings++;          }      }      return m_totalFieryBuildings;  }  private int m_valFieryBuildings = 0;  private int m_lastValFieryComputed = 0;  public int getValForFieryComparator(){      if(time() != m_lastValFieryComputed){          m_lastValFieryComputed = time();          m_valFieryBuildings = Integer.MAX_VALUE;          Building bldg;          for(Iterator it = this.getConnectedBuildings().iterator();it.hasNext();){              bldg = (Building) it.next();              if(!bldg.isBurning()) continue;              m_valFieryBuildings += bldg.fieryness() * bldg.buildingAreaTotal();          }      }      return m_valFieryBuildings;  }}

⌨️ 快捷键说明

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