示例#1
0
  /** merge estimate fire zone */
  private void mergeEstimateFireZone() {
    log.info("Estimate Fire Zone Merger Started");
    if (getFireSites().size() <= 1) return; // don't need to merge

    ArrayList<SOSAbstractFireZone> fireZones = new ArrayList<SOSAbstractFireZone>();
    for (Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> zn : getFireSites())
      fireZones.add(zn.second());

    ArrayList<ArrayList<SOSAbstractFireZone>> listMergeList =
        getMergableFireZones(fireZones, merger);

    for (ArrayList<SOSAbstractFireZone> mergeList : listMergeList) {
      if (mergeList.size() <= 1) continue;

      ArrayList<Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>> target =
          new ArrayList<Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>>();
      for (Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> ess : getFireSites()) {
        for (SOSAbstractFireZone p : mergeList) {
          if (ess.second().equals(p)) target.add(ess);
        }
      }
      mergeEstimateFireaite(target);

      log.info("Estimate merged   " + getFireSites());
    }
  }
示例#2
0
  private void justMakeReachable(Path path) throws SOSActionException {
    log.info("making reachable to " + path);
    if (!PoliceConstants.IS_NEW_CLEAR) {

      ArrayList<Blockade> blocks = new ArrayList<Blockade>();

      ArrayList<Blockade> blockadeEdge = reachableWithEdge.getBlockingBlockadeOfPath(path);
      blocks.addAll(blockadeEdge);
      //
      if (blocks.isEmpty()) {
        blocks.addAll(reachablityTool.getBlockingBlockadeOfPath(path));
        log.debug("clearableBlockadeToReachablebyReachablityTool is " + blocks);
        //	ArrayList<Blockade> blockadeEdge =
        // clearableBlockadeToFullReachable.getBlockingBlockadeOfPath(path);
      }
      log.debug("clearableBlockadeToReachableWithEdge is " + blocks);

      Blockade clearBlock = chooseBestBlockade(blocks);

      if (clearBlock != null) clear(clearBlock);
      else log.debug("No Blockade found---> we can move");
    } else {
      Point next = agent.degreeClearableToPoint.nextPointToClear(path, true, true);
      if (next != null) {
        //				log.warn("clear at" + next);
        clear(next);
      }
    }
  }
示例#3
0
  public Pair<Area, Point2D> getEntrancePoint(Area dest) {
    if (dest == null) {
      log.error("why try to move to " + dest + "?????");
      return null;
    }
    Path path = agent.move.getPathTo(Collections.singleton(dest), PoliceMove.class);
    ArrayList<EntityID> pathArray = path.getIds();
    if (pathArray.isEmpty()) {
      log.error("path is empty. why????");
      return null;
    }

    Edge inComingEdge;
    if (pathArray.size() == 1) {
      inComingEdge = dest.getEdgeTo(agent.location());
    } else {
      inComingEdge = dest.getEdgeTo(pathArray.get(pathArray.size() - 2));
    }
    if (inComingEdge == null) return new Pair<Area, Point2D>(dest, dest.getPositionPoint());
    Line2D wallLine =
        inComingEdge
            .getLine(); // new Line2D(edge.getStartX(), edge.getStartY(), edge.getEndX() -
                        // edge.getStartX(), edge.getEndY() - edge.getStartY());

    Vector2D offset;
    if (AliGeometryTools.havecorrectDirection(dest)) {
      offset = wallLine.getDirection().getNormal().normalised().scale(10);
    } else {
      offset = wallLine.getDirection().getNormal().normalised().scale(-10);
    }
    Point2D destXY = inComingEdge.getMidPoint().plus(offset);
    return new Pair<Area, Point2D>(dest, destXY);
  }
示例#4
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);
      }
    }
  }
示例#5
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;
  }
示例#6
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;
  }
示例#7
0
  public static void launch() {
    println("Launching sos test agents");
    try {

      int port =
          config.getIntValue(
              Constants.KERNEL_PORT_NUMBER_KEY, Constants.DEFAULT_KERNEL_PORT_NUMBER);
      String host =
          config.getValue(Constants.KERNEL_HOST_NAME_KEY, Constants.DEFAULT_KERNEL_HOST_NAME);

      ComponentLauncher launcher = new TCPComponentLauncher(host, port, config);
      connect(launcher, new MessageTestAgent(), config);
    } catch (ConnectionException e) {
      sosLogger.fatal("Error connecting agents", e);
      System.exit(-1);
    } catch (InterruptedException e) {
      sosLogger.fatal("Error connecting agents", e);
      System.exit(-1);
    } catch (ComponentConnectionException e) {
      if (e.getMessage() != null && e.getMessage().indexOf("No more agents") < 0)
        sosLogger.fatal(e.getMessage(), e);
      else {
        sosLogger.fatal("No more agents");
      }
      System.exit(-1);
    }
    System.out.println("============================================================");
  }
