Timefold Quickstarts

repository·stable·Indexed 20 days ago

https://github.com/timefoldai/timefold-quickstarts

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

Tokens
17.2K
Snippets
82
Records
107
Agent score
69%

What's inside timefold-quickstarts

  1. Overview of the Facility Location Problem quickstart

    stable

    This 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:

    NameLevelDescription
    Facility capacityHardA facility's total assigned demand must not exceed its capacity.
    Setup costSoftMinimize the total setup cost of opened facilities.
    Distance from facilitySoftMinimize the total distance from consumers to their assigned facility.
  2. Overview of Flight Crew Scheduling Quickstart

    stable

    This 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.
  3. Overview of Conference Scheduling Quickstart

    stable
    The 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).
  4. Maintenance Scheduling Use Case Overview

    stable

    The 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.
  5. Vehicle Routing with time windows and capacity planning

    stable

    This 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.
  6. Explore Timefold Solver Quickstart Implementations

    stable
    This 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.
  7. Overview of Optimization Use Cases and Solver Concepts

    stable

    The repository covers a wide range of optimization problems. Use the following table to identify which solver concepts are used in specific use cases:

    Use CaseNotable Solver Concepts
    🚚 Vehicle RoutingChained Through Time, Shadow Variables
    🧑 Employee SchedulingLoad Balancing
    🛠️ Maintenance SchedulingTimeGrain, Shadow Variable, Variable Listener
    📦 Food PackagingMixed Model, Shadow Variables, Pinning
    🛒 Order PickingChained Planning Variable, Shadow Variables
    🏫 School TimetablingTimeslot
    🏭 Facility Location ProblemShadow Variable
    🎤 Conference SchedulingTimeslot, Justifications
    🛏️ Bed Allocation SchedulingAllows Unassigned
    🛫 Flight Crew Scheduling-
    👥 Meeting SchedulingTimeGrain
    ✅ Task AssigningBendable Score, Chained Through Time, Allows Unassigned
    📆 Project Job SchedulingShadow Variables, Variable Listener, Strenght Comparator
    🏆 Sports League SchedulingConsecutive Sequences
    🏅 Tournament SchedulingPinning, Load Balancing
  8. Constraints in the Meeting Scheduling Example

    stable

    The 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.
  9. Constraints in Project Job Scheduling

    stable

    The Project Job Scheduling solver uses the following constraint hierarchy to optimize job allocations:

    NameLevelDescription
    Non-renewable resource capacityHardThe total use of each non-renewable resource must not exceed its capacity.
    Renewable resource capacityHardThe use of each renewable resource at any given time must not exceed its capacity.
    Total project delayMediumMinimize the total delay across all projects.
    Total makespanSoftMinimize the overall project completion time.
  10. Create a native image for the School Timetabling application

    stable

    You 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