/** * 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); } } }
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; }
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); } } } }
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; }
/** * 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)); }
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); } } } } }