Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlexShop - Intelligent Job Shop Scheduler

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.

Overview

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

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         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              │   │
│  └──────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────┘

Features

Scheduling Strategies

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

Learning System

The system implements adaptive learning based on the thesis:

  1. Reinforcement Learning

    • Strategy weights are updated based on performance
    • Good decisions increase strategy weight
    • Poor decisions decrease strategy weight
    • Forgetting factor decays old decisions
  2. Genetic Algorithms

    • Chromosome encoding of strategy preferences
    • Mutation introduces variation
    • Crossover combines successful strategies
    • Selection favors better-performing products

Simulation Modes

  • Fast Mode: Run simulation as fast as possible
  • Real-time Mode: Simulate at 1x speed (adjustable)
  • Step Mode: Manual step-by-step execution

Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • npm or yarn

Backend Setup

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 8000

Frontend Setup

cd frontend

# Install dependencies
npm install

# Run development server
npm run dev

Access the Application

Project Structure

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

API Endpoints

Simulation Control

  • POST /api/simulation/create - Create new simulation
  • GET /api/simulation/{id} - Get simulation state
  • POST /api/simulation/{id}/start - Start simulation
  • POST /api/simulation/{id}/pause - Pause simulation
  • POST /api/simulation/{id}/resume - Resume simulation
  • POST /api/simulation/{id}/stop - Stop simulation
  • POST /api/simulation/{id}/step - Single step
  • POST /api/simulation/{id}/reset - Reset simulation

Configuration

  • GET /api/configuration/strategies - Get available strategies
  • PUT /api/configuration/{id}/learning - Update learning parameters

Statistics

  • GET /api/statistics/{id}/summary - Performance summary
  • GET /api/statistics/{id}/machines - Machine statistics
  • GET /api/statistics/{id}/strategies - Strategy analysis
  • GET /api/statistics/{id}/learning - Learning curves
  • GET /api/statistics/{id}/events - Event log

Learning Parameters

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

Testing

Backend Tests

cd backend
pytest tests/ -v
pytest tests/ --cov=app --cov-report=html

Frontend Tests

cd frontend
npm run test

Configuration Example

{
  "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
  }
}

Performance Metrics

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

Based On

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

License

MIT License

About

Flexible job-shop scheduling simulator using autonomous manufacturing agents, reinforcement learning and genetic algorithms, with a React and FastAPI interface.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages