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