Class Simulation2

java.lang.Object
  |
  +--Simulation
        |
        +--Simulation2

public class Simulation2
extends Simulation


Field Summary
private  java.util.Vector waiting
          Holds all waiting parties.
 
Fields inherited from class Simulation
MAX_PARTY_SIZE, MIN_PARTY_SIZE, PARTY_SIZES, schedule, stats, TABLE_COUNTS, tablesTaken, timer
 
Constructor Summary
Simulation2(long seed1, long seed2)
          Creates a new instance of the simulation.
 
Method Summary
protected  void addToQueue(Party p)
          If a table is not available for the party, the party will be added to this "queue".
protected  int findTable(Party p)
          Attempts to find a table for the specified party.
protected  void freeTable(int tableSize)
          Frees a table of a specific size.
 
Methods inherited from class Simulation
addArrivals, arrivalTime, eatingTime, isFree, processArrival, processDeparture, processEvent, runSimulation, seatAtTable
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

waiting

private java.util.Vector waiting
Holds all waiting parties. A Vector is used as it is more searchable than a Queue: we may not be seating the party that has been waiting the longest, so we need to be able to access internal elements
Constructor Detail

Simulation2

public Simulation2(long seed1,
                   long seed2)
Creates a new instance of the simulation. Also initializes the "queue" for people waiting for tables, and initializes the EventTimer with the specified seeds.
Parameters:
seed1 - a seed to initialize the EventTimer
seed2 - a seed to initialize the EventTimer
Method Detail

findTable

protected int findTable(Party p)
Attempts to find a table for the specified party. Checks to see if a table for this party is available. The table size may be larger than the size of the party. If there is no table available, -1 is returned.
Parameters:
p - the party to be seated
Returns:
the size of the table the party will be seated at; -1 if there is no table available
Overrides:
findTable in class Simulation

addToQueue

protected void addToQueue(Party p)
If a table is not available for the party, the party will be added to this "queue". This is a single queue which holds all waiting parties in the order in which they arrived
Parameters:
p - the party to be added to the "queue"
Overrides:
addToQueue in class Simulation

freeTable

protected void freeTable(int tableSize)
Frees a table of a specific size. If there are other parties waiting for a table, this method also tries to seat a party. The party to be seated will be the party which has waited the longest and is able to fit at the recently freed table.
Parameters:
tableSize - the size of the table to be freed
Overrides:
freeTable in class Simulation