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)); }
@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); }
@Override public void step () { for (EvCustomer customer : evCustomers) { customer.step(service.getTimeslotRepo().currentTimeslot()); } }
private Instant getNowInstant () { return service.getTimeslotRepo().currentTimeslot().getStartInstant(); }
/** * Returns the spot market price per kWh - * This is the most recent valid clearing price for the current timeslot. */ double getSpotPrice () { Double result = defaultSpotPrice; // most recent trade is determined by Competition parameters // orderbooks have timeslot and execution time Orderbook ob = orderbookRepo.findSpotByTimeslot(timeslotRepo.currentTimeslot()); if (ob != null) { result = ob.getClearingPrice(); } else { log.info("null Orderbook"); } return result / 1000.0; // convert to kwh }
@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); } }
/** * Returns the zero-quantity price for down-regulation energy * in the current timeslot. Price is per kWh. */ @Override public double getPMinus () { double result = defaultSpotPrice; List<Orderbook> obs = orderbookRepo.findAllByTimeslot(timeslotRepo.currentTimeslot()); if (obs != null && obs.size() > 0) { Double min = null; for (Orderbook ob : obs) { Double price = ob.getClearingPrice(); if (price != null && (min == null || price < min)) min = price; } if (min != null) result = min; } return -result / rmPremium / 1000.0; }
/** * Returns the zero-quantity price for up-regulation energy * in the current timeslot. Units are per kWh */ @Override public double getPPlus () { double result = defaultSpotPrice; List<Orderbook> obs = orderbookRepo.findAllByTimeslot(timeslotRepo.currentTimeslot()); if (obs != null && obs.size() > 0) { Double max = null; for (Orderbook ob : obs) { Double price = ob.getClearingPrice(); if (price != null && (max == null || price > max)) max = price; } if (max != null) result = max; } return result * rmPremium / 1000.0; }
@Override public void evaluateTariffs () { Timeslot timeslot = getTimeslotRepo().currentTimeslot(); log.info("Customer " + getName() + " evaluating tariffs at timeslot " + timeslot.getSerialNumber()); utilityOptimizer.evaluateTariffs(); }
@Override public void handleNewTimeslot () { Timeslot timeslot = getTimeslotRepo().currentTimeslot(); log.info("Customer " + getName() + " activated for timeslot " + timeslot.getSerialNumber()); utilityOptimizer.handleNewTimeslot(timeslot); }
/** * 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 void broadcastWeatherReports () { WeatherReport report = null; try { report = weatherReportRepo.currentWeatherReport(); } catch (PowerTacException e) { log.error("Weather Service reports Weather Report Repo empty"); } if (report == null) { // In the event of an error return a default log.error("null weather-report for : " + timeslotRepo.currentSerialNumber() +" " + timeslotRepo.currentTimeslot()); brokerProxyService.broadcastMessage(new WeatherReport(timeslotRepo.currentSerialNumber(), 0.0, 0.0, 0.0, 0.0)); } else { brokerProxyService.broadcastMessage(report); } }
/** * 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(); }
protected Instant startOfDay () { Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); return start.toDateTime(DateTimeZone.UTC).withHourOfDay(0).toInstant(); }
@Override public void activate (Instant time, int phaseNumber) { log.info("Activate"); List<Broker> brokerList = brokerRepo.findRetailBrokers(); if (brokerList == null) { log.error("Failed to retrieve retail broker list"); return; } // create the BalanceReport to carry the total imbalance Timeslot current = timeslotRepo.currentTimeslot(); DoubleWrapper sum = makeDoubleWrapper(); // Run the balancing market // Transactions are posted to the Accounting Service and Brokers are // notified of balancing transactions balancingResults = balanceTimeslot(brokerList, sum); // Send the balance report BalanceReport report = new BalanceReport(current.getSerialNumber(), sum.getValue()); brokerProxyService.broadcastMessage(report); }
protected Instant nextStartOfDay () { Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); return start.toDateTime(DateTimeZone.UTC) .withHourOfDay(0).toInstant().plus(TimeService.DAY); }
@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); } } } }
protected Instant lastSunday () { Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); return start.toDateTime(DateTimeZone.UTC) .withDayOfWeek(1).withHourOfDay(0).toInstant(); }
double[] getPrices () { if (null != this.prices) return prices; double nhc = getNominalHourlyConsumption(); prices = new double[profileSize]; double cumulativeUsage = 0.0; Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); for (int i = 0; i < profileSize; i++) { Instant when = start.plus(i * TimeService.HOUR); if (when.get(DateTimeFieldType.hourOfDay()) == 0) { cumulativeUsage = 0.0; } prices[i] = tariff.getUsageCharge(when, nhc, cumulativeUsage) / nhc; cumulativeUsage += nhc; } return prices; }
/** * TODO: this does not appear to be a reasonable profile */ @Override public CapacityProfile getCapacityProfile (Tariff tariff) { double[] result = new double[config.getProfileLength()]; for (int i = 0; i < result.length; i++) { result[i] = getDominantLoad() / hrsPerDay; } // Assume profile starts at midnight Instant start = service.getTimeslotRepo().currentTimeslot().getStartInstant(); return new CapacityProfile(result, start.toDateTime(DateTimeZone.UTC) .withHourOfDay(0).toInstant() .plus(TimeService.DAY)); }