Skip to content

Commit

Permalink
Restructured the Basic example as per convention of other examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeetu committed Jul 16, 2016
1 parent da4c1b4 commit 007e6f4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
34 changes: 27 additions & 7 deletions examples/Basic/Readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
# Example Code
# Basic Grid with two agents

This directory contains multiple examples of basic functionality of Mesa.
## Summary

## shapes
A very basic example model to showcase the visulaization on web browser.

Showcases following features:
A simple grid is dispalyed on browesr with two agents. The example does not
have any agent motion involved. This example does not have any movenment of
agents so as to keep it to the simplest of level possible.

This model showcases following features:

* A rectangular grid
* ArrowHead shaped agent for displaying heading of the agent on CanvasGrid
* Text Overlay on the agent's shape on CanvasGrid
* ArrowHead shaped agent for displaying heading of the agent on CanvasGrid

## Installation

To install the dependencies use pip and the requirements.txt in this directory.
e.g.

#### How to Run
```
$ pip install -r requirements.txt
```

## How to Run

To run the model interactively, run ``run.py`` in this directory. e.g.

```
$ python shapes_viz.py
```

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

## Files

* ``basic/model.py: Defines the Basic model and agents.
* ``basic/server.py``: Sets up the interactive visualization server.
* ``run.py``: Launches a model visualization server.
File renamed without changes.
10 changes: 5 additions & 5 deletions examples/Basic/shapes_viz.py → examples/Basic/basic/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from shapes_model import Walker, ShapesModel
from basic.model import Walker, ShapesModel
from mesa.visualization.modules import CanvasGrid
from mesa.visualization.ModularVisualization import ModularServer

Expand All @@ -25,19 +25,19 @@ def agent_draw(agent):
}
return portrayal

def main():
def launch_basic():
width = 15
height = 10
num_agents = 2
pixel_ratio = 50
grid = CanvasGrid(agent_draw, width, height,
width*pixel_ratio, height*pixel_ratio)
server = ModularServer(ShapesModel, [grid], "Shapes Examples",
server = ModularServer(ShapesModel, [grid], "Basic Example",
num_agents, width, height)
server.max_steps = 0
server.port = 8889
server.port = 8888
server.launch()

if __name__ == "__main__":
random.seed(3)
main()
launch_basic()
1 change: 1 addition & 0 deletions examples/Basic/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mesa
3 changes: 3 additions & 0 deletions examples/Basic/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from basic.server import launch_basic

launch_basic()
6 changes: 3 additions & 3 deletions examples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

This directory contains example models meant to test and demonstrate Mesa's features, and provide demonstrations for how to build and analyze agent-based models. For more information on each model, see its own Readme and documentation.

### Basic
Examples of basic funcionality of Mesa.

### Color Patches
A cellular automaton model where agents opinions are influenced by that of their neighbors. As the model evolves, color patches representing the prevailing opinion in a given area expand, contract, and sometimes disappear.

Expand Down Expand Up @@ -32,3 +29,6 @@ Completed code to go along with the [tutorial]() on making a simple model of how

### WolfSheep
Implementation of an ecological model of predation and reproduction, based on the NetLogo [Wolf Sheep Predation model](http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation).

### Basic
Example of grid display and direction showing agents in the form of arrow-head shape.

0 comments on commit 007e6f4

Please sign in to comment.