|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Simulation
A class to run the lunch simulation problem. This is an abstract class, because we are going to run two different seating schemes: each of these schemes will be implemented by the classes Simulation1 and Simulation2
Clock
,
Event
,
Party
,
Simulation1
,
Simulation2
,
SimulationStats
Field Summary | |
static int |
MAX_PARTY_SIZE
The maximum possible size of a party |
static int |
MIN_PARTY_SIZE
The minimum possible size of a party |
static int[] |
PARTY_SIZES
An array of all of the various party sizes. |
protected Clock |
schedule
The schedule to which all events will be added and extracted |
protected SimulationStats |
stats
Keeps track of all of the statistics for this Simulation |
static int[] |
TABLE_COUNTS
An array containing the the number of tables for the index's size. |
protected int[] |
tablesTaken
An array of size MAX_PARTY_SIZE + 1 which keeps track of how many tables have been taken for the index's size. |
protected static EventTimer |
timer
The object used to get the times for all of the events |
Constructor Summary | |
protected |
Simulation(long seed1,
long seed2)
Creates a new lunch Simulation: initializing tablesTaken, and adding all arrival events to the schedule. |
Method Summary | |
protected void |
addArrivals()
Adds all of the arrivals to the schedule in a uniform fashion. |
protected abstract void |
addToQueue(Party p)
If a party is not able to find a table to be seated at, they will be inserted into some queue. |
protected double |
arrivalTime()
Returns a arrival time. |
protected double |
eatingTime()
Returns an eating time. |
protected abstract int |
findTable(Party p)
A method to choose the table the party will sit at. |
protected abstract void |
freeTable(int tableSize)
Frees a table of the specified size. |
protected boolean |
isFree(int tableSize)
Checks is there is a table of the specified size available for immediate seating. |
protected void |
processArrival(ArrivalEvent e)
A method to process an arrival event. |
protected void |
processDeparture(DepartureEvent e)
A method to process a departure event. |
protected void |
processEvent(Event e)
This method forwards an event to either processArrival or processDeparture, depending upon the type of the event. |
SimulationStats |
runSimulation()
Processes events until there are no more events to process, returning a summary of the simulation statistics |
protected void |
seatAtTable(Party p,
int tableNum)
Seats a party at a certain table size. |
Methods inherited from class java.lang.Object |
|
Field Detail |
public static final int MAX_PARTY_SIZE
public static final int MIN_PARTY_SIZE
public static final int[] PARTY_SIZES
public static final int[] TABLE_COUNTS
protected Clock schedule
protected static EventTimer timer
protected int[] tablesTaken
protected SimulationStats stats
Constructor Detail |
protected Simulation(long seed1, long seed2)
seed1
- a value used to seed the EventTimerseed2
- a value used to seed the EventTimerMethod Detail |
protected void addArrivals()
public SimulationStats runSimulation()
SimulationStats
protected void processEvent(Event e)
e
- the event to be processed (forwarded)protected void processArrival(ArrivalEvent e)
e
- the arrival event to be processedprotected abstract int findTable(Party p)
p
- the party for which a table is to be foundprotected abstract void addToQueue(Party p)
p
- the party that has to wait for a table to open up.protected void seatAtTable(Party p, int tableNum)
protected void processDeparture(DepartureEvent e)
e
- the departure event to be processedprotected abstract void freeTable(int tableSize)
tableSize
- the size of the table to be freedprotected boolean isFree(int tableSize)
tableSize
- the size of the table to be queriedprotected double eatingTime()
protected double arrivalTime()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |