B.A.R.G.A.M.E.
v2.0
El Farol Bar Problem Implementation
|
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. |
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.
Town::Town | ( | ) |
Default Town Constructor.
Default constructor NOT utilized within code.
Town::~Town | ( | ) |
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.
number_bars | indicates how many bars will be available for simulated population to choose from. |
population | indicates 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. |
isPercent | indicates whether the user inputted the bar capacities as a percentage of the population or just a Cap. |
grpSize | indicates the maximum size that a group within the population can be |
avgAge2 | indicates the Average Age at which an Agent expires |
dropValue | Indicates 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. |
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[]).
numbars | indicates 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. |
isPercent | indicates whether the user inputted the bar capacities as a percentage of the population or just a Cap. |
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.
population | indicates how many Agents will be initialized for the simulation. |
numGrps | indicates how many groups will be initialized for the simulation. |
avgAge | indicates the average age that will be initialized for the simulation. |
dropValue | indicates the alpha value for score dropping that will be initialized for the simulation. |
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.
a[256] | structure that holds information about which bar has won the current 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.
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.
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.
a[256] | structure that holds information about which bar has won the current round |
graphPtr Town::turn | ( | ) |
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().
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.
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.
int Town::numpeeps [protected] |
Number of Agnets Variable that holds population size.
Agent Town::people[16384] [protected] |
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.