Timefold Quickstarts
repository·stable·Indexed 20 days ago
https://github.com/timefoldai/timefold-quickstartsA collection of practical implementations for Timefold Solver demonstrating how to solve real-world optimization problems using Java and Kotlin. Includes quickstarts for vehicle routing, employee scheduling, school timetabling, and bed allocation scheduling, with integration examples for Quarkus and Spring Boot.
What's inside timefold-quickstarts
- The Bed Allocation Scheduling quickstart demonstrates how to use Timefold to assign beds to patient stays to optimize hospital schedules. It is implemented using Java, Quarkus, and Maven.
Overview of the Facility Location Problem quickstart
stableThis quickstart demonstrates how to use Timefold to solve the Facility Location Problem using Java, Quarkus, and Maven. The goal is to select the optimal geographical locations for new facilities (such as stores, distribution centers, or test centers) to minimize costs and distance.
The implementation includes the following constraints:
Name Level Description Facility capacity Hard A facility's total assigned demand must not exceed its capacity. Setup cost Soft Minimize the total setup cost of opened facilities. Distance from facility Soft Minimize the total distance from consumers to their assigned facility. Overview of Flight Crew Scheduling Quickstart
stableThis quickstart demonstrates how to use Timefold to assign crew members to flights to optimize flight assignments. The implementation uses Java, Quarkus, and Maven.
The scheduling problem is defined by several hard and soft constraints:
Hard Constraints (Must be satisfied):
- Required skill: A crew member must have the required skill for their assigned flight.
- Flight conflict: A crew member cannot be assigned to two overlapping flights.
- Transfer between two flights: A crew member must have enough time to transfer between consecutive flights.
- Employee unavailability: A crew member cannot be assigned during their unavailability period.
Soft Constraints (Should be optimized):
- First assignment not departing from home: The first flight assignment should depart from the crew member's home airport.
- Last assignment not arriving at home: The last flight assignment should arrive at the crew member's home airport.
Overview of Food Packaging Quickstart
stableThe Food Packaging quickstart demonstrates how to schedule food packaging orders to manufacturing lines using Timefold. The goal is to minimize downtime and ensure all orders are fulfilled on time. This implementation uses Java, Quarkus, and Maven.Overview of Conference Scheduling Quickstart
stableThe Conference Scheduling quickstart is a Java-based implementation using Quarkus and Maven. It demonstrates how to assign conference talks to specific timeslots and rooms to optimize a schedule for speakers. The project uses both Hard and Soft constraints to balance logistical requirements (like avoiding room conflicts) with speaker preferences (like preferred room tags).Maintenance Scheduling Use Case Overview
stableThe Maintenance Scheduling implementation uses Java, Quarkus, and Maven to solve the problem of scheduling maintenance jobs to crews over time. The goal is to minimize both premature and overdue maintenance.
Constraints
The solver handles the following constraints:
Hard Constraints (Must be satisfied):
- Crew conflict: A maintenance crew cannot be assigned to two overlapping jobs.
- Min start date: A job must not start before its minimum start date.
- Max end date: A job must not finish after its maximum end date.
Soft Constraints (Should be optimized):
- Before ideal end date: Avoid finishing a job too early before its ideal end date.
- After ideal end date: Avoid finishing a job after its ideal end date.
- Tag conflict: Jobs sharing the same tag should not overlap.
Vehicle Routing with time windows and capacity planning
stableThis quickstart implementation uses Java, Quarkus, and Maven to solve Vehicle Routing Problems (VRP). It aims to find the most efficient routes for a fleet of vehicles while respecting various constraints.
Constraints implemented:
- Vehicle capacity (Hard): The total demand of all visits assigned to a vehicle must not exceed its capacity.
- Service finished after max end time (Hard): A visit must be serviced before its maximum end time.
- Maximize visits assigned (Medium): As many visits as possible should be assigned to a vehicle.
- Minimize travel time (Soft): Minimize the total travel time of all vehicles.
Explore Timefold Solver Quickstart Implementations
stableThis repository provides various quickstart implementations of Timefold Solver, an AI constraint solver for Java and Kotlin. These implementations serve as starting points or inspiration for building optimization applications. While Timefold Solver is a library without a built-in UI, these quickstarts include rudimentary UIs to demonstrate the use cases visually.Overview of Optimization Use Cases and Solver Concepts
stableThe repository covers a wide range of optimization problems. Use the following table to identify which solver concepts are used in specific use cases:
Use Case Notable Solver Concepts 🚚 Vehicle Routing Chained Through Time, Shadow Variables 🧑 Employee Scheduling Load Balancing 🛠️ Maintenance Scheduling TimeGrain, Shadow Variable, Variable Listener 📦 Food Packaging Mixed Model, Shadow Variables, Pinning 🛒 Order Picking Chained Planning Variable, Shadow Variables 🏫 School Timetabling Timeslot 🏭 Facility Location Problem Shadow Variable 🎤 Conference Scheduling Timeslot, Justifications 🛏️ Bed Allocation Scheduling Allows Unassigned 🛫 Flight Crew Scheduling - 👥 Meeting Scheduling TimeGrain ✅ Task Assigning Bendable Score, Chained Through Time, Allows Unassigned 📆 Project Job Scheduling Shadow Variables, Variable Listener, Strenght Comparator 🏆 Sports League Scheduling Consecutive Sequences 🏅 Tournament Scheduling Pinning, Load Balancing Constraints in the Meeting Scheduling Example
stableThe meeting scheduling implementation uses three levels of constraints to define a valid and optimized schedule:
Hard Constraints (Must be satisfied)
- Room conflict: Two meetings cannot be held in the same room at the same time.
- Avoid overtime: Meetings should not be scheduled outside working hours.
- Required attendance conflict: A required attendee cannot be in two meetings at the same time.
- Required room capacity: The room must be large enough for all required attendees.
- Start and end on same day: A meeting must start and end on the same day.
Medium Constraints
- Required and preferred attendance conflict: Avoid scheduling a required and preferred attendee in conflicting meetings.
- Preferred attendance conflict: Avoid scheduling a preferred attendee in two meetings at the same time.
Soft Constraints (Optimization goals)
- Do meetings as soon as possible: Schedule meetings as early as possible in the day.
- One break between consecutive meetings: There should be a break between consecutive meetings for an attendee.
- Overlapping meetings: Minimize overlapping meetings for attendees.
- Assign larger rooms first: Assign the largest available room to each meeting.
- Room stability: An attendee's consecutive meetings should be in the same room.
Constraints in Project Job Scheduling
stableThe Project Job Scheduling solver uses the following constraint hierarchy to optimize job allocations:
Name Level Description Non-renewable resource capacity Hard The total use of each non-renewable resource must not exceed its capacity. Renewable resource capacity Hard The use of each renewable resource at any given time must not exceed its capacity. Total project delay Medium Minimize the total delay across all projects. Total makespan Soft Minimize the overall project completion time. Create a native image for the School Timetabling application
stableYou can build a native image for faster startup times or for environments without a JVM. Note that the solver performance is considerably slower when running in a native image.
Using Docker
Build a Docker image containing the native executable.
Using locally installed GraalVM
Compile the application directly into a native binary using GraalVM.
# --- Build using Docker --- $ mvn -Pnative spring-boot:build-image # or $ gradle bootBuildImage # Run the Docker image $ docker run --rm -p 8080:8080 docker.io/library/spring-boot-integration:1.0-SNAPSHOT # --- Build using GraalVM --- $ mvn -Pnative native:compile # or $ gradle nativeCompile # Run the Maven output $ ./target/spring-boot-integration # Run the Gradle output $ ./build/native/nativeCompile/spring-boot-integration