Class SimulationStats

java.lang.Object
  |
  +--SimulationStats

public class SimulationStats
extends java.lang.Object

A class which hold all of the statistics for a Simulation or set of simulations. Provides ways to store the waiting time for all parties, as well as methods to display the results of the experiments

See Also:
Tester, Simulation

Field Summary
private  int[] counts
          How many of each party size has finished eating.
private static java.text.DecimalFormat formatter
          Used for pretty printing.
private  int runCount
          The number of Simulations this SimulationStats is keeping track of
private  double runTime
          The total run time for all Simulations this SimulationStats is keeping track of
private  double[][] waitTimes
          The waiting times for the various parties.
 
Constructor Summary
SimulationStats(int[] partyCounts)
          Initializes all stat keepers based upon expected party sizes
SimulationStats(SimulationStats set1, SimulationStats set2)
          Creates a new set of SimulationStats by combining two sets of stats.
 
Method Summary
 void addRunTime(double time)
          Adds the total running time for a Simulation to this set of stats
 void addWaitTime(double time, int partySize)
          Adds a new waiting time for a specified party size to the statistics.
private  double average(double[] times, int count)
          Computes and returns the average of all values in an array
private  int countNonZero(double[] times)
          Counts and returns the number of non-zero elements in a specified array
private  double[] expand(double[] values, int multiplier)
          Converts an array of values into an expanded array of values by duplicating each value in the array multiplier number of times.
 java.lang.String getHeader()
          Returns a header which shows the meaning of all output values
 double getRunTime()
          Returns the run times for this set of statistics
private  void insert(double value, double[] values, int maxIndex)
          Inserts a value into an array of values, such that the array remains in sorted order.
private  double median(double[] values, int count)
          Computes and returns the median value in a sorted array of values
private  double[] merge(double[] vals1, int counts1, double[] vals2, int counts2)
          Merges two arrays, already assumed to be in sorted order, into a larger array in sorted order.
 java.lang.String toString()
          Returns a summary of all statistics in this set of stats
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

waitTimes

private double[][] waitTimes
The waiting times for the various parties. Each row number corresponds to the party size, and the column corresponds to the waiting time. Note that each row is stored in sorted order

counts

private int[] counts
How many of each party size has finished eating. The row number corresponds to the party size

runCount

private int runCount
The number of Simulations this SimulationStats is keeping track of

runTime

private double runTime
The total run time for all Simulations this SimulationStats is keeping track of

formatter

private static java.text.DecimalFormat formatter
Used for pretty printing. Shows up to two decimal places (initialized with "#.##")
Constructor Detail

SimulationStats

public SimulationStats(int[] partyCounts)
Initializes all stat keepers based upon expected party sizes
Parameters:
partyCounts - the number of parties of each size expected. The index number corresponds to the party size

SimulationStats

public SimulationStats(SimulationStats set1,
                       SimulationStats set2)
Creates a new set of SimulationStats by combining two sets of stats. It is assumed that both sets of stats contained the same range of party sizes.
Parameters:
set1 - the first set of stats
set2 - the second set of stats
Method Detail

merge

private double[] merge(double[] vals1,
                       int counts1,
                       double[] vals2,
                       int counts2)
Merges two arrays, already assumed to be in sorted order, into a larger array in sorted order.
Parameters:
vals1 - one set of values to merge
counts1 - the number of valid items in vals1. It is expected that 0 <= counts1 < vals1.length
vals2 - another set of values to merge
counts1 - the number of valid items in vals2. It is expected that 0 <= counts2 < vals2.length
Returns:
an array of size counts1 + counts 2 containing all of the values in vals1 and vals2

addWaitTime

public void addWaitTime(double time,
                        int partySize)
Adds a new waiting time for a specified party size to the statistics. It is assumed that the partySize is valid. It is important to note that if a party does not wait, you should still call this method; use a wait time of 0.
Parameters:
time - the amount of time the party waited
partySize - the size of the waiting party

addRunTime

public void addRunTime(double time)
Adds the total running time for a Simulation to this set of stats
Parameters:
time - the amount of time it took to run the simulation

getRunTime

public double getRunTime()
Returns the run times for this set of statistics

insert

private void insert(double value,
                    double[] values,
                    int maxIndex)
Inserts a value into an array of values, such that the array remains in sorted order.
Parameters:
value - the value to be inserted. the value will be inserted in the range [0, maxIndex]
values - an array of values in sorted order
maxIndex - the maximum possible index the value could be inserted

getHeader

public java.lang.String getHeader()
Returns a header which shows the meaning of all output values

toString

public java.lang.String toString()
Returns a summary of all statistics in this set of stats
Overrides:
toString in class java.lang.Object

expand

private double[] expand(double[] values,
                        int multiplier)
Converts an array of values into an expanded array of values by duplicating each value in the array multiplier number of times. That is, if the array initially contained:

and multiplier were 3, the returned array would be

Parameters:
values - an array of values to be expanded
multiplier - how many times to repeat each value in the array

countNonZero

private int countNonZero(double[] times)
Counts and returns the number of non-zero elements in a specified array

median

private double median(double[] values,
                      int count)
Computes and returns the median value in a sorted array of values
Parameters:
values - a sorted array of values
count - the number of valid entries in the array. It is expected that 0 < count < values.length

average

private double average(double[] times,
                       int count)
Computes and returns the average of all values in an array
Parameters:
values - the values in the array
count - the number of valid entries in the array. It is expected that 0 < count < values.length