uk.ac.liv.auction.agent
Class AbstractTradingAgent

java.lang.Object
  extended byuk.ac.liv.auction.agent.AbstractTradingAgent
All Implemented Interfaces:
AuctionEventListener, java.lang.Cloneable, Parameterizable, Prototypeable, Resetable, java.io.Serializable, TradingAgent
Direct Known Subclasses:
ElectricityTrader, ZITraderAgent

public abstract class AbstractTradingAgent
extends java.lang.Object
implements TradingAgent, AuctionEventListener, java.io.Serializable, Parameterizable, Prototypeable, java.lang.Cloneable

An abstract class representing a simple agent trading in a round-robin auction. Traders of this type deal in a single commodity for which they have a well-defined valuation.

Parameters

base.isseller
boolean
(is this agent a seller)
base.strategy
class
(the trading strategy to use)
base.initialstock
int >= 0
(the initial quantity of the commoditiy possessed by this agent)
base.initialfunds
double
(the initial funds)
base.valuer
class, inherits uk.ac.liv.auction.agent.Valuer
(the valuation policy to use)
base.group
int >= 0
(the group that this agent belongs to)

Version:
$Revision: 1.6 $
Author:
Steve Phelps
See Also:
RoundRobinAuction, Serialized Form

Field Summary
protected  Shout currentShout
          The current shout for this trader.
protected  double funds
          The amount of money this agent posseses.
protected  AgentGroup group
          The arbitrary grouping that this agent belongs to.
protected  long id
          Unique id for this trader.
protected  double initialFunds
          The initial amount of money for this agent
protected  int initialStock
          The initial stock of this agent
protected  boolean isSeller
          Flag indicating whether this trader is a seller or buyer.
protected  double lastProfit
          The profit made in the last round.
protected  boolean lastShoutAccepted
          Did the last shout we place in the auction result in a transaction?
static java.lang.String P_DEFAULT_STRATEGY
           
static java.lang.String P_GROUP
           
static java.lang.String P_INITIAL_FUNDS
           
static java.lang.String P_INITIAL_STOCK
           
static java.lang.String P_IS_SELLER
          Parameter names used when initialising from parameter db
static java.lang.String P_STRATEGY
           
static java.lang.String P_VALUER
           
protected  double profits
          The total profits to date
protected  int stock
          The number of items of stock this agent posseses.
protected  Strategy strategy
          The bidding strategy for this trader.
protected  ValuationPolicy valuer
          The valuer for this agent.
 
Constructor Summary
AbstractTradingAgent()
          Construct a truthful buyer with no money and no funds.
AbstractTradingAgent(int stock, double funds)
           
AbstractTradingAgent(int stock, double funds, double privateValue, boolean isSeller)
          Construct a trader with given stock level and funds.
AbstractTradingAgent(int stock, double funds, double privateValue, boolean isSeller, Strategy strategy)
           
 
Method Summary
abstract  boolean active()
          Determine whether or not this trader is active.
 void auctionClosed(AuctionEvent event)
           
 void auctionOpen(AuctionEvent event)
           
 int deliver(Auction auction, int quantity, double price)
          This method is invoked by a seller on a buyer when it is transfering stock
 int determineQuantity(Auction auction)
           
 void endOfDay(AuctionEvent event)
           
abstract  double equilibriumProfits(Auction auction, double equilibriumPrice, int quantity)
          Calculate the hypothetical surplus this agent will receive if the market had cleared uniformly at the specified equilibrium price and quantity.
 void eventOccurred(AuctionEvent event)
           
 Shout getCurrentShout()
           
 double getFunds()
           
 AgentGroup getGroup()
           
 long getId()
           
 double getLastProfit()
          Return the profit made in the most recent auction round.
 double getProfits()
           
 int getStock()
           
 Strategy getStrategy()
           
 double getValuation(Auction auction)
           
 ValuationPolicy getValuationPolicy()
           
 void giveFunds(AbstractTradingAgent seller, double amount)
           
 void informOfBuyer(Auction auction, TradingAgent buyer, double price, int quantity)
          This method is used by a buyer to notify a seller that one of its bids has been successful.
 void informOfSeller(Auction auction, Shout winningShout, TradingAgent seller, double price, int quantity)
          This method is used by an auction to notify a buyer that one of its bids has been successful.
