Appendix TO E39 SIDECAST -- COHEN Et Al'S "Garbage can model" 

Translation of the original FORTRAN 66 program into Python

Tom Galvin, 12 February 2018

I translated the garbage can model from FORTRAN 66 into Python 3.6, now a popular programming language for beginners, and I have made the source code available. Unfortunately, while it appears to work properly, I am not generating the same results as the original model. I suspect it has to do with differences in the way arrays are indexed between the two languages. I’m still trying. Perhaps someone with more Python experience can look at this and offer suggestions?

To use the program, you must first download and install the Python interactive environment. It is available from The website is a little complicated because they make many versions available based on your platform and operating system. If you are using Microsoft® Windows on a standard PC platform, then you can use Python for Windows version 3.6.4 – the same version I used for the computer. You can click here to access the page for this version for Windows, and then scroll down to the bottom and select “Windows x86-64 executable installer.” Running this application will install Python as an app.

Once this is completed, you can download the Python source file by clicking the below button:

Download the file from this site and save it in your documents folder. You can use any standard text editor (like Notepad, not a word processing app like Microsoft ® Word) to view the file.

When you open the Python app, you will have a command line prompt. Type the following commands first (case sensitive)

     import sys

Where <directory> is the directory you placed the Python file in. Python required that you specify it using the full path name, surround it using single quotes, and use double backslashes between directory levels. For example, on my computer, the append command looks like this:


This allows Python to ‘see’ the directory which will make things much easier for importing program files. Next you import the garbagecan file as follows:

     import garbagecan

Then to run the garbagecan model, you choose the parameters you wish to set based on the access, decision, and energy matrices in the program. The original FORTRAN program ran the model 81 times, cycling through all the permutations of distribution matrices shown in the Cohen article. For this Python version, you run the model once per iteration, setting these parameters manually.

The specification is as follows, and the pages mentioned below correspond to the Cohen, et al article:

     runloop(IL, JAB, JDB, JEB, NA=1, IO=1)

With the parameters defined as follows:

#  IL  = net energy load, or the amount of energy required to make a choice, as defined on page 5:
     1 specifies a ‘light’ load, or 1.1 for each problem
     2 specified a ‘moderate’ load, or 2.2 for each problem
     3 specifies a ‘heavy’ load, or 3.3 for each problem
#  JAB = decision entry structure found on pages 6 and 7:
     1 activates D0 (unsegmented decisions or all 1s)
     2 activates D1 (hierarchical decisions)
     3 activates D2 (specialized decisions)
#  JDB = decision access structure found on pages 5 and 6
     1 activates A0 (unsegmented access)
     2 activates A1 (hierarchical access)
     3 activates A2 (specialized access)
#  JEB = energy distribution structure page 7
     1 activates E0 (important people, less energy)
     2 activates E1 (equal energy)
     3 activates E2 (important people, more energy)
#  NA = simulation parameter representing the following
     1 = when problems and decision makers both move (default)
     2 = when decision makers move only
     3 = when problems move only
     4 = when neither problems nor decision makers move
#  IO = (NOT CURRENT USED) input-output parameter representing the following
     1 = summary statistics only (default)
     2 = summary statistics plus histories

So for example, if you want to execute the program using a light net energy load, hierarchical decision structure, specialized access structure, and an equal energy distribution following the default setting of both problems and decision makers able to move, you run the program by typing the following at the prompt:


And the program will produce the following output. Because there is no usage of random variables, the output should always be the same.

For simulation under parameters:
Load =  0 , Problem Acc. =  1 , Decision Strength =  2 , En. Distance =  1
Choice failures (KZ) =  6
Choice persistence (KY) =  101
Decision maker velocity (KX) =  13
Problem failures (KW) =  20
Problem velocity (KV) =  48
Problem latency (KU) =  0
Problem persistence (KT) =  310
Decision maker inactivity (KS) =  95
Energy reserve (XR) =  31.07499999999992
Energy wastage (XS) =  0.0


Caveats and Disclaimers

The program appears to work correctly in terms of how the decisions and choices enter, activate, and are resolved. However, certain statistics like Problem Failures (KW) and energy wastage (XS) do not appear to be calculated correctly and I have yet to figure out why. My challenge is that I am not experienced with Python, but I have already identified some important behavior differences with FORTRAN such as array indexing. I welcome any reader with Python experience to review the code and see if they can uncover any errors.