org.powertac.du
Class DefaultBrokerService

java.lang.Object
  extended by org.powertac.du.DefaultBrokerService
All Implemented Interfaces:
org.powertac.common.interfaces.BootstrapDataCollector, org.powertac.common.interfaces.InitializationService

@Service
public class DefaultBrokerService
extends Object
implements org.powertac.common.interfaces.BootstrapDataCollector, org.powertac.common.interfaces.InitializationService

Default broker implementation. We do the implementation in a service, because the default broker is a singleton and it's convenient. The actual Broker instance is implemented in an inner class. Note that this is not a type of TimeslotPhaseProcessor. It's a broker, and so it runs after the last message of the timeslot goes out, the TimeslotComplete message. As implemented, it runs in the message-sending thread. If this turns out to cause problems with real brokers, it could run in its own thread.

Author:
John Collins

Constructor Summary
DefaultBrokerService()
          Default constructor, called once when the server starts, before any application-specific initialization has been done.
 
Method Summary
 void activate()
          In each timeslot, we must trade in the wholesale market to satisfy the predicted load of our current customer base.
 List<Object> collectBootstrapData(int maxTimeslots)
          Collects and returns a list of messages representing collected customer demand, market price, and weather records for the bootstrap period.
 org.powertac.common.Broker createBroker(String username)
          Creates the internal Broker instance that can receive messages intended for local Brokers.
 double getBuyLimitPriceMax()
           
 double getBuyLimitPriceMin()
           
 double getConsumptionRate()
           
 org.powertac.du.DefaultBrokerService.LocalBroker getFace()
           
 double getInitialBidKWh()
           
 double getProductionRate()
           
 double getSellLimitPriceMax()
           
 double getSellLimitPriceMin()
           
 void handleMessage(org.powertac.common.CashPosition cp)
          CashPosition is the last message sent by Accounting.
 void handleMessage(org.powertac.common.msg.CustomerBootstrapData cbd)
          Handles CustomerBootstrapData by populating the customer model corresponding to the given customer and power type.
 void handleMessage(org.powertac.common.MarketTransaction tx)
          Receives a new MarketTransaction.
 void handleMessage(org.powertac.common.TariffTransaction ttx)
          Handles a TariffTransaction.
 void handleMessage(org.powertac.common.msg.TimeslotComplete tc)
          TimeslotComplete is the last message sent in each timeslot.
 void handleMessage(org.powertac.common.WeatherReport report)
          Receives a new WeatherReport.
 String initialize(org.powertac.common.Competition competition, List<String> completedInits)
          Called by initialization service once at the beginning of each game.
 void receiveBrokerMessage(Object msg)
          Incoming messages for brokers include: TariffTransaction tells us about customer subscription activity and power usage, MarketPosition tells us how much power we have bought or sold in a given timeslot, TimeslotComplete that tell us it's time to send in our bids/asks along with a number of other message types that we can safely ignore.
 void setBuyLimitPriceMax(double buyLimitPriceMax)
           
 void setBuyLimitPriceMin(double buyLimitPriceMin)
           
 void setConsumptionRate(double defaultConsumptionRate)
           
 void setDefaults()
           
 void setInitialBidKWh(double initialBidKWh)
           
 void setProductionRate(double defaultProductionRate)
           
 void setSellLimitPriceMax(double sellLimitPriceMax)
           
 void setSellLimitPriceMin(double sellLimitPriceMin)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultBrokerService

public DefaultBrokerService()
Default constructor, called once when the server starts, before any application-specific initialization has been done.

Method Detail

setDefaults

public void setDefaults()
Specified by:
setDefaults in interface org.powertac.common.interfaces.InitializationService

initialize

public String initialize(org.powertac.common.Competition competition,
                         List<String> completedInits)
Called by initialization service once at the beginning of each game. Configures parameters, sets up and publishes default tariffs.

Specified by:
initialize in interface org.powertac.common.interfaces.InitializationService

createBroker

public org.powertac.common.Broker createBroker(String username)
Creates the internal Broker instance that can receive messages intended for local Brokers. It would be a Really Bad Idea to call this at any time other than during the pre-game phase of a competition, because this method does not register the broker in the BrokerRepo, which is a requirement to see the messages.


