de.upb.swtpra05.group03.shuttle
Class MarginController

java.lang.Object
  extended byde.upb.swtpra05.group03.shuttle.MarginController
All Implemented Interfaces:
MarginControllerInterface, Module, SentModule, ShuttleModule

public class MarginController
extends java.lang.Object
implements ShuttleModule, SentModule, MarginControllerInterface

Controls the margin and its selfadopting according to the success rate of the last offers.

Version:
$Revision: 1.3 $

Field Summary
protected static float DEFAULT_MARGIN
          default value
protected static float DEFAULT_MARGIN_STEP_DOWN
          default value
protected static float DEFAULT_MARGIN_STEP_UP
          default value
protected static float DEFAULT_MAX_OFFER_SUCCESS_RATE
          default value
protected static float DEFAULT_MIN_MARGIN
          default value
protected static float DEFAULT_MIN_OFFER_SUCCESS_RATE
          default value
protected static int DEFAULT_OBSERVATION_RATE
          default observation rate
protected static boolean DEFAULT_SELF_ADOPTING
          default value
protected static float FIRST_ORDER_MARGIN
          margin to get the first order
protected  boolean firstOrderMargin
          always return FIRST_ORDER_MARGIN if we havn't any order before
private static java.util.logging.Logger log
          Logger for debugging
protected  float margin
          current margin used to calculate an offer
protected  int marginStepCounter
          counts relative how often the margin is in- decreased
protected  float marginStepDown
          the step how much to decrease margin
protected  float marginStepUp
          the step how much to increase margin
protected  float maxOfferSuccessRate
          if offerSuccessRate is greater than this the margin will be increased
protected  float minMargin
          minimal margin, used for selfAdopting of margin
protected  float minOfferSuccessRate
          if offerSuccessRate is lower than this the margin will be decreased
protected  int observationRate
          The Rate how many Offers are observed
protected  java.util.LinkedList offerList
          This list contains the success of the last offers.
protected  float offerSuccessRate
          the offerSuccessRate
protected  boolean selfAdopting
          flag for self adopting of margin
protected static de.upb.swtpra.kernel.id.OrderID WON_ID
          The WON_ID is placed at the location where the orderID of an order was that is won
 
Constructor Summary
MarginController()
          Constructor
 
Method Summary
protected  void assignOrder(de.upb.swtpra.kernel.message.AssignOrder msg)
          If an offer is successfull, this method is called and it replaces the entry in the Queue so that the offer is signed as successfull
protected  void checkSuccessRate()
          Checks the SuccessRate and adpats the margin if necessary
protected  int countWonOffers()
          counts how often a value is present in the queue
 float getMargin()
          Gets the current margin to calculate an offer
 int getMarginStepCounter()
           
 float getMinMargin()
           
 void init(ModuleContainerInterface container)
          Initializes this module.
 boolean isSelfAdopting()
           
protected  void makeOffer(de.upb.swtpra.kernel.message.MakeOffer msg)
          Reacts on MakeOffer messages to be send by the shuttle by adjusting the offerList.
 float marginStep()
           
 void newMessageReceived(de.upb.swtpra.kernel.message.Message msg)
          React on the received message of the shuttle or not.
 void newMessageSent(de.upb.swtpra.kernel.message.Message msg)
          React on the message sent by the shuttle or not.
protected  void newShuttleParams(ApplyNewShuttleParamsMessage paramsMsg)
          updates MinMargin, MarginStep, Margin & selfAdopting if an ApplyNewShuttleParamsMessage is received
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MARGIN

protected static final float DEFAULT_MARGIN
default value

See Also:
Constant Field Values

DEFAULT_SELF_ADOPTING

protected static final boolean DEFAULT_SELF_ADOPTING
default value

See Also:
Constant Field Values

DEFAULT_MIN_MARGIN

protected static final float DEFAULT_MIN_MARGIN
default value

See Also:
Constant Field Values

DEFAULT_MARGIN_STEP_UP

protected static final float DEFAULT_MARGIN_STEP_UP
default value

See Also:
Constant Field Values

DEFAULT_MARGIN_STEP_DOWN

protected static final float DEFAULT_MARGIN_STEP_DOWN
default value

See Also:
Constant Field Values

DEFAULT_MIN_OFFER_SUCCESS_RATE

