/** * Compute needed quantities for each open timeslot, then submit orders for those quantities. * * @see org.powertac.samplebroker.MarketManager#activate() */ @Override public synchronized void activate(int timeslotIndex) { double neededKWh = 0.0; log.debug("Current timeslot is " + timeslotRepo.currentTimeslot().getSerialNumber()); for (Timeslot timeslot : timeslotRepo.enabledTimeslots()) { int index = (timeslot.getSerialNumber()) % broker.getUsageRecordLength(); neededKWh = portfolioManager.collectUsage(index); submitOrder(neededKWh, timeslot.getSerialNumber()); } }
@Override public void handleNewTariffs(List<Tariff> newTariffs) { Timeslot timeslot = timeslotRepo.currentTimeslot(); log.info( "Customer " + getName() + " received " + newTariffs.size() + " new tariffs at timeslot " + timeslot.getSerialNumber()); utilityOptimizer.handleNewTariffs(newTariffs); }
// set commitment leadtime to a larger number and make sure ordering // behavior is correct @Test public void testGenerateOrders2() { // set up the genco with commitment leadtime=3 PluginConfig config = new PluginConfig("Genco", "").addConfiguration("commitmentLeadtime", "3"); genco.configure(config); // all defaults // capture orders final ArrayList<Order> orderList = new ArrayList<Order>(); doAnswer( new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); orderList.add((Order) args[0]); return null; } }) .when(mockProxy) .routeMessage(isA(Order.class)); // set up some timeslots Timeslot ts0 = timeslotRepo.makeTimeslot(start); ts0.disable(); assertEquals("first ts has sn=0", 0, ts0.getSerialNumber()); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 2)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 3)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 4)); assertEquals("4 enabled timeslots", 4, timeslotRepo.enabledTimeslots().size()); // generate orders and check genco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("two orders", 2, orderList.size()); Order first = orderList.get(0); assertEquals("first order for ts3", 3, first.getTimeslot().getSerialNumber()); assertEquals("first order price", 1.0, first.getLimitPrice(), 1e-6); assertEquals("first order for 50 mwh", -100.0, first.getMWh(), 1e-6); Order second = orderList.get(1); assertEquals("second order for ts4", 4, second.getTimeslot().getSerialNumber()); assertEquals("second order price", 1.0, second.getLimitPrice(), 1e-6); assertEquals("second order for 100 mwh", -100.0, second.getMWh(), 1e-6); }
@Test public void testGenerateOrders() { // set up the genco PluginConfig config = new PluginConfig("Genco", ""); genco.configure(config); // all defaults // capture orders final ArrayList<Order> orderList = new ArrayList<Order>(); doAnswer( new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); orderList.add((Order) args[0]); return null; } }) .when(mockProxy) .routeMessage(isA(Order.class)); // set up some timeslots Timeslot ts1 = timeslotRepo.makeTimeslot(start); ts1.disable(); Timeslot ts2 = timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR)); Timeslot ts3 = timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 2)); assertEquals("2 enabled timeslots", 2, timeslotRepo.enabledTimeslots().size()); // 50 mwh already sold in ts2 MarketPosition posn2 = new MarketPosition(genco, ts2, -50.0); genco.addMarketPosition(posn2, ts2); // generate orders and check genco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("two orders", 2, orderList.size()); Order first = orderList.get(0); assertEquals("first order for ts2", ts2, first.getTimeslot()); assertEquals("first order price", 1.0, first.getLimitPrice(), 1e-6); assertEquals("first order for 50 mwh", -50.0, first.getMWh(), 1e-6); Order second = orderList.get(1); assertEquals("second order for ts3", ts3, second.getTimeslot()); assertEquals("second order price", 1.0, second.getLimitPrice(), 1e-6); assertEquals("second order for 100 mwh", -100.0, second.getMWh(), 1e-6); }
private void usePower(Timeslot timeslot) { for (CapacityBundle bundle : capacityBundles) { List<TariffSubscription> subscriptions = getTariffSubscriptionRepo().findActiveSubscriptionsForCustomer(bundle.getCustomerInfo()); double totalCapacity = 0.0; double totalUsageCharge = 0.0; for (TariffSubscription subscription : subscriptions) { double usageSign = bundle.getPowerType().isConsumption() ? +1 : -1; double currCapacity = usageSign * useCapacity(subscription, bundle); if (Config.getInstance().isUsageChargesLogging()) { double charge = subscription .getTariff() .getUsageCharge(currCapacity, subscription.getTotalUsage(), false); totalUsageCharge += charge; } subscription.usePower(currCapacity); totalCapacity += currCapacity; } log.info( bundle.getName() + ": Total " + bundle.getPowerType() + " capacity for timeslot " + timeslot.getSerialNumber() + " = " + totalCapacity); logUsageCharges( bundle.getName() + ": Total " + bundle.getPowerType() + " usage charge for timeslot " + timeslot.getSerialNumber() + " = " + totalUsageCharge); } }
@Override public void handleNewTimeslot() { Timeslot timeslot = timeslotRepo.currentTimeslot(); log.info("Customer " + getName() + " activated for timeslot " + timeslot.getSerialNumber()); utilityOptimizer.handleNewTimeslot(timeslot); }