Пример #1
0
  private ArrayList<Building> getProbabilisticBuilding() {

    ArrayList<Building> probabilisticBuildings = new ArrayList<Building>();
    boolean[] checked = new boolean[agent.model().buildings().size()];

    for (Building b : agent.model().buildings()) {
      b.setSpecialForFire(0, "reset");
      boolean fireProbability = hasFireProbability(b);

      if (fireProbability) {
        log.info("Fire Prob  " + b);
        if (!checked[b.getBuildingIndex()]) {
          b.setSpecialForFire(0, "reset");
          probabilisticBuildings.add(b);
          checked[b.getBuildingIndex()] = true;
          log.info("\t\t aded " + b);
        }

        for (Building neigh : b.realNeighbors_Building()) {
          if (!checked[neigh.getBuildingIndex()]) { // && hasFireProbability(neigh)
            neigh.setSpecialForFire(0, "reset");
            probabilisticBuildings.add(neigh);
            checked[neigh.getBuildingIndex()] = true;
            log.info("\t\t aded " + neigh);
          }
        }
      }
    }

    return probabilisticBuildings;
  }
Пример #2
0
  private void chooseSearchForCivilianBuildings() {
    PriorityQueue<Building> buildings =
        new PriorityQueue<Building>(
            100,
            new Comparator<Building>() {

              @Override
              public int compare(Building o1, Building o2) {
                if (!o1.isSearchedForCivilian() && !o2.isSearchedForCivilian()) return 0;
                if (!o1.isSearchedForCivilian()) return 1;
                if (!o2.isSearchedForCivilian()) return -1;
                if (searchedForCivilianBuildings.contains(o1)
                    != searchedForCivilianBuildings.contains(o2))
                  return searchedForCivilianBuildings.contains(o1) ? 1 : -1;
                //				ClusterData myCluster = SOSAgent.currentAgent().getMyClusterData();
                //
                //	if(myCluster.getBuildings().contains(o1)!=myCluster.getBuildings().contains(o2))
                //					return myCluster.getBuildings().contains(o1)?1:-1;
                //				if(o1.getLastSearchedForCivilianTime()>o2.getLastSearchedForCivilianTime())
                //					return -1;
                //				if(o1.getLastSearchedForCivilianTime()<o2.getLastSearchedForCivilianTime())
                //					return 1;
                double distanceTo1 =
                    SOSAgent.currentAgent().me().getPositionPoint().distance(o1.getPositionPoint());
                double distanceTo2 =
                    SOSAgent.currentAgent().me().getPositionPoint().distance(o2.getPositionPoint());
                if (distanceTo1 > distanceTo2) return 1;
                if (distanceTo1 < distanceTo2) return -1;
                return 0;
              }
            });
    int priority = 10;
    int count = 0;
    for (Building b : model().buildings()) {
      if (b.isEitherFieryOrBurnt()) continue;
      if (!b.isSearchedForCivilian()) continue;
      buildings.add(b);
    }
    for (Building b : buildings) {
      count++;
      if (priority > 0 && count % 10 == 0) priority--;

      searchedForCivilianBuildings.add(b);
      MessageBlock messageBlock = new MessageBlock(HEADER_NO_COMM_SEARCHED_FOR_CIVILIAN);
      messageBlock.addData(DATA_BUILDING_INDEX, b.getBuildingIndex());
      messageBlock.addData(DATA_TIME, b.getLastSearchedForCivilianTime());

      sayMessages.add(messageBlock);
    }
  }
Пример #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);
          }
        }
      }
    }
  }
Пример #4
0
 String getBuildValue(Building b, Building b2) {
   for (Entry<Short, Float> buildValue : b.neighbors_BuildValue().entrySet()) {
     if (buildValue.getKey() == b2.getBuildingIndex()) return buildValue.getValue() + "";
   }
   return "-";
 }