edu.cuny.cat.market.matching
Class LazyMaxVolumeShoutEngine

java.lang.Object
  extended by edu.cuny.cat.market.AuctioneerPolicy
      extended by edu.cuny.cat.market.matching.ShoutEngine
          extended by edu.cuny.cat.market.matching.LazyMaxVolumeShoutEngine
All Implemented Interfaces:
AuctionEventListener, edu.cuny.config.param.Parameterizable, edu.cuny.obj.Resetable
Direct Known Subclasses:
ThetaShoutEngine

public class LazyMaxVolumeShoutEngine
extends ShoutEngine

This class provides a matching policy that differs from FourHeapShoutEngine in the sense that it maximizes the matching quantity by pairing high intra-marginal shouts with extra-marginal shouts.

Due to performance consideration, this engine does not maintain a matched set of shouts for the moment.

Version:
$Revision: 1.14 $
Author:
Jinzhong Niu

Field Summary
protected  edu.cuny.struct.SortedTreeList<Shout> asks
          asks in ascending order
protected  edu.cuny.struct.SortedTreeList<Shout> bids
          bids in ascending order
protected  edu.cuny.struct.SortedTreeList<Shout> bIn
          Matched bids in ascending order
protected  edu.cuny.struct.SortedTreeList<Shout> bOut
          Unmatched bids in ascending order
protected  int matchingVolume
          the matching quantity with the current supply and demand
protected  edu.cuny.struct.SortedTreeList<Shout> sIn
          Matched asks in ascending order
protected  edu.cuny.struct.SortedTreeList<Shout> sOut
          Unmatched asks in ascending order
protected  edu.cuny.random.Uniform uniform
          used to randomize the order of matching pairs of shouts
 
Fields inherited from class edu.cuny.cat.market.matching.ShoutEngine
AscendingOrder, DescendingOrder
 
Fields inherited from class edu.cuny.cat.market.AuctioneerPolicy
auctioneer
 
Constructor Summary
LazyMaxVolumeShoutEngine()
           
 
Method Summary
 java.util.Iterator<Shout> ascendingAskIterator()
           
 java.util.Iterator<Shout> askIterator()
           
 java.util.Iterator<Shout> bidIterator()
           
 int calculateMatchingQuantity()
           
 java.util.Iterator<Shout> descendingBidIterator()
           
protected  void distributeShouts(int quantity, edu.cuny.struct.SortedTreeList<Shout> list, edu.cuny.struct.SortedTreeList<Shout> in, edu.cuny.struct.SortedTreeList<Shout> out, boolean fromTail)
           
protected  void distributeShoutsFromHead(int quantity, edu.cuny.struct.SortedTreeList<Shout> list, edu.cuny.struct.SortedTreeList<Shout> in, edu.cuny.struct.SortedTreeList<Shout> out)
           
protected  void distributeShoutsFromTail(int quantity, edu.cuny.struct.SortedTreeList<Shout> list, edu.cuny.struct.SortedTreeList<Shout> in, edu.cuny.struct.SortedTreeList<Shout> out)
           
 Shout getHighestMatchedAsk()
          Get the highest matched ask.
 Shout getHighestUnmatchedBid()
          Get the highest unmatched bid in the auction.
 Shout getLowestMatchedBid()
          Get the lowest matched bid in the auction.
 Shout getLowestUnmatchedAsk()
          Get the lowest unmatched ask.
 org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getMatchedAsks()
           
 org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getMatchedBids()
           
 int getMatchedVolume()
           
 int getNumOfMatchedAsks()
           
 int getNumOfMatchedBids()
           
 int getNumOfUnmatchedAsks()
           
 int getNumOfUnmatchedBids()
           
 org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getUnmatchedAsks()
           
 org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getUnmatchedBids()
           
 int getUnmatchedDemand()
           
 int getUnmatchedSupply()
           
 java.util.Iterator<Shout> matchedAskIterator()
           
 java.util.Iterator<Shout> matchedBidIterator()
           
 java.util.List<Shout> matchShouts()
           Return a list of matched bids and asks.
 void newShout(Shout shout)
           
 void prettyPrint(java.lang.String title, java.util.List<Shout> shouts)
           
 void printState()
          Log the current status of the auction.
