private double[] getTsCoefficients (Timeslot slot) { int horizon = timeslotCoefficients.length; if (-1 == ringOffset) { // first encounter ringOffset = slot.getSerialNumber(); lastTsGenerated = slot.getSerialNumber(); walkCoefficients(getCoefficientArray(), timeslotCoefficients[0]); logCoefficients(slot.getSerialNumber(), timeslotCoefficients[0]); } int index = (slot.getSerialNumber() - ringOffset) % horizon; if (slot.getSerialNumber() > lastTsGenerated) { int prev = (slot.getSerialNumber() - ringOffset - 1) % horizon; walkCoefficients(timeslotCoefficients[prev], timeslotCoefficients[index]); logCoefficients(slot.getSerialNumber(), timeslotCoefficients[index]); lastTsGenerated = slot.getSerialNumber(); } return timeslotCoefficients[index]; }
int oldSerial = (current.getSerialNumber() + competition.getDeactivateTimeslotsAhead() - 1); Timeslot oldTs = timeslotRepo.findBySerialNumber(oldSerial); log.info("Deactivated timeslot " + oldSerial + ", start " + oldTs.getStartInstant().toString()); int newSerial = (current.getSerialNumber() + competition.getDeactivateTimeslotsAhead() - 1 + competition.getTimeslotsOpen()); if (newTs == null) { log.info("newTS null in activateNextTimeslot"); long start = (current.getStartInstant().getMillis() + (newSerial - current.getSerialNumber()) * timeslotMillis); newTs = timeslotRepo.makeTimeslot(new Instant(start)); log.info("Activated timeslot " + newSerial + ", start " + newTs.getStartInstant()); return current.getSerialNumber();
private int getTimeIndex (DateTime dateTime) { // Used for testing if (simulationBaseTime == null) { simulationBaseTime = timeslotRepo.currentTimeslot().getStartTime(); } long diff = dateTime.getMillis() - simulationBaseTime.getMillis(); return (int) (diff / (1000 * 3600)); }
CustomerRecord (CustomerInfo customer, int population) { super(); this.customer = customer; this.subscribedPopulation = population; base = timeslotRepo.findBySerialNumber(0).getStartInstant(); }
@Override public void step () { int serial = service.getTimeslotRepo().currentSerialNumber(); Timeslot ts = service.getTimeslotRepo().currentTimeslot(); // TODO - this code assumes that games start at midnight. Bad assumption. int day = (int) (serial / VillageConstants.HOURS_OF_DAY); int hour = ts.getStartTime().getHourOfDay(); Instant now = ts.getStartInstant(); weatherCheck(day, hour, now); checkCurtailment(serial, day, hour); consumePower(); // for (Household house: getHouses()) // house.test(); if (hour == 23) { for (String type: numberOfHouses.keySet()) { if (!(type.equals("NS"))) { log.info("Rescheduling " + type); rescheduleNextDay(type); } } } }
@Override public void activate (Instant time, int phaseNumber) { long msec = time.getMillis(); if (msec % (getWeatherReqInterval() * TimeService.HOUR) != 0) { log.info("WeatherService reports not time to grab weather data."); } else { log.info("Timeslot " + timeslotRepo.currentTimeslot().getId() + " WeatherService reports time to make request for weather data"); DateTime dateTime = timeslotRepo.currentTimeslot().getStartTime(); if (blocking) { WeatherRequester wr = new WeatherRequester(dateTime); wr.run(); } else { aheadDays.add(dateTime.plusDays(daysAhead)); while (aheadDays.size() > 0) { WeatherRequester wr = new WeatherRequester(aheadDays.remove(0)); new Thread(wr).start(); } } } broadcastWeatherReports(); broadcastWeatherForecasts(); }
/** * This is the basic evaluation function, taking into consideration the * minimum cost without shifting the appliances' load but the tariff chosen * is * picked up randomly by using a possibility pattern. The better tariffs * have * more chances to be chosen. */ @Override public void evaluateTariffs (List<Tariff> tariffs) { for (CustomerInfo customer: getCustomerInfos()) { log.info("Customer " + customer.toString() + " evaluating tariffs for timeslot " + service.getTimeslotRepo().currentTimeslot().getId()); TariffEvaluator evaluator = tariffEvaluators.get(customer); evaluator.evaluateTariffs(); } }
private Instant getNowInstant () { return service.getTimeslotRepo().currentTimeslot().getStartInstant(); }
@Override public void step () { int serial = service.getTimeslotRepo().currentSerialNumber(); Timeslot ts = service.getTimeslotRepo().currentTimeslot(); // TODO - this code assumes that games start at midnight. Bad assumption. int day = (int) (serial / OfficeComplexConstants.HOURS_OF_DAY); int hour = ts.getStartTime().getHourOfDay(); Instant now = ts.getStartInstant(); weatherCheck(day, hour, now); // checkRevokedSubscriptions(); checkCurtailment(serial, day, hour); consumePower(); // for (Office office: getOffices()) // office.test(); if (hour == 23) { for (String type: numberOfOffices.keySet()) { if (!(type.equals("NS"))) { log.info("Rescheduling " + type); rescheduleNextDay(type); } } } }
private TimeslotUpdate makeTimeslotUpdate () { List<Timeslot> enabled = timeslotRepo.enabledTimeslots(); TimeslotUpdate msg = new TimeslotUpdate(timeService.getCurrentTime(), enabled.get(0).getSerialNumber(), enabled.get(enabled.size() - 1).getSerialNumber()); return msg; }
@Override public CapacityProfile getCapacityProfile (Tariff tariff) { Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); double drain = capacityKWh * (1.0 - chargeEfficiency) / 2.0; double[] profile = new double[24]; Arrays.fill(profile, drain); return new CapacityProfile (profile, start); } }
@Override public String initialize (Competition competition, List<String> completedInits) { super.init(); aheadDays = new CopyOnWriteArrayList<DateTime>(); serverProps.configureMe(this); weatherReqInterval = Math.min(24, weatherReqInterval); simulationBaseTime = competition.getSimulationBaseTime().toDateTime(); if (weatherData != null && (weatherData.endsWith(".xml") || weatherData.endsWith(".state"))) { log.info("read from file in blocking mode"); blocking = true; } if (!blocking) { DateTime dateTime = timeslotRepo.currentTimeslot().getStartTime(); // Get the first 3 days of weather, blocking! for (int i = 0; i < daysAhead; i++) { WeatherRequester weatherRequester = new WeatherRequester(dateTime); weatherRequester.run(); dateTime = dateTime.plusDays(1); } } return "WeatherService"; }
private void overwriteForecastCapacities (Timeslot timeslot, CapacityProfile profile) { Timeslot slider = timeslot; for (int i = 0; i < CapacityProfile.NUM_TIMESLOTS; ++i) { forecastCapacities.put(slider.getSerialNumber(), profile.getCapacity(i)); slider = timeslotRepo.getNext(slider); } }
protected Instant startOfDay () { Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); return start.toDateTime(DateTimeZone.UTC).withHourOfDay(0).toInstant(); }
/** * Runs the model forward one step */ public void step (Timeslot timeslot) { int day = timeslot.getStartTime().getDayOfWeek(); int hour = timeslot.getStartTime().getHourOfDay(); // find the current active subscription TariffSubscription sub = null; List<TariffSubscription> subs = service.getTariffSubscriptionRepo(). findActiveSubscriptionsForCustomer(customerInfo); if (null == subs || subs.size() == 0) { log.error("No subscriptions found for " + name); return; } else { sub = subs.get(0); } driving = false; // Always do handleRegulations first, setRegulation last handleRegulation(day, hour, sub); makeDayPlanning(hour, day); doActivities(day, hour); double[] loads = getLoads(day, hour); consumePower(loads, sub); setRegulation(loads[2], loads[3], sub); }
@Override public void postEconomicControl (EconomicControlEvent event) { int tsIndex = event.getTimeslotIndex(); int current = timeslotRepo.currentTimeslot().getSerialNumber(); if (tsIndex < current) { log.warn("attempt to save old economic control for ts " + tsIndex + " during timeslot " + current); return; } List<EconomicControlEvent> tsList = pendingEconomicControls.get(tsIndex); if (null == tsList) { tsList = new ArrayList<EconomicControlEvent>(); pendingEconomicControls.put(tsIndex, tsList); } tsList.add(event); }
protected Instant nextStartOfDay () { Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); return start.toDateTime(DateTimeZone.UTC) .withHourOfDay(0).toInstant().plus(TimeService.DAY); }
private void submitOrder (double neededKWh, Timeslot timeslot) { double neededMWh = neededKWh / 1000.0; if (Math.abs(neededMWh) < competition.getMinimumOrderQuantity()) { // don't bother return; } Double limitPrice; MarketPosition posn = face.findMarketPositionByTimeslot(timeslot.getSerialNumber()); if (posn != null) neededMWh -= posn.getOverallBalance(); log.debug("needed mWh=" + neededMWh); if (Math.abs(neededMWh) < minMWh) { log.info("no power required in timeslot " + timeslot.getSerialNumber()); return; } else { limitPrice = computeLimitPrice(timeslot, neededMWh); } log.info("new order for " + neededMWh + " at " + limitPrice + " in timeslot " + timeslot.getSerialNumber()); Order result = new Order(face, timeslot.getSerialNumber(), neededMWh, limitPrice); lastOrder.put(timeslot, result); brokerProxyService.routeMessage(result); }
protected Instant lastSunday () { Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); return start.toDateTime(DateTimeZone.UTC) .withDayOfWeek(1).withHourOfDay(0).toInstant(); }
/** * Gets the net market position for the current timeslot. This only works on * processed transactions, but it can be used before activation in case there * can be no new market transactions for the current timeslot. This is the * normal case. The value will be positive if the broker is importing power * during the current timeslot. */ @Override public synchronized double getCurrentMarketPosition(Broker broker) { Timeslot current = timeslotRepo.currentTimeslot(); log.debug("current timeslot: " + current.getSerialNumber()); MarketPosition position = broker.findMarketPositionByTimeslot(current.getSerialNumber()); if (position == null) { log.debug("null position for ts " + current.getSerialNumber()); return 0.0; } log.info("market position for " + broker.getUsername() + ": " + position.getOverallBalance()); return position.getOverallBalance(); }