B.A.R.G.A.M.E.  v2.0
El Farol Bar Problem Implementation
 All Classes Namespaces Files Functions Variables Typedefs Defines
Public Member Functions | Protected Attributes
Town Class Reference

Town Class. More...

List of all members.

Public Member Functions

 Town ()
 Default Town Constructor.
 ~Town ()
 Town Destructor.
 Town (int number_bars, int population, int user_cap[], bool isPercent, int grpSize, int avgAge2, int dropValue))
 Constructor used in the application.
void createBars (int numbars, int user_cap[], bool isPercent)
 Initializes all bars to their respective "maxcapacity".
void createGroups (int population, int numGrps, int avgAge, int dropValue)
 Creates and initializes all Agents participating in a given simulation.
graphPtr turn ()
 Simulates a turn in the Simulation.
int * goingToBar ()
 Polls all Agents to get their consensus for a given turn.
int * getWinners (int a[256])
 Calculates winners for a given round.
void tellWinners (int a[256])
 Converts statistics into visually respresentable data for GUI to utilize.
void popcontrol ()
 Controls Population.

Protected Attributes

int numBars
 Number of Bars in Simulations Reference variable that is used for loops to iterate through all active bars in simulation.
int numPeeps
 Population in Simulation Reference variable that is used for loops to iterate through all Agents that are in the simulation profile.
Bar barNums [256]
 Bar holder array Array structure used for keeping track of status of a bar ( i.e. won/lost)
Agent people [16384]
 Agent holder array Array structure that holds all Agent objects for the simulation.
int * STM
 Short Term Memory Pointer to structure that keeps track of recent winnners in the simulation.
graphPtr Stuff
 Connecting Medium The connecting structure medium that allows communication between the frontend GUI interface and computational backend. Allows the update of statistics to applied to graphs and recording mechanism for later review.
int grpSize
 Group Size Variable that holds the max size that a group can be.
int numpeeps
 Number of Agnets Variable that holds population size.
int drop
 Alpha Value Variable that holds the alpha value which represents the threshold in which strategies are dropped inside groups.
Bar ** barnums
 Bar Array A double pointer holding all bars and how many people went to each bar.
list< Group * > groups
 Groups List that holds all groups.
list< Group * >::iterator it
 Group Iterator Iterator for group list.
Strategy ** topStrats
 Top Strategies Double pointer holding the top strategies.
int STI
 Short Term Index The index of which strategy is being used.
int avgAge
 Average Age Variable holds the average age.

Detailed Description

Town Class.

This class takes care of the initialization of all structures contained within a town (i.e. the Agents within the population and Bar Array structures) deriving its parameters from the GUI with which the client interacts and sets his/her desired simulation constraints.


Constructor & Destructor Documentation

Default Town Constructor.

Default constructor NOT utilized within code.

Town Destructor.

Destructor NOT explicitly utilized within code.

Town::Town ( int  number_bars,
int  population,
int  user_cap[],
bool  isPercent,
int  grpSize,
int  avgAge2,
int  dropValue 
)

Constructor used in the application.

Description: This is the backbone to initializing a town for a given simulation profile created via the GUI. Town Constructor which creates the Bar and Agent Objects using inputted parameters by the createBars() and createAgents() functions.

Parameters:
number_barsindicates how many bars will be available for simulated population to choose from.
populationindicates how many Agents will be participating in the simulation.
user_cap[]the array which holds each bars respective capacity specified by the user through the GUI interface.
isPercentindicates whether the user inputted the bar capacities as a percentage of the population or just a Cap.
grpSizeindicates the maximum size that a group within the population can be
avgAge2indicates the Average Age at which an Agent expires
dropValueIndicates the threshold at which an Agent will generally drop a poorly performing Strategy and replace it with one of the top 20 performing Strategy's at random.
Precondition:
The parameters are initialized within the following constraints: 0 < number_bars < 256 & 0 < population < 16385 (2^14-1) and user_cap is the array for the capacity for each bar. ( whose size may exceed the population.)
Postcondition:
Barnums array and people array initialized as well as STM array which keeps track which bar has won.

Member Function Documentation

void Town::createBars ( int  numbars,
int  user_cap[],
bool  isPercent 
)

Initializes all bars to their respective "maxcapacity".

Description: The Bar array barnums[] is initialized and bar[0] is the normalizing home location that if the population is greater than the sum of all "user_cap[]"s, then bar [0] gets the value of population - SUM(user_cap[]).

Parameters:
numbarsindicates how many bars will be available for simulated population to choose from.
user_cap[]the array which holds each bars respective capacity specified by the user through the GUI interface.
isPercentindicates whether the user inputted the bar capacities as a percentage of the population or just a Cap.
Precondition:
0 < numbars < 256
Postcondition:
Bar array barnums[] has been initialized.
void Town::createGroups ( int  population,
int  numGrps,
int  avgAge,
int  dropValue 
)

