예제 #1
0
  /**
   * create new fire zones by buildings that don't belong to any existence fire zones
   *
   * @param time
   */
  private void createNewZones(int time) {
    for (Iterator<Building> it = model.fieryBuildings().iterator(); it.hasNext(); ) {
      Building b = it.next();

      if (b.getSOSEstimateFireSite() == null) {
        SOSEstimatedFireZone estimatefz = new SOSEstimatedFireZone(lastAssignedIndex, this);
        lastAssignedIndex++;
        log.info("New Estimate Fire Zone Created  " + estimatefz + "\t" + b);
        getFireSites()
            .add(
                new Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>(
                    new ArrayList<SOSRealFireZone>(), estimatefz));
        updateNewSite(b, estimatefz);
        estimatefz.update(time);
      }

      if (b.getSOSRealFireSite() == null) {
        SOSRealFireZone realfz = new SOSRealFireZone(lastAssignedIndex, this);
        lastAssignedIndex++;
        log.info("New Real Fire Zone Created  " + realfz + "\t" + b);
        getFireZonePair(b.getSOSEstimateFireSite()).first().add(realfz);
        updateNewSite(b, realfz);
        realfz.update(time);
      }
    }
  }
예제 #2
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;
  }
예제 #3
0
  /**
   * merge real fire zones
   *
   * @param targets
   * @param mergeList
   */
  private void mergeRealFireZones(
      Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> target,
      ArrayList<SOSAbstractFireZone> mergeList) {
    if (target == null) return;
    ArrayList<SOSRealFireZone> realZones = target.first();

    getFireSites().remove(target);

    SOSRealFireZone newRealFireSite = new SOSRealFireZone(lastAssignedIndex++, this);
    SOSRealFireZone real;

    for (SOSAbstractFireZone fz : mergeList) {
      real = (SOSRealFireZone) fz;
      realZones.remove(real);
      for (Building b : real.getAllBuildings()) {
        if (!b.getSOSRealFireSite().equals(newRealFireSite)) {
          b.setSOSRealFireSite(newRealFireSite);
          newRealFireSite.addFieryBuilding(b);
          newRealFireSite.updateXY(b, 1);
        }
      }
      real.update(model.time());
    }

    realZones.add(newRealFireSite);
    getFireSites()
        .add(
            new Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>(realZones, target.second()));
  }
예제 #4
0
  public ArrayList<Building> getProbabilisticFieryBuilding() {
    if (agent.model().time() == time) return res;
    time = agent.model().time();
    res.clear();
    resCluster.clear();
    log.info("new fire probability computer");

    ArrayList<Building> probabilisticBuilding = getProbabilisticBuilding();
    log.info("Probabilistic buildings :::> " + probabilisticBuilding);

    ArrayList<ArrayList<Building>> regions = getRegions(probabilisticBuilding);

    removeCheckedBuildings(regions);

    int index = 0;

    for (ArrayList<Building> region : regions) {
      HashSet<Building> x = new HashSet<Building>();
      for (Building b : getBestProb(region))
        if (b.getValuSpecialForFire() > 0) {
          res.add(b);
          x.add(b);
        }
      if (x.size() > 0) {
        ClusterData cd = new ClusterData(x, index++);
        resCluster.add(cd);
      }
    }

    log.info("result ::> " + res);

    return res;
  }
예제 #5
0
 private void checkEstimator(SOSEstimatedFireZone second) {
   if (second.isEstimating()) return;
   for (Building b : second.getAllBuildings()) {
     if (b.isBurning()) {
       second.setEstimating(true);
       return;
     }
   }
 }
예제 #6
0
 @Override
 protected void paint(Building entity, Graphics2D g, ScreenTransform transform) {
   Shape shape;
   g.setColor(Color.yellow);
   for (Building b : entity.neighbors_Building()) {
     shape = NamayangarUtils.transformShape(b, transform);
     g.draw(shape);
     NamayangarUtils.drawString(entity.getNeighValue(b) + "", g, transform, b);
   }
   g.setColor(Color.GREEN);
   shape = NamayangarUtils.transformShape(entity, transform);
   g.fill(shape);
 }
예제 #7
0
  private ArrayList<Building> bfs(ArrayList<Building> probabilisticBuilding) {
    ArrayList<Building> searched = new ArrayList<Building>();

    Queue<Building> queue = new LinkedList<Building>();
    Building start = probabilisticBuilding.remove(0);

    queue.add(start);
    searched.add(start);

    while (queue.size() > 0) {

      Building b = queue.poll();
      for (Building neigh : b.realNeighbors_Building()) {
        boolean removed = probabilisticBuilding.remove(neigh);
        if (removed) {
          queue.add(neigh);
          searched.add(neigh);
        }
      }
    }

    return searched;
  }
