A new AI constraint solver for Python: OptaPy


Python developers can now solve AI planning problems (such as the vehicle routing problem and employee rostering) with OptaPy.
Let me show you how to use OptaPy and a bit of plain Python code to tackle a typical mathematical optimization problem: generate a better school timetable schedule for teachers and students.
OptaPy is an open source project. It’s available in PyPI and is usable from a normal Python installation.
Internally, OptaPy uses OptaPlanner, so it does need a JDK installed.
Currently, it’s significantly slower than using OptaPlanner directly from Java (or Kotlin for that matter), but it works and we’re investigating ways to bridge the performance gap.
Let’s optimize that school timetable in pure Python. Feel free to follow along in the OptaPy Jupyter notebook.

Assign rooms and timeslots to lessons using OptaPy



  1. Create a new Python virtual environment.
    python3 -m venv optapy-env
  2. Activate the Python virtual environment.
    source optapy-env/bin/activate
  3. Use pip to install OptaPy.
    python3 -m pip install optapy
This post was original published on here.
0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments