# luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination architecture

> Architecture diagram of the GitHub repository luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination
- Repository: https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination

## Overview

##### Main Components
- Environment/Simulation Grid: Represented by files like ForestModel.py, this is the simulation’s core that manages a grid-based forest environment with fires and obstacles.
- Agents: There are several agent classes in the agents folder:
– Drone Agent (in agents/drone_agent.py): Acts as a task manager, using strategies like BFS clustering and managing global contracts.
– Firefighter Agent (in agents/fireFighter_agent.py): Acts as the execution unit bidding to handle fires.
– Tree Agent (in agents/tree_agent.py): Likely responsible for handling forest objects or obstacles.
- Communication & Coordination Layer: The implemented Contract-Net Protocol (CNP) that defines:
– Task creation (e.g., generating fire contracts from detected clusters)
– Bid evaluation (using criteria like distance and resource availability)
– Assignment and task completion feedback (JSON-based message structure)
- Data & Logging Modules: Though not separate files, the README mentions logging for contracts, debugging, and positional data, which are crucial for traceability and evaluation.
- Supporting Assets & Configurations: assets (e.g. model_demo.png) for visual outputs, main.py to run the simulation, and requirements.txt for dependency management.

##### Highlighting Relationships and Interactions
- Environment as the central stage where fires occur and agents operate.
- Interaction flow: Drones detect fires → Perform clustering → Create Fire Contracts → Append the contract to a global contract pool.
- Bid submission from Firefighter agents towards the contracts, followed by the assignment of tasks by the Drone agents.

##### Architectural Patterns & Design Principles
- Decentralized Coordination: Emphasize that each agent makes decisions locally, and that there is no central planner.
- Modular Communication: The simulation separates the protocol logic (communication messages, bid evaluation, etc.) from the basic simulation engine.
- Asynchronous Processing: Capture dynamic feedback and non-blocking interactions between agent communications.
- Real-time Metrics & Logging: Incorporate components that log and track performance (like response time, resource use, etc.), which is vital for analysis and performance visualization.

##### Technologies, Frameworks, and Libraries
- Python 3.11 as the development language.
- The agent-based simulation library (agentpy, as mentioned in the README) that likely manages the grid and agent interactions.
- Standard Python modules dealing with JSON for messaging in the CNP protocol.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Simulation Execution Layer
    subgraph "Simulation Execution"
        Main["Simulation Execution<br/>(main.py)"]:::execution
    end

    %% Simulation Environment Layer
    subgraph "Simulation Environment"
        Forest["Forest Environment<br/>(ForestModel.py)"]:::environment
    end

    %% Agents Layer
    subgraph "Agents"
        Drone["Drone Agent<br/>(agents/drone_agent.py)"]:::agents
        FireFighter["Firefighter Agent<br/>(agents/fireFighter_agent.py)"]:::agents
        Tree["Tree Agent<br/>(agents/tree_agent.py)"]:::agents
    end

    %% Coordination/Communication Layer (Contract-Net Protocol)
    subgraph "CNP Coordination"
        GlobalContract["Global Contract Pool<br/>(CNP)"]:::cnp
        BidEval["Bid Evaluation Module"]:::cnp
        AsyncComm["Async Communication Channels"]:::cnp
    end

    %% Data & Logging Layer
    subgraph "Data & Logging"
        Logging["Logging & Metrics"]:::logging
    end

    %% Assets & Configurations Layer
    subgraph "Assets & Configurations"
        Assets["Assets"]:::assets
        Requirements["requirements.txt"]:::assets
    end

    %% Connections
    Main -->|"starts"| Forest
    Forest -->|"detects_fire_events"| Drone
    Forest -->|"detects_fire_events"| FireFighter
    Forest -->|"maps_obstacles"| Tree

    Drone -->|"creates_fire_contracts"| GlobalContract
    FireFighter -->|"submits_bids"| GlobalContract

    GlobalContract -->|"assigns_tasks"| Drone
    Drone -->|"sends_task_assignment"| FireFighter

    GlobalContract -->|"communicates_async"| AsyncComm
    AsyncComm -->|"notifies_task_updates"| Drone
    AsyncComm -->|"notifies_bid_results"| FireFighter

    Drone -->|"logs_events"| Logging
    FireFighter -->|"logs_actions"| Logging
    Forest -->|"logs_environment_data"| Logging

    Main -->|"loads_assets"| Assets
    Main -->|"reads_dependencies"| Requirements

    %% Click Events
    click Main "https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination/blob/main/main.py"
    click Forest "https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination/blob/main/ForestModel.py"
    click Drone "https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination/blob/main/agents/drone_agent.py"
    click FireFighter "https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination/blob/main/agents/fireFighter_agent.py"
    click Tree "https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination/blob/main/agents/tree_agent.py"
    click Assets "https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination/tree/main/assets/"
    click Requirements "https://github.com/luispostigo/a_multi-agent_system_for_dynamic_firefighting_coordination/blob/main/requirements.txt"

    %% Styles
    classDef environment fill:#D6E9C6,stroke:#4CAF50,stroke-width:2px;
    classDef agents fill:#CCE5FF,stroke:#1E88E5,stroke-width:2px;
    classDef cnp fill:#FFCCCC,stroke:#E53935,stroke-width:2px;
    classDef logging fill:#FFF3CD,stroke:#FDD835,stroke-width:2px;
    classDef execution fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef assets fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
```
