Convert Figma logo to code with AI

apache logoincubator-kie-optaplanner

AI constraint solver in Java to optimize the vehicle routing problem, employee rostering, task assignment, maintenance scheduling, conference scheduling and other planning problems.

3,323
947
3,323
23

Top Related Projects

11,147

Google's Operations Research tools:

2,080

A python Linear Programming API

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

  1. Defining a planning entity:
@PlanningEntity
public class Task {
    @PlanningVariable(valueRangeProviderRefs = "employeeRange")
    private Employee employee;
    
    // Other properties and methods
}
  1. 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();
  1. Solving a problem:
TaskAssignmentSolution problem = // ... create or load a problem
TaskAssignmentSolution solution = solver.solve(problem);

Getting Started

  1. Add OptaPlanner dependency to your project:
<dependency>
    <groupId>org.optaplanner</groupId>
    <artifactId>optaplanner-core</artifactId>
    <version>8.32.0.Final</version>
</dependency>
  1. Define your domain model with @PlanningSolution, @PlanningEntity, and @PlanningVariable annotations.

  2. Implement a ConstraintProvider to define score rules.

  3. Configure and run the solver as shown in the code examples above.

  4. For more detailed instructions, refer to the OptaPlanner documentation: https://www.optaplanner.org/docs/optaplanner/latest/quickstart/quickstart.html

Competitor Comparisons

11,147

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.

2,080

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

//// 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. ////

:projectKey: org.optaplanner:optaplanner :sonarBadge: image:https://sonarcloud.io/api/project_badges/measure?project={projectKey} :sonarLink: link="https://sonarcloud.io/dashboard?id={projectKey}"

:branch: main

:jenkinsUrl: https://eng-jenkins-csb-business-automation.apps.ocp-c1.prod.psi.redhat.com/job/KIE/job/optaplanner :branchJenkinsUrl: {jenkinsUrl}/job/{branch} :toolsFolderJenkinsUrl: {branchJenkinsUrl}/job/tools :releaseFolderJenkinsUrl: {branchJenkinsUrl}/job/release

image::optaplanner-docs/src/modules/ROOT/images/shared/optaPlannerLogo.png[link="https://www.optaplanner.org/",OptaPlanner,150,150,align="center"]

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/commit-activity/m/kiegroup/optaplanner?label=commits&style=for-the-badge["Commit Activity", link="https://github.com/kiegroup/optaplanner/pulse"] image:https://img.shields.io/github/license/kiegroup/optaplanner?style=for-the-badge&logo=apache["Livense", link="https://www.apache.org/licenses/LICENSE-2.0"] image:https://img.shields.io/badge/JVM-11--17-brightgreen.svg?style=for-the-badge["JVM support", link="https://github.com/kiegroup/optaplanner/actions/workflows/pull_request.yml"] image:https://img.shields.io/badge/Maven-3.x-blue?style=for-the-badge["Maven",link="https://maven.apache.org/install.html"] image:https://img.shields.io/github/languages/code-size/kiegroup/optaplanner?style=for-the-badge["Code size", link="https://github.com/kiegroup/optaplanner/actions/workflows/pull_request.yml"]

{sonarBadge}&style=for-the-badge&metric=reliability_rating["Reliability Rating", {sonarLink}] {sonarBadge}&metric=security_rating["Security Rating", {sonarLink}] {sonarBadge}&metric=sqale_rating["Maintainability Rating", {sonarLink}] {sonarBadge}&metric=coverage["Coverage", {sonarLink}]

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

This is an open source project, and you are more than welcome to contribute :heart:!

=== Time to make a change?

Every change must be submitted through a GitHub pull request (PR). OptaPlanner uses continuous integration (CI). The OptaPlanner CI runs checks against your branch after you submit the PR to ensure that your PR doesn't introduce errors. If the CI identifies a potential problem, our friendly PR maintainers will help you resolve it.

=== Contributing

. Fork it (https://github.com/kiegroup/optaplanner). . Create your feature branch: (git checkout -b feature). . Commit your changes with a comment: (git commit -am 'Add some feature'). . Push to the branch to GitHub: (git push origin feature). . Create a new pull request.

=== 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 -Dquickly skips any checks and code analysis (~1 min)

  • :hammer: build-normally: mvn clean install runs tests, checks code style, skips documentation (~17 min)

  • :receipt: build-doc: mvn clean install at optaplanner/optaplanner-docs creates asciidoctor documentation target/optaplanner-docs-*/html_single/index.html (~2 min)

  • :mechanical_arm: build-all: mvn clean install -Dfull runs all checks + creates documentation and distribution files (~20 min)

== OptaPlanner CI status

You can check the CI status of the OptaPlanner repositories from the https://kiegroup.github.io/optaplanner/[Chain Status webpage].

=== Jenkins CI Jobs (need VPN access) ===

All Jenkins jobs can be found under the OptaPlanner folder: {jenkinsUrl}

Interesting Jenkins CI jobs (need VPN access):

  • {toolsFolderJenkinsUrl}/job/update-quarkus-all/[Update Quarkus version]
  • {toolsFolderJenkinsUrl}/job/update-drools-optaplanner/[Update Drools version]
  • {releasefolderjenkinsurl}/job/optaplanner-release[Release pipeline] (only available on release branches)
  • {releasefolderjenkinsurl}/job/optaplanner-post-release[Post-Release pipeline] (only available on release branches)