private void createInitialTimeslots (Instant base, int initialSlots, int openSlots) { log.info("createInitialTimeslots(" + base + ", " + initialSlots + ", " + openSlots + "), at " + timeService.getCurrentTime()); //long timeslotMillis = competition.getTimeslotDuration(); // set timeslot index according to bootstrap mode //for (int i = 0; i < initialSlots - 1; i++) { // timeslotRepo.makeTimeslot(base); //} //for (int i = initialSlots - 1; i < (initialSlots + openSlots - 1); i++) { // timeslotRepo.makeTimeslot(base.plus(i * timeslotMillis)); //} }
/** * Sets up the simulator, with config overrides provided in a file. */ private boolean preGame (Document document) { log.info("preGame(File) - start"); // run the basic pre-game setup preGame(); // read the config info from the bootReader - We need to find a Competition Competition bootstrapCompetition = readBootRecord(document); if (null == bootstrapCompetition) return false; // update the existing Competition - should be the current competition Competition.currentCompetition().update(bootstrapCompetition); timeService.setClockParameters(competition); timeService.setCurrentTime(competition.getSimulationBaseTime()); return true; }
private SimulationClockControl (CompetitionControlService competitionControl, TimeService timeService) { super(); this.competitionControl = competitionControl; this.timeService = timeService; this.base = timeService.getBase(); this.rate = timeService.getRate(); this.modulo = timeService.getModulo(); this.tickInterval = this.modulo / this.rate; theTimer = new Timer(); this.waitUntilStopSemaphores = Collections.synchronizedSet(new HashSet<Semaphore>()); }
log.info("sim start at " + timeService.getCurrentTime()); timeService.init(timeService.getCurrentTime());
for (Broker broker : brokerRepo.list()) { if (timeService.getHourOfDay() == 0) { double brokerRate = rate; double cash = broker.getCashBalance();
public void doActivities (int day, int hour) { //TODO - keep track of plugged-in state and capacity of charger TimeslotData timeslotData = todayMap[hour]; double intendedDistance = timeslotData.getIntendedDistance(); double neededCapacity = getNeededCapacity(intendedDistance); if (intendedDistance < distanceEpsilon) { return; } if (neededCapacity > currentCapacity) { log.warn("Customer {} out of juice!", getName()); return; } try { double before = currentCapacity; discharge(neededCapacity); log.info("{} {} at {}, {} kms {} kWh from {} to {}", name, timeslotData.getActivity().get().getName(), dtf.print(service.getTimeService().getCurrentDateTime()), intendedDistance, neededCapacity, before, currentCapacity); driving = true; } catch (ChargeException ce) { log.error(ce); } }
private void updateTime (String time) { Instant value = Instant.parse(time); timeService.setCurrentTime(value); log.debug("time set to " + time); }
private double adjustCapacityForTariffRates ( int timeslot, double baseCapacity, TariffSubscription subscription) { if ((baseCapacity - 0.0) < 0.01) { return baseCapacity; } double chargeForBase = subscription.getTariff().getUsageCharge( timeslotRepo.getTimeForIndex(timeslot), baseCapacity, subscription.getTotalUsage()); double rateForBase = chargeForBase / baseCapacity; double benchmarkRate = capacityStructure.getBenchmarkRate(timeService.getHourOfDay()); double rateRatio = rateForBase / benchmarkRate; double tariffRatesFactor = determineTariffRatesFactor(rateRatio); logCapacityDetails(logIdentifier + ": tariff rates factor = " + tariffRatesFactor); return baseCapacity * tariffRatesFactor; }
@Override public CapacityAccumulator useCapacity (TariffSubscription subscription) { int timeslot = timeslotRepo.currentSerialNumber(); double baseCapacity = getBaseCapacity(timeslot); if (Double.isNaN(baseCapacity)) { throw new Error("Base capacity is NaN!"); } //else if (parentBundle.getPowerType().isProduction()) { // // correct sign before going further // baseCapacity *= -1.0; //} logCapacityDetails(logIdentifier + ": Base capacity for timeslot " + timeslot + " = " + baseCapacity); // total adjusted capacity double adjustedCapacity = baseCapacity; adjustedCapacity = adjustCapacityForPeriodicSkew(adjustedCapacity, timeService.getCurrentDateTime(), true); adjustedCapacity = adjustCapacityForCurrentWeather(adjustedCapacity, true); // moved up one level //adjustedCapacity = // adjustCapacityForSubscription(timeslot, adjustedCapacity, subscription); CapacityAccumulator result = addRegCapacityMaybe(subscription, timeslot, adjustedCapacity); actualCapacities.put(timeslot, result.getCapacity()); log.info(logIdentifier + ": Adjusted capacity for tariff " + subscription.getTariff().getId() + " = " + result.getCapacity()); return result; }
private synchronized List<Tariff> getPendingRevokes () { Instant now = timeService.getCurrentTime(); if (now.isAfter(lastRevokeProcess)) { lastRevokeProcess = now; List<Tariff> result = new ArrayList<>(pendingRevokedTariffs); pendingRevokedTariffs.clear(); return result; } return null; // only get non-null result once/timeslot }
rate = (mult + 1) * competition.getTimeslotLength(); timeService.setClockParameters(base.getMillis(), rate, competition.getTimeslotDuration()); timeService.setCurrentTime(base.plus(slotCount * competition.getTimeslotDuration()));
customer, customersCommitted, -actualKwh, customersCommitted * -tariff.getUsageCharge(actualKwh / customersCommitted, totalUsage, true)); if (getTimeService().getHourOfDay() == 0) {
private long computeNextTickTime () { long current = new Date().getTime(); // not a valid test in sim mode... if (current < start) { // first tick is special //System.out.println("first tick at " + start + "; current is " + current); return start; } else { // second and subsequent ticks long simTime = timeService.getCurrentTime().getMillis(); long nextSimTime = simTime + modulo; long nextTick = start + (nextSimTime - base) / rate; //System.out.println("next tick: current " + current + "; next tick at " + nextTick); return nextTick; } }
timeService.setClockParameters(competition); timeService.setCurrentTime(competition.getSimulationBaseTime());
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; }
/** * Returns the number of individual customers who may withdraw from this * subscription without penalty. Should return the total customer count * for a non-expiring tariff. */ public int getExpiredCustomerCount () { int cc = 0; Instant now = getTimeService().getCurrentTime(); for (ExpirationRecord exp : expirations) { if (exp.getHorizon() <= now.getMillis()) { cc += exp.getCount(); } } return cc; }
/** * Called once/timeslot, simply calls updateModel() and generateOrders() on * each of the gencos. */ @Override public void activate(Instant now, int phase) { log.info("Activate"); List<Timeslot> openSlots = timeslotRepo.enabledTimeslots(); Instant when = timeService.getCurrentTime(); for (Genco genco : gencos) { genco.updateModel(when); genco.generateOrders(when, openSlots); } if (null != cpGenco) { cpGenco.generateOrders(when, openSlots); } if (null != misoBuyer) { misoBuyer.generateOrders(when, openSlots); } }
if (!running) return; Instant time = timeService.getCurrentTime(); log.info("step at " + time.toString());
@Override public void activate (Instant time, int phase) { log.info("Activate"); processPendingVrus(); long msec = timeService.getCurrentTime().getMillis(); if (!subsequentPublication || (msec / TimeService.HOUR) % publicationInterval == publicationOffset) { // time to publish or never published revokeTariffsForDisabledBrokers(); updateRevokedTariffs(); publishTariffs(); //removeRevokedTariffs(); processPendingSubscriptions(); subsequentPublication = true; } }
Instant start = getTimeService().getCurrentTime(); if (expirations.size() > 0 && expirations.get(expirations.size() - 1).getHorizon() == start.getMillis() + minDuration) {