timefold-solver
The open source Solver AI for Java, Python and Kotlin to optimize scheduling and routing. Solve the vehicle routing problem, employee rostering, task assignment, maintenance scheduling and other planning problems.
Top Related Projects
Google's Operations Research tools:
Quick Overview
Timefold-solver is an open-source constraint satisfaction solver designed for optimizing planning and scheduling problems. It provides a powerful engine for solving complex optimization challenges in various domains, such as vehicle routing, employee rostering, and task scheduling.
Pros
- Highly flexible and adaptable to a wide range of optimization problems
- Offers multiple optimization algorithms and heuristics
- Integrates well with Java and other JVM languages
- Provides comprehensive documentation and examples
Cons
- Steep learning curve for beginners in optimization
- Performance can vary depending on problem complexity and configuration
- May require significant tuning for optimal results in complex scenarios
- Limited support for non-JVM languages
Code Examples
- Defining a planning entity:
@PlanningEntity
public class Task {
@PlanningVariable(valueRangeProviderRefs = "employeeRange")
private Employee employee;
@PlanningVariable(valueRangeProviderRefs = "timeSlotRange")
private TimeSlot timeSlot;
// Getters and setters
}
- Configuring the solver:
SolverConfig solverConfig = new SolverConfig()
.withSolutionClass(TaskSchedule.class)
.withEntityClasses(Task.class)
.withConstraintProviderClass(TaskSchedulingConstraintProvider.class)
.withTerminationSpentLimit(Duration.ofMinutes(5));
SolverFactory<TaskSchedule> solverFactory = SolverFactory.create(solverConfig);
Solver<TaskSchedule> solver = solverFactory.buildSolver();
- Solving the problem:
TaskSchedule problem = // ... create or load the problem
TaskSchedule solution = solver.solve(problem);
System.out.println("Best score: " + solution.getScore());
Getting Started
To start using Timefold-solver in your project:
- Add the dependency to your
pom.xml
(for Maven):
<dependency>
<groupId>ai.timefold.solver</groupId>
<artifactId>timefold-solver-core</artifactId>
<version>1.0.0</version>
</dependency>
- Define your problem domain classes (planning entities, planning variables, and problem facts).
- Implement the
@PlanningSolution
class to represent your entire problem and solution. - Create a constraint provider to define the scoring rules.
- Configure and run the solver as shown in the code examples above.
For more detailed instructions and examples, refer to the official Timefold-solver documentation.
Competitor Comparisons
Google's Operations Research tools:
Pros of OR-Tools
- Extensive library with a wide range of optimization algorithms and techniques
- Strong support for mixed-integer programming and constraint programming
- Backed by Google, ensuring long-term support and development
Cons of OR-Tools
- Steeper learning curve due to its comprehensive nature
- Less focus on specific business problem domains compared to Timefold
- May require more setup and configuration for certain use cases
Code Comparison
Timefold-solver (Java):
SolverFactory<VehicleRoutingSolution> solverFactory = SolverFactory.create(solverConfig);
Solver<VehicleRoutingSolution> solver = solverFactory.buildSolver();
VehicleRoutingSolution solution = solver.solve(problem);
OR-Tools (Python):
routing = pywrapcp.RoutingModel(manager)
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
solution = routing.SolveWithParameters(search_parameters)
Both libraries offer powerful optimization capabilities, but Timefold-solver focuses more on business-oriented problems with a simpler API, while OR-Tools provides a broader range of optimization tools with more flexibility and control over the solving process.
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
:projectKey: ai.timefold:timefold-solver :sonarBadge: image:https://sonarcloud.io/api/project_badges/measure?project={projectKey} :sonarLink: link="https://sonarcloud.io/dashboard?id={projectKey}" :branch: main
image::docs/src/modules/ROOT/images/shared/timefold-logo.png[link="https://timefold.ai",Timefold,align="center"]
Planning optimization made easy. + https://timefold.ai[timefold.ai]
image:https://img.shields.io/badge/stackoverflow-ask_question-orange.svg?logo=stackoverflow&style=for-the-badge["Stackoverflow", link="https://stackoverflow.com/questions/tagged/timefold"] image:https://img.shields.io/github/discussions/TimefoldAI/timefold-solver?style=for-the-badge&logo=github["GitHub Discussions", link="https://github.com/TimefoldAI/timefold-solver/discussions"]
image:https://img.shields.io/github/commit-activity/m/TimefoldAI/timefold-solver?label=commits&style=for-the-badge["Commit Activity", link="https://github.com/TimefoldAI/timefold-solver/pulse"] image:https://img.shields.io/github/issues/TimefoldAI/timefold-solver?style=for-the-badge&logo=github["GitHub Issues", link="https://github.com/TimefoldAI/timefold-solver/issues"]
{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}]
Timefold Solver is an AI constraint solver for Java, https://github.com/TimefoldAI/timefold-solver/tree/main/python#readme[Python] and Kotlin. You can use Timefold Solver to optimize the Vehicle Routing Problem, Employee Rostering, Maintenance Scheduling, Task Assignment, School Timetabling, Cloud Optimization, Conference Scheduling, Job Shop Scheduling and many more planning problems.
Developed by the original OptaPlanner team, our aim is to free the world of wasteful planning.
== Get started with Timefold Solver in Java
image:https://img.shields.io/maven-central/v/ai.timefold.solver/timefold-solver-bom?logo=apache-maven&style=for-the-badge["Maven artifact", link="https://ossindex.sonatype.org/component/pkg:maven/ai.timefold.solver/timefold-solver-bom"] image:https://img.shields.io/badge/Java-17+-brightgreen.svg?style=for-the-badge["JVM support", link="https://sdkman.io"]
- https://timefold.ai/docs[Read a Getting Started guide.]
- https://github.com/TimefoldAI/timefold-quickstarts[Clone the Quickstarts repository.]
== Build from source
. Install JDK 17+ and Maven 3.9+, for example with https://sdkman.io[Sdkman]: +
$ sdk install java $ sdk install maven
. Git clone this repository: +
$ git clone https://github.com/TimefoldAI/timefold-solver.git $ cd timefold-solver
. Build it from source: +
$ mvn clean install -Dquickly
== Contribute
This is an open source project, and you are more than welcome to contribute! For more, see link:CONTRIBUTING.adoc[Contributing].
== Editions
There are 2 editions of Timefold Solver:
- Timefold Solver Community Edition (CE) (this repo).
- https://timefold.ai/pricing[Timefold Solver Enterprise Edition (EE)], a licensed version of Timefold Solver.
=== Key Features of Timefold Solver Enterprise Edition (EE)
- Multi-threaded Solving: Experience enhanced performance with multi-threaded solving capabilities.
- Nearby Selection: Get better solutions quicker, especially with spatial problems.
- Dedicated Support: Get direct support from the Timefold team for all your questions and requirements.
=== Licensing and Usage
Unlike the Apache-2.0 licensed Community Edition in this repo, the Enterprise Edition is not open source. If you wish to use the Enterprise Edition in a production environment, please https://timefold.ai/company/contact/[contact Timefold] to obtain the appropriate license.
== Legal notice
Timefold Solver was https://timefold.ai/blog/2023/optaplanner-fork/[forked] on 20 April 2023 from OptaPlanner, which was entirely Apache-2.0 licensed (a permissive license).
Timefold Solver is a derivative work of OptaPlanner and OptaPy, which includes copyrights of the original creator, Red Hat Inc., affiliates, and contributors, that were all entirely licensed under the Apache-2.0 license. Every source file has been modified.
Top Related Projects
Google's Operations Research tools:
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