예제 #8
0
  public SOSEstimatedFireZone createUnknownFireZone(ArrayList<Building> building) {
    for (Building b : building) {
      b.virtualData[0].artificialFire(1);
    }
    SOSEstimatedFireZone estimatefz = null;
    for (Iterator<Building> it = building.iterator(); it.hasNext(); ) {
      Building b = it.next();

      if (b.getSOSEstimateFireSite() == null) {
        estimatefz = new SOSEstimatedFireZone(lastAssignedIndex, this);
        lastAssignedIndex++;
        estimatefz.setEstimating(false);
        log.info("New Estimate Fire Zone Created Unknown " + estimatefz + "\t" + b);
        getFireSites()
            .add(
                new Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>(
                    new ArrayList<SOSRealFireZone>(), estimatefz));
        updateNewSite(b, estimatefz);
        estimatefz.update(model.time());
      }
    }

    return estimatefz;
  }
예제 #9
0
  private boolean hasFireProbability(Building b) {
    if (b.getEstimator() != null || b.getSOSEstimateFireSite() != null) return false;

    if ((int) b.virtualData[0].getTemperature() == 0) return false;

    if (b.getFieryness() > 0 && b.getFieryness() != 4) return false;

    //		if (b.getFieryness() == 4 && agent instanceof FireBrigadeAgent)
    //			return false;

    for (Building near : b.neighbors_Building()) {
      if ((near.virtualData[0].getFieryness() > 0 && near.virtualData[0].getFieryness() != 4)
          || (near.getFieryness() > 0 && near.getFieryness() != 4)) return false;
    }

    return true;
  }
예제 #10
0
 public static double distance(Building b1, Building b2) {
   double distance = Integer.MAX_VALUE;
   for (int i = 0; i < b1.getApexes().length / 2; i += 2) {
     for (int j = 0; j < b2.getApexes().length / 2; j += 2) {
       double dis =
           SOSGeometryTools.distance(
               b1.getApexes()[i], b1.getApexes()[i + 1], b2.getApexes()[j], b2.getApexes()[j + 1]);
       if (dis < distance) distance = dis;
     }
   }
   return distance;
 }
예제 #11
0
파일: No_Comm.java 프로젝트: jpollo/rcrss
  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);
    }
  }
예제 #12
0
 private void updateNewSite(Building b, SOSAbstractFireZone f) { // TODO BFS
   log.info("updating building of new Site " + f + "     checkin for " + b);
   if (f instanceof SOSEstimatedFireZone) {
     if ((b.virtualData[0].getFieryness() > 0) && b.getSOSEstimateFireSite() == null) {
       f.addFieryBuilding(b);
       log.info(b + "  addet to fireSite " + f);
       b.setSOSEstimateFireSite((SOSEstimatedFireZone) f);
       for (Building b2 : b.realNeighbors_Building()) {
         updateNewSite(b2, f);
       }
     }
   } else if (f instanceof SOSRealFireZone) {
     if ((b.getFieryness() > 0) && b.getSOSRealFireSite() == null) {
       f.addFieryBuilding(b);
       log.info(b + "  addet to fireSite " + f);
       b.setSOSRealFireSite((SOSRealFireZone) f);
       for (Building b2 : b.realNeighbors_Building()) {
         updateNewSite(b2, f);
       }
     }
   }
 }
예제 #13
0
  /**
   * merge array of fire zone in one fire zone
   *
   * @param target
   */
  private void mergeEstimateFireaite(
      ArrayList<Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>> target) {

    ArrayList<SOSRealFireZone> realZones = new ArrayList<SOSRealFireZone>();

    getFireSites().removeAll(target);

    SOSEstimatedFireZone newEstimateFireSite = new SOSEstimatedFireZone(lastAssignedIndex++, this);
    SOSEstimatedFireZone fz;

    for (Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> zone : target) {
      fz = zone.second();

      for (Building b : fz.getAllBuildings()) {
        if (!b.getSOSEstimateFireSite().equals(newEstimateFireSite)) {
          b.setSOSEstimateFireSite(newEstimateFireSite);
          newEstimateFireSite.getAllBuildings().add(b);
          newEstimateFireSite.updateXY(b, 1);
        }
      }

      for (Building b : fz.getEstimatorBuilding()) {
        if (!b.getEstimator().equals(newEstimateFireSite)) {
          b.addToEstimator(newEstimateFireSite);
          newEstimateFireSite.getEstimatorBuilding().add(b);
        }
      }

      realZones.addAll(zone.first());
    }
    newEstimateFireSite.update(model.time());
    getFireSites()
        .add(
            new Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>(
                realZones, newEstimateFireSite));
  }
예제 #14
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);
          }
        }
      }
    }
  }
예제 #15
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;
  }
예제 #16
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 "-";
 }
예제 #17
0
 private int temperatureScore(Building b) {
   int tmp = (int) Math.ceil(Math.min(b.getTemperature(), 120) / 1d);
   if (b.getTemperature() > 120) tmp = 10;
   return (int) Math.pow(tmp, 4);
 }
예제 #18
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);

    }
  }