protected  void randomizeMatches(java.util.List<Shout> result)
          randomizes the bid-ask pairs in the given list.
 void removeShout(Shout shout)
           
 void reset()
          resets the state to be the same as the policy is created and initialized.
 java.lang.String toString()
           
protected  void updateMatchedShouts()
           
 
Methods inherited from class edu.cuny.cat.market.matching.ShoutEngine
getMatchedShouts
 
Methods inherited from class edu.cuny.cat.market.AuctioneerPolicy
eventOccurred, getAuctioneer, initialize, setAuctioneer, setup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

asks

protected edu.cuny.struct.SortedTreeList<Shout> asks
asks in ascending order


bids

protected edu.cuny.struct.SortedTreeList<Shout> bids
bids in ascending order


bIn

protected edu.cuny.struct.SortedTreeList<Shout> bIn
Matched bids in ascending order


bOut

protected edu.cuny.struct.SortedTreeList<Shout> bOut
Unmatched bids in ascending order


sIn

protected edu.cuny.struct.SortedTreeList<Shout> sIn
Matched asks in ascending order


sOut

protected edu.cuny.struct.SortedTreeList<Shout> sOut
Unmatched asks in ascending order


uniform

protected edu.cuny.random.Uniform uniform
used to randomize the order of matching pairs of shouts


matchingVolume

protected int matchingVolume
the matching quantity with the current supply and demand

Constructor Detail

LazyMaxVolumeShoutEngine

public LazyMaxVolumeShoutEngine()
Method Detail

reset

public void reset()
Description copied from class: AuctioneerPolicy
resets the state to be the same as the policy is created and initialized.

Specified by:
reset in interface edu.cuny.obj.Resetable
Overrides:
reset in class AuctioneerPolicy

removeShout

public void removeShout(Shout shout)
Specified by:
removeShout in class ShoutEngine

newShout

public void newShout(Shout shout)
              throws DuplicateShoutException
Specified by:
newShout in class ShoutEngine
Throws:
DuplicateShoutException

updateMatchedShouts

protected void updateMatchedShouts()

distributeShoutsFromTail

protected void distributeShoutsFromTail(int quantity,
                                        edu.cuny.struct.SortedTreeList<Shout> list,
                                        edu.cuny.struct.SortedTreeList<Shout> in,
                                        edu.cuny.struct.SortedTreeList<Shout> out)

distributeShoutsFromHead

protected void distributeShoutsFromHead(int quantity,
                                        edu.cuny.struct.SortedTreeList<Shout> list,
                                        edu.cuny.struct.SortedTreeList<Shout> in,
                                        edu.cuny.struct.SortedTreeList<Shout> out)

distributeShouts

protected void distributeShouts(int quantity,
                                edu.cuny.struct.SortedTreeList<Shout> list,
                                edu.cuny.struct.SortedTreeList<Shout> in,
                                edu.cuny.struct.SortedTreeList<Shout> out,
                                boolean fromTail)

calculateMatchingQuantity

public int calculateMatchingQuantity()
Returns:
the matching quantity given the current supply and demand

matchShouts

public java.util.List<Shout> matchShouts()

Return a list of matched bids and asks. The list is of the form


( b0, a0, b1, a1 .. bn, an )

where bi is the ith bid and a0 is the ith ask. A typical auctioneer would clear by matching bi with ai for all i at some price.

Specified by:
matchShouts in class ShoutEngine

randomizeMatches

protected void randomizeMatches(java.util.List<Shout> result)
randomizes the bid-ask pairs in the given list.

Parameters:
result -

askIterator

public java.util.Iterator<Shout> askIterator()
Specified by:
askIterator in class ShoutEngine
Returns:
an iterator that non-destructively iterates over every ask in the auction (both matched and unmatched).

