예제 #1
0
  private ArrayList<Building> getBestProb(ArrayList<Building> region) {

    for (Building b : region) {

      if (hasFireProbability(b)) {

        addProbScore(region, b);

      } else {

        if (agent.model().time() - b.updatedtime() < Math.min(7, agent.model().time() / 2)
            && b.isTemperatureDefined()
            && b.getTemperature() == 0) {
          for (Building neigh : b.realNeighbors_Building()) {
            double t = 0;
            double c = 0;
            for (Building n2 : neigh.realNeighbors_Building()) {
              if (n2.getTemperature() > 0) c -= neigh.getRealNeighValue(n2);
              else c += neigh.getRealNeighValue(n2);
            }
            t =
                (b.getRealNeighValue(neigh) + 0.001)
                    * 100d
                    / (Math.max(1, distance(b, neigh) / 1000))
                    * 3;
            if (c > 0)
              neigh.setSpecialForFire(
                  neigh.getValuSpecialForFire() - (int) (Math.ceil(t * c)),
                  "negative center=" + b + "  t" + t + "  c" + c);
          }
        }

        if (agent.model().time() == b.updatedtime()) {
          if (b.getTemperature() == 0) {
            for (Building neigh : b.realNeighbors_Building()) {
              if (neigh.getGroundArea() > 1.7 * b.getGroundArea())
                neigh.setSpecialForFire(
                    neigh.getValuSpecialForFire() - 50,
                    "negative value update in big building=" + b + "   " + (-50));
            }
          }
        }
      }
    }

    return region;
  }
예제 #2
0
파일: No_Comm.java 프로젝트: jpollo/rcrss
  private void chooseFireMessages() {
    for (Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> fz :
        model().sosAgent().fireSiteManager.getFireSites()) {
      for (SOSRealFireZone firezone : fz.first()) {
        ArrayList<Building> outers = firezone.getOuter();
        if (outers.isEmpty()) outers = firezone.getFires();
        if (!outers.isEmpty()) {
          Building b = outers.get(0);
          MessageBlock messageBlock = new MessageBlock(HEADER_FIRE);
          messageBlock.setPriority(11);
          messageBlock.addData(DATA_BUILDING_INDEX, b.getBuildingIndex());
          messageBlock.addData(DATA_FIERYNESS, b.getFieryness());
          messageBlock.addData(DATA_HEAT, b.getTemperature() / 3);
          messageBlock.addData(DATA_TIME, b.updatedtime());
          sayMessages.add(messageBlock);
        }
      }
    }
    try {
      for (Building sensed : model().sosAgent().getVisibleEntities(Building.class)) {
        if (sensed.isTemperatureDefined() && sensed.getTemperature() == 0) {
          Building b = sensed;
          MessageBlock messageBlock = new MessageBlock(HEADER_FIRE);
          messageBlock.setPriority(11);
          messageBlock.addData(DATA_BUILDING_INDEX, b.getBuildingIndex());
          messageBlock.addData(DATA_FIERYNESS, b.getFieryness());
          messageBlock.addData(DATA_HEAT, 0);
          messageBlock.addData(DATA_TIME, b.updatedtime());
          sayMessages.add(messageBlock);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    PriorityQueue<Building> buildings =
        new PriorityQueue<Building>(
            100,
            new Comparator<Building>() {
              @Override
              public int compare(Building o1, Building o2) {
                if (o1.getFieryness() != o2.getFieryness()) {
                  if (o1.getFieryness() == 1) return -1;
                  if (o2.getFieryness() == 1) return 1;
                  if (o1.getFieryness() == 2) return -1;
                  if (o2.getFieryness() == 2) return 1;
                  if (o1.getFieryness() == 3) return -1;
                  if (o2.getFieryness() == 3) return 1;
                }
                return 0;
              }
            });
    for (Building b : agent.model().buildings()) {
      if (b.getFieryness() == 0) continue;
      buildings.add(b);
    }
    int priority = 10;
    int count = 0;
    for (Building b : buildings) {
      if (b.getFieryness() == 0) continue;

      count++;
      if (priority > 0 && count % 10 == 0) priority--;

      if (agent.model().time() - b.updatedtime() < 100) {
        MessageBlock messageBlock = new MessageBlock(HEADER_FIRE);
        messageBlock.addData(DATA_BUILDING_INDEX, b.getBuildingIndex());
        messageBlock.addData(DATA_FIERYNESS, b.getFieryness());
        messageBlock.addData(DATA_HEAT, b.getTemperature() / 3);
        messageBlock.addData(DATA_TIME, b.updatedtime());

        CommunicationlessSearch<?> nocommSearch =
            b.model().sosAgent().newSearch.strategyChooser.noCommunication;
        if (nocommSearch.getCenteralMan() != null
            && nocommSearch.getCenteralMan().equals(b.model().me())) {
          sayMessages.add(messageBlock);
        } else {
          if (b.getSOSEstimateFireSite() != null && b.getSOSEstimateFireSite().shouldBeReported()) {
            sayMessages.add(messageBlock);
          } else if (agent.model().time() - b.updatedtime() < 30) {
            sayMessages.add(messageBlock);
          }
        }
      }
    }
  }