Package org.powertac.du
Class DefaultBrokerService
- java.lang.Object
-
- org.powertac.du.DefaultBrokerService
-
- All Implemented Interfaces:
BootstrapDataCollector
,InitializationService
@Service public class DefaultBrokerService extends Object implements BootstrapDataCollector, 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
Constructors Constructor Description DefaultBrokerService()
Default constructor, called once when the server starts, before any application-specific initialization has been done.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.Broker
createBroker(String username)
Creates the internal Broker instance that can receive messages intended for local Brokers.double
getBuyLimitPriceMax()
double
getBuyLimitPriceMin()
double
getConsumptionRate()
DefaultBroker
getFace()
double
getInitialBidKWh()
double
getProductionRate()
double
getSellLimitPriceMax()
double
getSellLimitPriceMin()
double
getStorageTariffMargin()
double
getStorageTariffValue()
void
handleMessage(CashPosition cp)
CashPosition is the last message sent by Accounting.void
handleMessage(MarketTransaction tx)
Receives a new MarketTransaction.void
handleMessage(BrokerAccept ba)
Handles the BrokerAccept message for completenessvoid
handleMessage(CustomerBootstrapData cbd)
Handles CustomerBootstrapData by populating the customer model corresponding to the given customer and power type.void
handleMessage(TimeslotComplete tc)
TimeslotComplete is the last message sent in each timeslot.void
handleMessage(TariffTransaction ttx)
Handles a TariffTransaction.void
handleMessage(WeatherReport report)
Receives a new WeatherReport.String
initialize(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
setInitialBidKWh(double initialBidKWh)
void
setProductionRate(double defaultProductionRate)
void
setSellLimitPriceMax(double sellLimitPriceMax)
void
setSellLimitPriceMin(double sellLimitPriceMin)
void
setStorageTariffMargin(double storageTariffMargin)
void
setStorageTariffValue(double storageTariffValue)
-
-
-
Method Detail
-
initialize
public String initialize(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 interfaceInitializationService
-
createBroker
public 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 DefaultBroker 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:- 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
-
handleMessage
public void handleMessage(BrokerAccept ba)
Handles the BrokerAccept message for completeness
-
handleMessage
public void handleMessage(TariffTransaction ttx)
Handles a TariffTransaction. We only care about certain types: PRODUCE, CONSUME, SIGNUP, and WITHDRAW.
-
handleMessage
public void handleMessage(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(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(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(CashPosition cp)
CashPosition is the last message sent by Accounting. In bootstrapMode, this is when we collect customer usage data.
-
handleMessage
public void handleMessage(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 interfaceBootstrapDataCollector
-
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)
-
getStorageTariffValue
public double getStorageTariffValue()
-
setStorageTariffValue
@ConfigurableValue(valueType="Double", description="Bootstrap value for regulation in storage tariff") public void setStorageTariffValue(double storageTariffValue)
-
getStorageTariffMargin
public double getStorageTariffMargin()
-
setStorageTariffMargin
@ConfigurableValue(valueType="Double", description="margin for regulation in storage tariff") public void setStorageTariffMargin(double storageTariffMargin)
-
-