ascendingAskIterator

public java.util.Iterator<Shout> ascendingAskIterator()
Specified by:
ascendingAskIterator in class ShoutEngine
Returns:
an iterator that non-destructively iterates over every ask in the auction (both matched and unmatched) in ascending order

bidIterator

public java.util.Iterator<Shout> bidIterator()
Specified by:
bidIterator in class ShoutEngine
Returns:
an iterator that non-destructively iterates over every bid in the auction (both matched and unmatched).

descendingBidIterator

public java.util.Iterator<Shout> descendingBidIterator()
Specified by:
descendingBidIterator in class ShoutEngine
Returns:
an iterator that non-destructively iterates over every bid in the auction (both matched and unmatched) in descending order.

matchedAskIterator

public java.util.Iterator<Shout> matchedAskIterator()
Specified by:
matchedAskIterator in class ShoutEngine
Returns:
an iterator that non-destructively iterates over every matched ask in the auction in ascending order.

matchedBidIterator

public java.util.Iterator<Shout> matchedBidIterator()
Specified by:
matchedBidIterator in class ShoutEngine
Returns:
an iterator that non-destructively iterates over every matched bid in the auction in descending order.

getLowestUnmatchedAsk

public Shout getLowestUnmatchedAsk()
Description copied from class: ShoutEngine
Get the lowest unmatched ask.

Specified by:
getLowestUnmatchedAsk in class ShoutEngine

getHighestMatchedAsk

public Shout getHighestMatchedAsk()
Description copied from class: ShoutEngine
Get the highest matched ask.

Specified by:
getHighestMatchedAsk in class ShoutEngine

getHighestUnmatchedBid

public Shout getHighestUnmatchedBid()
Description copied from class: ShoutEngine
Get the highest unmatched bid in the auction.

Specified by:
getHighestUnmatchedBid in class ShoutEngine

getLowestMatchedBid

public Shout getLowestMatchedBid()
Description copied from class: ShoutEngine
Get the lowest matched bid in the auction.

Specified by:
getLowestMatchedBid in class ShoutEngine

getMatchedVolume

public int getMatchedVolume()
Specified by:
getMatchedVolume in class ShoutEngine
Returns:
matchingVolume.

getUnmatchedSupply

public int getUnmatchedSupply()
Specified by:
getUnmatchedSupply in class ShoutEngine

getUnmatchedDemand

public int getUnmatchedDemand()
Specified by:
getUnmatchedDemand in class ShoutEngine

getNumOfUnmatchedBids

public int getNumOfUnmatchedBids()
Specified by:
getNumOfUnmatchedBids in class ShoutEngine

getNumOfMatchedBids

public int getNumOfMatchedBids()
Specified by:
getNumOfMatchedBids in class ShoutEngine

getNumOfUnmatchedAsks

public int getNumOfUnmatchedAsks()
Specified by:
getNumOfUnmatchedAsks in class ShoutEngine

getNumOfMatchedAsks

public int getNumOfMatchedAsks()
Specified by:
getNumOfMatchedAsks in class ShoutEngine

getMatchedBids

public org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getMatchedBids()
Specified by:
getMatchedBids in class ShoutEngine

getUnmatchedBids

public org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getUnmatchedBids()
Specified by:
getUnmatchedBids in class ShoutEngine

getMatchedAsks

public org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getMatchedAsks()
Specified by:
getMatchedAsks in class ShoutEngine

getUnmatchedAsks

public org.apache.commons.collections15.buffer.PriorityBuffer<Shout> getUnmatchedAsks()
Specified by:
getUnmatchedAsks in class ShoutEngine

printState

public void printState()
Log the current status of the auction.

Specified by:
printState in class ShoutEngine

prettyPrint

public void prettyPrint(java.lang.String title,
                        java.util.List<Shout> shouts)

toString

public java.lang.String toString()
Overrides:
toString in class AuctioneerPolicy