A modern implementation of a heterarchical manufacturing control system with reinforcement learning and genetic algorithms. Based on the thesis by Salah Ben Hédi Bousbia (2006), this system demonstrates how autonomous agents can learn optimal scheduling strategies through experience.
This system simulates a flexible job shop scheduling environment where:
- Products (EMP) autonomously select machines using learned strategies
- Machines (EFT) select tasks from their queues using adaptive strategies
- Learning System uses reinforcement learning and genetic algorithms to improve scheduling decisions over time
┌─────────────────────────────────────────────────────────────────┐
│ Frontend (React) │
│ Dashboard │ Configuration │ Simulation │ Statistics │ Journal │
└─────────────────────────────┬───────────────────────────────────┘
│ REST API / WebSocket
┌─────────────────────────────┴───────────────────────────────────┐
│ Backend (FastAPI) │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ Simulation │ │ Learning │ │ Strategies │ │
│ │ Engine │◄─┤ System │◄─┤ Product │ Machine │ │
│ └──────┬──────┘ └─────────────┘ └─────────────────────────┘ │
│ │ │
│ ┌──────▼──────────────────────────────────────────────────┐ │
│ │ Domain Models │ │
│ │ Workshop │ Machine │ Product │ Job │ Task │ │
│ └──────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Product Strategies (Machine Selection):
| Code | Strategy | Description |
|---|---|---|
| SPT | Shortest Processing Time | Select machine with minimum processing time |
| LPT | Longest Processing Time | Select machine with maximum processing time |
| FIFO | First In First Out | Select first available machine |
| SQS | Shortest Queue Size | Select machine with shortest queue |
| LQS | Longest Queue Size | Select machine with longest queue |
| SWT | Shortest Waiting Time | Select machine with minimum expected wait |
| LWT | Longest Waiting Time | Select machine with maximum expected wait |
| MCT | Minimum Completion Time | Select machine with earliest completion |
| RND | Random | Random machine selection |
Machine Strategies (Task Selection):
| Code | Strategy | Description |
|---|---|---|
| FIFO | First Come First Serve | Process tasks in arrival order |
| SPT | Shortest Processing Time | Process shortest task first |
| LPT | Longest Processing Time | Process longest task first |
| EDD | Earliest Due Date | Process task with earliest deadline |
| PRIORITY | Priority Based | Process highest priority task |
| SLACK | Minimum Slack | Process task with least slack time |
| CR | Critical Ratio | Process by critical ratio |
| LW | Least Work | Process task with least remaining work |
| RND | Random | Random task selection |
The system implements adaptive learning based on the thesis:
-
Reinforcement Learning
- Strategy weights are updated based on performance
- Good decisions increase strategy weight
- Poor decisions decrease strategy weight
- Forgetting factor decays old decisions
-
Genetic Algorithms
- Chromosome encoding of strategy preferences
- Mutation introduces variation
- Crossover combines successful strategies
- Selection favors better-performing products
- Fast Mode: Run simulation as fast as possible
- Real-time Mode: Simulate at 1x speed (adjustable)
- Step Mode: Manual step-by-step execution
- Python 3.11+
- Node.js 18+
- npm or yarn
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the server
uvicorn app.main:app --reload --port 8000cd frontend
# Install dependencies
npm install
# Run development server
npm run dev- Frontend: http://localhost:5173
- API Documentation: http://localhost:8000/docs
- WebSocket: ws://localhost:8000/ws/simulation/{id}
PFE/
├── backend/
│ ├── app/
│ │ ├── models/ # Domain models
│ │ ├── strategies/ # Scheduling strategies
│ │ ├── learning/ # Learning system
│ │ ├── simulation/ # Simulation engine
│ │ ├── api/ # REST API endpoints
│ │ └── main.py # FastAPI entry point
│ ├── tests/ # Backend tests
│ └── requirements.txt
├── frontend/
│ ├── src/
│ │ ├── pages/ # React pages
│ │ ├── components/ # UI components
│ │ ├── hooks/ # Custom hooks
│ │ ├── services/ # API client
│ │ ├── store/ # State management
│ │ └── types/ # TypeScript types
│ └── package.json
└── README.md
POST /api/simulation/create- Create new simulationGET /api/simulation/{id}- Get simulation statePOST /api/simulation/{id}/start- Start simulationPOST /api/simulation/{id}/pause- Pause simulationPOST /api/simulation/{id}/resume- Resume simulationPOST /api/simulation/{id}/stop- Stop simulationPOST /api/simulation/{id}/step- Single stepPOST /api/simulation/{id}/reset- Reset simulation
GET /api/configuration/strategies- Get available strategiesPUT /api/configuration/{id}/learning- Update learning parameters
GET /api/statistics/{id}/summary- Performance summaryGET /api/statistics/{id}/machines- Machine statisticsGET /api/statistics/{id}/strategies- Strategy analysisGET /api/statistics/{id}/learning- Learning curvesGET /api/statistics/{id}/events- Event log
| Parameter | Symbol | Default | Description |
|---|---|---|---|
| Forgetting Factor | λ | 0.9 | Rate at which old decisions decay |
| Performance Threshold | θ | 0.7 | Threshold for positive reinforcement |
| Reinforcement Signal | σ | 0.1 | Strength of weight updates |
| Mutation Rate | μ | 0.05 | Probability of gene mutation |
cd backend
pytest tests/ -v
pytest tests/ --cov=app --cov-report=htmlcd frontend
npm run test{
"name": "Production Line Simulation",
"mode": "fast",
"num_machines": 5,
"jobs": [
{
"id": 1,
"name": "Assembly Job",
"tasks": [
{
"operation_index": 0,
"operation_type": 1,
"compatible_machines": [1, 2],
"processing_times": {"1": 10.0, "2": 12.0}
}
]
}
],
"learning": {
"enabled": true,
"forgetting_factor": 0.9,
"performance_threshold": 0.7,
"reinforcement_signal": 0.1,
"mutation_rate": 0.05
}
}The system tracks these key performance indicators:
- Makespan: Total time to complete all products
- Flow Time: Time each product spends in the system
- Throughput: Products completed per time unit
- Utilization: Machine busy time percentage
- Tardiness: Delay beyond due dates
- Strategy Effectiveness: Performance of each strategy
This implementation is based on the thesis:
"Proposition d'une architecture de pilotage hétérarchique basée sur des entités autonomes: application au pilotage d'atelier de type Job Shop Flexible" by Salah Ben Hédi Bousbia, 2006
MIT License