Skip to content

triangle-park/ForFiS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

30 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Forest Fire Simulation

A comprehensive forest fire simulation system with agent-based modeling, real-time visualization, and modular architecture.

๐Ÿš€ Features

  • Grid-based Simulation: Minecraft-style grid cell representation for terrain and fire
  • Agent System: Helicopter and ground crew agents with intelligent movement
  • Real-time Visualization: Live GUI with step-by-step simulation display
  • Ultra-Modular Architecture: 60% code reduction through expert modularization
  • Fixed UI Layout: Consistent user interface that doesn't change unexpectedly
  • Raster Data Support: Import and visualize real geographic data

๐ŸŽฏ Recent Refactoring Achievement

Major Modularization Completed! โœจ

Component Before After Reduction New Modules
GUI Main 774 lines 275 lines 64% 4 modules
Simulation Controller 628 lines 197 lines 69% 3 modules
Scenario Input GUI 578 lines 167 lines 71% 5 modules
Cell Manager 439 lines 330 lines 25% 3 modules
Total 2,419 lines 969 lines 60% 15 modules

Benefits Achieved:

  • ๐Ÿ”ง Maintainability: Each module has single responsibility
  • ๐Ÿš€ Readability: All files under 500 lines, most under 300
  • ๐Ÿงช Testability: Individual modules can be tested independently
  • ๐Ÿ”„ Reusability: Components can be used in other projects
  • ๐Ÿ‘ฅ Collaboration: Multiple developers can work simultaneously

๐Ÿ“ Project Structure (Updated - Highly Modularized)

ForFiS/
โ”œโ”€โ”€ agents/                 # Agent behavior and movement logic
โ”‚   โ”œโ”€โ”€ base/              # Base agent classes
โ”‚   โ”œโ”€โ”€ types/             # Agent type definitions  
โ”‚   โ”œโ”€โ”€ movement/          # Movement algorithms
โ”‚   โ””โ”€โ”€ pathfinding/       # Pathfinding systems
โ”œโ”€โ”€ core/                   # Core simulation engine
โ”‚   โ”œโ”€โ”€ cells/             # Cell system (highly modular)
โ”‚   โ”‚   โ”œโ”€โ”€ cell_manager.py     # Main cell manager (330 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ cell_factory.py     # Cell creation (262 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ cell_updater.py     # State updates (291 lines)
โ”‚   โ”‚   โ””โ”€โ”€ cell_validator.py   # Data validation (298 lines)
โ”‚   โ”œโ”€โ”€ simulation/        # Simulation components
โ”‚   โ”œโ”€โ”€ forest/            # Forest and terrain models
โ”‚   โ””โ”€โ”€ fire/              # Fire spread algorithms
โ”œโ”€โ”€ gui/                    # User interface (modularized)
โ”‚   โ”œโ”€โ”€ core/              # Core GUI components
โ”‚   โ”‚   โ”œโ”€โ”€ main_window.py      # Window management (94 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ state_manager.py    # State management (139 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ event_handler.py    # Event handling (339 lines)
โ”‚   โ”‚   โ””โ”€โ”€ logger.py           # Logging system (130 lines)
โ”‚   โ”œโ”€โ”€ gui_main.py        # Main GUI coordinator (275 lines)
โ”‚   โ”œโ”€โ”€ simulation/        # Simulation control
โ”‚   โ”‚   โ”œโ”€โ”€ controller.py       # Main controller (197 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ execution_controller.py  # Execution control (214 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ data_manager.py     # Data management (244 lines)
โ”‚   โ”‚   โ””โ”€โ”€ step_controller.py  # Step control (217 lines)
โ”‚   โ”œโ”€โ”€ visualization/     # Plotting and visualization
โ”‚   โ”œโ”€โ”€ controls/          # User controls
โ”‚   โ””โ”€โ”€ animation/         # Animation and step management
โ”œโ”€โ”€ scenario/               # Scenario input system (ultra-modular)
โ”‚   โ”œโ”€โ”€ gui/               # GUI components
โ”‚   โ”‚   โ”œโ”€โ”€ input_window.py     # Window management (140 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ map_controller.py   # Map interaction (298 lines)
โ”‚   โ”‚   โ””โ”€โ”€ form_controller.py  # Form controls (304 lines)
โ”‚   โ”œโ”€โ”€ logic/             # Logic components
โ”‚   โ”‚   โ”œโ”€โ”€ scenario_validator.py    # Validation (255 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ scenario_data_manager.py # Data management (291 lines)
โ”‚   โ”‚   โ””โ”€โ”€ scenario_event_handler.py # Event handling (470 lines)
โ”‚   โ””โ”€โ”€ scenario_input_gui.py # Main coordinator (167 lines)
โ”œโ”€โ”€ config/                 # Configuration files
โ”œโ”€โ”€ docs/                   # Project documentation
โ”‚   โ”œโ”€โ”€ PROJECT_ARCHITECTURE.md  # Architecture overview
โ”‚   โ”œโ”€โ”€ CURSOR_RULES.md          # Development guidelines
โ”‚   โ”œโ”€โ”€ REFACTORING_GUIDE.md     # Code refactoring guide
โ”‚   โ””โ”€โ”€ REFACTORING_RESULTS.md   # Latest refactoring results
โ””โ”€โ”€ tests/                  # Test suite

๐Ÿ—๏ธ Architecture Principles

1. Layered Architecture

  • GUI Layer: User interface and interaction
  • Visualization Layer: Plotting and rendering
  • Simulation Layer: Core simulation logic
  • Agent Layer: Agent behavior and movement
  • Core/Model Layer: Data models and algorithms

2. Modularity

  • Single Responsibility: Each module has one clear purpose
  • Dependency Management: Clear interfaces between layers
  • Code Reuse: Common functionality in utility modules

3. No Code Duplication

  • DRY Principle: Don't Repeat Yourself
  • Common Interfaces: Unified APIs for similar functionality
  • Shared Utilities: Centralized common functions

๐Ÿš€ Quick Start

Prerequisites

pip install -r requirements.txt

Basic Usage

from gui.gui_main import GUIMain

# Create configuration
config = {
    "mode": "Haksar",
    "grid": "rectangular",
    "size": 42,
    "agent_config": {"helicopter": 1, "groundcrew": 2}
}

# Start GUI
gui = GUIMain(config)

Running the Simulation

  1. Start: Click "Start" to begin simulation
  2. Step: Use "Step" for manual progression
  3. Pause/Resume: Control simulation flow
  4. Reset: Restart simulation from beginning

๐Ÿ”ง Configuration

UI Layout Configuration

The UI layout is controlled by config/ui_fixed_config.yml:

ui:
  fixed_layout: true
  grid_spec:
    width_ratios: [0.6, 0.2, 0.2]  # [main_map, fire_cbar, terrain_cbar]
  colorbar:
    terrain:
      levels: 7  # Matches raster data levels
    fire:
      levels: 5  # Fire intensity levels

Agent Configuration

agent_config:
  helicopter: 1      # Number of helicopter agents
  groundcrew: 2     # Number of ground crew agents
  movement_speed: 1.0
  pathfinding_enabled: true

๐Ÿ“Š Visualization Features

Grid Cell Representation

  • Terrain: 7 distinct levels with custom colormap
  • Fire: 5 intensity levels with hot colormap
  • Forest State: 3 states (Healthy, Burning, Burnt)
  • Grid Lines: Clear cell boundaries for easy identification

Colorbar Labels

  • English Labels: Intuitive descriptions for each color
  • Terrain Types: Water, Dense Forest, Forest, Light Forest, Grassland, Rocky, Bare Soil
  • Fire Intensity: No Fire, Low, Medium, High, Extreme
  • Forest States: Healthy, Burning, Burnt

Agent Visualization

  • Helicopters: Red circles with numbers
  • Ground Crew: Blue squares with numbers
  • Movement: Real-time position updates
  • Status: Visual indicators for agent states

๐Ÿงช Testing

Running Tests

# Run all tests
python -m pytest tests/

# Run specific test categories
python -m pytest tests/unit/
python -m pytest tests/integration/
python -m pytest tests/system/

Test Structure

  • Unit Tests: Individual module functionality
  • Integration Tests: Module interaction testing
  • System Tests: End-to-end functionality

๐Ÿ“š Documentation

Core Documents

API Reference

  • Agent System: Agent behavior and movement APIs
  • Simulation Engine: Core simulation interfaces
  • GUI Components: User interface APIs
  • Visualization: Plotting and rendering APIs

๐Ÿ”„ Development Workflow

1. New Feature Development

  1. Review existing code for similar functionality
  2. Choose appropriate layer for the feature
  3. Define interfaces for module communication
  4. Implement and document the feature
  5. Write tests for the new functionality

2. Code Refactoring

  1. Identify duplicate code across modules
  2. Extract common functionality to utility modules
  3. Update interfaces for consistency
  4. Run tests to ensure functionality
  5. Update documentation to reflect changes

3. Quality Assurance

  • PEP 8 compliance for Python code style
  • Type hints where appropriate
  • Comprehensive docstrings for all public APIs
  • Test coverage for critical functionality

๐Ÿšซ Development Rules

Absolute Prohibitions

  • Code duplication across modules
  • Layer violations (lower layers depending on higher layers)
  • GUI logic in core modules
  • Hardcoded values in code

Best Practices

  • Use configuration files for settings
  • Implement proper error handling
  • Write comprehensive tests
  • Maintain clear documentation

๐Ÿค Contributing

Before Contributing

  1. Read the documentation thoroughly
  2. Understand the architecture and layer structure
  3. Follow the coding guidelines in CURSOR_RULES.md
  4. Check for existing implementations to avoid duplication

Contribution Process

  1. Create feature branch from main
  2. Implement changes following project rules
  3. Write/update tests for new functionality
  4. Update documentation as needed
  5. Submit pull request with detailed description

๐Ÿ“ˆ Performance Considerations

Optimization Strategies

  • Efficient algorithms for pathfinding and movement
  • Memory management for large datasets
  • Caching of frequently computed results
  • Parallel processing where applicable

Monitoring

  • Memory usage during simulation
  • Computation time for each step
  • GUI responsiveness during updates
  • Scalability with different grid sizes

๐Ÿ”ฎ Future Enhancements

Planned Features

  • 3D Visualization: Enhanced terrain representation
  • Weather Integration: Real-time weather effects
  • Multi-agent Cooperation: Coordinated firefighting strategies
  • Machine Learning: Adaptive agent behavior

Architecture Improvements

  • Plugin System: Extensible functionality
  • API Standardization: RESTful interfaces
  • Cloud Integration: Distributed simulation
  • Real-time Data: Live sensor integration

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Research Team: Forest fire modeling algorithms
  • Open Source Community: Libraries and tools
  • Contributors: Code improvements and bug fixes

Note: This project follows strict architectural principles to maintain code quality and consistency. Please refer to the documentation before making any changes.

About

Forest Fire Simulation Project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages