/**
  * 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());
   }
 }
Exemplo n.º 2
0
  // 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);
  }
Exemplo n.º 3
0
 @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);
 }