Skip to content

Commit 9deafba

Browse files
FoFFoloFedericopre-commit-ci[bot]
authored
fix sugarscape_g1mt running options, requirements and changes to README (#109)
* fix sugarscape_g1mt running options, requirements and changes to README * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixes to README and run.py check * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Federico <federico.serratorevr@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bd0468c commit 9deafba

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

examples/sugarscape_g1mt/Readme.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
## Summary
44

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

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

1010
### Agents:
1111

12-
- **Sugar**: Sugar agents grow back at one unit per time step and can be harvested and traded by the trader agents. Sugar
13-
is unequally distributed across the landscape with sugar hills in the upper left and lower right of the space.
14-
(green if you do the interactive run)
15-
- **Spice**: Spice agents grow back at one unit per time step and can be harvested and traded by the trader agents. Spice
16-
is unequally distributed across the landscape with spice hills in the upper right and lower left of the space.
17-
(yellow if you do the interactive run)
12+
- **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.
13+
(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)
1814
- **Traders**: Trader agents have the following attributes: (1) metabolism for sugar, (2) metabolism for spice, (3) vision,
1915
(4) initial sugar endowment and (5) initial spice endowment. The traverse the landscape harvesting sugar and spice and
20-
trading with other agents. If they run out of sugar or spice then they are removed from the model.
16+
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)
2117

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

5147
```
52-
$ pip install -r requirements.txt
48+
$ pip install -r requirements.txt
5349
```
5450

5551
## How to Run
@@ -69,19 +65,19 @@ To run the model with BatchRunner:
6965
To run the model interactively:
7066

7167
```
72-
$ mesa runserver
68+
$ mesa runserver
7369
```
7470

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

7773
## Files
7874

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
jupyter
2-
mesa
2+
mesa~=2.0
33
numpy
44
matplotlib
55
networkx
6+
pandas

examples/sugarscape_g1mt/run.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ def assess_results(results, single_agent):
6464

6565
args = sys.argv[1:]
6666

67-
68-
if args[0] == "runserver":
67+
if len(args) == 0:
6968
server.launch()
7069

71-
elif "s" in args[0] or "Single" in args[0]:
70+
elif args[0] == "-s":
7271
print("Running Single Model")
7372
# instantiate the model
7473
model = SugarscapeG1mt()
@@ -83,7 +82,7 @@ def assess_results(results, single_agent):
8382
# assess the results
8483
assess_results(model_results, agent_results)
8584

86-
else:
85+
elif args[0] == "-b":
8786
print("Conducting a Batch Run")
8887
# Batch Run
8988
params = {
@@ -103,3 +102,6 @@ def assess_results(results, single_agent):
103102
)
104103

105104
assess_results(results_batch, None)
105+
106+
else:
107+
raise Exception("Option not found")

0 commit comments

Comments
 (0)