protected static final float DEFAULT_MIN_OFFER_SUCCESS_RATE
default value

See Also:
Constant Field Values

DEFAULT_MAX_OFFER_SUCCESS_RATE

protected static final float DEFAULT_MAX_OFFER_SUCCESS_RATE
default value

See Also:
Constant Field Values

DEFAULT_OBSERVATION_RATE

protected static final int DEFAULT_OBSERVATION_RATE
default observation rate

See Also:
Constant Field Values

FIRST_ORDER_MARGIN

protected static final float FIRST_ORDER_MARGIN
margin to get the first order

See Also:
Constant Field Values

marginStepCounter

protected int marginStepCounter
counts relative how often the margin is in- decreased


log

private static final java.util.logging.Logger log
Logger for debugging


margin

protected float margin
current margin used to calculate an offer


selfAdopting

protected boolean selfAdopting
flag for self adopting of margin


minMargin

protected float minMargin
minimal margin, used for selfAdopting of margin


marginStepUp

protected float marginStepUp
the step how much to increase margin


marginStepDown

protected float marginStepDown
the step how much to decrease margin


offerSuccessRate

protected float offerSuccessRate
the offerSuccessRate


minOfferSuccessRate

protected float minOfferSuccessRate
if offerSuccessRate is lower than this the margin will be decreased


maxOfferSuccessRate

protected float maxOfferSuccessRate
if offerSuccessRate is greater than this the margin will be increased


observationRate

protected int observationRate
The Rate how many Offers are observed


offerList

protected java.util.LinkedList offerList
This list contains the success of the last offers.


WON_ID

protected static final de.upb.swtpra.kernel.id.OrderID WON_ID
The WON_ID is placed at the location where the orderID of an order was that is won


firstOrderMargin

protected boolean firstOrderMargin
always return FIRST_ORDER_MARGIN if we havn't any order before

Constructor Detail

MarginController

public MarginController()
Constructor

Method Detail

init

public void init(ModuleContainerInterface container)
Description copied from interface: Module
Initializes this module. References to other modules should be set here to avoid circle dependencies.

Specified by:
init in interface Module
Parameters:
container - The module manager which contain all modules

newMessageReceived

public void newMessageReceived(de.upb.swtpra.kernel.message.Message msg)
Description copied from interface: ShuttleModule
React on the received message of the shuttle or not.

Specified by:
newMessageReceived in interface ShuttleModule
Parameters:
msg - The received message of the shuttle

newMessageSent

public void newMessageSent(de.upb.swtpra.kernel.message.Message msg)
Description copied from interface: SentModule
React on the message sent by the shuttle or not.

Specified by:
newMessageSent in interface SentModule
Parameters:
msg - The message sent by the shuttle

newShuttleParams

protected void newShuttleParams(ApplyNewShuttleParamsMessage paramsMsg)
updates MinMargin, MarginStep, Margin & selfAdopting if an ApplyNewShuttleParamsMessage is received

Parameters:
paramsMsg - ApplyNewShuttleParamsMessage

getMargin

public float getMargin()
Description copied from interface: MarginControllerInterface
Gets the current margin to calculate an offer

Specified by:
getMargin in interface MarginControllerInterface
Returns:
The margin to calculate an offer

makeOffer

protected void makeOffer(de.upb.swtpra.kernel.message.MakeOffer msg)
Reacts on MakeOffer messages to be send by the shuttle by adjusting the offerList.

Parameters:
msg - The MakeOffer message

assignOrder

protected void assignOrder(de.upb.swtpra.kernel.message.AssignOrder msg)
If an offer is successfull, this method is called and it replaces the entry in the Queue so that the offer is signed as successfull

Parameters:
msg - msg that contains the id of the order that has been won

checkSuccessRate

protected void checkSuccessRate()
Checks the SuccessRate and adpats the margin if necessary


countWonOffers

protected int countWonOffers()
counts how often a value is present in the queue

Returns:
count Frequency of value

getMinMargin

public float getMinMargin()
Returns:
minMargin

isSelfAdopting

public boolean isSelfAdopting()
Returns:
selfAdopting

marginStep

public float marginStep()
Returns:
marginStep

getMarginStepCounter

public int getMarginStepCounter()
Specified by:
getMarginStepCounter in interface MarginControllerInterface
Returns:
marginStepCounter