getFace

public org.powertac.du.DefaultBrokerService.LocalBroker getFace()

activate

public void activate()
In each timeslot, we must trade in the wholesale market to satisfy the predicted load of our current customer base.


receiveBrokerMessage

public void receiveBrokerMessage(Object msg)
Incoming messages for brokers include: along with a number of other message types that we can safely ignore.


handleMessage

public void handleMessage(org.powertac.common.TariffTransaction ttx)
Handles a TariffTransaction. We only care about certain types: PRODUCE, CONSUME, SIGNUP, and WITHDRAW.


handleMessage

public void handleMessage(org.powertac.common.WeatherReport report)
Receives a new WeatherReport. We only care about this if in bootstrap mode, in which case we simply store it in the bootstrap dataset.


handleMessage

public void handleMessage(org.powertac.common.MarketTransaction tx)
Receives a new MarketTransaction. In bootstrapMode, we need to record these as they arrive in order to be able to compute delivered price of power purchased in the wholesale market. Note that this computation will ignore balancing cost. This is intentional.


handleMessage

public void handleMessage(org.powertac.common.msg.CustomerBootstrapData cbd)
Handles CustomerBootstrapData by populating the customer model corresponding to the given customer and power type. This gives the broker a running start.


handleMessage

public void handleMessage(org.powertac.common.CashPosition cp)
CashPosition is the last message sent by Accounting. In bootstrapMode, this is when we collect customer usage data.


handleMessage

public void handleMessage(org.powertac.common.msg.TimeslotComplete tc)
TimeslotComplete is the last message sent in each timeslot. This is normally when any broker would submit its bids, so that's when the DefaultBroker will do it. Any earlier, and we will find ourselves unable to trade in the furthest slot, because it will not yet have been enabled.


collectBootstrapData

public List<Object> collectBootstrapData(int maxTimeslots)
Collects and returns a list of messages representing collected customer demand, market price, and weather records for the bootstrap period. Note that the customer and weather info is flattened.

Specified by:
collectBootstrapData in interface org.powertac.common.interfaces.BootstrapDataCollector

getConsumptionRate

public double getConsumptionRate()

setConsumptionRate

@ConfigurableValue(valueType="Double",
                   description="Fixed price/kwh for default consumption tariff")
public void setConsumptionRate(double defaultConsumptionRate)

getProductionRate

public double getProductionRate()

setProductionRate

@ConfigurableValue(valueType="Double",
                   description="Fixed price/kwh for default production tariff")
public void setProductionRate(double defaultProductionRate)

getInitialBidKWh

public double getInitialBidKWh()

setInitialBidKWh

@ConfigurableValue(valueType="Double",
                   description="Quantity to buy in day-ahead market before seeing actual customer data")
public void setInitialBidKWh(double initialBidKWh)

getBuyLimitPriceMax

public double getBuyLimitPriceMax()

setBuyLimitPriceMax

@ConfigurableValue(valueType="Double",
                   description="Initial limit price/mwh for bids in day-ahead market")
public void setBuyLimitPriceMax(double buyLimitPriceMax)

getBuyLimitPriceMin

public double getBuyLimitPriceMin()

setBuyLimitPriceMin

@ConfigurableValue(valueType="Double",
                   description="Final limit price/mwh for bids in day-ahead market")
public void setBuyLimitPriceMin(double buyLimitPriceMin)

getSellLimitPriceMax

public double getSellLimitPriceMax()

setSellLimitPriceMax

@ConfigurableValue(valueType="Double",
                   description="Initial limit price/mwh for asks in day-ahead market")
public void setSellLimitPriceMax(double sellLimitPriceMax)

getSellLimitPriceMin

public double getSellLimitPriceMin()

setSellLimitPriceMin

@ConfigurableValue(valueType="Double",
                   description="Final limit price/mwh for asks in day-ahead market")
public void setSellLimitPriceMin(double sellLimitPriceMin)


Copyright © 2012 Power TAC. All Rights Reserved.