Hello! Welcome to the sixth lesson in our module on Constraint Programming for Scheduling.
In the previous lesson, we successfully built a complete CP model for the standard Job Shop Scheduling Problem (JSSP). We saw how to represent operations as interval variables and use NoOverlap and precedence constraints to define a valid schedule. This provided us with a solid foundation.
Today, we will build directly on that knowledge to tackle a more complex and realistic problem that is central to your thesis work: the Flexible Job Shop Problem (FJSP). Your learning outcome for this lesson is to extend a CP model to solve the FJSP by incorporating alternative interval variables.
The key difference between JSSP and FJSP is machine flexibility: in an FJSP, each operation has a set of eligible machines it can be processed on, often with different processing times. This introduces a new layer of decision-making: we must not only sequence the operations but also assign each one to a specific machine. You will learn how CP's specialized scheduling constructs handle this "assignment and scheduling" problem in a unified and elegant way.
1. From Job Shop to Flexible Job Shop
Let's start by formalizing the difference between JSSP and FJSP.
- In the JSSP, an operation is rigidly tied to one specific machine.
- In the FJSP, an operation can be processed by one machine from a given set of alternatives. This is sometimes called "machine flexibility" or having "alternative resources."
This flexibility is common in modern manufacturing, where multi-purpose machines can perform various types of tasks. The decision is now two-fold:
- Assignment: Which machine should process each operation?
- Sequencing: In what order should operations be run on each machine?
A formal definition is crucial for modeling. The following paper provides a concise mathematical definition of the FJSP.
Types of Flexible Job Shop Scheduling: A Constraint ...
This paper, 'Types of Flexible Job Shop Scheduling: A Constraint ...', begins by formally defining the FJSP. Understanding this definition is the first step to building a correct model.
Please read Section 2, 'THE FLEXIBLE JOB SHOP SCHEDULING PROBLEM'. Focus on Definition 1, which lays out the sets, constraints, and objective. Note particularly points (2) and (3), which introduce the set of machines Mo for an operation o and the machine-dependent processing times time_o,m. This is the core distinction from the JSSP.
2. The Modeling Strategy: Optional and Alternative Intervals
So, how do we model this choice in CP? A simple interval variable for each operation is no longer sufficient, as its duration depends on the machine we choose.
The solution in modern CP solvers is to use a powerful two-level structure involving optional intervals and an alternative constraint.
First, let's understand the concept of an optional interval.
Planning/Scheduling with CP Optimizer
This tutorial by Philippe Laborie, a key architect of IBM's CP Optimizer, introduces the concept of optional interval variables. This is the fundamental building block for modeling choices.
Watch the segment from slide 21 to 22 (timestamp 10:13 - 10:50). The key idea is that an optional interval has an additional state: it can be 'absent' from the final solution.
With optional intervals, our strategy for modeling an operation o in an FJSP becomes:
- Create an abstract "master" interval (
op_o): This represents the operation itself, without being tied to any specific machine. Its start, end, and duration are yet to be determined. - Create a set of "mode" intervals: For each eligible machine
mfor operationo, create an optional intervalmode_o_m. This optional interval represents the concrete choice of running operationoon machinem. Its size is set to the specific processing timep_o,m.
Now, we need to link the master interval to its possible modes. This is done with the alternative global constraint.

The alternative(op_o, [mode_o_m1, mode_o_m2, ...]) constraint is the magic that ties everything together. It enforces two critical properties:
- If the master interval
op_ois present in the solution, then exactly one of its optional mode intervals (mode_o_m1,mode_o_m2, etc.) must also be present. All other modes for that operation will be absent. - The start and end times of the master interval
op_oare synchronized with the chosen mode interval.
To see this explained, let's return to the tutorial.
Planning/Scheduling with CP Optimizer
This next segment explains the alternative constraint, which connects the abstract operation to its concrete machine choices.
Watch the segment on slide 25 (timestamp 11:25 - 11:51). This visually and conceptually explains how the alternative constraint works.
Test your understanding!
Imagine you are modeling a manufacturing process where an operation o_1 not only has a choice of machines but can also be skipped entirely if a certain raw material is unavailable. How might you use the concepts of optional and alternative intervals to model this "skippable" operation?
Show answer
You would model the operation o_1 itself as an optional interval variable. Let's call it optional_op_1. You would still have the optional "mode" intervals for each machine choice. The alternative constraint would then be alternative(optional_op_1, [mode_1_m1, mode_1_m2, ...]).
Because the master interval optional_op_1 is optional, the solver has the freedom to make it 'absent'. The alternative constraint dictates that if the master interval is absent, all its constituent mode intervals must also be absent. This elegantly models the decision to skip the operation entirely.
3. Implementing the FJSP Model
Now we have all the components to extend our JSSP model to an FJSP model. We'll use the same structure as before (variables, constraints, objective), but we'll modify it to incorporate the alternative structure.
A complete, state-of-the-art model is presented in the paper we looked at earlier. We will analyze its structure, as it perfectly demonstrates the concepts we've discussed.
Types of Flexible Job Shop Scheduling: A Constraint ...
The paper 'Types of Flexible Job Shop Scheduling...' provides a full OPL (Optimization Programming Language) implementation for the FJSP. We will dissect this model to see how the pieces fit together.
Read Section 3, 'CP MODEL', and study the code in 'Listing 1'. The accompanying text explains each part of the model line by line. Pay close attention to: Line 24: Declaration of the 'master' interval variables ops. Line 25: Declaration of the 'mode' interval variables modes as optional. Lines 31-32: The alternative constraint linking ops and modes. Lines 33-34: The noOverlap constraint applied to the modes for each machine. Lines 35-36: The endBeforeStart precedence constraint applied to the master ops variables.
Let's summarize the key adjustments from our previous JSSP model:
- Variables:
- We now have two sets of interval variables:
ops: One interval for each operation (the "master").modes: One optional interval for each valid operation-machine combination.
- We now have two sets of interval variables:
- Constraints:
- Precedence Constraints (
endBeforeStart): These are applied to theops(master) variables. This is clean and intuitive, as the precedence relationship between operations exists regardless of which machines are chosen. - Capacity Constraints (
noOverlap): These are applied to themodes(optional) variables. For each machinem, anoOverlapconstraint is placed on allmodesthat could potentially run on it. The solver ensures that the present modes on that machine do not overlap. - Alternative Constraints: For each operation, an
alternativeconstraint is added to link its masteropsvariable to its set ofmodesvariables. This enforces the machine selection.
- Precedence Constraints (
To see this in a more familiar Python-based syntax, the CP Optimizer tutorial provides a concise implementation snippet that mirrors the structure of the OR-Tools code from our last lesson.
Planning/Scheduling with CP Optimizer
This final clip shows a Python implementation for the FJSP, which should look very similar to the OR-Tools model you are familiar with.
Review the code on slide 29 (timestamp 14:02 - 14:50). Notice the parallel structure to the OPL model: o = [...]: The master interval variables. a = [...]: The optional mode interval variables (optional=True). model.add([alternative(...)]): The machine allocation constraint. model.add([no_overlap(...)]): The resource capacity constraint.
This two-level modeling pattern is a cornerstone of advanced scheduling with Constraint Programming. It cleanly separates the logical structure of the problem (precedences between abstract operations) from the resource allocation details (assigning operations to non-overlapping slots on specific machines).
Conclusion
In this lesson, we have made the crucial leap from the standard Job Shop to the more complex and practical Flexible Job Shop Problem. You have seen how Constraint Programming provides specialized tools to manage the added complexity of machine flexibility in a declarative and powerful way.
Key Takeaways:
- The FJSP extends the JSSP by allowing each operation to be processed on one of a set of alternative machines.
- CP models this choice using a two-level structure: an abstract interval for the operation and a set of optional intervals for each machine choice (or "mode").
- The
alternativeglobal constraint is the key that links the abstract operation to its modes, ensuring exactly one is chosen and synchronizing their start/end times. - Precedence constraints are applied to the abstract operation intervals, while
NoOverlapconstraints are applied to the optional mode intervals for each machine. - This approach cleanly decomposes the problem into an assignment component (handled by
alternative) and a sequencing component (handled byNoOverlap).
Preview of the Next Lesson:
We have now seen how to model both JSSP and FJSP using Constraint Programming. But as you know from your research preparation, CP is not the only tool for optimization. Mixed-Integer Linear Programming (MILP) is another major paradigm. In our next lesson, we will compare the strengths and weaknesses of CP and MILP for modeling and solving scheduling problems. We will discuss how an FJSP would be formulated in MILP and contrast that with the CP model you learned today, giving you the critical perspective needed to select and justify the right tools for your thesis.