Description
OptaPy is an AI constraint solver for Python to optimize the Vehicle Routing Problem, Employee Rostering, Maintenance Scheduling, Task Assignment, School Timetabling, Cloud Optimization, Conference Scheduling, Job Shop Scheduling, Bin Packing and many more planning problems.
OptaPy alternatives and similar packages
Based on the "Machine Learning" category.
Alternatively, view optapy alternatives based on common mentions on social networks and blogs.
-
xgboost
Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library, for Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Dask, Flink and DataFlow -
PaddlePaddle
PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署) -
CNTK
Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit -
Prophet
Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth. -
TFLearn
Deep learning library featuring a higher-level API for TensorFlow. -
H2O
H2O is an Open Source, Distributed, Fast & Scalable Machine Learning Platform: Deep Learning, Gradient Boosting (GBM) & XGBoost, Random Forest, Generalized Linear Modeling (GLM with Elastic Net), K-Means, PCA, Generalized Additive Models (GAM), RuleFit, Support Vector Machine (SVM), Stacked Ensembles, Automatic Machine Learning (AutoML), etc. -
NuPIC
Numenta Platform for Intelligent Computing is an implementation of Hierarchical Temporal Memory (HTM), a theory of intelligence based strictly on the neuroscience of the neocortex. -
Surprise
A Python scikit for building and analyzing recommender systems -
LightFM
A Python implementation of LightFM, a hybrid recommendation algorithm. -
Pylearn2
Warning: This project does not have any current developer. See bellow. -
Sacred
Sacred is a tool to help you configure, organize, log and reproduce experiments developed at IDSIA. -
skflow
Simplified interface for TensorFlow (mimicking Scikit Learn) for Deep Learning -
Clairvoyant
Software designed to identify and monitor social/historical cues for short term stock movement -
python-recsys
A python library for implementing a recommender system -
Metrics
Machine learning evaluation metrics, implemented in Python, R, Haskell, and MATLAB / Octave -
karateclub
Karate Club: An API Oriented Open-source Python Framework for Unsupervised Learning on Graphs (CIKM 2020) -
awesome-embedding-models
A curated list of awesome embedding models tutorials, projects and communities. -
Crab
Crab is a flexible, fast recommender engine for Python that integrates classic information filtering recommendation algorithms in the world of scientific Python packages (numpy, scipy, matplotlib). -
seqeval
A Python framework for sequence labeling evaluation(named-entity recognition, pos tagging, etc...) -
adaptive
:chart_with_upwards_trend: Adaptive: parallel active learning of mathematical functions -
Xorbits
Scalable Python DS & ML, in an API compatible & lightning fast way. -
TrueSkill, the video game rating system
An implementation of the TrueSkill rating system for Python -
SciKit-Learn Laboratory
SciKit-Learn Laboratory (SKLL) makes it easy to run machine learning experiments. -
Feature Forge
A set of tools for creating and testing machine learning features, with a scikit-learn compatible API -
Data Flow Facilitator for Machine Learning (dffml)
The easiest way to use Machine Learning. Mix and match underlying ML libraries and data set sources. Generate new datasets or modify existing ones with ease. -
Robocorp Action Server
Create 🐍 Python AI Actions and 🤖 Automations, and deploy & operate them anywhere -
MLP Classifier
A handwritten multilayer perceptron classifer using numpy. -
omega-ml
MLOps simplified. From ML Pipeline ⇨ Data Product without the hassle -
ChaiPy
A developer interface for creating advanced chatbots for the Chai app. -
tfgraphviz
A visualization tool to show a TensorFlow's graph like TensorBoard
InfluxDB - Power Real-Time Data Analytics at Scale
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of OptaPy or a related project?
README
OptaPy
OptaPy is an AI constraint solver for Python to optimize the Vehicle Routing Problem, Employee Rostering, Maintenance Scheduling, Task Assignment, School Timetabling, Cloud Optimization, Conference Scheduling, Job Shop Scheduling, Bin Packing and many more planning problems.
OptaPy wraps the OptaPlanner engine internally, but using OptaPy in Python is significantly slower than using OptaPlanner in Java or Kotlin.
Try the OptaPy Jupyter notebook.
Requirements
- Install Python 3.9 or later.
- Install JDK 11 or later with the environment variable
JAVA_HOME
configured to the JDK installation directory.
Source code overview
Domain
In OptaPy, the domain has three parts:
- Problem Facts, which do not change
- Planning Entities, which have one or more planning variables
- Planning Solution, which define the facts and entities of the problem
Problem Facts
To declare Problem Facts, use the @problem_fact
decorator
from optapy import problem_fact
@problem_fact
class Timeslot:
def __init__(self, id, day_of_week, start_time, end_time):
self.id = id
self.day_of_week = day_of_week
self.start_time = start_time
self.end_time = end_time
Planning Entities
To declare Planning Entities, use the @planning_entity
decorator
from optapy import planning_entity, planning_id, planning_variable
@planning_entity
class Lesson:
def __init__(self, id, subject, teacher, student_group, timeslot=None, room=None):
self.id = id
self.subject = subject
self.teacher = teacher
self.student_group = student_group
self.timeslot = timeslot
self.room = room
@planning_id
def get_id(self):
return self.id
@planning_variable(Timeslot, value_range_provider_refs=["timeslotRange"])
def get_timeslot(self):
return self.timeslot
def set_timeslot(self, new_timeslot):
self.timeslot = new_timeslot
@planning_variable(Room, value_range_provider_refs=["roomRange"])
def get_room(self):
return self.room
def set_room(self, new_room):
self.room = new_room
@planning_variable
method decorators are used to indicate what fields can change. MUST begin with get and have a corresponding set method (i.e.get_room(self)
,set_room(self, newRoom)
). The first parameter of the decorator is the type of the Planning Variable (required). Thevalue_range_provider_refs
parameter tells OptaPlanner what value range providers on the Planning Solution this Planning Variable can take values from.@planning_id
is used to uniquely identify an entity object of a particular class. The same Planning Id can be used on entities of different classes, but the ids of all entities in the same class must be different.
Planning Solution
To declare the Planning Solution, use the @planning_solution
decorator
from optapy import planning_solution, problem_fact_collection_property, value_range_provider, planning_entity_collection_property, planning_score
@planning_solution
class TimeTable:
def __init__(self, timeslot_list, room_list, lesson_list, score=None):
self.timeslot_list = timeslot_list
self.room_list = room_list
self.lesson_list = lesson_list
self.score = score
@problem_fact_collection_property(Timeslot)
@value_range_provider(range_id = "timeslotRange")
def get_timeslot_list(self):
return self.timeslot_list
@problem_fact_collection_property(Room)
@value_range_provider(range_id = "roomRange")
def get_room_list(self):
return self.room_list
@planning_entity_collection_property(Lesson)
def get_lesson_list(self):
return self.lesson_list
@planning_score(HardSoftScore)
def get_score(self):
return self.score
def set_score(self, score):
self.score = score
@value_range_provider(range_id)
is used to indicate a method returns values a Planning Variable can take. It can be referenced by its id in thevalue_range_provider_refs
parameter of@planning_variable
. It should also have a@problem_fact_collection_property
or a@planning_entity_collection_property
.@problem_fact_collection_property(type)
is used to indicate a method returns Problem Facts. The first parameter of the decorator is the type of the Problem Fact Collection (required). It should be a list.@planning_entity_collection_property(type)
is used to indicate a method returns Planning Entities. The first parameter of the decorator is the type of the Planning Entity Collection (required). It should be a list.@planning_score(scoreType)
is used to tell OptaPlanner what field holds the score. The method MUST begin with get and have a corresponding set method (i.e.get_score(self)
,set_score(self, score)
). The first parameter of the decorator is the score type (required).
Constraints
You define your constraints by using the ConstraintFactory
from domain import Lesson
from optapy import constraint_provider
from optapy.types import Joiners, HardSoftScore
@constraint_provider
def define_constraints(constraint_factory):
return [
# Hard constraints
room_conflict(constraint_factory),
# Other constraints here...
]
def room_conflict(constraint_factory):
# A room can accommodate at most one lesson at the same time.
return constraint_factory.for_each_unique_pair(Lesson,
# ... in the same timeslot ...
Joiners.equal(lambda lesson: lesson.timeslot),
# ... in the same room ...
Joiners.equal(lambda lesson: lesson.room)) \
.penalize("Room conflict", HardSoftScore.ONE_HARD)
for more details on Constraint Streams, see https://www.optaplanner.org/docs/optaplanner/latest/constraint-streams/constraint-streams.html
Solve
from optapy import solver_factory_create
from optapy.types import SolverConfig, Duration
from constraints import define_constraints
from domain import TimeTable, Lesson, generate_problem
solver_config = SolverConfig().withEntityClasses(Lesson) \
.withSolutionClass(TimeTable) \
.withConstraintProviderClass(define_constraints) \
.withTerminationSpentLimit(Duration.ofSeconds(30))
solver = solver_factory_create(solver_config).buildSolver()
solution = solver.solve(generate_problem())
solution
will be a TimeTable
instance with planning
variables set to the final best solution found.
More information
For quickstarts, visit the optapy quickstart repository. For a full API spec, visit the OptaPy Documentation.