Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dor-sketch/simulation-earth
Implementation of a Cellular Automaton for a variety of cause-effect inferences, with simple GUI and graph support.
https://github.com/dor-sketch/simulation-earth
biological-computing cellular-automata matplotlib simulation tkinter
Last synced: about 1 month ago
JSON representation
Implementation of a Cellular Automaton for a variety of cause-effect inferences, with simple GUI and graph support.
- Host: GitHub
- URL: https://github.com/dor-sketch/simulation-earth
- Owner: Dor-sketch
- Created: 2024-01-28T22:30:03.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-26T20:02:33.000Z (5 months ago)
- Last Synced: 2024-07-26T21:48:57.178Z (5 months ago)
- Topics: biological-computing, cellular-automata, matplotlib, simulation, tkinter
- Language: Python
- Homepage: https://dorpascal.com/simulation-earth/
- Size: 63.7 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Simulation Earth
Welcome to "Simulation Earth" - a groundbreaking project that models our planet using the principles of `cellular automata`. Inspired by Conway's Game of Life, this 2D `grid-based simulation` vividly illustrates the complexity of Earth's ecosystems.
In each cell of the grid, diverse ecosystems are represented, ranging from seas and mountains to urban landscapes. Key environmental attributes like temperature, wind speed, rainfall, and pollution levels are dynamically simulated. As each generation progresses, the cells' states evolve, creating a rich tapestry of interconnected ecological phenomena.
Developed for the **Biological Computation** class at the _Open University of Israel_ in 2024, this project earned a perfect score of `100/100`.
> **Update:** The project is now available as an online executable on [itch.io](https://dor-sketch.itch.io/simulation-earth) for easy access and exploration.
---
- [๐ณ Background](#-background)
- [๐ Key Features](#-key-features)
- [๐ Getting Started](#-getting-started)
- [๐ก Insights and Usage](#-insights-and-usage)
- [๐ ๏ธ Technical Implementation](#๏ธ-technical-implementation)
- [๐ผ๏ธ Screenshots](#๏ธ-screenshots)
- [๐ License](#-license)
- [๐ซ Contact](#-contact)---
## ๐ณ Background
A cellular automata is a Computation model that is based on a world (grid) of cells, where each cell has a state and a set of rules that determine the state of the cell in the next generation. The rules are based on the state of the cell and the state of its neighbours. The rules are applied to all cells in the grid at the same time, and the next generation is calculated based on the current generation.
The cellular automata model is a powerful tool for modeling complex systems, such as ecosystems, traffic flow, and even social dynamics. The model is based on the idea that complex systems can emerge from simple rules and interactions between individual elements. By simulating the interactions between individual elements, the model can capture the emergent properties of the system as a whole.
For more information about cellular automata, see [Wikipedia](https://en.wikipedia.org/wiki/Cellular_automaton).
This project is a simulation of Earth's ecosystem using cellular automata. The simulation is based on a 2D grid of cells, where each cell represents a different part of the ecosystem, such as the sea, mountains, or urban areas. The cells have different attributes, such as temperature, wind speed, rainfall, and pollution levels. The simulation evolves over time, with the cells' states changing based on the rules of the simulation.
## ๐ Key Features
- ๐ **Dynamic World Modeling:** Explore complex cause-effect relationships as each cell's behavior evolves based on its environment and neighboring cells.
- ๐ฅ๏ธ **Real-time Visualization:** Watch ecological patterns unfold in real time, with the ability to adjust initial conditions and monitor the simulation's progress.
- ๐ฉ **Modular Design:** Experiment with different simulation rules and initial states, adaptable to scenarios from board games to real-world ecosystem modeling.
- ๐ **Statistical Analysis:** Delve into detailed statistics such as average values, standard deviation, and standard error, enriching the analytical depth.
---
## ๐ Getting Started
### ๐ฆ Requirements
- `matplotlib`: Powers the visualizations.
- `tkinter`: Drives the GUI interface.### ๐ Running the Simulation
1. **Prepare the Environment:** Ensure `csv` files are placed in the same directory as the program.
2. **Launch the Simulation:**```bash
python3 grid.py
# If multiple Python versions are installed:
python3.11 grid.py
```3. **Customize Your Experience:** Modify simulation parameters, select initial states, and apply rules through the intuitive GUI.
### ๐งช Testing and Analysis
- **Example State:** Discover with `enums.csv`, which provides a sample initial state.
- **Rich Data:** Access comprehensive statistics for in-depth analysis and insights.
- **Rule Exploration:** Dive into various ecological outcomes by experimenting with different initial states and rules.
Example Rule Exploration:
---
## ๐ก Insights and Usage
"Simulation Earth" is more than just a project; it's a journey into the interconnectedness of our environment. Through detailed testing and rule adjustment, we've uncovered significant correlations between pollution levels and other environmental aspects. The `manually increase temperature` rule, for example, demonstrates the profound impact of individual factors on the broader ecosystem.
---
## ๐ ๏ธ Technical Implementation
- ๐งฌ **Cellular Automaton Core:** A seamless blend of Python's capabilities with the core theories of cellular automata.
- ๐ฒ **State and Neighbors:** Cells in a 2D array ([CA.py](CA.py)) each possess a unique state ([states.py](state.py)) and a Moore neighborhood configuration.
- ๐ท๏ธ **Custom Enum Classes:** Enhance rule implementation and maintain finite state values, ensuring robustness and preventing errors.
- ๐ **Grid and GUI Separation:** The `grid` class ([grid.py](grid.py)) handles cell layout and state transitions, while the `GUI` class ([GUI.py](GUI.py)) manages simulation control.
- ๐จโโ๏ธ **Dynamic Rules and Initial States:** The [rules.py](rules.py) and [enums.csv](enums.csv) files enable easy customization of simulation rules and initial states.
### ๐ ๏ธ Advanced Coding Techniques and Concepts
The project's simple appearance belies the advanced techniques and concepts that underpin the simulation. By examining specific code snippets, including the `update_state` method from the `Cell` class and rules from the `TransitionRules` class, we can explore how these advanced techniques contribute to a robust, adaptable, and user-friendly simulation environment.
**Key Code Snippets:**
1. **Cell Class - State Update Method:**
```python
def update_state(self):
rules = TransitionRules(self)
with rules:
return rules.apply_rules()
```2. **TransitionRules Class - Sample Rules for Rain, Air Quality, and Temperature:**
```python
# Rain Rule: Stop rain if no neighbors have clouds and current cell has wind
# Air Quality Rule: Cities create pollution based on the number of city neighbors
# Temperature Rule: Pollution increases temperature
{
'name': 'TEMP: Pollution increases temperature',
'enabled': True,
'condition': lambda neighborhood: neighborhood['center'].air_pollution > AirQuality.CLEAN,
'action': lambda neighborhood: setattr(neighborhood['center'], 'temperature', neighborhood['center'].temperature + neighborhood['center'].air_pollution.value)
},
```3. **Custom Comparable Enum Class:**
```python
class ComparableEnum(Enum):
# Custom comparison methods (__lt__, __le__, __gt__, __ge__)
...
```4. **Dynamic GUI Interaction:**
```python
def setup_rules_checkboxes(self):
# GUI setup for dynamic rule modification
...
def update_rule_state(self, rule, var):
# Method to update rule state based on GUI interaction
...
```**Analysis of Techniques:**
1. **Enhanced Encapsulation in the Cell Class:**
The `Cell` class demonstrates encapsulation, managing its state internally. The `update_state` method leverages `TransitionRules` to handle state transitions, keeping the logic neatly contained.2. **Complex Rule-Based Logic in TransitionRules:**
The selected rules illustrate the complexity of interactions within the simulation. Each rule encapsulates specific environmental logic, such as how rain, air quality, and temperature interact with other elements.3. **Context Manager for Controlled Rule Application:**
The `TransitionRules` class employs a context manager to apply rules in a controlled and precise manner. This ensures that the simulation's state changes are coherent and that side effects are minimized.4. **Dynamic GUI for Real-Time Interactivity:**
The GUI setup enables real-time, dynamic modifications of the simulation rules, showcasing an advanced level of user interactivity and responsiveness to user inputs.5. **Type Safety and Flexibility with Custom Enums:**
The `ComparableEnum` class extends Python's Enum, facilitating easy comparisons crucial for rule implementation. This ensures type safety and enhances the simulation's flexibility in modeling complex environmental interactions.These advanced techniques not only demonstrate robust programming practices but also underscore the project's dedication to creating a sophisticated, adaptable, and user-friendly simulation environment.
---
## ๐ผ๏ธ Screenshots
*Explore the GUI Interface and Statistics Panels*
The 3D effect is achieved by using a 2D grid with a color gradient.
*Delve into Detailed Statistical Analysis Over Time*
*Uncover the Correlation Between Pollution and Temperature*
---
## ๐ License
This project is open-sourced under the MIT License - see the [LICENSE](docs/LICENSE) file for details.
---
## ๐ซ Contact
For inquiries, collaborations, or more information, feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/dor-pascal/).