Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 53

Integrating CP for Hybrid Solving

Recommended resources

Hello! Welcome to our fourth lesson on advanced hybrid optimization methods.

In our previous lessons, we've explored several powerful concepts:

  • Using Large Neighborhood Search (LNS) as a metaheuristic to guide a search.
  • Embedding constraint propagation within a local search to intelligently prune neighborhoods.

Today, we will synthesize these ideas into a practical and widely-used design pattern. Our goal is to move from understanding the components to architecting a complete hybrid system.

Your learning outcome for this lesson is to design a hybrid approach where Constraint Programming (CP) is used as a subroutine to evaluate or complete partial solutions. This is a cornerstone technique for solving complex scheduling problems like the Flexible Job Shop Problem (FJSP) that is the focus of your thesis.

The "Ruin and Recreate" Paradigm with CP

The most common and effective way to use CP as a subroutine is within a framework known as Large Neighborhood Search (LNS), or sometimes called "Ruin and Recreate." This approach combines the broad, exploratory power of a metaheuristic with the deep, constraint-satisfying power of a CP solver.

The basic loop is simple yet powerful:

  1. Start: Generate an initial, good-quality feasible solution, , typically using your base CP model with a time limit.
  2. Ruin (or Destroy): "Ruin" a portion of the solution . This means selecting a subset of decisions (e.g., the machine assignments and schedules for a few jobs) and "un-fixing" them. This transforms your complete solution into a partial solution.
  3. Recreate (or Repair): This is where the CP subroutine comes in. You call your CP solver to find the best possible way to complete the partial solution. The solver works on the original problem, but with added constraints that fix the decisions from the "un-ruined" part of the solution.
  4. Accept: Based on some criterion (e.g., if the new solution is better), you decide whether to accept the newly created solution as your new incumbent solution, .
  5. Iterate: Repeat the ruin-and-recreate process until a stopping condition is met (e.g., a time limit or number of iterations).

This is a powerful pattern because the CP solver isn't tasked with solving the entire massive problem from scratch. Instead, it solves a much smaller, more constrained subproblem: finding an optimal completion for a partial schedule. This leverages CP's strength in handling complex constraints over a reduced search space.

To get a clear overview of this concept, let's watch a short video that introduces LNS.

Discrete Optimization || 01 Large Neighborhood Search asymmetric TSP with time windows 8 42

This video, 'Discrete Optimization || 01 Large Neighborhood Search', provides an excellent high-level introduction to the LNS framework. It explains the core idea of fixing some variables and re-optimizing the rest using CP.

Please watch the sections from 00:31 to 02:56. Focus on the four main steps of the LNS algorithm and the central idea of defining a neighborhood by fixing a subset of variables and letting the CP solver find better values for the remaining ones.

As the video explained, the key is to take a solution, fix what you think is good, and let CP find an optimal way to fill in the rest. This directly addresses our goal of using CP to complete a partial solution.


Designing a CP-based LNS for Flexible Job Shop Scheduling

Now, let's move from the general concept to the specific design for an FJSP. The design of a successful LNS-CP hybrid revolves around one critical component: the destruction operators (the "ruin" phase). How you choose to destroy part of the solution determines the subproblem that the CP solver will tackle.

A recent research paper provides an excellent, practical blueprint for exactly this kind of system, applied to the FJSP with resource constraints—a context highly relevant to your thesis.

A unified solution framework for flexible job shop scheduling ...

The paper 'A unified solution framework for flexible job shop scheduling...' presents a method called ALNS-CP (Adaptive Large Neighbourhood Search with Constraint Programming). This is a state-of-the-art implementation of the pattern we are studying.

Please read Section 4, 'The adaptive large neighbourhood search-constraint programming method' (up to 4.1). Pay close attention to Algorithm 1, which outlines the main loop. Notice how in our terminology, the 'constraint extraction' phase (line 5) corresponds to the 'ruin' step, and the 'solution reconstruction' phase (line 6), which calls 'CPSolveSequential', is the 'recreate' step using the CP subroutine.

The key insight from this paper is that the "destruction" of the solution is achieved by generating a set of additional constraints that are passed to the CP solver. These constraints enforce the "undestroyed" part of the schedule. The CP solver then re-solves the problem with the original model constraints plus these new fixing constraints.

Designing the Destruction Operators

The effectiveness of LNS hinges on the design of its destruction operators. A good operator creates subproblems that are both (1) small enough for the CP solver to handle quickly and (2) large enough to contain solutions better than the current one. The paper you just read gives several powerful, structure-based ideas.

Let's examine these design patterns.

A unified solution framework for flexible job shop scheduling ...

Let's continue with the same paper and focus on the specific design of the destruction operators. These are concrete examples of how to create meaningful partial solutions for the CP solver to complete.

Please read Section 4.1, 'The constraint extraction operators'. You don't need to understand every detail of the equations, but focus on the high-level concept behind each operator: Time window operator: What does it free up? Machine removal operator: How does it define the part of the solution to be re-optimized? Machine Assignment Operators (MAO-I, II, III): How do they use information from 'elite' solutions to guide the destruction? Operation Relationship Operator (ORO): How does this operator differ by focusing on precedence relationships?

