aim4.im.v2i.policy
Class BasePolicy

java.lang.Object
  extended by aim4.im.v2i.policy.BasePolicy
All Implemented Interfaces:
BasePolicyCallback, ExtendedBasePolicyCallback, Policy

public final class BasePolicy
extends Object
implements Policy, ExtendedBasePolicyCallback

The base policy.


Nested Class Summary
static class BasePolicy.ProposalFilterResult
          The result of the standard proposal filter
static class BasePolicy.ReservationRecord
          The record of a reservation.
static class BasePolicy.ReserveParam
          The reservation parameter record generated by processProposals()
 
Field Summary
protected  V2IManagerCallback im
          The V2IManager of which this Policy is a part.
 
Constructor Summary
BasePolicy(V2IManagerCallback im, RequestHandler requestHandler)
          Create a new base policy for a given V2IManagerCallback (implemented by a V2IManager) and a request handler.
BasePolicy(V2IManagerCallback im, RequestHandler requestHandler, StatCollector<BasePolicy> statCollector)
          Create a new base policy for a given V2IManagerCallback (implemented by a V2IManager) and a request handler.
 
Method Summary
 void act(double timeStep)
          Give the policy a chance to do any processing it might need to do in order to respond to requests, if it hasn't responded to them already.
 BasePolicy.ReserveParam findReserveParam(Request msg, List<Request.Proposal> proposals)
          Compute the reservation parameter given the request message and a set of proposals.
 double getCurrentTime()
          Get the current time
 RequestHandler getRequestHandler()
          Get the request handler.
 ReservationGrid getReservationGrid()
          Get the reservation grid.
 StatCollector<BasePolicy> getStatCollector()
          Get the statistic collector.
 TrackModel getTrackMode()
          
 boolean hasReservation(int vin)
          Check whether the vehicle currently has a reservation.
 void processAwayMsg(Away msg)
          Submit an away message to the policy.
 void processCancelMsg(Cancel msg)
          Submit a cancel message to the policy.
 void processDoneMsg(Done msg)
          Submit a done message to the policy.
 void processV2IMessage(V2IMessage msg)
          Process a V2I message
 void sendComfirmMsg(int latestRequestId, BasePolicy.ReserveParam reserveParam)
          Send a confirm message
 void sendRejectMsg(int vin, int latestRequestId, Reject.Reason reason)
          Send a reject message
 void setRequestHandler(RequestHandler RequestHandler)
          Set the request handler.
 void setV2IManagerCallback(V2IManagerCallback im)
          Set the V2I manager call-back.
static BasePolicy.ProposalFilterResult standardProposalsFilter(List<Request.Proposal> proposals, double currentTime)
          Remove the proposals that are either too early or too late.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

im

protected V2IManagerCallback im
The V2IManager of which this Policy is a part.

Constructor Detail

BasePolicy

public BasePolicy(V2IManagerCallback im,
                  RequestHandler requestHandler)
Create a new base policy for a given V2IManagerCallback (implemented by a V2IManager) and a request handler.

Parameters:
im - the V2IManagerCallback for which this FCFSPolicy is being created
requestHandler - the request handler

BasePolicy

public BasePolicy(V2IManagerCallback im,
                  RequestHandler requestHandler,
                  StatCollector<BasePolicy> statCollector)
Create a new base policy for a given V2IManagerCallback (implemented by a V2IManager) and a request handler.

Parameters:
im - the V2IManagerCallback for which this FCFSPolicy is being created
requestHandler - the request handler
statCollector - the statistic collector
Method Detail

standardProposalsFilter

public static BasePolicy.ProposalFilterResult standardProposalsFilter(List<Request.Proposal> proposals,
                                                                      double currentTime)
Remove the proposals that are either too early or too late.

Parameters:
proposals - the list of proposals
currentTime - the current time
Returns:
the proposal filter result

setV2IManagerCallback

public void setV2IManagerCallback(V2IManagerCallback im)
Set the V2I manager call-back.

Specified by:
setV2IManagerCallback in interface Policy
Parameters:
im - the V2I manager's call-back

getRequestHandler

public RequestHandler getRequestHandler()
Get the request handler.

Returns:
the request handler.

setRequestHandler

public void setRequestHandler(RequestHandler RequestHandler)
Set the request handler.

Parameters:
RequestHandler - the request handler.

act

public void act(double timeStep)
Give the policy a chance to do any processing it might need to do in order to respond to requests, if it hasn't responded to them already. Only used for policies that don't respond immediately to requests.

Specified by:
act in interface Policy
Parameters:
timeStep - the size of the time step to simulate, in seconds

sendComfirmMsg

public void sendComfirmMsg(int latestRequestId,
                           BasePolicy.ReserveParam reserveParam)
Send a confirm message

Specified by:
sendComfirmMsg in interface BasePolicyCallback
Parameters:
latestRequestId - the latest request id of the vehicle
reserveParam - the reservation parameter

sendRejectMsg

public void sendRejectMsg(int vin,
                          int latestRequestId,
                          Reject.Reason reason)
Send a reject message

Specified by:
sendRejectMsg in interface BasePolicyCallback
Parameters:
vin - the VIN
latestRequestId - the latest request id of the vehicle
reason - the reason of rejection

findReserveParam

public BasePolicy.ReserveParam findReserveParam(Request msg,
                                                List<Request.Proposal> proposals)
Compute the reservation parameter given the request message and a set of proposals.

Specified by:
findReserveParam in interface BasePolicyCallback
Parameters:
msg - the request message
proposals - the set of proposals
Returns:
the reservation parameters; null if the reservation is infeasible.

getCurrentTime

public double getCurrentTime()
Get the current time

Specified by:
getCurrentTime in interface BasePolicyCallback
Returns:
the current time

getReservationGrid

public ReservationGrid getReservationGrid()
Get the reservation grid.

Specified by:
getReservationGrid in interface ExtendedBasePolicyCallback
Returns:
the reservation grid.

hasReservation

public boolean hasReservation(int vin)
Check whether the vehicle currently has a reservation.

Specified by:
hasReservation in interface BasePolicyCallback
Parameters:
vin - the VIN of the vehicle
Returns:
whether the vehicle currently has a reservation.

processV2IMessage

public void processV2IMessage(V2IMessage msg)
Process a V2I message

Specified by:
processV2IMessage in interface Policy
Parameters:
msg - the V2I message

processCancelMsg

public void processCancelMsg(Cancel msg)
Submit a cancel message to the policy.

Parameters:
msg - the cancel message

processDoneMsg

public void processDoneMsg(Done msg)
Submit a done message to the policy.

Parameters:
msg - the done message

processAwayMsg

public void processAwayMsg(Away msg)
Submit an away message to the policy.

Parameters:
msg - the away message

getStatCollector

public StatCollector<BasePolicy> getStatCollector()
Get the statistic collector.

Specified by:
getStatCollector in interface Policy
Returns:
the statistic collector

getTrackMode

public TrackModel getTrackMode()

Specified by:
getTrackMode in interface BasePolicyCallback


Copyright © 2011. All Rights Reserved.