Skip to content

fix sugarscape_g1mt running options, requirements and changes to README #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions examples/sugarscape_g1mt/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
## Summary

This is Epstein & Axtell's Sugarscape model with Traders, a detailed description is in Chapter four of
*Growing Artificial Societies: Social Science from the Bottom Up.* (1996) The model shows an emergent price equilibrium can happen via a decentralized dynamics.
*Growing Artificial Societies: Social Science from the Bottom Up (1996)*. The model shows an emergent price equilibrium can happen via a decentralized dynamics.

This code generally matches the code in the Complexity Explorer Tutorial, but in `.py` instead of `.ipynb` format.

### Agents:

- **Sugar**: Sugar agents grow back at one unit per time step and can be harvested and traded by the trader agents. Sugar
is unequally distributed across the landscape with sugar hills in the upper left and lower right of the space.
(green if you do the interactive run)
- **Spice**: Spice agents grow back at one unit per time step and can be harvested and traded by the trader agents. Spice
is unequally distributed across the landscape with spice hills in the upper right and lower left of the space.
(yellow if you do the interactive run)
- **Resource**: Resource agents grow back at one unit of sugar and spice per time step up to a specified max amount and can be harvested and traded by the trader agents.
(if you do the interactive run, the color will be green if the resource agent has a bigger amount of sugar, or yellow if it has a bigger amount of spice)
- **Traders**: Trader agents have the following attributes: (1) metabolism for sugar, (2) metabolism for spice, (3) vision,
(4) initial sugar endowment and (5) initial spice endowment. The traverse the landscape harvesting sugar and spice and
trading with other agents. If they run out of sugar or spice then they are removed from the model.
trading with other agents. If they run out of sugar or spice then they are removed from the model. (red circle if you do the interactive run)

The trader agents traverse the landscape according to rule **M**:
- Look out as far as vision permits in the four principal lattice directions and identify the unoccupied site(s).
Expand Down Expand Up @@ -49,7 +45,7 @@ The model demonstrates several Mesa concepts and features:
To install the dependencies use pip and the requirements.txt in this directory. e.g.

```
$ pip install -r requirements.txt
$ pip install -r requirements.txt
```

## How to Run
Expand All @@ -69,19 +65,19 @@ To run the model with BatchRunner:
To run the model interactively:

```
$ mesa runserver
$ mesa runserver
```

Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and press Reset, then Run.

## Files

* ``sugarscape_g1mt/trader_agents.py``: Defines the Trader agent class.
* ``sugarscape_g1mt/resource_agents.py``: Defines the Sugar and Spice agent classes.
* ``sugarscape_g1mt/model.py``: Manages the Sugarscape Constant Growback with Traders model.
* ``sugarscape_g1mt/sugar_map.txt``: Provides sugar and spice landscape in raster type format.
* ``server.py``: Sets up and launches and interactive visualization server.
* ``run.py``: Runs Server, Single Run or Batch Run with data collection and basic analysis.
* `sugarscape_g1mt/trader_agents.py`: Defines the Trader agent class.
* `sugarscape_g1mt/resource_agents.py`: Defines the Resource agent class which contains an amount of sugar and spice.
* `sugarscape_g1mt/model.py`: Manages the Sugarscape Constant Growback with Traders model.
* `sugarscape_g1mt/sugar_map.txt`: Provides sugar and spice landscape in raster type format.
* `server.py`: Sets up an interactive visualization server.
* `run.py`: Runs Server, Single Run or Batch Run with data collection and basic analysis.
* `app.py`: Runs a visualization server via Solara (`solara run app.py`).
* `tests.py`: Has tests to ensure that the model reproduces the results in shown in Growing Artificial Societies.

Expand Down
3 changes: 2 additions & 1 deletion examples/sugarscape_g1mt/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jupyter
mesa
mesa~=2.0
numpy
matplotlib
networkx
pandas
10 changes: 6 additions & 4 deletions examples/sugarscape_g1mt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ def assess_results(results, single_agent):

args = sys.argv[1:]


if args[0] == "runserver":
if len(args) == 0:
server.launch()

elif "s" in args[0] or "Single" in args[0]:
elif args[0] == "-s":
print("Running Single Model")
# instantiate the model
model = SugarscapeG1mt()
Expand All @@ -83,7 +82,7 @@ def assess_results(results, single_agent):
# assess the results
assess_results(model_results, agent_results)

else:
elif args[0] == "-b":
print("Conducting a Batch Run")
# Batch Run
params = {
Expand All @@ -103,3 +102,6 @@ def assess_results(results, single_agent):
)

assess_results(results_batch, None)

else:
raise Exception("Option not found")