Let's synthesize what you've read into a design blueprint. When designing your LNS-CP solver, you can implement a portfolio of destruction operators, such as:

  • Random Operator: Randomly select a percentage of operations to "free" (i.e., un-fix their machine assignment and schedule). This is simple and good for diversification.
  • Time-Window Operator: Select a random start time and a duration. Free all operations that are currently scheduled within this time window. This is effective for fixing issues in a specific temporal region of the schedule.
  • Machine Operator: Select one or more machines (e.g., the one with the highest workload, the critical machine). Free all operations assigned to these machines. This attempts to resolve bottlenecks.
  • Job Operator: Select one or more jobs (e.g., jobs that finish late). Free all operations belonging to these jobs. This focuses on improving the schedule for problematic jobs.
  • Pattern-based Operators (like MAO and ORO): These are more advanced. They use memory of previously found good solutions to either (a) forbid assignments that were rarely seen in good solutions or (b) enforce assignments that were very common in good solutions.

The CP Subroutine in Action

Let's formalize how the CP subroutine works. Suppose you use a Machine Operator and decide to "ruin" all operations on Machine M2. Your original solution s contains all decisions. The partial solution passed to the CP solver is constructed as follows:

  1. Identify Fixed Operations: Let be the set of all operations not on machine M2.
  2. Generate Fixing Constraints: For each operation :
    • Add a constraint to fix its machine assignment to what it was in solution s. For example, if operation was on machine M1, add PresenceOf(op_i_on_M1) = 1.
    • Add constraints to fix its precedence relative to other fixed operations on the same machine. If operation was scheduled before operation on M1 in solution s, add EndBeforeStart(op_i_on_M1, op_j_on_M1).
  3. Call the CP Solver: Execute the CP solver with the original FJSP model plus this new set of fixing constraints. The solver will only search for machine assignments and schedules for the operations on M2, taking the rest of the schedule as fixed.
Test your understanding!

Imagine you have a small FJSP solution represented by a Gantt chart. You decide to apply a Job Operator to "ruin" all operations belonging to Job 2. What information about Job 1 and Job 3 would you encode as additional constraints for the CP "recreate" subroutine?

Show answer

For every operation belonging to Job 1 and Job 3, you would add constraints to fix:

  1. Machine Assignments: For each operation, you would enforce the machine it was assigned to in the original solution. For example, if Job 1's first operation was on M3, a constraint would fix it to M3.
  2. Intra-Job Precedences: These are already part of the base model (e.g., operation 1.1 must precede 1.2).
  3. Inter-Job Precedences on Machines: For any machine that processes operations from both Job 1 and Job 3, you would enforce their relative order from the original solution. For example, if on machine M1, Job 1's operation finished before Job 3's operation started, you would add a corresponding EndBeforeStart constraint.

The CP solver would then be free to schedule and assign machines only for the operations of Job 2, fitting them into the "frozen" schedule of Jobs 1 and 3.


The Value of the Hybrid Approach

Why go to all this trouble? Because it works exceptionally well. The metaheuristic (LNS) provides a powerful way to explore the vast search space, while the CP solver ensures that the "recreation" of any part of the solution is done optimally and feasibly with respect to all complex constraints.

Let's look at the results from the paper to see the performance difference.

A unified solution framework for flexible job shop scheduling ...

Finally, let's look at the computational results in the same paper to see the payoff of this hybrid design.

Please look at Section 5.4.4 and specifically Table 10. This table compares the performance of the standalone CP model against the hybrid ALNS-CP algorithm on large-scale, complex instances. Compare the 'Gap (%)' and 'Time(s)' columns for both methods.

As the results show, the ALNS-CP hybrid consistently finds better solutions (lower gap) in significantly less time than the pure CP solver, which often hits the time limit. This demonstrates the practical power of using CP as an intelligent subroutine for completing partial solutions, making it a very promising direction for your thesis work.



Conclusion

In this lesson, we have moved from concepts to a concrete architectural design for a powerful hybrid solver.

Key Takeaways:

  • The LNS (or Ruin-and-Recreate) framework is a highly effective way to hybridize a metaheuristic with a CP solver.
  • In this pattern, the metaheuristic creates a partial solution by "ruining" a part of a complete solution.
  • The CP solver acts as an intelligent "recreate" subroutine, which receives the partial solution in the form of additional fixing constraints and optimally completes it.
  • The core of the design lies in creating a portfolio of destruction operators (e.g., time-based, machine-based, job-based) that generate meaningful subproblems for the CP solver to tackle.
  • This hybrid approach allows you to solve large, complex problems more effectively than using a pure CP model alone.

Preview of the Next Lesson:

This lesson focused on the design of an LNS-CP hybrid. Our next and final lesson in this module will focus on the next logical step: implementing a Large Neighborhood Search (LNS) framework that uses CP to repair or improve solutions. We will discuss the practical coding aspects and data structures needed to bring this design to life.