示例#8
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);

    }
  }
示例#9
0
 public void move(Path path) throws SOSActionException {
   log.info("moving to path: " + path);
   if (path == null) {
     log.error("path is null!!!");
     moveToARandomArea();
   }
   justMakeReachable(path);
   agent.move(path);
 }
示例#10
0
 public void clearNearestBlockade() throws SOSActionException {
   log.info("clearing NearestBlockade");
   PriorityQueue<Blockade> blockadesInRange =
       model().getBlockadesInRange(agent.me().getX(), agent.me().getY(), agent.clearDistance);
   log.debug("Blockades in Range=" + blockadesInRange);
   Blockade selectedBlock = null;
   if (!blockadesInRange.isEmpty()) selectedBlock = blockadesInRange.remove();
   log.debug("best blockade:" + selectedBlock);
   if (selectedBlock != null) clear(selectedBlock);
 }
示例#11
0
  protected void move(Collection<? extends Area> destination) throws SOSActionException {
    log.info("moving to: " + destination);
    if (destination.isEmpty()) {
      log.error("Move to empty destination????? random move....");
      moveToARandomArea();
    }

    Path path = agent.move.getPathTo(destination, PoliceMove.class);
    move(path);
  }
示例#12
0
  @SuppressWarnings("unused")
  private void moveToPointWithGoodReachablity(ArrayList<Pair<? extends Area, Point2D>> destinations)
      throws SOSActionException {
    log.info("moving to: " + destinations);
    if (destinations.isEmpty()) {
      log.error("Move to empty destination????? random move....");
      moveToARandomArea();
    }

    Path path = agent.move.getPathToPoints(destinations, PoliceMove.class);
    moveWithGoodReachablity(path);
  }
示例#13
0
  /** grouping mergable fire zones */
  private ArrayList<ArrayList<SOSAbstractFireZone>> getMergableFireZones(
      ArrayList<? extends SOSAbstractFireZone> fireZones, Mergable merger) {
    log.info("Mergable Fire Zone Compute");

    // making graph for merge fireZone, if vertex(fire zone) u,v is mergable then (u,v) is a member
    // of E
    boolean[][] mergable = new boolean[fireZones.size()][fireZones.size()];
    for (int i = 0; i < fireZones.size(); i++) {
      mergable[i][i] = true;
      for (int j = 0; j < i; j++) {
        SOSAbstractFireZone fireZone1 = fireZones.get(i);
        SOSAbstractFireZone fireZone2 = fireZones.get(j);
        mergable[i][j] = merger.isMergable(fireZone1, fireZone2);
        mergable[j][i] = merger.isMergable(fireZone1, fireZone2);
      }
    }

    ArrayList<ArrayList<SOSAbstractFireZone>> listMergeList =
        new ArrayList<ArrayList<SOSAbstractFireZone>>();

    boolean[] visited = new boolean[fireZones.size()];
    for (int temp = 0; temp < visited.length; temp++) visited[temp] = false;

    for (int i = 0; i < fireZones.size(); i++) {
      if (visited[i]) // is added befor
      continue;
      Queue<Integer> queue = new LinkedList<Integer>();
      queue.add(i);

      visited[i] = true;

      ArrayList<SOSAbstractFireZone> mergeList = new ArrayList<SOSAbstractFireZone>();
      listMergeList.add(mergeList);
      while (queue.size() > 0) { // BFS for finding all the mergable firezone in graph
        int from = queue.poll();
        mergeList.add(fireZones.get(from));
        for (int to = 0; to < fireZones.size(); to++) {
          if (visited[to] == false) { // it didn't add before
            if (mergable[from][to] == true) {
              visited[to] = true;
              queue.add(to);
            }
          }
        }
      }
      log.info("mergable fire zone group (" + i + ")  " + mergeList);
    }
    return listMergeList;
  }