protected  void initialise()
           
 boolean isBuyer()
           
 boolean isSeller()
           
 boolean lastShoutAccepted()
           
 void pay(double amount)
          This method is invoked by a buyer on a seller when it wishes to transfer funds.
 java.lang.Object protoClone()
           
 void purchaseFrom(Auction auction, AbstractTradingAgent seller, int quantity, double price)
           
 void requestShout(Auction auction)
          Place a shout in the auction as determined by our currently configured strategy.
 void reset()
          Reinitialise our state to the original settings.
 void roundClosed(AuctionEvent event)
           
 void setGroup(AgentGroup group)
           
 void setIsSeller(boolean isSeller)
           
 void setPrivateValue(double privateValue)
           
 void setStrategy(Strategy strategy)
           
 void setup(ec.util.ParameterDatabase parameters, ec.util.Parameter base)
          Initialise this object from a parameter database.
 void setValuationPolicy(ValuationPolicy valuer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stock

protected int stock
The number of items of stock this agent posseses.


initialStock

protected int initialStock
The initial stock of this agent


funds

protected double funds
The amount of money this agent posseses.


initialFunds

protected double initialFunds
The initial amount of money for this agent


valuer

protected ValuationPolicy valuer
The valuer for this agent.


id

protected long id
Unique id for this trader. Its used mainly for debugging purposes.


isSeller

protected boolean isSeller
Flag indicating whether this trader is a seller or buyer.


strategy

protected Strategy strategy
The bidding strategy for this trader. The default strategy is to bid truthfully for a single unit.


lastProfit

protected double lastProfit
The profit made in the last round.


profits

protected double profits
The total profits to date


lastShoutAccepted

protected boolean lastShoutAccepted
Did the last shout we place in the auction result in a transaction?


currentShout

protected Shout currentShout
The current shout for this trader.


group

protected AgentGroup group
The arbitrary grouping that this agent belongs to.


P_IS_SELLER

public static final java.lang.String P_IS_SELLER
Parameter names used when initialising from parameter db

See Also:
Constant Field Values

P_STRATEGY

public static final java.lang.String P_STRATEGY
See Also:
Constant Field Values

P_INITIAL_STOCK

public static final java.lang.String P_INITIAL_STOCK
See Also:
Constant Field Values

P_INITIAL_FUNDS

public static final java.lang.String P_INITIAL_FUNDS
See Also:
Constant Field Values

P_VALUER

public static final java.lang.String P_VALUER
See Also:
Constant Field Values

P_GROUP

public static final java.lang.String P_GROUP
See Also:
Constant Field Values

P_DEFAULT_STRATEGY

public static final java.lang.String P_DEFAULT_STRATEGY
See Also:
Constant Field Values
Constructor Detail

AbstractTradingAgent

public AbstractTradingAgent(int stock,
                            double funds,
                            double privateValue,
                            boolean isSeller)
Construct a trader with given stock level and funds.

Parameters:
stock - The quantity of stock for this trader.
funds - The amount of money for this trader.
privateValue - The private value of the commodity traded by this trader.
isSeller - Whether or not this trader is a seller.

AbstractTradingAgent

public AbstractTradingAgent(int stock,
                            double funds,
                            double privateValue,
                            boolean isSeller,
                            Strategy strategy)

AbstractTradingAgent

public AbstractTradingAgent(int stock,
                            double funds)

AbstractTradingAgent

public AbstractTradingAgent()
Construct a truthful buyer with no money and no funds.

Method Detail

setup

public void setup(ec.util.ParameterDatabase parameters,
                  ec.util.Parameter base)
Description copied from interface: Parameterizable
Initialise this object from a parameter database.

Specified by:
setup in interface Parameterizable

requestShout

public void requestShout(Auction auction)
Place a shout in the auction as determined by our currently configured strategy.

Specified by:
requestShout in interface TradingAgent
Parameters:
auction - The auction in which to trade

eventOccurred

public void eventOccurred(AuctionEvent event)
Specified by:
eventOccurred in interface AuctionEventListener

roundClosed

public void roundClosed(AuctionEvent event)

endOfDay

public void endOfDay(AuctionEvent event)

auctionOpen

public void auctionOpen(AuctionEvent event)

auctionClosed

public void auctionClosed(AuctionEvent event)

getCurrentShout

public Shout getCurrentShout()

purchaseFrom

public void purchaseFrom(Auction auction,
                         AbstractTradingAgent seller,
                         int quantity,
                         double price)

giveFunds

public void giveFunds(AbstractTradingAgent seller,
                      double amount)

pay

public void pay(double amount)
This method is invoked by a buyer on a seller when it wishes to transfer funds.

Parameters:
amount - The total amount of money to give to the seller

deliver

public int deliver(Auction auction,
                   int quantity,
                   double price)
This method is invoked by a seller on a buyer when it is transfering stock

Parameters:
quantity - The number of items of stock to transfer

getId

public long getId()

getFunds

public double getFunds()

getStock

public int getStock()

initialise

protected void initialise()

reset

public void reset()
Description copied from interface: Resetable
Reinitialise our state to the original settings.

Specified by:
reset in interface Resetable

getValuation

public double getValuation(Auction auction)

setPrivateValue

public void setPrivateValue(double privateValue)

isSeller

public boolean isSeller()
Specified by:
isSeller in interface TradingAgent

isBuyer

public boolean isBuyer()
Specified by:
isBuyer in interface TradingAgent

setStrategy

public void setStrategy(Strategy strategy)

setIsSeller

public void setIsSeller(boolean isSeller)

getStrategy

public Strategy getStrategy()

getLastProfit

public double getLastProfit()
Return the profit made in the most recent auction round. This can be used as, e.g. input to a re-inforcement learning algorithm.


getProfits

public double getProfits()

determineQuantity

public int determineQuantity(Auction auction)

protoClone

public java.lang.Object protoClone()
Specified by:
protoClone in interface Prototypeable

informOfSeller

public void informOfSeller(Auction auction,
                           Shout winningShout,
                           TradingAgent seller,
                           double price,
                           int quantity)
Description copied from interface: TradingAgent
This method is used by an auction to notify a buyer that one of its bids has been successful.

Specified by:
informOfSeller in interface TradingAgent
Parameters:
seller - The seller whose ask has been matched
price - The price of the goods as determined by the auction

informOfBuyer

public void informOfBuyer(Auction auction,
                          TradingAgent buyer,
                          double price,
                          int quantity)
Description copied from interface: TradingAgent
This method is used by a buyer to notify a seller that one of its bids has been successful.

Specified by:
informOfBuyer in interface TradingAgent

lastShoutAccepted

public boolean lastShoutAccepted()

getValuationPolicy

public ValuationPolicy getValuationPolicy()

setValuationPolicy

public void setValuationPolicy(ValuationPolicy valuer)

getGroup

public AgentGroup getGroup()

setGroup

public void setGroup(AgentGroup group)

equilibriumProfits

public abstract double equilibriumProfits(Auction auction,
                                          double equilibriumPrice,
                                          int quantity)
Calculate the hypothetical surplus this agent will receive if the market had cleared uniformly at the specified equilibrium price and quantity.


active

public abstract boolean active()
Determine whether or not this trader is active. Inactive traders do not place shouts in the auction, but do carry on learning through their strategy.

Returns:
true if the trader is active.