Creates and initializes all Agents participating in a given simulation.

Description: Populates Agent array people[] with initialized Agent Objects.

Parameters:
populationindicates how many Agents will be initialized for the simulation.
numGrpsindicates how many groups will be initialized for the simulation.
avgAgeindicates the average age that will be initialized for the simulation.
dropValueindicates the alpha value for score dropping that will be initialized for the simulation.
Precondition:
0 < population < 16385 (2^14-1)
Postcondition:
Agent array people[] is initialized and holds all initialized Agents in the population.
Note:
By Default, if Group option is not selected there will only be one group that the entire population is a part of.
int* Town::getWinners ( int  a[256])

Calculates winners for a given round.

Description: Function updates the STM to add current turn data and also updates other optional statistics such as how many bars won and how many Agents won for the current round. Also populates Stuff structure to pass back to the GUI for graph output.

Parameters:
a[256]structure that holds information about which bar has won the current round
Precondition:
Input is an int array which contains 1s's where bars won and 0's where bars lost
Postcondition:
Bars that have won for a particular round have been acknowledged and updated
Returns:
Integer pointer to array which contains information whether a given instialized bar has won that round.
int* Town::goingToBar ( )

Polls all Agents to get their consensus for a given turn.

Description: Polls all the Agents participating in the simulation of which bar they are going to and tallies the Agents answers for each bar. A pointer to an Array is returned which contains this information.

Precondition:
All necessary variables are set and a simulation is underway.
Postcondition:
Returns a pointer to an array which holds counters for how many Agents are going to a particular bar for a given turn.
Returns:
Integer pointer to array which contains the tally of how many Agents went to each bar for a given turn.
void Town::popcontrol ( )

Controls Population.

Description: Controls the dynamic Agent Population by keeping track of the groups within the population. While a group is not full, new Agents are created to fill this gap.

Precondition:
All necessary variables are set and a simulation is underway. At least one group within the population is NOT at maximum occupancy.
Postcondition:
Every group has maximum occupancy.
void Town::tellWinners ( int  a[256])

Converts statistics into visually respresentable data for GUI to utilize.

Description: Function goes through the population and tells an agent they have either won or lost the current round which depends if the bar has won or lost that round. Also populates Stuff structure to pass back to the GUI for graph output.

Parameters:
a[256]structure that holds information about which bar has won the current round
Precondition:
The array that holds valid bars for the current simulation has been populated.
Postcondition:
Stuff sructure has been populated.

Simulates a turn in the Simulation.

Description: One turn is simulated when turn() is run. This includes polling all Agents of which Bar they are going to through goingToBar(), deciding the winners of that particular turn through getWinners(), and updates the statistics through tellWinners().

Precondition:
Input parameters have been passed from the GUI and have initialized all appropriate instances.
Postcondition:
One turn has passed, all parameters have been updated and recorded.
Returns:
graphPtr object which contains all information for the past turn.

Member Data Documentation

int Town::avgAge [protected]

Average Age Variable holds the average age.

Bar Town::barNums[256] [protected]

Bar holder array Array structure used for keeping track of status of a bar ( i.e. won/lost)

Bar** Town::barnums [protected]

Bar Array A double pointer holding all bars and how many people went to each bar.

int Town::drop [protected]

Alpha Value Variable that holds the alpha value which represents the threshold in which strategies are dropped inside groups.

list<Group *> Town::groups [protected]

Groups List that holds all groups.

int Town::grpSize [protected]

Group Size Variable that holds the max size that a group can be.

list<Group *>::iterator Town::it [protected]

Group Iterator Iterator for group list.

int Town::numBars [protected]

Number of Bars in Simulations Reference variable that is used for loops to iterate through all active bars in simulation.

int Town::numPeeps [protected]

Population in Simulation Reference variable that is used for loops to iterate through all Agents that are in the simulation profile.

Note:
Will be constant unless simulation option chosen to have deaths and births.
int Town::numpeeps [protected]

Number of Agnets Variable that holds population size.

Agent Town::people[16384] [protected]

Agent holder array Array structure that holds all Agent objects for the simulation.

int Town::STI [protected]

Short Term Index The index of which strategy is being used.

int* Town::STM [protected]

Short Term Memory Pointer to structure that keeps track of recent winnners in the simulation.

graphPtr Town::Stuff [protected]

Connecting Medium The connecting structure medium that allows communication between the frontend GUI interface and computational backend. Allows the update of statistics to applied to graphs and recording mechanism for later review.

Strategy** Town::topStrats [protected]

Top Strategies Double pointer holding the top strategies.


The documentation for this class was generated from the following file: