# kaydo214/mec architecture

> Architecture diagram of the GitHub repository kaydo214/mec, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaydo214/mec
- Repository: https://github.com/kaydo214/mec

## Overview

This repository is a Python simulation for learning mobile-task offloading policies and comparing tabular Q-learning with DQN. The principal workflow generates tasks and MEC conditions, represents them as state, selects Local/Edge/Cloud execution, computes costs and battery effects, and learns from repeated episodes before evaluating policy metrics. The two implementations are standalone entry points sharing the MEC environment: MEC.py contains the tabular baseline, while DQN.py adds neural value estimation and replay-based training. The map follows the README and excerpts; relationships for unsampled code are included only where documented.

Main entry points: [`DQN.py`](https://github.com/kaydo214/mec/blob/main/DQN.py) (DQN training), [`MEC.py`](https://github.com/kaydo214/mec/blob/main/MEC.py) (Q-learning training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["MEC Simulation"]
  node_task_conditions["Task and conditions<br/>[MEC.py]"]
  node_state["State encoding<br/>[MEC.py]"]
  node_execution["Offload execution<br/>[MEC.py]"]
  node_cost_battery["Reward and battery<br/>[MEC.py]"]
end

subgraph group_qlearning["Tabular Q-Learning"]
  node_mec_entry["MEC entry point<br/>[MEC.py]"]
  node_q_agent["Q-table agent<br/>[MEC.py]"]
end

subgraph group_dqn["Deep Q-Network"]
  node_dqn_entry["DQN entry point<br/>[DQN.py]"]
  node_dqn_agent["DQN agent<br/>[DQN.py]"]
  node_policy_net["Policy network<br/>[DQN.py]"]
  node_target_net["Target network<br/>[DQN.py]"]
  node_replay[("Replay memory<br/>[DQN.py]")]
end

subgraph group_results["Training And Evaluation"]
  node_q_training["Q-learning training<br/>[MEC.py]"]
  node_dqn_training["DQN training<br/>[DQN.py]"]
  node_evaluation["Policy evaluation<br/>[MEC.py]"]
  node_dqn_evaluation["DQN evaluation<br/>[DQN.py]"]
  node_reporting["Metrics and plots<br/>[DQN.py]"]
end

node_user(("Experiment runner"))

node_user -->|"runs baseline"| node_mec_entry
node_user -->|"runs DQN"| node_dqn_entry
node_mec_entry -->|"starts training"| node_q_training
node_dqn_entry -->|"starts training"| node_dqn_training
node_q_training -->|"resets episode"| node_task_conditions
node_q_training -->|"selects and updates"| node_q_agent
node_q_training -->|"steps environment"| node_execution
node_dqn_training -->|"resets episode"| node_task_conditions
node_dqn_training -->|"selects actions"| node_dqn_agent
node_dqn_training -->|"steps environment"| node_execution
node_dqn_training -->|"stores transitions"| node_replay
node_dqn_agent -->|"predicts values"| node_policy_net
node_dqn_agent -->|"computes targets"| node_target_net
node_dqn_agent -->|"samples batches"| node_replay
node_task_conditions -->|"encodes features"| node_state
node_state -->|"provides state"| node_q_agent
node_state -->|"provides state"| node_dqn_agent
node_execution -->|"calculates costs"| node_cost_battery
node_cost_battery -->|"prepares next task"| node_task_conditions
node_mec_entry -->|"evaluates policy"| node_evaluation
node_dqn_entry -->|"evaluates policy"| node_dqn_evaluation
node_evaluation -->|"reports metrics"| node_reporting
node_dqn_evaluation -->|"reports metrics"| node_reporting

click node_mec_entry "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_dqn_entry "https://github.com/kaydo214/mec/blob/main/DQN.py"
click node_task_conditions "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_state "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_execution "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_cost_battery "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_q_agent "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_dqn_agent "https://github.com/kaydo214/mec/blob/main/DQN.py"
click node_policy_net "https://github.com/kaydo214/mec/blob/main/DQN.py"
click node_target_net "https://github.com/kaydo214/mec/blob/main/DQN.py"
click node_replay "https://github.com/kaydo214/mec/blob/main/DQN.py"
click node_q_training "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_dqn_training "https://github.com/kaydo214/mec/blob/main/DQN.py"
click node_evaluation "https://github.com/kaydo214/mec/blob/main/MEC.py"
click node_dqn_evaluation "https://github.com/kaydo214/mec/blob/main/DQN.py"
click node_reporting "https://github.com/kaydo214/mec/blob/main/DQN.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_task_conditions,node_state,node_execution,node_cost_battery toneBlue
class node_mec_entry,node_q_agent toneAmber
class node_dqn_entry,node_dqn_agent,node_policy_net,node_target_net,node_replay toneMint
class node_q_training,node_dqn_training,node_evaluation,node_dqn_evaluation,node_reporting toneRose
class node_user toneIndigo
```

## Components

### MEC Simulation

- [Task and conditions](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`
- [State encoding](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`
- [Offload execution](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`
- [Reward and battery](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`

### Tabular Q-Learning

- [MEC entry point](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`
- [Q-table agent](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`

### Deep Q-Network

- [DQN entry point](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`
- [DQN agent](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`
- [Policy network](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`
- [Target network](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`
- [Replay memory](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`

### Training And Evaluation

- [Q-learning training](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`
- [DQN training](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`
- [Policy evaluation](https://github.com/kaydo214/mec/blob/main/MEC.py): `MEC.py`
- [DQN evaluation](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`
- [Metrics and plots](https://github.com/kaydo214/mec/blob/main/DQN.py): `DQN.py`

### Other components

- **Experiment runner**

## Connections

- Experiment runner → MEC entry point: runs baseline (evidence: `README.md`)
- Experiment runner → DQN entry point: runs DQN (evidence: `README.md`)
- MEC entry point → Q-learning training: starts training (evidence: `MEC.py`)
- DQN entry point → DQN training: starts training (evidence: `DQN.py`)
- Q-learning training → Task and conditions: resets episode (evidence: `MEC.py`)
- Q-learning training → Q-table agent: selects and updates (evidence: `MEC.py`)
- Q-learning training → Offload execution: steps environment (evidence: `MEC.py`)
- DQN training → Task and conditions: resets episode (evidence: `README.md`)
- DQN training → DQN agent: selects actions (evidence: `DQN.py`)
- DQN training → Offload execution: steps environment (evidence: `DQN.py`)
- DQN training → Replay memory: stores transitions (evidence: `DQN.py`)
- DQN agent → Policy network: predicts values (evidence: `DQN.py`)
- DQN agent → Target network: computes targets (evidence: `DQN.py`)
- DQN agent → Replay memory: samples batches (evidence: `DQN.py`)
- Task and conditions → State encoding: encodes features (evidence: `README.md`)
- State encoding → Q-table agent: provides state (evidence: `MEC.py`)
- State encoding → DQN agent: provides state (evidence: `README.md`)
- Offload execution → Reward and battery: calculates costs (evidence: `MEC.py`)
- Reward and battery → Task and conditions: prepares next task (evidence: `MEC.py`)
- MEC entry point → Policy evaluation: evaluates policy (evidence: `MEC.py`)
- DQN entry point → DQN evaluation: evaluates policy (evidence: `DQN.py`)
- Policy evaluation → Metrics and plots: reports metrics (evidence: `README.md`)
- DQN evaluation → Metrics and plots: reports metrics (evidence: `DQN.py`)
