private int getUsageIndexOffset () { if (usageIndexOffset < 0) { // not yet initialized usageIndexOffset = 0; // offset for bootstrap mode if (!bootstrapMode) { usageIndexOffset = Competition.currentCompetition().getBootstrapTimeslotCount() + Competition.currentCompetition().getBootstrapDiscardedTimeslots(); } } return usageIndexOffset; } }
@SuppressWarnings("deprecation") public static void setDaysOfWeek () { Instant base = Competition.currentCompetition().getSimulationBaseTime(); int bias = Math.abs(base.toDate().getDay() - DAYS_OF_WEEK) % DAYS_OF_WEEK; MONDAY = (MONDAY + bias) % DAYS_OF_WEEK; TUESDAY = (TUESDAY + bias) % DAYS_OF_WEEK; WEDNESDAY = (WEDNESDAY + bias) % DAYS_OF_WEEK; THURSDAY = (THURSDAY + bias) % DAYS_OF_WEEK; FRIDAY = (FRIDAY + bias) % DAYS_OF_WEEK; SATURDAY = (SATURDAY + bias) % DAYS_OF_WEEK; SUNDAY = (SUNDAY + bias) % DAYS_OF_WEEK; }
int getIndex (Instant when) { int offset = getUsageIndexOffset(); int result = (int)((when.getMillis() - base.getMillis()) / (Competition.currentCompetition().getTimeslotDuration())) - offset; log.debug("offset=" + offset + ", index=" + result); return result; }
private void setTimeParameters() Instant base = competition.getSimulationBaseTime(); long rate = competition.getSimulationRate(); rate = competition.getTimeslotDuration() / bootstrapTimeslotMillis; log.info("bootstrap mode clock rate: " + rate); long rem = rate % competition.getTimeslotLength(); if (rem > 0) { long mult = competition.getSimulationRate() / competition.getTimeslotLength(); log.warn("Simulation rate " + rate + " not a multiple of " + competition.getTimeslotLength() + "; adjust to " + (mult + 1) * competition.getTimeslotLength()); rate = (mult + 1) * competition.getTimeslotLength(); competition.getTimeslotDuration()); timeService.setCurrentTime(base.plus(slotCount * competition.getTimeslotDuration()));
competition.getId(), "game-setup"); bootstrapOffset = competition.getBootstrapTimeslotCount() + competition.getBootstrapDiscardedTimeslots(); createInitialTimeslots(competition.getSimulationBaseTime(), (bootstrapOffset + 1), 0); competition.getDeactivateTimeslotsAhead(), competition.getTimeslotsOpen()); competition.addCustomer(customer); timeslotCount = competition.getBootstrapTimeslotCount() + competition.getBootstrapDiscardedTimeslots(); if (!bootstrapMode) { timeslotCount = computeGameLength(competition.getFixedTimeslotCount(), competition.getMinimumTimeslotCount(), competition.getExpectedTimeslotCount()); log.info("timeslotCount = " + timeslotCount); competition.addBroker(retailer);
- Competition.currentCompetition().getDeactivateTimeslotsAhead()); if (skip < 0) skip = 0; if (availableCapacity > Competition.currentCompetition() .getMinimumOrderQuantity()) {
/** * Generates buy orders. Price is distributed exponentially with a mean value * of priceBeta. Quantity is mwh/price. */ @Override public void generateOrders (Instant now, List<Timeslot> openSlots) { log.info("generate orders for " + getUsername()); for (Timeslot slot : openSlots) { int slotNum = slot.getSerialNumber(); double price = - priceBeta * Math.log(1.0 - seed.nextDouble()); double qty = mwh / price; if (Math.abs(qty) < Competition.currentCompetition() .getMinimumOrderQuantity()) return; Order offer = new Order(this, slotNum, qty, -price); log.debug(getUsername() + " wants " + qty + " in " + slotNum + " for " + price); brokerProxyService.routeMessage(offer); } }
/** * 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; }
public void init (BrokerProxy proxy, int seedId, RandomSeedRepo randomSeedRepo, TimeslotRepo timeslotRepo) { log.info("init(" + seedId + ") " + getUsername()); this.brokerProxyService = proxy; this.timeslotRepo = timeslotRepo; // set up the random generator this.seed = randomSeedRepo.getRandomSeed(CpGenco.class.getName(), seedId, "bid"); normal01 = new NormalDistribution(0.0, 1.0); normal01.reseedRandomGenerator(seed.nextLong()); // set up the supply-curve generating function if (!function.validateCoefficients(coefficients)) log.error("wrong number of coefficients for quadratic"); int to = Competition.currentCompetition().getTimeslotsOpen(); timeslotCoefficients = new double[to][getCoefficients().size()]; }
int remainingTries = (timeslot.getSerialNumber() - current.getSerialNumber() - Competition.currentCompetition().getDeactivateTimeslotsAhead()); if (remainingTries > 0) { double range = (minPrice - oldLimitPrice) * 2.0 / (double)remainingTries;
competition = Competition.currentCompetition(); runSimulation((long) (competition.getTimeslotLength() * TimeService.MINUTE / competition.getSimulationRate()));
Competition.currentCompetition().getBootstrapTimeslotCount()) { log.error("Short boot record {} for customer {} -- filling with zeros", cbd.getNetUsage().length, i < Competition.currentCompetition().getBootstrapTimeslotCount(); i++) { record.produceConsume(0.0, i);//) + offset);
private int activateNextTimeslot () long timeslotMillis = competition.getTimeslotDuration(); Timeslot current = findCurrentTimeslot(); if (current == null) { competition.getDeactivateTimeslotsAhead() - 1); Timeslot oldTs = timeslotRepo.findBySerialNumber(oldSerial); log.info("Deactivated timeslot " + oldSerial + ", start " + oldTs.getStartInstant().toString()); competition.getDeactivateTimeslotsAhead() - 1 + competition.getTimeslotsOpen()); Timeslot newTs = timeslotRepo.findBySerialNumber(newSerial); if (newTs == null) {
IdGenerator.recycle(); competition = Competition.newInstance(gameId); Competition.setCurrent(competition); configureCompetition(competition); timeService.setClockParameters(competition); timeService.setCurrentTime(competition.getSimulationBaseTime());
* competition.getTimeslotDuration() / competition.getSimulationRate();
@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 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); }
defaultBroker.collectBootstrapData(competition.getBootstrapTimeslotCount()); try {
public boolean validateOrder (Order order) { if (order.getMWh().equals(Double.NaN) || order.getMWh().equals(Double.POSITIVE_INFINITY) || order.getMWh().equals(Double.NEGATIVE_INFINITY)) { log.warn("Order from " + order.getBroker().getUsername() + " with invalid quantity " + order.getMWh()); return false; } double minQuantity = Competition.currentCompetition().getMinimumOrderQuantity(); if (Math.abs(order.getMWh()) < minQuantity) { log.warn("Order from " + order.getBroker().getUsername() + " with quantity " + order.getMWh() + " < minimum quantity " + minQuantity); return false; } if (!timeslotRepo.isTimeslotEnabled(order.getTimeslot())) { OrderStatus status = new OrderStatus(order.getBroker(), order.getId()); brokerProxyService.sendMessage(order.getBroker(), status); log.warn("Order from " + order.getBroker().getUsername() +" for disabled timeslot " + order.getTimeslot()); return false; } return true; }
public void init (BrokerProxy proxy, int seedId, ContextService service) { log.info("init(" + seedId + ") " + getUsername()); timeslotsOpen = Competition.currentCompetition().getTimeslotsOpen(); this.brokerProxyService = proxy; //this.service = service; this.timeslotRepo = (TimeslotRepo)service.getBean("timeslotRepo"); this.weatherReportRepo = (WeatherReportRepo)service.getBean("weatherReportRepo"); this.weatherForecastRepo = (WeatherForecastRepo)service.getBean("weatherForecastRepo"); RandomSeedRepo randomSeedRepo = (RandomSeedRepo)service.getBean("randomSeedRepo"); // set up the random generator this.tsSeed = randomSeedRepo.getRandomSeed(MisoBuyer.class.getName(), seedId, "ts"); // compute offsets for daily and weekly seasonal data int ts = timeslotRepo.currentSerialNumber(); timeslotOffset = ts; DateTime start = timeslotRepo.getDateTimeForIndex(ts); dailyOffset = start.getHourOfDay(); weeklyOffset = (start.getDayOfWeek() - 1) * 24 + dailyOffset; timeseries = new ComposedTS(); timeseries.initialize(ts); }