示例#14
0
 protected Blockade chooseFirstBlockade(List<Blockade> list) {
   log.debug("Choosing first blockade from list(" + list + ")");
   if (list == null) {
     log.warn("clearableBlockades is null!!! it shouldn't be happened!");
     return null;
   }
   for (Blockade blockade : list) {
     if (PoliceUtils.isValid(blockade)) {
       log.info(" first valid blockade is " + blockade);
       return blockade;
     }
   }
   log.info(" can't choos a blockade ");
   return null;
 }
示例#15
0
  /** merge the fireZones are near according to gravity */
  private void mergeFireZones() {
    log.info("Fire Zone Merger Started");

    mergeEstimateFireZone();

    mergeRealFireZone();
  }
示例#16
0
 private void printZoneData() {
   log.info("-------------------------  FIRE ZONE DATA  ----------------------------------");
   for (Iterator<Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>> it =
           getFireSites().iterator();
       it.hasNext(); ) {
     Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> p = it.next();
     String r = "";
     for (SOSRealFireZone sor : p.first()) r += "  allBuilding=" + sor.allBuilding.size();
     log.info("Real " + p.first() + "     " + r);
     log.info(
         "Estimate " + p.second() + "  " + " allbuilding=" + p.second().allBuilding.size() + " ");
     log.log("-------------------------------------------\n");
   }
   log.info(
       "-------------------------  FIRE ZONE DATA FINISH  ----------------------------------");
 }
示例#17
0
 protected void moveXY(Area destination, int x, int y) throws SOSActionException {
   log.info("moving to: " + destination + " x:" + x + " y:" + y);
   Pair<? extends Area, Point2D> dest = new Pair<Area, Point2D>(destination, new Point2D(x, y));
   ArrayList<Pair<? extends Area, Point2D>> dests = new ArrayList<Pair<? extends Area, Point2D>>();
   dests.add(dest);
   Path path = agent.move.getPathToPoints(dests, PoliceMove.class);
   move(path);
 }
示例#18
0
  /** merge real fire zone */
  private void mergeRealFireZone() {
    log.info("start merging real fire zone");

    for (int i = 0; i < getFireSites().size(); i++) {
      ArrayList<SOSRealFireZone> realfireSites = getFireSites().get(i).first();

      if (realfireSites.size() <= 1) continue; // dont need to merge

      ArrayList<ArrayList<SOSAbstractFireZone>> listMergeList =
          getMergableFireZones(realfireSites, merger);

      for (ArrayList<SOSAbstractFireZone> mergeList : listMergeList) {

        if (mergeList.size() <= 1) continue;

        mergeRealFireZones(getFireSites().get(i), mergeList);
        log.info("real merged   " + getFireSites());
      }
    }
  }
示例#19
0
  private ArrayList<ArrayList<Building>> getRegions(ArrayList<Building> probabilisticBuilding) {

    ArrayList<ArrayList<Building>> regions = new ArrayList<ArrayList<Building>>();

    while (probabilisticBuilding.size() > 0) {
      ArrayList<Building> region = bfs(probabilisticBuilding);
      log.info("region ::>  " + region);
      if (region != null) regions.add(region);
    }
    return regions;
  }
示例#20
0
 protected Blockade chooseBestBlockade(List<Blockade> list) {
   log.debug("Choosing best blockade from list(" + list + ")");
   if (list == null) {
     log.warn("clearableBlockades is null!!! it shouldn't be happened!");
     return null;
   }
   Blockade best = null;
   double bestValue = 0;
   for (Blockade blockade : list) {
     if (PoliceUtils.isValid(blockade)) {
       int value = computeBlockadeValue(blockade);
       if (value > bestValue) {
         bestValue = value;
         best = blockade;
       }
     }
   }
   log.info(" best blockade is " + best);
   return best;
 }
