1 - What is Planning Optimization?
Introduction to planning optimization and constraint satisfaction.
Planning
The need to create plans generally arises from a desire to achieve a goal:
- Build a house
- Correctly staff a hospital shift
- Complete work at all customer locations
- Deliver packages efficiently
Achieving those goals involves organizing the available resources. To correctly staff a hospital you need enough qualified personnel in a variety of fields and specializations to cover the opening hours of the hospital.
Any plan to deploy resources, whether to staff a hospital shift or to assemble the building materials for a new house, is done under constraints.
Constraints could be:
- Physical laws - People can’t work two shifts in two separate locations at the same time, and you can’t mount a roof on a house that doesn’t exist
- Regulations - Employees need a certain number of hours between shifts or are only allowed to work a maximum number of hours per week
- Preferences - Certain employees prefer to work specific shift patterns
Feasible Plans
Any plan needs to consider all three elements—goals, resources, and constraints—in balance to be a feasible plan. A plan that fails to account for all the elements of the problem is an infeasible plan.
For instance, if a hospital staff roster covers all shifts, but assigns employees back-to-back shifts with no breaks for sleep or life outside work, it is not a valid plan.
Why Planning Problems are Hard
Planning problems become harder to solve as the number of resources and constraints increase. Creating an employee shift schedule for a small team of four employees is fairly straightforward. However, if each employee performs a specific function within the business and those functions need to be performed in a specific order, changes that affect one employee quickly cascade and affect everybody on the team.
As more employees and different work specializations are added, things become much more complicated.
Example: For a trivial field service routing problem with 4 vehicles and 8 visits, the number of possibilities that a brute force algorithm considers is 19,958,418.
What would take a team of planners many hours to schedule can be automatically scheduled by SolverForge in a fraction of the time.
Operations Research
Operations Research (OR) is a field of research focused on finding optimal (or near optimal) solutions to problems with techniques that improve decision-making.
Constraint satisfaction programming is part of Operations Research that aims to satisfy all the constraints of a problem.
Planning AI
Planning AI is a type of artificial intelligence designed specifically to handle complex planning and scheduling tasks, and to satisfy the constraints of planning problems. Instead of just automating simple, repetitive tasks, it helps you make better decisions by sorting through countless possibilities to find the best solutions—saving you time, reducing costs, and improving efficiency.
Why Planning AI is Different
Traditional methods of planning often involve manually sifting through options or relying on basic tools that can’t keep up with the complexity of real-world problems. Planning AI, on the other hand, uses advanced strategies to quickly focus on the most promising solutions, even when the situation is extremely complicated.
Planning AI also makes it possible to understand the final solution with a breakdown of:
- Which constraints have been violated
- Scores for individual constraints
- An overall score
This makes Planning AI incredibly valuable in industries where getting the right plan is crucial—whether that’s scheduling workers, routing deliveries, or managing resources in a factory.
Constraints and Scoring
Constraints can be considered hard, medium, or soft.
Hard Constraints
Hard constraints represent rules and limitations of the real world that any planning solution has to respect. For instance, there are only 24 hours in a day and people can only be in one place at a time. Hard constraints also include rules that must be adhered to, such as employee contracts and the order in which dependent tasks are completed.
Breaking hard constraints results in infeasible plans.
Medium Constraints
Medium constraints help manage plans when resources are limited (for instance, when there aren’t enough technicians to complete all the customer visits or there aren’t enough employees to work all the available shifts). Medium constraints incentivize SolverForge to assign as many entities (visits or shifts) as possible.
Soft Constraints
Soft constraints help optimize plans based on the business goals, for instance:
- Minimize travel time between customer visits
- Assign employees to their preferred shifts
- Keep teachers in the same room for consecutive lessons
Understanding Scores
To help determine the quality of the solution, plans are assigned a score with values for hard, medium, and soft constraints.
0hard/-257medium/-6119520soft
From this example score we can see:
- Zero hard constraints were broken (feasible!)
- Medium and soft scores have negative values (room for optimization)
Note: The scores do not show how many constraints were broken, but weighted values associated with those constraints.
Score Comparison
Because breaking hard constraints would result in an infeasible solution, a solution that breaks zero hard constraints and has a soft constraint score of -1,000,000 is better than a solution that breaks one hard constraint and has a soft constraint score of 0.
The weight of constraints can be tweaked to adjust their impact on the solution.
2 - Problem Types
Common categories of planning and scheduling problems.
SolverForge can solve a wide variety of planning and scheduling problems. Here are some common categories:
Scheduling Problems
Assign activities to time slots and resources.
Employee Scheduling (Rostering)
Assign employees to shifts based on:
- Skills and qualifications
- Availability and preferences
- Labor regulations (max hours, rest periods)
- Fairness (balanced workload)
Examples: Hospital nurse scheduling, retail staff scheduling, call center scheduling
Assign lessons to timeslots and rooms:
- Teachers can only teach one class at a time
- Rooms have limited capacity
- Student groups shouldn’t have conflicts
- Preference for consecutive lessons
Examples: University course scheduling, school class scheduling
Meeting Scheduling
Find optimal times for meetings:
- Required attendees must be available
- Rooms must be available and large enough
- Minimize conflicts with other meetings
- Consider timezone differences
Job Shop Scheduling
Schedule jobs on machines:
- Operations must follow a specific order
- Machines can only do one job at a time
- Minimize total completion time (makespan)
Examples: Manufacturing scheduling, print shop scheduling
Routing Problems
Plan routes and sequences for vehicles or resources.
Vehicle Routing Problem (VRP)
Plan delivery or service routes:
- Vehicle capacity constraints
- Time windows for deliveries
- Minimize total travel distance/time
- Multiple depots possible
Variants:
- CVRP - Capacitated VRP
- VRPTW - VRP with Time Windows
- PDPTW - Pickup and Delivery with Time Windows
Examples: Delivery route planning, field service scheduling, waste collection
Traveling Salesman Problem (TSP)
Visit all locations exactly once with minimum travel:
- Single vehicle
- Return to starting point
- Minimize total distance
Examples: Sales territory planning, circuit board drilling
Assignment Problems
Assign entities to resources or positions.
Task Assignment
Assign tasks to workers or machines:
- Match skills/capabilities
- Balance workload
- Meet deadlines
- Minimize cost
Examples: Project team assignment, warehouse task allocation
Bin Packing
Pack items into containers:
- Items have sizes/weights
- Containers have capacity limits
- Minimize number of containers used
Examples: Truck loading, cloud server allocation, cutting stock
Resource Allocation
Allocate limited resources to competing demands:
- Budget allocation
- Equipment assignment
- Space allocation
Complex Planning Problems
Real-world problems often combine multiple problem types:
Field Service Scheduling
Combines:
- Routing - Travel between customer locations
- Scheduling - Time windows and appointment slots
- Assignment - Match technician skills to job requirements
Project Planning
Combines:
- Task scheduling - Activities with durations and dependencies
- Resource assignment - Assign people/equipment to tasks
- Constraint satisfaction - Deadlines, budgets, availability
Problem Characteristics
When modeling your problem, consider these characteristics:
| Characteristic | Description | Example |
|---|
| Hard constraints | Must be satisfied | Legal requirements |
| Soft constraints | Should be optimized | Customer preferences |
| Planning entities | What gets assigned | Lessons, visits, shifts |
| Planning variables | The assignments | Timeslot, room, vehicle |
| Problem facts | Fixed data | Employees, rooms, skills |
Choosing the Right Model
When modeling your problem:
- Identify entities - What things need to be assigned or scheduled?
- Identify variables - What values are you assigning?
- Identify constraints - What rules must be followed?
- Define the score - How do you measure solution quality?
The Quickstarts section provides complete examples for common problem types.
3 - Terminology
Glossary of terms used in SolverForge documentation.
Core Concepts
Planning Problem
The input to the solver: a set of planning entities with uninitialized planning variables, plus all problem facts and constraints.
Planning Solution
The container class that holds all problem data (entities and facts) and the resulting score. Decorated with @planning_solution.
Planning Entity
A class whose instances are modified during solving. Planning entities contain planning variables. Decorated with @planning_entity.
Planning Variable
A property of a planning entity that the solver changes during optimization. Annotated with PlanningVariable.
Problem Fact
Immutable data that defines the problem but is not changed by the solver (e.g., rooms, timeslots, employees). Annotated with ProblemFactCollectionProperty or ProblemFactProperty.
Value Range
The set of possible values for a planning variable. Provided via ValueRangeProvider.
Scoring
Score
A measure of solution quality. Higher scores are better. Common types: SimpleScore, HardSoftScore, HardMediumSoftScore.
Hard Constraint
A constraint that must be satisfied for a solution to be feasible. Broken hard constraints make a solution invalid.
Soft Constraint
A constraint that should be optimized but isn’t required. Used for preferences and optimization goals.
Medium Constraint
A constraint between hard and soft, typically used for “assign as many as possible” scenarios.
Feasible Solution
A solution with no broken hard constraints (hard score of 0 or positive).
Optimal Solution
A feasible solution with the best possible soft score. May be impractical to find for large problems.
Constraint Stream
The fluent API for defining constraints. Starts with ConstraintFactory.for_each().
Algorithms
Construction Heuristic
An algorithm that builds an initial solution quickly by assigning values to all planning variables.
Local Search
An algorithm that improves an existing solution by making incremental changes (moves).
Move
A change to the solution, such as swapping two assignments or changing a single variable.
Step
One iteration of the optimization algorithm, consisting of selecting and applying a move.
Termination
The condition that stops the solver (time limit, score target, no improvement, etc.).
Advanced Concepts
Shadow Variable
A planning variable whose value is calculated from other variables, not directly assigned by the solver. Used for derived values like arrival times.
Inverse Shadow Variable
A shadow variable that maintains a reverse reference (e.g., a visit knowing which vehicle it belongs to).
Previous/Next Element Shadow Variable
Shadow variables that track the previous or next element in a list variable.
Cascading Update Shadow Variable
A shadow variable that triggers recalculation when upstream variables change.
List Variable
A planning variable that holds an ordered list of values (used for routing problems). Annotated with PlanningListVariable.
Pinning
Locking certain assignments so the solver cannot change them. Useful for preserving manual decisions or already-executed plans.
Problem Change
A modification to the problem while the solver is running (real-time planning).
Solver Components
Solver
The main component that performs optimization. Created via SolverFactory.
SolverFactory
Factory for creating Solver instances from configuration.
SolverConfig
Configuration object specifying solution class, entities, constraints, and termination.
SolverManager
Manages multiple concurrent solving jobs. Useful for web applications.
SolutionManager
Analyzes solutions: explains scores, identifies constraint violations.
ScoreDirector
Internal component that calculates scores efficiently. Used in problem changes.
Constraint Provider
A function decorated with @constraint_provider that returns a list of constraints.
Constraint Stream Operations
for_each / forEach
Start a constraint stream by iterating over all instances of a class.
for_each_unique_pair
Iterate over all unique pairs of instances (A,B where A != B, without duplicates like (B,A)).
filter
Remove items that don’t match a predicate.
join
Combine two streams by matching on joiners.
Joiner
A condition for matching items in joins (e.g., Joiners.equal(), Joiners.overlapping()).
group_by
Aggregate items by key with collectors.
Collector
Aggregation function (count, sum, min, max, toList, etc.).
penalize / reward
Apply score impact for matching items.
as_constraint
Finalize the constraint with a name.
Score Analysis
Score Explanation
Breakdown of which constraints contributed to the score.
Constraint Match
A single instance of a constraint being triggered.
Indictment
List of constraint violations associated with a specific entity.
Justification
Explanation of why a constraint was triggered.