# El Farol

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## WHAT IS IT?

El Farol is a bar in Santa Fe, New Mexico. The bar is popular --- especially on Thursday nights when they offer Irish music --- but sometimes becomes overcrowded and unpleasant. In fact, if the patrons of the bar think it will be overcrowded they stay home; otherwise they go enjoy themselves at El Farol. This model explores what happens to the overall attendance at the bar on these popular Thursday evenings, as the patrons use different strategies for determining how crowded they think the bar will be.

El Farol was originally put forth by Brian Arthur (1994) as an example of how one might model economic systems of boundedly rational agents who use inductive reasoning.

## HOW IT WORKS

An agent will go to the bar on Thursday night if they think that there will not be more than a certain number of people there --- a number given by the OVERCROWDING-THRESHOLD. To predict the attendance for any given week, each agent has access to a set of prediction strategies and the actual attendance figures of the bar from previous Thursdays. A prediction strategy is represented as a list of weights that determines how the agent believes that each time period of the historical data affects the attendance prediction for the current week. This definition of a strategy is based on an implementation of Arthur's model as revised by David Fogel et al. (1999). The agent decides which one of its strategies to use by determining which one would have done the best had they used it in the preceding weeks.

The number of potential strategies an agent has is given by NUMBER-STRATEGIES, and these potential strategies are distributed randomly to the agents during SETUP, but at any one tick each agent will only utilize one strategy, based on its previous ability to predict the attendance of the bar. The length of the attendance history the agents can use for a prediction or evaluation of a strategy is given by MEMORY-SIZE.

## HOW TO USE IT

To use the model, set the NUMBER-STRATEGIES, OVERCROWDING-THRESHOLD and MEMORY size, press SETUP, and then GO.

The plot shows the average attendance at the bar over time.

## THINGS TO NOTICE

The green part of the world represents the homes of the patrons, while the blue part of the world represents the El Farol Bar. Over time the attendance will increase and decrease but its mean value comes close to the OVERCROWDING-THRESHOLD.

## THINGS TO TRY

Try running the model with different settings for MEMORY-SIZE and NUMBER-STRATEGIES. What happens to the variability in attendance as you decrease NUMBER-STRATEGIES? What happens to the variability in the plot if you decrease MEMORY-SIZE?

## EXTENDING THE MODEL

Currently the weights that determine each strategy are randomly generated. Try altering the weights so that they only reflect a mix of the following agent strategies:

- always predict the same as last week's attendance
- an average of the last several week's attendance
- the same as 2 weeks ago

Can you think of other simple rules one might follow?

At the end of Arthur's original paper, he mentions that though he uses a simple learning technique (the "bag of strategies" method) almost any other kind of machine learning technique would achieve the same results. In fact Fogel et al. implemented a genetic algorithm and got different results. Try implementing another machine learning technique and see what the results are.

## NETLOGO FEATURES

Lists are used to represent strategies and attendance histories.

`n-values`

is useful for generating random strategies.

## RELATED MODELS

Arthur's original model has been generalized as the Minority Game which also exists in the Models Library. In addition there is a model called El Farol Network Congestion that uses the El Farol Bar Problem as a model of how to choose the best path in a network. Finally, there is an alternative implementation of this model with more parameters that is part of the NetLogo User Community Models.

## CREDITS AND REFERENCES

This model is inspired by a paper by W. Brian Arthur. "Inductive Reasoning and Bounded Rationality", W. Brian Arthur, The American Economic Review, 1994, v84n2, p406-411.

David Fogel et al. also built a version of this model using a genetic algorithm. "Inductive reasoning and bounded rationality reconsidered", Fogel, D.B.; Chellapilla, K.; Angeline, P.J., IEEE Transactions on Evolutionary Computation, 1999, v3n2, p142-146.

## HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

- Rand, W. and Wilensky, U. (2007). NetLogo El Farol model. http://ccl.northwestern.edu/netlogo/models/ElFarol. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

## COPYRIGHT AND LICENSE

Copyright 2007 Uri Wilensky.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

## Comments and Questions