示例#21
0
  /**
   * main method of fire zone manager</br> this method call each cycle to update and determine new
   * fire zone
   *
   * @param time
   */
  public void update(int time) {
    long t1 = System.currentTimeMillis();
    log.info("size of fireSites " + getFireSites().size());
    printZoneData();
    if (me instanceof FireBrigadeAgent) {
      //			log.info("move updateIslands to updater ! ", null);
      ((FireWorldModel) model).updateIslands();
    }
    for (Iterator<Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone>> it =
            getFireSites().iterator();
        it.hasNext(); ) {
      Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> p = it.next();
      checkEstimator(p.second());
      log.info("update fireZone  " + p);
      log.info("\tupdate estimated fireZone  " + p.second());
      p.second().update(time);
      for (SOSRealFireZone f : p.first()) {
        log.info("\tupdate real fireZone  " + f);
        f.update(time);
      }
    }
    log.info("going to create new fireZones  ");
    createNewZones(time);

    log.info("going to merge fireZones    ");
    mergeFireZones();
    printZoneData();
    //		if (!SOSConstant.IS_CHALLENGE_RUNNING)
    //			log.warn("Fire Zone Updater Finished  Time= " + (System.currentTimeMillis() - t1) + " ms
    // ");

  }
示例#22
0
 public void makeReachableTo(List<? extends StandardEntity> targets) throws SOSActionException {
   log.info("makeReachableTo " + targets);
   ArrayList<Pair<? extends Area, Point2D>> reachableAreas =
       new ArrayList<Pair<? extends Area, Point2D>>();
   for (StandardEntity entity : targets) {
     if (entity == null) {
       log.error("A null entity passed to makeReachableTo!!! WHY?");
       continue;
     }
     if (entity.getPositionPair() == null) {
       log.error("A null position entity(" + entity + ") passed to makeReachableTo!!! WHY?");
       continue;
     }
     if (!isReachableTo(entity)) {
       reachableAreas.addAll(PoliceUtils.getReachableAreasPair(entity));
     }
   }
   log.debug("reachableAreas = " + reachableAreas);
   if (!reachableAreas.isEmpty()) {
     moveToPoint(reachableAreas);
   }
 }
示例#23
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);
       }
     }
   }
 }
示例#24
0
  private static void setConstantsFromConfig(String[] args) throws IOException {

    try {
      config = new Config(new File("sos.config"));
      CommandLineOptions.processArgs(args, config);
      // if(config.getIntValue("sos.password")==SOSConstant.PASSWORD)
      if (!SOSConstant.IS_CHALLENGE_RUNNING)
        SOSConstant.IS_CHALLENGE_RUNNING = config.getBooleanValue("sos.IS_CHALLENGE_RUNNING", true);
      if (!SOSConstant.NO_ANY_LOG)
        SOSConstant.NO_ANY_LOG = config.getBooleanValue("sos.NO_ANY_LOG", true);
    } catch (ConfigException e1) {
      sosLogger.error(e1.getMessage());
    }
  }
示例#25
0
  private void justMakeReachableWithGoodReachablity(Path path) throws SOSActionException {
    log.info("making reachable with good reachablity to " + path);

    ArrayList<Blockade> blocks = reachablityTool.getBlockingBlockadeOfPath(path);
    log.debug("clearableBlockadeToReachablebyReachablityTool is " + blocks);
    ArrayList<Blockade> blockadeEdge = reachableWithEdge.getBlockingBlockadeOfPath(path);
    blocks.addAll(blockadeEdge);

    log.debug("clearableBlockadeToReachableWithEdge is " + blocks);

    Blockade clearBlock = chooseBestBlockade(blocks);

    if (clearBlock != null) clear(clearBlock);
    else if (clearBlock == null && !blocks.isEmpty()) {
      log.debug("No blockade is in range but the path is close!!! so move to close area");
      ArrayList<Pair<? extends Area, Point2D>> dest =
          new ArrayList<Pair<? extends Area, Point2D>>();
      for (Blockade blockade : blocks) {
        dest.add(blockade.getPositionPair());
      }
      path = agent.move.getPathToPoints(dest, PoliceMove.class);
      agent.move(path);
    } else log.debug("No Blockade found---> we can move");
  }
示例#26
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;
  }
示例#27
0
 public void log(String st) {
   log.info(st);
 }
示例#28
0
 public void moveToShape(Collection<ShapeInArea> area) throws SOSActionException {
   log.info("moving to shape in areas: " + area);
   Path path = agent.move.getPathToShapes(area, PoliceMove.class);
   move(path);
 }
示例#29
0
 protected void clear(Blockade blockade) throws SOSActionException {
   log.info("clearing " + blockade);
   agent.clear(blockade);
 }
示例#30
0
 private void moveWithGoodReachablity(Path path) throws SOSActionException {
   log.info("moving with good reachablity to path: " + path);
   justMakeReachableWithGoodReachablity(path);
   agent.move(path);
 }