Пример #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
  private void addProbScore(ArrayList<Building> region, Building center) {
    for (Building neigh : center.realNeighbors_Building()) {
      neigh.setSpecialForFire(neigh.getValuSpecialForFire() - 100000, " -100  " + center);
      //////////////////////////////////////
      if (neigh.updatedtime() >= center.updatedtime()) {
        log.info("\t\t\t Neigh is update " + neigh);
        continue;
      }
      if (neigh.updatedtime() >= center.getTemperatureIncreasedTime()) {
        log.info(
            "\t\t\t Neigh is update after sensed temp "
                + neigh
                + "    NeighUpdTime="
                + neigh.updatedtime()
                + "\t increaseTime="
                + center.getTemperatureIncreasedTime());
        continue;
      }
      /////////////////////////////////
      if (agent.model().time() - neigh.updatedtime() < Math.min(8, agent.model().time() / 2))
        continue;

      if (center.updatedtime() < neigh.updatedtime() + 3) continue;

      if (!region.contains(neigh)) continue;

      neigh.setSpecialForFire(neigh.getValuSpecialForFire() + 100000, "Add 100 score ");

      double t = temperatureScore(center);

      t *=
          (center.getRealNeighValue(neigh) + 0.001)
              * 100d
              / ((Math.max(1, distance(center, neigh) / 1000)));
      if (center.getTemperature() < 3)
        t += center.getNeighValue(neigh) * 200 * temperatureScore(center);

      double c = 1;
      for (Building n2 : neigh.realNeighbors_Building()) {
        if (n2.getTemperature() > 0) c -= neigh.getNeighValue(n2);
        else c += neigh.getRealNeighValue(n2);
      }

      neigh.setSpecialForFire(
          neigh.getValuSpecialForFire() + (int) (Math.ceil(t * c)),
          " temp = "
              + temperatureScore(center)
              + " distance and neigh = "
              + t
              + "  c "
              + c
              + " "
              + center);

      //			if (!res.contains(neigh))
      //				res.add(neigh);

    }
  }
Пример #3
0
  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);
          }
        }
      }
    }
  }