# dynam1co/ia_arboles_busqueda_python architecture

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

- Interactive diagram: https://gitdiagram.com/dynam1co/ia_arboles_busqueda_python
- Repository: https://github.com/dynam1co/ia_arboles_busqueda_python

## Overview

##### Main Components
- Problem Definition & Initial State: Represent the water jug problem and its constraints (jugs of capacities 5 and 3 liters, goal state, available actions).
- Node Representation: Highlight the shared “Nodo” class (located in arbol.py) that encapsulates the state (i.e., the current liters in each jug) along with parent-child relationships.
- BFS Algorithm Module: Identify the BFS implementation (in amplitud.py) that uses a FIFO strategy for node expansion. Include:
- Of nodes to visit (nodos_frontera)
- Visited nodes list (nodos_visitados)
- Node expansion process that applies all six operations (filling, emptying, and transferring between jugs)
- DFS Algorithm Module: Identify the DFS implementation (in profundidad.py) that uses a LIFO strategy. Similar to BFS, it also uses lists for tracking nodes but extracts nodes from the stack differently.
- Results/Output Executor: Show the main entry points in each file (the main routines) that assemble the final solution path traced via parent pointers.

##### Relationships and Interactions
- “Problem Definition” to both algorithm modules – indicating that both BFS and DFS share the same set of actions defined for transitions.
- Directional data flows:
- From the initial state into the algorithm modules.
- From each algorithm’s node expansion function (which uses the allowed actions) back into the “Nodo” structure.
- From the solution node back up through the parent links to print the complete path.

##### Architectural Patterns and Principles
- Reuse of common modules (Nodo and operator functions) to avoid redundancy, which is a key software design principle.

##### Relevant Technologies, Frameworks, or Libraries
- Python as the primary programming language.
- Basic data structures like lists (for nodos_frontera and nodos_visitados).

##### Detailed Component Elements
- A clear label for “Water Jug Problem Definition” showing the capacities (5L and 3L) and the goal ([4, 3] state).
- Separate blocks for “BFS Search” and “DFS Search” with sub-labels for:
- Initialization (estado_inicial setup)
- Node expansion (illustrate the set of operations: fill, empty, and transfer)
- Tracking mechanisms (visited and frontier lists)
- A block or a note indicating “Nodo Class” which provides the linkage for assembling the parent chain that eventually forms the solution path.

- It should clearly represent the separation between the different search strategies even though they share common building blocks.
- It must show how the initial state flows into a state space where each node’s children are generated by applying the allowed jug operations.
- It should denote the traversal methods: FIFO extraction for BFS and LIFO for DFS.
- And finally, it should represent how the solution is pulled from the discovered node via parent pointers.

## Diagram (Mermaid)

```mermaid
graph TD
    P["Water Jug Problem Definition (5L,3L,Goal:4L)"]:::definition

    subgraph "BFS Search"
        BFS["BFS Search Module"]:::bfs
        FIFO["FIFO Queue (nodos_frontera)"]:::bfs
        VIS1["Visited Nodes List (nodos_visitados)"]:::bfs
        NF_BFS["Creates Nodo Instances"]:::bfs
        R1["BFS Visualization Resource"]:::resource
        BFS -->|"uses"| FIFO
        BFS -->|"tracks"| VIS1
        BFS -->|"expands"| NF_BFS
        BFS -->|"visualizes"| R1
    end

    subgraph "DFS Search"
        DFS["DFS Search Module"]:::dfs
        LIFO["LIFO Stack (nodos_frontera)"]:::dfs
        VIS2["Visited Nodes List (nodos_visitados)"]:::dfs
        NF_DFS["Creates Nodo Instances"]:::dfs
        R2["DFS Visualization Resource"]:::resource
        DFS -->|"uses"| LIFO
        DFS -->|"tracks"| VIS2
        DFS -->|"expands"| NF_DFS
        DFS -->|"visualizes"| R2
    end

    OP["Allowed Jug Operations (fill,empty,transfer)"]:::op
    NF["Nodo Class"]:::common
    SP["Solution Path Output (via Parent Pointers)"]:::result

    P -->|"initializes"| BFS
    P -->|"initializes"| DFS
    BFS -->|"applies"| OP
    DFS -->|"applies"| OP
    NF_BFS --> NF
    NF_DFS --> NF
    NF -->|"forms"| SP

    classDef definition fill:#f9e6ff,stroke:#8a2be2,stroke-width:2px;
    classDef bfs fill:#cce5ff,stroke:#1f77b4,stroke-width:2px;
    classDef dfs fill:#ccffcc,stroke:#228B22,stroke-width:2px;
    classDef common fill:#fffacc,stroke:#daa520,stroke-width:2px;
    classDef op fill:#ffccff,stroke:#ff1493,stroke-width:2px;
    classDef result fill:#e6ffcc,stroke:#6b8e23,stroke-width:2px;
    classDef resource fill:#f0f8ff,stroke:#4682b4,stroke-width:2px;

    click P "https://github.com/dynam1co/ia_arboles_busqueda_python/blob/master/Readme.md"
    click NF "https://github.com/dynam1co/ia_arboles_busqueda_python/blob/master/arbol.py"
    click BFS "https://github.com/dynam1co/ia_arboles_busqueda_python/blob/master/amplitud.py"
    click DFS "https://github.com/dynam1co/ia_arboles_busqueda_python/blob/master/profundidad.py"
    click R1 "https://github.com/dynam1co/ia_arboles_busqueda_python/blob/master/resources/arbol_busqueda_amplitud.drawio"
    click R2 "https://github.com/dynam1co/ia_arboles_busqueda_python/blob/master/resources/arbol_busqueda_profundidad.drawio"
```
