incubator-kie-optaplanner
OplaPlanner has moved to https://github.com/apache/incubator-kie-drools. This repository is archived. OptaPlanner is an AI constraint solver in Java to optimize the vehicle routing problem, employee rostering, task assignment, maintenance scheduling, conference scheduling and other planning problems.
Top Related Projects
Quick Overview
Apache OptaPlanner is an AI constraint solver that optimizes planning and scheduling problems. It's a lightweight, embeddable planning engine that can help solve complex optimization problems such as vehicle routing, employee rostering, and task assignment.
Pros
- Powerful optimization capabilities for a wide range of planning problems
- Integrates well with Java and other JVM languages
- Supports various optimization algorithms and heuristics
- Open-source with active community support
Cons
- Steep learning curve for beginners
- Performance can be affected by problem complexity
- Limited built-in visualization tools
- May require fine-tuning for optimal performance in specific use cases
Code Examples
- Defining a planning entity:
@PlanningEntity
public class Task {
@PlanningVariable(valueRangeProviderRefs = "employeeRange")
private Employee employee;
// Other properties and methods
}
- Configuring a solver:
SolverConfig solverConfig = new SolverConfig()
.withSolutionClass(TaskAssignmentSolution.class)
.withEntityClasses(Task.class)
.withConstraintProviderClass(TaskAssignmentConstraintProvider.class)
.withTerminationSpentLimit(Duration.ofMinutes(5));
SolverFactory<TaskAssignmentSolution> solverFactory = SolverFactory.create(solverConfig);
Solver<TaskAssignmentSolution> solver = solverFactory.buildSolver();
- Solving a problem:
TaskAssignmentSolution problem = // ... create or load a problem
TaskAssignmentSolution solution = solver.solve(problem);
Getting Started
- Add OptaPlanner dependency to your project:
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
<version>8.32.0.Final</version>
</dependency>
-
Define your domain model with
@PlanningSolution,@PlanningEntity, and@PlanningVariableannotations. -
Implement a
ConstraintProviderto define score rules. -
Configure and run the solver as shown in the code examples above.
-
For more detailed instructions, refer to the OptaPlanner documentation: https://www.optaplanner.org/docs/optaplanner/latest/quickstart/quickstart.html
Competitor Comparisons
Google's Operations Research tools:
Pros of OR-Tools
- Broader scope: Supports a wide range of optimization problems beyond constraint satisfaction
- Multi-language support: Offers APIs for C++, Python, Java, and .NET
- Extensive documentation and examples for various use cases
Cons of OR-Tools
- Steeper learning curve due to its broader scope and more complex API
- Less focus on specific business planning problems compared to OptaPlanner
- May require more low-level programming for some use cases
Code Comparison
OptaPlanner (Java):
@PlanningEntity
public class Shift {
@PlanningVariable(valueRangeProviderRefs = {"employeeRange"})
private Employee employee;
// ...
}
OR-Tools (Python):
from ortools.sat.python import cp_model
model = cp_model.CpModel()
x = model.NewIntVar(0, 10, 'x')
y = model.NewIntVar(0, 10, 'y')
model.Add(x + 2 * y <= 15)
OptaPlanner focuses on high-level constraint modeling for business problems, while OR-Tools provides a more general-purpose optimization toolkit with lower-level constructs. OptaPlanner's approach may be more intuitive for domain-specific problems, whereas OR-Tools offers greater flexibility for a wider range of optimization scenarios.
COIN-OR Branch-and-Cut solver
Pros of Cbc
- Specialized for mixed-integer linear programming (MILP) problems
- Highly efficient for large-scale optimization tasks
- Extensive documentation and academic support
Cons of Cbc
- Limited to linear programming and mixed-integer linear programming
- Steeper learning curve for non-experts in mathematical optimization
- Less flexible for general-purpose constraint solving
Code Comparison
Cbc (C++):
OsiClpSolverInterface solver1;
CbcModel model(solver1);
int numcols = 3;
int numrows = 5;
double obj[3] = {1.0, 2.0, 3.0};
model.solver()->loadProblem(numcols, numrows, start, index, value, collb, colub, obj, rowlb, rowub);
KIE OptaPlanner (Java):
SolverFactory<VehicleRoutingSolution> solverFactory = SolverFactory.createFromXmlResource("vehicleRoutingSolverConfig.xml");
Solver<VehicleRoutingSolution> solver = solverFactory.buildSolver();
VehicleRoutingSolution solution = new VehicleRoutingSolution();
// ... populate solution
solver.solve(solution);
Cbc focuses on mathematical programming syntax, while KIE OptaPlanner uses a more object-oriented approach with domain-specific modeling. Cbc requires explicit problem formulation, whereas KIE OptaPlanner allows for more intuitive problem representation using Java objects and XML configuration.
A python Linear Programming API
Pros of PuLP
- Lightweight and easy to install, with minimal dependencies
- Supports multiple solvers, including open-source options like CBC
- Simple and intuitive Python API for linear programming problems
Cons of PuLP
- Limited to linear programming and mixed-integer programming
- Less comprehensive documentation and community support
- Fewer advanced optimization techniques compared to OptaPlanner
Code Comparison
PuLP example:
from pulp import *
prob = LpProblem("Simple LP Problem", LpMaximize)
x = LpVariable("x", lowBound=0)
y = LpVariable("y", lowBound=0)
prob += x + y <= 2
prob += -4*x + y <= 0
prob += x + 2*y <= 14
prob += 2*x - y
OptaPlanner example:
@PlanningSolution
public class CloudBalance {
@PlanningEntityCollectionProperty
private List<CloudProcess> processList;
@ValueRangeProvider(id = "computerRange")
@ProblemFactCollectionProperty
private List<CloudComputer> computerList;
@PlanningScore
private HardSoftScore score;
// ...
}
While PuLP focuses on mathematical programming with a concise syntax, OptaPlanner provides a more comprehensive framework for complex optimization problems with annotations and domain-specific modeling.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
//// Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ////
â¹ï¸ NOTE
This repository's source code has moved!
The OptaPlanner codebase has been merged into the https://github.com/apache/incubator-kie-drools[apache/incubator-kie-drools] repository. Please use it for the latest source code, to file issues, and to submit contributions.
This repository is archived.
image:https://img.shields.io/maven-central/v/org.optaplanner/optaplanner-bom?logo=apache-maven&style=for-the-badge["Maven artifact", link="https://ossindex.sonatype.org/component/pkg:maven/org.optaplanner/optaplanner-bom"] image:https://img.shields.io/badge/stackoverflow-ask_question-orange.svg?logo=stackoverflow&style=for-the-badge["Stackoverflow", link="https://stackoverflow.com/questions/tagged/optaplanner"] image:https://img.shields.io/badge/zulip-join_chat-brightgreen.svg?logo=zulip&style=for-the-badge[ "Join Zulip Chat", link="https://kie.zulipchat.com/#narrow/stream/232679-optaplanner"] image:https://img.shields.io/github/license/apache/incubator-kie-drools?style=for-the-badge&logo=apache["License", link="https://www.apache.org/licenses/LICENSE-2.0"] image:https://img.shields.io/badge/Maven-3.x-blue?style=for-the-badge["Maven",link="https://maven.apache.org/install.html"]
A fast, easy-to-use, open source AI constraint solver for software developers
== Looking for Quickstarts?
OptaPlanner's quickstarts are located in the https://github.com/kiegroup/optaplanner-quickstarts[optaplanner-quickstarts repository].
== Quick development start
To build and run from source:
$ mvn clean install -Dquickly $ cd optaplanner-examples $ mvn exec:java
To develop with IntelliJ IDEA, Eclipse or VSCode, open the root pom.xml as a new project
and configure a Run/Debug configuration like this:
- Type: Application
- Main class:
org.optaplanner.examples.app.OptaPlannerExamplesApp - VM options:
-Xmx2G -server(memory only needed when using the big datasets in the examples) - Program arguments: (none)
- Working directory:
$MODULE_DIR$(must resolve to optaplanner-examples directory) - Use classpath of module:
optaplanner-examples
== Contributing to OptaPlanner
[NOTE]
This repository is archived â contributions are no longer accepted here. Please contribute to https://github.com/apache/incubator-kie-drools[apache/incubator-kie-drools] instead.
=== Code standards
Your code is automatically formatted according to the Import and Code Style conventions during every Maven build. CI checks enforce those conventions too, so be sure to build your project with maven before creating your PR:
mvn clean install
For information about how to set up code style checks, see https://github.com/kiegroup/optaplanner/blob/main/build/optaplanner-ide-config/ide-configuration.adoc[IDE Setup Instructions].
=== Building your OptaPlanner project
Use one of the following ways to build your OptaPlanner project:
-
:rocket: build-fast:
mvn clean install -Dquicklyskips any checks and code analysis (~1 min) -
:hammer: build-normally:
mvn clean installruns tests, checks code style, skips documentation (~17 min) -
:receipt: build-doc:
mvn clean installatoptaplanner/optaplanner-docscreates asciidoctor documentationtarget/optaplanner-docs-*/html_single/index.html(~2 min) -
:mechanical_arm: build-all:
mvn clean install -Dfullruns all checks + creates documentation and distribution files (~20 min)
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot