The Python module OptAssign uses Reinforcement Learning to solve an assignment problem: A set of independent tasks should be assigned to simultaneously available resources in such a way that the completion time is minimized. It includes Python code for training and evaluating Reinforcement Learning models. The Reinforcement Learning approach allows for a similar solution quality compared to mathematical solvers with significantly reduced inference time. Training and evaluation of models are provided via services of an asynchronous OPC UA server.
OptAssign is built on a Reinforcement Learning approach for solving routing problems [1,2]. It views the assignment problem as a special routing problem through the assignment cost matrix, where nodes are given by (task-resource)-tuples. Visiting a node
where
The assign module can assign tasks, that do not depend on each other, to resources. The tasks are assigned to the resources with the goal of minimizing throughput time. The assignment does not set the order of the tasks, but only assigns the tasks to the resources.
The assign module uses a trained model to assign the tasks to the resources which was trained in a mixed setup of up to 10 resources and up to 50 tasks.
-
Install pyenv: https://github.com/pyenv/pyenv
-
Install python 3.12
pyenv install 3.12
- Select python 3.12
pyenv local 3.12
- Confirm that python 3.12 is selected
pyenv versions
If python 3.12 is not selected, run the following command instead of step 5:
pyenv exec python -m venv .venv
- Create a virtual environment
python -m venv .venv
- Activate the virtual environment
source .venv/bin/activate
- Install the required packages
pip install -r requirements.txt
To generate some random assignment problems (in terms of random cost and constraint matrices) for testing purposes, run the following command:
python src/generate_random_problems.py --num-to-gen NUM_TO_GEN --batch-size BATCH_SIZE --num-resources-max NUM_RESOURCES_MAX [--mixed-num-resources] --num-tasks-max NUM_TASKS_MAX [--mixed-num-tasks] --save-path SAVE_PATH
To train a model, run the following command:
python src/train.py
To assign tasks to resources using a trained model specified in config/assigner.json, run the following command:
python src/assign.py (--cost-constraint-matrices path | --user-input-json path)
- The user-input-json file defines the assignment problem in terms of the given resources and the given tasks. For each task, the constraints have to be specified in terms of on which resources a task can be processed and which processing cost it implies. See /assign_input/input.json for an example file.
- Alternatively, the assignment problem definition can be handed-over as a cost-constraint-matrix. It contains the cost matrix of size
$m \times n$ consisting of the cost values$c_{i,j}$ for all tasks$i$ and resources$j$ , as well as the binary constraint matrix of equal size which defines whether task$i$ can be assigned to resource$j$ (value=1) or not (value=0). See /source/generate_random_problems.py for the generation of multiple assignment problems in terms of const-constraint-matrices (=entry in generated_problems).
Our license can be found in the LICENSE.md file.
[1] Kwon, Y.D., Choo, J., Kim, B., Yoon, I., Gwon , Y., Min, S.: Pomo: Policy optimization with multiple optima for reinforcement learning. Advances in Neural Information Processing Systems 33,21188 21198 (2020)
[2] Kool, W., van Hoof, H., Welling, M.: Attention, learn to solve routing problems! In: International Conference on Learning Representations (2019)
[3] Paul, N., Kister, A., Schnellhardt, T., Fetz, M., Hecker, D., Wirtz, T.: Reinforcement learning for segmented manufacturing. Presented at the workshop AI for Manufacturing (AI4M), European Conference on Machine Learning and Principles and Practice of Knowledge Discovery in Databases (2023)