public void update() { if (timer > 10000) { Random rand = new Random(); boolean ok = false; while (!ok) { int randomInt = rand.nextInt(100); if (randomInt <= pbedroom1) { room = map.getRooms().get(0); if (room.getHumans() == 0) ok = true; } else if (randomInt <= pbedroom2) { room = map.getRooms().get(1); if (room.getHumans() == 0) ok = true; } else if (randomInt <= pkitchen) { room = map.getRooms().get(2); if (room.getHumans() < 2) ok = true; } else { room = map.getRooms().get(3); if (room.getHumans() < 3) ok = true; } } positionX = room.getPositionX() + room.getWidth() / 2; positionY = room.getPositionY() + room.getHeight() / 2; this.getRoom().action(this); } }
/** * Instantiate and populate a pems aggregate object from the next item in the result set of a pems * aggregate query. * * @param query string * @return PeMSStationAggregate */ protected PeMSStationAggregate aggregateFromQueryRS( String query, PeMSAggregate.AggregationLevel level) throws DatabaseException { PeMSStationAggregate sagg = null; if (dbr.psRSNext(query)) { // String columns = org.apache.commons.lang.StringUtils.join(dbr.psRSColumnNames(query), ", // "); // System.out.println("columns: [" + columns + "]"); sagg = new PeMSStationAggregate(); Long vdsId = dbr.psRSGetBigInt(query, "VDS_ID"); edu.berkeley.path.model_elements.DateTime timeMeasured = new edu.berkeley.path.model_elements.DateTime( dbr.psRSGetTimestampMilliseconds(query, "MEASURE_DT")); sagg.setVdsId(vdsId); sagg.setTimeMeasured(timeMeasured); PeMSAggregate total = new PeMSAggregate(); total.setSamples(dbr.psRSGetBigInt(query, "TOTAL_SAMPLES")); total.setObserved(dbr.psRSGetDouble(query, "PERCENT_OBSERVED")); total.setFlow(dbr.psRSGetDouble(query, "TOTAL_FLOW")); if (level == PeMSAggregate.AggregationLevel.PEMS_5MIN || level == PeMSAggregate.AggregationLevel.PEMS_1HOUR) { total.setAvgOccupancy(dbr.psRSGetDouble(query, "AVG_OCC")); total.setAvgSpeed(dbr.psRSGetDouble(query, "AVG_SPEED")); } sagg.setTotal(total); if (level == PeMSAggregate.AggregationLevel.PEMS_1HOUR || level == PeMSAggregate.AggregationLevel.PEMS_1DAY) { Map<CharSequence, Double> delay = new HashMap<CharSequence, Double>(); for (Integer mph = 35; mph <= 60; mph += 5) { delay.put(mph.toString(), dbr.psRSGetDouble(query, "DELAY_VT_" + mph)); } sagg.setDelay(delay); } if (level == PeMSAggregate.AggregationLevel.PEMS_5MIN || level == PeMSAggregate.AggregationLevel.PEMS_1HOUR) { List<PeMSAggregate> byLane = null; byLane = new ArrayList<PeMSAggregate>(); byLane.add(null); for (int lane = 1; lane <= 8; lane++) { PeMSAggregate agg = new PeMSAggregate(); String prefix = "LANE_" + lane + "_"; agg.setFlow(dbr.psRSGetDouble(query, prefix + "FLOW")); agg.setAvgOccupancy(dbr.psRSGetDouble(query, prefix + "AVG_OCC")); agg.setAvgSpeed(dbr.psRSGetDouble(query, prefix + "AVG_SPEED")); if (level == PeMSAggregate.AggregationLevel.PEMS_5MIN) { agg.setSamples(dbr.psRSGetBigInt(query, prefix + "SAMPLES")); String obs = dbr.psRSGetVarChar(query, prefix + "OBSERVED"); if (obs.equals("1")) { agg.setObserved(100.0); } else if (obs.equals("0")) { agg.setObserved(0.0); } else { System.out.println("Warning: unrecognized 'observed' value: '" + obs + "'."); // throw? log warning? } } byLane.add(agg); } sagg.setByLaneList(byLane); } } return sagg; }