globals [ attendance ;; the current attendance at the bar history ;; list of past values of attendance home-patches ;; agentset of green patches bar-patches ;; agentset of blue patches crowded-patch ;; patch where we show the "CROWDED" label ] turtles-own [ strategies ;; list of strategies best-strategy ;; index of the current best strategy attend? ;; true if the agent currently plans to attend the bar prediction ;; current prediction of the bar attendance ] to setup clear-all set-default-shape turtles "person" ;; create the 'homes' set home-patches patches with [pycor < 0 or (pxcor < 0 and pycor >= 0)] ask home-patches [ set pcolor green ] ;; create the 'bar' set bar-patches patches with [pxcor > 0 and pycor > 0] ask bar-patches [ set pcolor blue ] ;; initialize the previous attendance randomly so the agents have a history ;; to work with from the start set history n-values (memory-size * 2) [random 100] set attendance first history ;; use one of the patch labels to visually indicate whether or not the ;; bar is "crowded" ask patch (0.75 * max-pxcor) (0.5 * max-pycor) [ set crowded-patch self set plabel-color red ] ;; create the agents and give them random strategies crt 100 [ set color white move-to-empty-one-of home-patches set strategies n-values number-strategies [random-strategy] set best-strategy first strategies update-strategies ] ;; start the clock reset-ticks end to go ;; update the global variables ask crowded-patch [ set plabel "" ] ;; have each agent predict attendance at the bar and decide whether or not to go ask turtles [ set prediction predict-attendance best-strategy sublist history 0 memory-size set attend? (prediction <= overcrowding-threshold) ;; true or false ] ;; depending on their decision the turtles go to the bar or stay at home ask turtles [ ifelse attend? [ move-to-empty-one-of bar-patches set attendance attendance + 1 ] [ move-to-empty-one-of home-patches ] ] ;; if the bar is crowded indicate that on the view set attendance count turtles-on bar-patches if attendance > overcrowding-threshold [ ask crowded-patch [ set plabel "CROWDED" ] ] ;; update the attendance history set history fput attendance but-last history ;; have the agents decide what the new best strategy is ask turtles [ update-strategies ] ;; advance the clock tick end ;; determines which strategy would have predicted the best results had it been used this round. ;; the best strategy is the one that has the sum of smallest difference between the ;; current attendance and the predicted attendance for each of the preceding ;; weeks (going back MEMORY-SIZE weeks) to update-strategies let best-score memory-size * 100 + 1 foreach strategies [ let score 0 let week 1 repeat memory-size [ set prediction predict-attendance ? sublist history week (week + memory-size) set score score + abs (item (week - 1) history - prediction) ;set score score + abs (current-attendance - prediction) set week week + 1 ] if (score <= best-score) [ set best-score score set best-strategy ? ] ] end ;; this reports a random strategy. a strategy is just a set of weights from -1.0 to 1.0 which ;; determines how much emphasis is put on each previous time period when making ;; an attendance prediction for the next time period to-report random-strategy report n-values (memory-size + 1) [1.0 - random-float 2.0] end ;; This reports an agent's prediction of the current attendance ;; using a particular strategy and portion of the attendance history. ;; More specifically, the strategy is then described by the formula ;; p(t) = x(t - 1) * a(t - 1) + x(t - 2) * a(t -2) +.. ;; ... + x(t - MEMORY-SIZE) * a(t - MEMORY-SIZE) + c * 100, ;; where p(t) is the prediction at time t, x(t) is the attendance of the bar at time t, ;; a(t) is the weight for time t, c is a constant, and MEMORY-SIZE is an external parameter. to-report predict-attendance [strategy subhistory] ;; the first element of the strategy is the constant, c, in the prediction formula. ;; one can think of it as the the agent's prediction of the bar's attendance ;; in the absence of any other data ;; then we multiply each week in the history by its respective weight report first strategy + sum (map [?1 * ?2] butfirst strategy subhistory) end ;; In this model it doesn't really matter exactly which patch ;; a turtle is on, only whether the turtle is in the home area ;; or the bar area. Nonetheless, to make a nice visualization ;; this procedure is used to ensure that we only have one ;; turtle per patch. to move-to-empty-one-of [locations] ;; turtle procedure move-to one-of locations while [any? other turtles-here] [ move-to one-of locations ] end ; Copyright 2007 Uri Wilensky. ; See Info tab for full copyright and license.

There are 10 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

El Farol.png | preview | Preview for 'El Farol' | almost 11 years ago, by Uri Wilensky | Download |

This model does not have any ancestors.

This model does not have any descendants.

Giangiacomo Bravo

## update the model

You should update the model to the NetLogo 6 sintax

## Posted over 6 years ago