Contents  |  ‹ Previous  |  Next ›  |  Download EPUB  |  PDF

Chapter 15
Introduction to Integer Programming Formulations

Learning Outcomes

A.
Learn classic integer programming formulations.
B.
Demonstrate different uses of binary and integer variables.
C.
Demonstrate the format for modeling an optimization problem with sets, parameters, variables, and the model.

Your linear program says to build 2.7 warehouses and route 3.4 trucks. Rounding up to 3 warehouses might blow the budget; rounding down to 2 might leave demand unmet; and neither rounded plan is necessarily anywhere near the best whole-number plan. Worse, many decisions are not quantities at all but choices (open this facility or don’t, assign this job to that machine or not) where “0.7 of a yes” means nothing. Requiring variables to take integer values looks like a small change to a linear program. It is not: it buys enormous modeling power, and this chapter is a tour of what that power can express.

In this section, we will describe classical integer programming formulations. These formulations may reflect a real world problem exactly, or may be part of the setup of a real world problem.

15.1 Knapsack Problem

The knapsack problem can take different forms depending on if the variables are binary or integer. The binary version means that there is only one item of each item type that can be taken. This is typically illustrated as a backpack (knapsack) and some items to put into it (see Figure 15.1), but has applications in many contexts.

Illustration of the knapsack problem: a backpack with 15 kg capacity and a collection of boxes with different weights and dollar values, asking which boxes to select to maximize value.
Image: See page for author [CC BY-SA 2.5]. https://en.wikipedia.org/wiki/Knapsack_problem

Figure 15.1: Knapsack Problem: which items should we choose to take in the knapsack that maximizes the value while respecting the 15kg weight limit?

Binary Knapsack Problem

NP-complete

Given a non-negative weight vector a +n, a capacity b +, and objective coefficients c n,

maxcx  s.t. ax ≤ b x{0,1}n (15.1)

Example 15.1: Knapsack

[Excel] [PuLP] [Gurobipy]

You have a knapsack (bag) that can only hold W = 15 kgs. There are 5 items that you could possibly put into your knapsack. The items (weight, value) are given as: (12 kg, $4), (2 kg, $2), (1kg, $2), (1kg, $1), (4kg, $10). Which items should you take to maximize your value in the knapsack? See Figure 15.1.

Variables:

Model:

max 4x1 + 2x2 + 2x3 + 1x4 + 10x5 (Total value)  s.t.  12x1 + 2x2 + 1x3 + 1x4 + 4x5 15 (Capacity bound) xi {0,1} for all i = 1,,5 (Item taken or not)

In the integer case, we typically require the variables to be non-negative integers, hence we use the notation x +n. This setting reflects the fact that instead of single individual items, you have item types of which you can take as many of each type as you like that meets the constraint.

Integer Knapsack Problem

NP-complete

Given a non-negative weight vector a +n, a capacity b +, and objective coefficients c n,

maxcx  s.t. ax ≤ b x+n (15.2)

We can also consider an equality constrained version

Equality Constrained Integer Knapsack Problem

NP-hard

Given a non-negative weight vector a +n, a capacity b +, and objective coefficients c n,

max cx (15.3)  s.t.  ax = b (15.4) x +n (15.5)

Example 15.2: Min Coins

[Excel] [PuLP] [Gurobipy]

Using pennies, nickels, dimes, and quarters, how can you minimize the number of coins you need to make up a sum of 83¢?

Variables:

Model:

min p + n + d + q (total number of coins used)  s.t.  p + 5n + 10d + 25q = 83 sums to 83¢ p,d,n,q + (each is a non-negative integer)

15.2 Capital Budgeting

The capital budgeting problem is a nice generalization of the knapsack problem. This problem has the same structure as the knapsack problem, except now it has multiple constraints. We will first describe the problem, give a general model, and then look at an explicit example.

Capital Budgeting

A firm has n projects it could undertake to maximize revenue, but budget limitations require that not all can be completed.

Which projects should the firm invest in to maximize its expected return while satisfying its weekly budget constraints?

We will first provide a general formulation for this problem.

Capital Budgeting Model

Sets:

Parameters:

Variables:

Model:

max     j=1nc jxj (Total Expected Revenue) s.t.    j=1na ijxj bi,   i = 1,,m (Resource constraint week i) xj {0,1},j = 1,,n

Consider the example given in the following table.





Project 𝔼[Revenue] Resources required in week 1 Resources required in week 2




1 10 3 4




2 8 1 2




3 6 2 1




Resources available 5 6




Given this data, we can set up our problem explicitly as follows

Example 15.3: Capital Budgeting

[Excel] [PuLP] [Gurobipy]

Sets:

Parameters:

Variables:

The explicit model is given by
Model:

max 10x1 + 8x2 + 6x3 (Total Expected Revenue) s.t. 3x1 + 1x2 + 2x3 5 (Resource constraint week 1) 4x1 + 2x2 + 1x3 6 (Resource constraint week 2) xj {0,1},j = 1,2,3

15.3 Capacitated Lot Sizing Problem (CLSP)

The Capacitated Lot Sizing Problem (CLSP) is a fundamental optimization problem in production planning, where the goal is to determine an optimal production schedule that minimizes total costs while adhering to capacity constraints. The objective function accounts for production costs, setup costs, and inventory holding costs over a given planning horizon.

Let T denote the number of discrete time periods, indexed by t {1,2,,T}. The problem parameters are defined as follows:

The decision variables are:

The CLSP can be formulated as the following mixed-integer linear program:

min t=1T (p txt + ftyt + htst) (Minimize total cost)  s.t.  st1 + xt dt = st for all t = 1,2,,T (Inventory balance) xt ytct for all t = 1,2,,T (Capacity and setup constraint) xt,st 0 for all t = 1,2,,T (Non-negativity constraints) yt {0,1} for all t = 1,2,,T (Binary production decision)

The objective function (Minimize total cost) minimizes the total cost over the planning horizon, incorporating production, setup, and inventory holding costs. The inventory balance constraint (Inventory balance) ensures that demand in each period is met using either inventory from the previous period or newly produced units. The constraint (Capacity and setup constraint) enforces production capacity limits and ensures that a setup cost is incurred when production occurs. Constraints (Non-negativity constraints) enforce non-negativity on production and inventory levels, while (Binary production decision) ensures that the setup decision is binary.

For simplicity, we assume an initial inventory level of zero.

15.4 Facility Location

The basic model of the facility location problem is to determine where to place your stores or facilities in order to be close to all of your customers and hence reduce the costs of transportation to your customers. Each customer is known to have a certain demand for a product, and each facility has a capacity on how much of that demand it can satisfy. We also need to consider the cost of building the facility in a given location.

This basic framework can be applied in many types of problems and there are a number of variants to this problem. Here we present the capacitated facility location problem. Additional variants and alternative formulations are covered in Book 2.

15.4.1 Capacitated Facility Location

Capacitated Facility Location 1

NP-complete

Given connection costs cij, fixed building costs fi, demands dj, and facility capacities ui, the capacitated facility location problem is formulated as follows:

Sets:

Parameters:

Variables:

Model:

min i=1n j=1mc ijxij + i=1nf iyi (Totalcost)  s.t.  i=1nx ij = dj for all j = 1,,m (Meet demand) j=1mx ij uiyi for all i = 1,,n (Facility capacity) xij 0 for all i = 1,,n,j = 1,,m (Nonnegativity) yi {0,1} for all i = 1,,n (Open facility)

Example 15.4: Capacitated Facility Location: Retail Distribution Example

Gurobipy

Context: A retail company plans to establish distribution centers across a country to serve its stores efficiently. The company faces decisions on which distribution centers to open and which stores each center should serve. Costs associated with opening each center and serving stores from them are known, and each center has a maximum capacity. Each store also has a known demand.

Given Data: (distribution-data.xlsx)

Table 15.1: Combined Data for Distribution Centers and Stores
fi ui
cij (Cost to Serve a Store)
Center ($) (units) Store 1 Store 2 Store 3 Store 4
Center 1 150,000 100 $50 $60 $70 $85
Center 2 100,000 80 $75 $45 $55 $50
Center 3 180,000 90 $65 $80 $40 $60
Store Demand dj 400 300 200 250

Model Formulation: The capacitated facility location model described earlier can be applied to this scenario with the given data to determine the optimal number and location of distribution centers to open, and which stores each center should serve.

A network diagram for facility location showing three potential distribution centers with fixed costs and capacities, connected to four customer locations with demand values and shipping costs.

Figure 15.2: A network diagram for facility location: three potential distribution centers connected to stores.

If you build and solve this instance, you will discover that it is infeasible: the stores demand 1150 units in total, while the three centers combined can supply at most 270. This is on purpose. Not every problem has a nice solution, and discovering infeasibility is itself useful information a model gives you. As an exercise, decide how you would repair the instance: reduce demand or add capacity.

Case Study: Where Should the Water Bombers Sleep? Airtanker Basing in Ontario

Ontario fights forest fires with a fleet of airtankers (water bombers). A fire caught within the first few hours is usually a small story; a fire missed grows into a big one. So the province’s ability to hit new fires quickly depends on where the airtankers are based each morning. In the early 1990s the Ontario Ministry of Natural Resources asked operations researchers to help decide the home bases, and the resulting mathematical programming model informed the province’s actual basing strategy from the 1993 fire season onward.

The Challenge

Fires do not announce where they will start. What is known is the historical pattern: some fire management zones see far more fire starts than others, and an airtanker can only provide effective initial attack on fires within a limited flying range of its base. With a fixed fleet, where should the aircraft be based so that as much expected fire activity as possible is within reach?

The Solution: A Coverage Location Model

Model type: integer program (facility location / coverage). No machine learning; the fire-frequency inputs are historical averages.

Sets and Parameters:

Variables:

Model:

max iInizi (expected fires within reach)  s.t.  zi jJtijyj for all i I (coverage requires a nearby base) jJyj = N (fleet size) yj 0,zi {0,1}.

Assumptions and Simplifications

Implementation and Results

The Ontario Ministry of Natural Resources used the model to inform its airtanker home-basing strategy beginning with the 1993 fire season, and Ontario’s fire management program has continued to work with operations researchers for decades since, on deployment, dispatch, and detection-patrol planning.

References

15.5 Set Covering

The set covering problem can be used for a wide array of problems. We will see several examples in this section.

Set Covering

NP-complete

Given a set V with subsets V 1,,V l, determine the smallest subset S V such that S V i for all i = 1,,l.

The set cover problem can be modeled as

min1x  s.t. v∈V ixv ≥ 1 for all i = 1,…,l xv ∈{0,1} for all v ∈ V (15.6)

where xv is a 0/1 variable that takes the value 1 if we include item v in set S and 0 if we do not include it in the set S.

One specific type of set cover problem is the vertex cover problem.

Example: Vertex Cover

NP-complete

Given a graph G = (V,E) of vertices and edges, we want to find a smallest size subset S V such that for every e = (v,u) E, either u or v is in S.

We can write this as a mathematical program in the form:

min1x  s.t. xu + xv ≥ 1 for all (u,v) ∈ E xv ∈{0,1} for all v ∈ V. (15.7)

Example 15.5: Set cover: Fire station placement

https://github.com/open-optimization/open-optimization-or-examples/blob/master/integer-programming/fire-station-covering.ipynb

In the fire station problem, we seek to choose locations for fire stations such that any district either contains a fire station, or neighbors a district that contains a fire station. Figure 15.3 depicts the set of districts and an example placement of locations of fire stations. How can we minimize the total number of fire stations that we need?

Sets:

Variables:

Model:

min iV xi (#  open fire stations)  s.t.  xi + jV ixj 1 for all i V (Station proximity requirement) xi {0,1} for all i V (station either open or closed)

Layout of districts showing numbered regions and possible locations for fire stations.

Figure 15.3: Layout of districts and possible locations of fire stations.

Set cover representation of fire station problem showing which districts are covered by each potential fire station location.

Figure 15.4: Set cover representation of fire station problem. For example, choosing district 16 to have a fire station covers districts 13, 15, and 16.

Graph representation of fire station problem showing nodes connected to chosen fire station nodes by edges.

Figure 15.5: Graph representation of fire station problem. Every node is connected to a chosen node by an edge.

Figure 15.4 shows how the neighborhood structure translates into a set cover instance, and Figure 15.5 gives an equivalent graph view of the same solution.

Set Covering - Matrix description

NP-complete

Given a non-negative matrix A {0,1}m×n, a non-negative vector, and an objective vector c n, the set cover problem is

mincx s.t.Ax ≥1 x ∈{0,1}n. (15.8)

Example 15.6: Vertex Cover with matrix

An alternate way to solve equation is to define the incidence matrix A of the graph. The incidence matrix is a |E|×|V | matrix with {0,1} entries. Each row corresponds to an edge e and each column corresponds to a node v. For an edge e = (u,v), the corresponding row has a 1 in columns corresponding to the nodes u and v, and a 0 everywhere else. Hence, there are exactly two 1’s per row. Applying the formulation above in Graph representation of fire station problem. Every node is connected to a chosen node by an edge. models the problem.

15.5.1 Covering (Generalizing Set Cover)

We could also allow for a more general type of set covering where we have non-negative integer variables and a right hand side that has values other than 1.

Covering

NP-complete

Given a non-negative matrix A +m×n, a non-negative vector b m, and an objective vector c n, the covering problem is

mincx  s.t. Ax ≥ b x ∈ +n. (15.9)

Case Study: Kidney Exchange: Integer Programming that Saves Lives

Thousands of kidney patients have a friend or family member willing to donate a kidney, but with the wrong blood or tissue type. Kidney exchange programs fix this with a swap: donor A gives to patient B while donor B gives to patient A. With three pairs, a three-way cycle works the same way. National programs, including the United States’ kidney paired donation program (UNOS) and the United Kingdom’s Living Kidney Sharing Scheme, decide who swaps with whom by solving an integer program. In the UK, that integer program runs on a fixed schedule several times a year: the solver’s output is literally the list of surgeries to schedule.

The Challenge

Given a pool of incompatible patient–donor pairs, find a set of swap cycles that gives as many patients as possible a compatible kidney. Two hard rules shape the problem. First, a pair can appear in at most one cycle (each donor has one kidney to give). Second, all surgeries in a cycle must happen simultaneously, so that no donor can back out after their loved one has received a kidney; operating-room logistics therefore cap cycles at two or three pairs.

The Solution: A Cycle-Selection Integer Program

Model type: pure binary integer program. No machine learning; compatibility is determined by medical testing.

Sets:

Variables:

Model:

max cC|c|xc (total transplants)  s.t.  cC:icxc 1 for all i P (each pair in at most one cycle) xc {0,1} for all c C.

Here |c| is the number of pairs in cycle c, which equals the number of transplants the cycle produces. Real programs also include chains started by altruistic donors (someone who donates without a paired patient) and weight cycles by medical priority rather than just counting transplants; both are small extensions of the same model.

Assumptions and Simplifications

Implementation and Results

Cycle- and chain-based integer programs are the clearing engines of the US and UK national programs, and the published models have been benchmarked directly on real UNOS and UK datasets. The UK scheme’s matching runs are performed with algorithms developed by the University of Glasgow. Economist Alvin Roth shared the 2012 Nobel Prize in part for the market design behind kidney exchange.

References

15.6 Graph Coloring

Graph coloring

Petersen graph with vertices colored using three colors (red, green, blue) demonstrating a valid 3-coloring where no adjacent vertices share the same color.
Image: See page for author [Public domain], via Wikimedia Commons.
https://commons.wikimedia.org/wiki/File:Petersen_graph_3-coloring.svg

Figure 15.6: A valid 3-coloring of the Petersen graph: no two adjacent vertices share a color.

Figure 15.6is the problem of finding a minimum coloring in a graph, and it can be formulated in many ways. Each vertex is assigned a color and two vertices cannot share the same color if they are connected by an edge.

Since a graph on n vertices never needs more than n colors, we may fix the palette to be {1,,n}. For every vertex i V and every color j in the palette, introduce a binary variable xij that equals 1 exactly when vertex i receives color j. A second family of binaries records which colors actually get used: wj = 1 signals that color j appears on at least one vertex. Minimizing the number of colors used then gives a classical integer programming formulation:

min j=1nw j j=1nx ij = 1i V, xij + xkj wj{i,k} E,1 j n, xij {0,1}i V,1 j n wj {0,1}1 j n.

This basic model is highly symmetric: relabeling the colors in any feasible coloring produces a different solution with the same objective value, and a branch-and-bound solver may waste effort exploring all of these copies. We present two strengthened formulations from [?] that attack this symmetry; their paper goes further, adding several families of cutting planes.

Color order model: A coloring that uses k colors can be encoded in many interchangeable ways—any k labels chosen from {1,,n} will do. To keep a single representative from each such family, we force the labels to be consumed in numerical order: color j is available only once color j 1 appears somewhere in the graph. Every coloring that skips a label, or that uses a label larger than the number of colors it needs, is thereby cut off. Two extra constraint families accomplish this:

wj iV xij1 j n, wj wj+11 j n 1.

The first ties wj to actual use of color j; the second forbids gaps in the label sequence. The number of feasible solutions drops dramatically.

Independent set order model: Even when labels are used in order, the color classes of a k-coloring can still be shuffled among the labels 1,,k, so symmetric copies remain. A more aggressive fix sorts the color classes by size: the vertices receiving color j must be at least as numerous as those receiving color j + 1. This yields the constraints

wj iV xij1 j n i=1nx ij i=1nx ij+11 j n 1,

which are more restrictive than those of the color order model.

As an exercise, try implementing these different models and compare the solve times.

15.7 Basic Modeling Tricks - Using Binary Variables

In this section, we describe ways to model a variety of constraints that commonly appear in practice. The goal is changing constraints described in words to constraints defined by math.

Binary variables can allow you to model many types of constraints. We discuss here various logical constraints where we assume that xi {0,1} for i = 1,,n. We will take the meaning of the variable to be selecting an item.

1.
If item i is selected, then item j is also selected.
xi xj (15.10)

(a)
If any of items 1,,5 are selected, then item 6 is selected.
x1 + x2 + + x5 5 x6 (15.11)

Alternatively!

xi x6 for all i = 1,,5 (15.12)
2.
If item j is not selected, then item i is not selected. This is the contrapositive of the implication above, so the same inequality models it.
xi xj (15.13)

(a)
If item j is not selected, then none of the items 1,,i are selected.
x1 + x2 + + xi i xj (15.14)
3.
Either item i is selected or item j is selected, but not both.
xi + xj = 1 (15.15)
4.
Item i is selected or item j is selected or both.
xi + xj 1 (15.16)
5.
If item i is selected, then item j is not selected.
xj (1 xi) (15.17)
6.
At most one of items i, j, and k is selected.
xi + xj + xk 1 (15.18)
7.
At most two of items i,j, and k are selected.
xi + xj + xk 2 (15.19)
8.
Exactly one of items i,j, and k is selected.
xi + xj + xk = 1 (15.20)

These tricks can be connected to create different function values.

Example 15.7: Variable takes one of three values

Suppose that the variable x should take one of the three values {4,8,13}. This can be modeled using three binary variables as

x = 4z1 + 8z2 + 13z3 z1 + z2 + z3 = 1 zi {0,1} for i = 1,2,3.

As a convenient addition, if we want to add the possibility that it takes the value 0, then we can model this as

x = 4z1 + 8z2 + 13z3 z1 + z2 + z3 1 zi {0,1} for i = 1,2,3.

We can also model variable increases at different amounts.

Example 15.8: Discount for buying more

Suppose you can choose to buy 1, 2, or 3 units of a product, each with a decreasing cost. The first unit is $10, the second is $5, and the third unit is $3.

x = 10z1 + 5z2 + 3z3 z1 z2 z3 zi {0,1} for i = 1,2,3.

Here, zi represents if we buy the ith unit. The inequality constraints impose that if we buy unit j, then we must buy all units i with i < j.

15.7.1 Big M constraints - Activating/Deactivating Inequalities

Big M comes again! It’s extremely useful when trying to activate constraints based on a binary variable.

For instance, if we don’t rent a bus, then we can have at most 3 passengers join us on our trip. Consider passengers A,B,C,D,E and let xi {0,1} be 1 if we take passenger i and 0 otherwise. We can model the constraint that we can have at most 3 passengers as

xA + xB + xC + xD + xE 3.

We want to be able to activate this constraint in the event that we don’t rent a bus.

Let δ {0,1} be 1 if we rent a bus, and 0 otherwise.

Then we want to say

If δ = 0 , then

xA + xB + xC + xD + xE 3.

We can formulate this using a big-M constraint as

xA + xB + xC + xD + xE 3 + Mδ. (15.21)

Notice the two cases

{ xA + xB + xC + xD + xE 3  if δ = 0 xA + xB + xC + xD + xE 3 + M if δ = 1

In the second case, we choose M to be so large that the second case inequality is vacuous. That said, choosing smaller M values (that are still valid) will help the computer program solve the problem faster. In this case, it suffices to let M = 2.

We can speak about this technique more generally as

Big-M: If then

We aim to model the relationship

 If δ = 0,then ax b. (15.22)

By letting M be an upper bound on the quantity ax b, we can model this condition as

ax − b ≤ Mδ δ ∈{0,1} (15.23)

Below are several applications of this modeling technique:

Example 15.9: Network Flow with Toll Charges Using Big-M Constraints

Consider a transportation network where some arcs incur a toll cost if used. Let:

The objective is to route flow from a source node s to a sink node t at minimum total cost, including tolls when applicable:

min (i,j)A (cijxij + tijδij)

Subject to:

j:(i,j)Axij j:(j,i)Axji = { 1 if i = s 1 if  i = t 0 otherwise (Flow conservation) xij Mijδij (Big-M: toll applies only if arc is used) xij 0,δij {0,1} for all (i,j) A
Application: NYC Transportation Network with Tolls

Figure 15.7 illustrates a simplified transportation network over the five boroughs of New York City, with selected connections to model bridges and tunnels. Each node represents a borough, and directed arcs represent feasible travel routes. Some of these arcs include tolls, which are incurred only in one direction, mimicking real-world tolling policies.

Nodes. The nodes in the graph correspond to the following boroughs:

Arcs. The directed arcs model travel between boroughs, with an optional toll charge. These arcs represent crossings such as bridges or tunnels, and are defined as follows:

From To Toll
Manhattan Brooklyn Yes (e.g., Brooklyn-Battery Tunnel)
Manhattan Queens Yes (e.g., Queens-Midtown Tunnel)
Brooklyn Queens No
Manhattan Bronx Yes (e.g., RFK/Triborough Bridge)
Bronx Queens Yes
Manhattan Staten Island Yes (e.g., Verrazzano-Narrows Bridge)
Staten Island Brooklyn No
Table 15.2: Directed arcs between the boroughs and whether each crossing charges a toll.

Toll Modeling. Each arc (i,j) in the network has an associated binary toll flag. If a toll applies, the arc is subject to a fixed toll cost only if it is used. This can be modeled in a mixed-integer program using a binary variable δij {0,1} that indicates whether the arc is selected. A Big- M constraint of the form:

xij M δij

can be used to enforce toll cost and flow constraints, where xij is the flow over arc (i,j), and M is a suitably large upper bound on the possible flow.

Legend. In the figure, solid green arrows represent toll-free travel, while dashed red arrows indicate that a toll is applied in the direction of the arc.

Map of New York City's five boroughs showing a transportation network with red dashed toll roads and a green no-toll route connecting Staten Island, Brooklyn, and Queens.

Figure 15.7: Simplified NYC Transportation Network with Directional Tolls

Case Study: 108, 000 Fewer Truck Routes: Walmart’s Load Planning

Walmart moves goods from distribution centers to about 4,700 US stores on one of the largest private trucking fleets in the world. For the 2023 Franz Edelman Award (which it won), Walmart described an end-to-end optimization framework, from long-term network design down to daily routing and trailer load planning. In fiscal year 2023 the system eliminated 108,000 truck routes and 33 million driving miles, saving $91.5 million and preventing 98.6 million pounds of CO 2 emissions.

The Challenge

Every day, each store needs a set of orders delivered. Orders take up trailer space; trucks have capacity; stores have delivery windows; and every truck dispatched costs money and emissions. The daily question at the heart of load planning: pack the orders into as few trailer-loads as possible while respecting capacities and delivery requirements.

The Solution: A Packing/Consolidation Integer Program

Model type: integer programming for load consolidation and routing, inside a framework whose strategic layers are also optimization models. Forecasts feed the models as data.

The consolidation core, simplified:

Sets and Parameters:

Variables:

Model:

min tTyt (trucks dispatched)  s.t.  tTsotxot = 1 for all o O (every order ships) oOqoxot Qyt for all t T (capacity; ride only dispatched trucks) xot sot,xot,yt {0,1}.

The capacity constraint again uses the big- M linking pattern with M = Q. The deployed system couples this packing decision with routing (which stores share a route) and with strategic network design; the Edelman paper describes the full architecture.

Assumptions and Simplifications

Implementation and Results

Deployed across Walmart’s US supply chain: 108,000 routes and 33 million miles eliminated in FY2023, $91.5 million saved, 98.6 million pounds of CO 2 avoided. 2023 INFORMS Franz Edelman Award winner.

References

15.7.2 Either Or Constraints

The Big-M technique from the previous subsection activated a single constraint. A closely related situation is when we have two constraints and we need at least one of them to hold: an inclusive or. For example, a delivery might need to arrive either before a morning deadline or after an afternoon opening, or a budget must be satisfied in at least one of two currencies. The trick is to use one binary variable to decide which constraint is enforced, and a pair of Big-M constraints to relax whichever one is not selected.

Either Or

Eitherax b or cx dholds (15.24)

can be modeled as

ax − bM 1δ cx − dM 2(1 − δ) δ ∈{0,1}, (15.25)

where M1 is an upper bound on ax b and M2 is an upper bound on cx d.

Interpretation.

Either way, at least one of the two original constraints is enforced; the binary variable δ simply selects which one.

We now apply this recipe to a small example.

Example 15.10: Buses or Cars

To shuttle students to the football game, we need either at least 2 buses or at least 10 cars.

We want to enforce that x 2 or y 10. Writing these in the form used above, we need x 2 or y 10. Since x,y 0, we may take M1 = 2 as an upper bound on x (2) = 2 x and M2 = 10 as an upper bound on 10 y. The recipe gives

2 − x ≤ 2δ 10 − y ≤ 10(1 − δ) δ ∈{0,1}, (15.26)

which simplifies to x 2(1 δ) and y 10δ. If δ = 0 we must have at least 2 buses; if δ = 1 we must have at least 10 cars.

Choosing Big-M Values. The constants M1 and M2 should be chosen as valid upper bounds on the expressions ax b and cx d, respectively, over the feasible region. Overly large values may weaken the LP relaxation and cause numerical instability, so careful bounding is recommended whenever possible. In the example above, the bounds M1 = 2 and M2 = 10 are as tight as possible.

Use Cases. Either-or constraints naturally arise in problems with conditional decisions, such as:

We will see a substantial application of this idea, with more than two constraints in the disjunction, when we study 2D packing problems in Section 15.7.4.

15.7.3 If then implications - opposite direction

Suppose that we want to model the fact that if we have at most 10 students attending this course, then we must switch to a smaller classroom.

Let xi {0,1} be 1 if student i is in the course or not. Let δ {0,1} be 1 if we need to switch to a smaller classroom.

Thus, we want to model

If

iIxi 10

then

δ = 1.

Using the recipe below with b = 10, 𝜖 = 1 (the data are integer), and lower bound m = 10 on iIxi 10, we can model this as

iIxi 10 + 1(1 δ) + (10)δ = 11(1 δ). (15.27)

If δ = 0, the constraint forces at least 11 students; equivalently (by the contrapositive), whenever 10 or fewer students attend, the model must set δ = 1.

If inequality, then indicator

We let m be a lower bound on the quantity ax b and we let 𝜖 be a tiny number that is an error bound in verifying if an inequality is violated. If the data a,b are integer and x is an integer, then we can take 𝜖 = 1.

Now

If ax bthenδ = 1 (15.28)

can be modeled as

ax b 𝜖(1 δ) + mδ. (15.29)

Proof. We now justify the statement above.

A simple way to understand this constraint is to consider the contrapositive of the if then statement that we want to model. The contrapositive says that

If δ = 0, then ax − b > 0.(15.30)

To show the contrapositive, we set δ = 0. Then the inequality becomes

ax b 𝜖(1 0) + m0 = 𝜖 > 0.

Thus, the contrapositive holds.

If instead we wanted a direct proof:

Case 1: Suppose ax b. Then 0 ax b, which implies that

δ(ax b) ax b

Therefore

δ(ax b) 𝜖(1 δ) + mδ

After rearranging

δ(ax b m) 𝜖(1 δ)

Since ax b m 0 and 𝜖 > 0, the only feasible choice is δ = 1.

Case 2: Suppose ax > b. By the choice of 𝜖, this implies ax b 𝜖, so the inequality holds with δ = 0. Since also ax b m, it holds with δ = 1 as well. Thus both choices of δ are feasible, as they should be. □

Many other combinations of if then statements are summarized in the following table:



Implication Constraint


If δ = 0, then ax b ax b + Mδ
If ax b, then δ = 1 ax mδ + 𝜖(1 δ)


Table 15.3: Short list: If/then models with a constraint and a binary variable. Here M and m are upper and lower bounds on ax b and 𝜖 is a small number such that if ax > b, then ax b + 𝜖.

These two implications can be used to derive the following longer list of implications.



Implication Constraint


If δ = 0, then ax b ax b + Mδ
If δ = 0, then ax b ax b + mδ
If δ = 1, then ax b ax b + M(1 δ)
If δ = 1, then ax b ax b + m(1 δ)
If ax b, then δ = 1 ax b + mδ + 𝜖(1 δ)
If ax b, then δ = 1 ax b + Mδ 𝜖(1 δ)
If ax b, then δ = 0 ax b + m(1 δ) + 𝜖δ
If ax b, then δ = 0 ax b + M(1 δ) 𝜖δ


Table 15.4: Long list: If/then models with a constraint and a binary variable. Here M and m are upper and lower bounds on ax b and 𝜖 is a small number such that if ax > b, then ax b + 𝜖.

Lastly, if you insist on having exact correspondence, that is, “ δ = 0 if and only if ax b” you can simply include both constraints for “if δ = 0, then ax b” and “if ax b, then δ = 0”. Although many problems may be phrased in a way that suggests you need “if and only if”, it is often not necessary to use both constraints due to the objectives in the problem that naturally prevent one of these from happening.

For example, if we want to add a binary variable δ that means

{ δ = 0 implies ax b δ = 1 Otherwise

If δ = 1 does not affect the rest of the optimization problem, then adding the constraint regarding δ = 1 is not necessary. Hence, typically, in this scenario, we only need to add the constraint ax b + Mδ.

15.7.4 Multi Term Disjunction with application to 2D packing

A disjunction is a generalization of an “or” statement. Suppose that we have n constraints

a1x b 1,a2x b 2,,anx b n

and we want to enforce at least k of them. This can be accomplished linearly by introducing a new binary indicator variable δi for each of the disjunctive constraints i {1,,n}:

a1x b 1 + M(1 δ1) a2x b 2 + M(1 δ2) anx b n + M(1 δn) i=1nδ i k

If δi = 1, then the i

th disjunctiveconstraintisactivelyenforced.Thelastconstraint ( i=1nδi k) ensures that at least k of the constraints are active.

Strip Packing Problem

Suppose we have a collection of rectangles I and a 2-dimensional strip with width W and infinite height. Each rectangle i I has width wi and height hi and we want to pack the rectangles into the strip so that (15.31a) overall height is minimized, (15.31b) overall width is less than W, and (15.31c) none of the rectangles overlap. See Figure 15.8 for an example: Figure 15.8a shows the rectangles to be packed, and Figure 15.8b shows a packing whose overall height H we wish to minimize.

Strip packing problem input showing four rectangles with their dimensions labeled, alongside an empty strip where they need to be packed.

(a) Pack the rectangles into the strip

A strip packing diagram showing several gray rectangles of varying sizes packed within a vertical strip of width W, with a dotted horizontal line at height H indicating the current maximum height.

(b) Minimize overall height H.
Figure 15.8: An Example of the Strip Packing Problem

Let (xi,yi) denote the position of the lower-left-hand corner of each rectangle i I. The overlapping constraint (15.31c) is the trickiest part. Consider a pair of rectangles i and j: rectangle j is located entirely to the left of rectangle i if xi has a value larger than xj + wj. That is, if xj + wj xi. On the other hand, if yj yi + hi, then rectangle j is located entirely above rectangle i. If either of these constraints is satisfied then rectangles i and j do not overlap. We could also place i above or to the right of j. This gives four constraints that we need to satisfy at least one of. The model can be thought of as follows:

Minimize max iI {yi + hi } (15.31a)  s.t.  max iI{xi + wi} W (15.31b) xi + wi xj xj + wj xi yi + hi yj yj + hj yi } At least one of these for every distinct pair of rectangles i,j I (15.31c) xi,yi 0 i I (15.31d)

Constraint (15.31c) is a set of four disjunctive constraints. This can be expressed linearly by introducing a new binary indicator variable δijk for each of the disjunctive constraints in (15.31c):

Minimize H  s.t.  yi + hi H i I (15.31a) xi + wi W i I (15.31b) xi + wi xj + M(1 δij1) i,j I : i > j xj + wj xi + M(1 δij2) i,j I : i > j yi + hi yj + M(1 δij3) i,j I : i > j (15.31c) yj + hj yi + M(1 δij4) i,j I : i > j k=14δ ijk 1 i,j I : i > j xi,yi 0 i I δij {0,1}4 i,j I : i > j

If δijk = 1, then the k

th disjunctiveconstraintisactivelyenforced.Thelastconstraint ( k=14δijk 1) ensures that at least one of the constraints is active. An optimal solution to the example is given in Figure 15.9; it was found via GurobiPy.

A feasible strip packing solution showing rectangles packed into the strip with coordinate positions listed for each rectangle.

Figure 15.9: An optimal solution to the strip packing example.

This problem is considered strongly NP-Hard.

15.7.5 SOS1 Constraints

The modeling tricks so far in this section were built by hand out of binary variables and Big-M constraints. Certain logical structures come up so often, however, that modern solvers accept them directly as special ordered sets (SOS). Declaring an SOS constraint tells the solver about the structure explicitly, which both simplifies the model you write and lets the solver use specialized branching rules.

Definition 15.11: Special Ordered Sets of Type 1 (SOS1)

A Special Ordered Set of type 1 (SOS1) constraint on a vector indicates that at most one element of the vector can be non-zero.

SOS1 constraints arise whenever a set of options is mutually exclusive: choosing one supplier out of several, operating a machine in one of several modes, or assigning a shipment to one of several routes. If each xi has an upper bound Ui, we could model this ourselves by introducing a binary variable zi for each xi and writing xi Uizi together with izi 1. Declaring an SOS1 constraint achieves the same effect with a single line of code and no extra variables.

The following small example is deliberately simple: the point is not the optimization problem itself, but seeing both modeling styles side by side in code.

Example 15.12: SOS1 Constraints

Gurobipy

Solve the following optimization problem:

maximize3x1 + 4x2 + x3 + 5x4  s.t.  0 xi 5 at most one of the xi can be nonzero

Since only one variable may be nonzero, the best choice is to push the variable with the largest objective coefficient, x4, to its upper bound: the optimal solution is x4 = 5 with value 25.

15.7.6 SOS2 Constraints

Definition 15.13: Special Ordered Sets of Type 2 (SOS2)

A Special Ordered Set of Type 2 (SOS2) constraint on a vector indicates that at most two elements of the vector can be non-zero AND the non-zero elements must appear consecutively.

At first glance this looks like a strange condition to single out, but it is exactly what is needed to model piecewise linear functions: a point on a piecewise linear curve lies on one segment, and can therefore be written as a weighted average of the two consecutive breakpoints at the ends of that segment. We develop that application in the next subsection; here we first get comfortable with the constraint itself.

The example below modifies the SOS1 example in only one way (two consecutive nonzeros are now allowed), so the two examples are easy to compare. As before, the accompanying code shows both a binary-variable formulation and the one-line SOS2 declaration.

Example 15.14: SOS2

Gurobipy

Solve the following optimization problem:

maximize3x1 + 4x2 + x3 + 5x4  s.t.  0 xi 5 at most two of the xi can be nonzero and the nonzero xi must be consecutive

The pairs of consecutive variables are (x1,x2), (x2,x3), and (x3,x4). Comparing the objective coefficients, the best pair is (x1,x2) at x1 = x2 = 5, giving value (3 + 4) 5 = 35. Note that the SOS1 solution x4 = 5 alone would give only 25.

15.7.7 Piecewise linear functions with SOS2 constraint

Example 15.15: Piecewise Linear Function

Gurobipy

Consider the piecewise linear function c(x) given by

c(x) = { 25x  if 0 x 5 20x + 25 if 5 x 10 15x + 75 if 10 x 15

Plot of a piecewise linear function composed of several line segments with breakpoints marked on the horizontal axis.

Figure 15.10: Piecewise linear function.

We will use integer programming to describe this function. We will fix x = a and then the integer program will set the value y to c(a).

min 0  s.t.  x = 5z2 + 10z3 + 15z4 y = 125z2 + 225z3 + 300z4 z1 + z2 + z3 + z4 = 1 SOS2 : {z1,z2,z3,z4} 0 zi 1 for all i {1,2,3,4} x = a

Example 15.16: Piecewise Linear Function Application

Gurobipy

Consider the following optimization problem where the objective function includes the term c(x), where c(x) is the piecewise linear function described in Piecewise linear functions with SOS2 constraint:

max z = 12x11 + 12x21 + 14x12 + 14x22 c(x) (15.32)  s.t.  x11 + x12 x + 5 (15.33) x21 + x22 10 (15.34) 0.5x11 0.5x21 0 (15.35) 0.4x12 0.6x22 0 (15.36) xij 0 (15.37) 0 x 15 (15.38)

Given the piecewise linear function, we can model the whole problem explicitly as a mixed-integer linear program.

max 12X1,1 + 12X2,1 + 14X1,2 + 14X2,2 − y  s.t.  x − 5z2 − 10z3 − 15z4 = 0 y − 125z2 − 225z3 − 300z4 = 0 z1 + z2 + z3 + z4 = 1 X1,1 + X1,2 − x ≤ 5 X2,1 + X2,2 ≤ 10 0.5X1,1 − 0.5X2,1 ≥ 0 0.4X1,2 − 0.6X2,2 ≥ 0 SOS2 : {z1,z2,z3,z4} Xi,j ≥ 0 ∀i ∈{1,2},j ∈{1,2} 0 ≤ zi ≤ 1 ∀i ∈{1,2,3,4} 0 ≤ x ≤ 15 y  free (15.39)

SOS2 with binary variables

If the solver does not support SOS2 constraints directly, we can enforce the same condition with binary variables. The recipe for a piecewise linear function f with breakpoints a1 < a2 < < ak is:

min i=1kλ if(ai)  s.t.  i=1kλ i = 1 x = i=1kλ iai i=1k1z i = 1 λ1 z1 λi zi1 + zi for all i = 2,,k 1, λk zk1 λi 0,zi {0,1}.

Here the binary variable zi selects segment i: the constraint i=1k1zi = 1 picks exactly one interval [ai,ai+1], and the constraints λj zj1 + zj then force λj = 0 for every index j outside {i,i + 1}. Only λi and λi+1 can be nonzero, which is exactly the SOS2 condition.

15.7.8 Maximizing a minimum

When the constraints could be general, we will write x X to define general constraints. For instance, we could have X = {x n : Ax b} or X = {x n : Ax b,x n} or many other possibilities.

Consider the problem

max min {x1, ,xn}  such that  x X Having the minimum on the inside is inconvenient. To remove this, we just define a new variable y and enforce that y xi and then we maximize y. Since we are maximizing y, it will take the value of the smallest xi. Thus, we can recast the problem as

max y  such that  y xi for i = 1,,n x X

15.7.9 Relaxing (nonlinear) equality constraints

There are a number of scenarios where the constraints can be relaxed without sacrificing optimal solutions to your problem. In a similar vein to maximizing a minimum, if because of the objective we know that certain constraints will be tight at optimal solutions, we can relax the equality to an inequality. For example,

max x1 + x2 + + xn  such that  xi = yi2 + z i2 for i = 1,,n

Since the objective pushes each xi upward, we can relax the equality to

max x1 + x2 + + xn  such that  xi yi2 + z i2 for i = 1,,n

At any optimal solution of the relaxed problem, each xi is as large as its constraint allows, so xi = yi2 + zi2 holds and the optimal solutions are unchanged. This trick is valid whenever the objective pressure forces the relaxed inequality to be tight at optimality. Note that the direction matters: relaxing to xi yi2 + zi2 instead would let the xi grow without bound.

15.7.10 Modeling the Exact Absolute Value

In many formulations we need to enforce the constraint |x| = t where t 0. Note that the inequality version |x| t is equivalent to the pair of linear constraints t x t and requires no integer variables. However, the equality |x| = t defines a non-convex set (the union of x = t and x = t), and so it cannot be modeled with linear constraints alone.

To handle this, decompose x into its positive and negative parts: write x = x+ x with x+,x 0. Then |x| = x+ + x provided that x+ and x are not simultaneously positive. We enforce this complementarity condition using a binary variable z {0,1} and a sufficiently large constant M (an upper bound on |x| in the context of the problem):

x = x+ x, t = x+ + x, x+ Mz, (15.40) x M(1 z), (15.41) x+,x 0,z {0,1}.

When z = 1, constraint (15.41) forces x = 0, so x = x+ 0. When z = 0, constraint (15.40) forces x+ = 0, so x = x 0. In either case, t = |x| as required.

Exact 1-norm

The technique above extends naturally to model the exact 1-norm constraint x1 = i=1n|xi| = c, where x n is a vector of decision variables and c > 0 is a given constant. Such constraints appear, for example, in portfolio optimization where a budget constraint requires that long and short positions sum to a fixed investment level.

We introduce variables xi+,xi 0 and binary variables zi {0,1} for each component i = 1,,n:

xi = xi+ x i, i = 1,,n, xi+ cz i, i = 1,,n, xi c(1 z i), i = 1,,n, i=1n(x i+ + x i) = c, xi+,x i 0,z i {0,1}.

The bound c is used here because no individual |xi| can exceed c when the total 1-norm equals c.

Modeling the Exact Maximum

Suppose we need to model t = max {x1, ,xn} exactly. The inequality version t max {x1, ,xn} can be modeled simply as t xi for all i, and if the objective is minimizing t, the optimizer will push t down to the true maximum. However, when the equality t = max {x1, ,xn} is required as a general constraint, we need to ensure that t also satisfies t xi for some i.

Introduce binary indicator variables z1,,zn where zi = 1 indicates that xi achieves the maximum. With a sufficiently large constant M:

xi t, i = 1,,n, t xi + M(1 zi), i = 1,,n, i=1nz i = 1, zi {0,1}, i = 1,,n.

The first set of constraints ensures t xi for all i. For the index i where zi = 1, the second constraint becomes t xi, forcing t = xi. Together with the first constraints, this gives t = max ixi.

15.8 Job Shop Scheduling

Try it out visually!

Job-Shop Schedule (Gantt): this chapter’s scheduling problem, solved and animated.

The Job Shop Scheduling Problem (JSSP) is a classical combinatorial optimization problem that is NP-hard. A set of jobs must be processed on a set of machines, where each job follows a prescribed sequence of operations across the machines. Each operation has a fixed processing time, each machine can handle only one job at a time, and once a machine begins processing an operation it must finish without interruption. The objective is to minimize the makespan, the time at which the last job completes.

Consider a small workshop with three machines ( m1, m2, m3) and four jobs. Each job must visit each machine exactly once, in a job-specific order, with the following processing times (in hours):

Processing jobs one after another (sequentially) yields a makespan of 9 + 7 + 7 + 7 = 30 hours. By allowing jobs to run concurrently on different machines, the makespan can be significantly reduced.

15.8.1 JSSP Components

Two pieces of data specify an instance. First, we collect the n jobs in a set J = {1,,n} and the m machines in a set I = {1,,m}. Second, each job carries its own route through the shop together with the time it needs at each stop: we write orj for the machine on which job j runs its r-th operation, so that the route of job j is the sequence Oj = (o1j,,omj), and we write pij 0 for the time job j occupies machine i.

A schedule assigns a start time to every operation. Three rules separate the feasible schedules from the infeasible ones: the operations of a job may not start out of order—each waits for its predecessor on the route Oj to finish; a machine hosts at most one job at any moment; and processing cannot be paused, so an operation that starts at time t on machine i blocks that machine until time t + pij. Among all feasible schedules we want one whose makespan—the time when the final operation ends—is as small as possible.

Example 15.17: Job Shop Scheduling Problem Input Data

Basic Parameters. Consider n = 4 jobs and m = 3 machines, using the workshop data introduced above.

Processing Times. The matrix of processing times (one row per job, one column per machine) is:

P = [ 3 2 4 4 2 1 1 3 3 2 2 3 ]

The entry in row  j, column  i gives the processing time pij of job  j on machine  i.

Machine Sequences. The order in which each job visits the machines is:

O = [ 1 2 3 2 1 3 3 1 2 1 3 2 ]

Each row gives the machine sequence for a job. For instance, job 1 is processed first on machine 1, then machine 2, then machine 3, while job 3 starts on machine 3, then visits machine 1, and finishes on machine 2.

Big M Calculation. A large constant M is used in the big- M formulation to enforce disjunctive constraints. A valid choice is the sum of all processing times:

M = i=1m j=1np ij = (3+2+4)+(4+2+1)+(1+3+3)+(2+2+3) = 30.

Gantt chart showing a job shop scheduling solution with three machines processing five jobs over time. Colored horizontal bars represent job operations on each machine, demonstrating how jobs are sequenced to minimize makespan.

Figure 15.11: Job shop scheduling solution shown as a Gantt chart.

Applications of JSSP The JSSP has numerous practical applications, including:

15.8.2 Mathematical Model

We now build a mixed-integer program from the ingredients above. This disjunctive formulation is classical and is due to Manne1.

Sets:

Parameters:

Variables: The main decisions are continuous start times

sij =  start time of job j on machine i,

together with a variable Cmax for the makespan. Start times alone cannot express “one of these two jobs must wait for the other,” so for each machine i and each pair of jobs j < k we add a binary variable that records which job goes first:

zijk = { 1,when machine i processes job j before job k, 0, when job  k takes its turn on machine  i first, i I,j,k J,j < k.

Constraints: Precedence within a job. Each job must follow its route: operation r of job j cannot begin until operation r 1 has finished, that is,

sorjj sor1jj + por1jjj J,r {2,,m}.

One job at a time per machine. Fix a machine i and two jobs j < k. Feasibility demands that either job j clears the machine before job k arrives, sij + pij sik, or the reverse, sik + pik sij. This is precisely the either-or situation of Section 15.7.2, and applying that recipe with zijk in the role of the selector variable δ yields the big- M pair

sij + pij sik + M(1 zijk)i I,j,k J,j < k, sik + pik sij + Mzijki I,j,k J,j < k.

When zijk = 1 the first inequality forces job j ahead of job k while the second is switched off; when zijk = 0 the roles swap.

Makespan. The makespan must sit above the completion time of every job’s last operation:

Cmax somjj + pomjjj J.

Model:

min Cmax  s.t.  sorjj sor−1jj + por−1jj ∀j ∈ J,r ∈{2,…,m} follow the route of job j sij + pij sik + M(1 − zijk) ∀i ∈ I,j,k ∈ J,j < k j first when zijk = 1 sik + pik sij + Mzijk ∀i ∈ I,j,k ∈ J,j < k k first when zijk = 0 Cmax somjj + pomjj ∀j ∈ J makespan covers every job sij ≥ 0 ∀i ∈ I,j ∈ J zijk ∈{0,1} ∀i ∈ I,j,k ∈ J,j < k Cmax ≥ 0 (15.42a)

Solving this model on the four-job, three-machine instance above gives an optimal makespan of 12 hours—a substantial improvement over the 30 hours needed to run the jobs one at a time.

Example 15.18: Duplo Scheduling

[Excel] [PuLP] [Gurobipy]

The Duplo in-class exercise is solved with Gurobi in the link.

The optimal value is 11.

Gantt chart showing a Job Shop Scheduling Problem solution with three machines and four jobs represented by colored bars over a time horizon of 0 to 12 units.

Figure 15.12: Gantt chart of the Duplo job shop scheduling solution with three machines and four color-coded jobs.

Photograph of colorful Duplo building blocks arranged on a table, representing a physical demonstration of a job shop scheduling problem with blocks of different colors and sizes.

Figure 15.13: Photograph of Duplo building blocks arranged as a physical demonstration of the job shop schedule.

15.8.3 Job Shop Scheduling Variations

Makespan minimization of assigning jobs to machines.

In this variation, each machine can handle a number of different types of jobs. Some machines can do certain jobs faster than others.

We want to minimize the completion time of all of the jobs.

In this variation, each job visits its listed machines in sequence: most jobs require processing on two machines, in the order given, while a few need only one.

Machines:

Jobs:

Objective: Minimize the makespan (i.e. the total time it takes to complete all the jobs)

Constraints:

We leave this as an exercise for the reader to model and solve.

15.9 Exercises

Warm-ups

Exercise 15.19: Knapsack Problem

  A hiker is packing a backpack with a weight capacity of 15 kg. The available items are:

Item Weight (kg) Value



Tent 5 8
Sleeping Bag 3 6
Stove 4 5
Food 7 10
Camera 2 4
Table 15.5: Weights and values of the items available to the hiker.

1.
Formulate a binary integer program to maximize the total value of items packed without exceeding the weight capacity.
2.
Suppose the hiker also requires that if the stove is packed, then the food must also be packed (you cannot cook without food). Add this logical constraint to your formulation.

[Example 15.1, §15.7]

Exercise 15.20: Courier Van Knapsack

  A courier van can carry at most 15 kg on its last run of the day. Five packages are waiting, with weights and payouts:

Package 1 2 3 4 5






Weight (kg) 11 3 2 5 4
Payout ($) 5 3 3 7 4
Table 15.6: Package weights and payouts for the courier van.

1.
Formulate a binary knapsack problem for choosing which packages to load.
2.
Solve it, by hand or with a solver. Which packages ride along, and what is the total payout?

[Example 15.1]

Exercise 15.21: Covering a Small Town

  A town has six districts arranged in a 2 × 3 grid:




1 2 3



4 5 6



Two districts are neighbors when their cells share a side. A fire station placed in a district covers that district and all of its neighbors.

1.
Write out the neighbor sets V i for each district i.
2.
Formulate the set covering integer program that minimizes the number of fire stations so that every district is covered.
3.
Solve the instance. How many stations are needed, and where can they go?

[Example 15.5, 15.5]

Exercise 15.22: Big-M Activation Drill

  A tour company runs three excursions with sign-up counts x1,x2,x3, where each excursion can take at most 30 tourists ( 0 xi 30). Let δ {0,1} equal 1 if the company hires a second guide. Company policy: if no second guide is hired, then the three excursions can take at most 40 tourists in total.

1.
Write this if-then requirement as a single linear constraint using a big- M parameter.
2.
What is the smallest valid value of M? Justify it using the bounds on the xi.

15.7.1, §15.7]

Core problems

Exercise 15.23: Locating Distribution Terminals

  Suppose that a company based in St. John’s is considering adding distribution terminals in (1) Halifax, (2) Moncton, (3) Montréal, (4) Ottawa, and (5) Toronto.

The cost of building the five terminals in millions of dollars would be 10 in Halifax, 12 in Moncton, 20 in Montréal, 18 in Ottawa, and 25 in Toronto.

1.
No more than two terminals may be built.
2.
If no terminal is built in Halifax, then one must be built in Moncton.
3.
At least one terminal must be built in central Canada (i.e. at locations (3), (4), or (5)).

Define the variables: yi = { 1 if a terminal is built in city i(i = 1,,5) 0  otherwise 

Using these variables, write a (binary) integer program that models the problem of determining which terminals to build subject to the constraints above that minimizes cost.

15.2, §15.7]

Exercise 15.24: Warehouse Location

  A retail company must decide which of four potential warehouse sites to open. Each warehouse has a fixed opening cost and can serve a subset of five customer regions. The data are as follows:

Warehouse Fixed Cost ($1000s) Regions Served



A 150 1, 2, 3
B 200 2, 3, 4, 5
C 120 1, 4
D 180 3, 4, 5
Table 15.7: Fixed opening costs and regions served for each candidate warehouse.

Every customer region must be served by at least one open warehouse.

1.
Define binary decision variables and formulate an integer program that minimizes the total fixed cost while ensuring every region is served.
2.
What type of classic IP problem does this resemble?

[15.5, Example 15.5]

Exercise 15.25: Capital Budgeting with Dependencies

  A firm is screening five projects over a two-year horizon. The net present values and the cash outlays (all in $1000s) are:

Project 1 2 3 4 5






NPV 20 40 20 15 30
Year 1 outlay 5 4 3 7 8
Year 2 outlay 1 7 9 4 6
Table 15.8: Net present values and cash outlays for the five candidate projects (in $1000s).

The budget is 20 in each year. In addition: project 3 is an expansion of project 1, so it can only be undertaken if project 1 is; and projects 2 and 5 would serve the same market, so at most one of them may be chosen.

1.
Formulate a binary integer program that maximizes total NPV subject to both budgets and both logical conditions.
2.
Solve the instance. Which projects are funded, and what is the optimal NPV?

15.2, §15.7]

Exercise 15.26: Facility Location: Two Distribution Centers

  A company can open distribution centers at two sites to serve three stores. Opening costs, capacities, per-unit serving costs, and demands are:

fi ($) ui (units) Store 1 Store 2 Store 3
Center 1 80 40 $2 $3 $1
Center 2 60 25 $4 $1 $2
Demand dj 10 12 15
Table 15.9: Opening costs, capacities, per-unit serving costs, and store demands for the two candidate centers.

1.
Check that this instance, unlike the retail distribution example in the text, has enough capacity to be feasible.
2.
Formulate the capacitated facility location model for this data.
3.
Solve the instance. Which centers open, how is demand assigned, and what is the total cost? In particular, is it worth opening the cheaper center?

15.4]

Exercise 15.27: Coloring a Five-Node Graph

  Consider the graph on vertices {A,B,C,D,E} with edges

{A,B},{B,C},{C,D},{D,E},{E,A},{A,C},

a five-cycle together with the chord {A,C}.

1.
Write the classical integer programming formulation for coloring this graph with variables xij and wj.
2.
Solve the instance to find the chromatic number, and exhibit an optimal coloring.
3.
Explain how the triangle A,B,C gives a quick lower bound that matches your answer.

15.6]

Exercise 15.28: Either-Or Constraints

  A company produces two products, x1 and x2. Production of product 1 requires a special machine that can either run in mode A or mode B, but not both simultaneously. The constraints are:

Exactly one of these two constraints must hold (the machine operates in exactly one mode). The objective is to maximize 5x1 + 4x2 with x1,x2 0.

Introduce a binary variable and a big- M parameter to formulate this either-or constraint as a mixed-integer program.

15.7.2]

Exercise 15.29: Fixed-Charge Production

  A factory can produce a product in any quantity x 0, but starting up production incurs a fixed cost of $500. The variable production cost is $8 per unit, and each unit sells for $15. The factory has capacity to produce at most 200 units.

1.
Define a binary variable y that indicates whether the factory produces any units at all. Write a mixed-integer program that maximizes profit (revenue minus variable cost minus fixed cost).
2.
Explain the role of the constraint that links x and y.

15.7.1]

Concepts and connections

Exercise 15.30: Why Rounding the Relaxation Fails

  Return to the knapsack instance of Example 15.1 and replace xi {0,1} by 0 xi 1 (the LP relaxation).

1.
Solve the LP relaxation. (For a single knapsack constraint the relaxation can be solved greedily: sort items by value per kilogram and fill the bag in that order, taking a fraction of the last item.) You should find value 523 17.33 with x1 = 712 and all other variables equal to 1.
2.
Round the fractional variable up. Is the result feasible? Round it down. What value do you get, and how does it compare to the true integer optimum of 15?
3.
Rounding down happened to give an optimal integer solution here. Explain why rounding cannot be trusted in general. In particular, describe what rounding does to a model with equality constraints such as Example 15.2, and to binary choice variables such as those in Exercise 15.23, where a value like yi = 0.5 has no meaning.

[Example 15.1, Example 15.2, §15]

Exercise 15.31: When is Big-M Too Big?

  In Exercise 15.28, the value M = 106 is perfectly valid: the resulting mixed-integer program has the same optimal solution as with M = 20.

1.
Explain what such a huge M does to the LP relaxation: how much does a tiny fractional value of δ, say δ = 105, relax each mode constraint? Why does this weaken the bounds a solver gets from the relaxation?
2.
Derive the tightest valid constants for that exercise. When mode B is active, the constraint x1 + 3x2 12 bounds 2x1 + x2; when mode A is active, 2x1 + x2 10 bounds x1 + 3x2. Show that M1 = 14 and M2 = 18 suffice.
3.
Name one numerical (floating-point) hazard of very large M values mentioned in the text.

[Choosing Big-M Values paragraph in §15.7.2, Exercise 15.28]

Exercise 15.32: Reading the Kidney Exchange Model

  Consider the cycle-selection integer program in the kidney exchange case study.

1.
Explain in plain language what the constraint cC:icxc 1 enforces, and what could go wrong medically if it were dropped.
2.
The objective uses coefficients |c|. Why does c|c|xc equal the number of transplants performed?
3.
The set C only contains cycles of length at most 3. Give the operational reason for this cap, and describe what happens to the size of C if the cap is raised.
4.
An altruistic donor donates a kidney without a paired patient, starting a chain rather than a cycle. Describe how you would extend the sets and variables of the model to include chains of bounded length.

[Kidney exchange case study in §15.5.1]

Challenge problems

Exercise 15.33: Piecewise-Linear Production Cost

  A plant can produce up to 30 tons of product, sold at $6 per ton. Production cost is piecewise linear in the quantity x: the first 10 tons cost $5 per ton, the next 10 tons cost $3 per ton (a bulk discount on inputs), and the final 10 tons cost $8 per ton (overtime).

1.
Write the total cost C(x) at the breakpoints x = 0,10,20,30 and explain why C is not convex, so the standard LP tricks for convex piecewise-linear costs do not apply.
2.
Formulate profit maximization using breakpoint weights λ1,,λ4 with an SOS2 condition, and also write the equivalent binary-variable formulation from the text.
3.
Solve the model. You should find that producing 20 tons is optimal with profit $40. Why does the plant stop exactly at the end of the discounted segment?

15.7.7, Example 15.15, Example 15.14]

Exercise 15.34: Two Jobs, Three Machines

  Two jobs must each pass through machines M1 M2 M3 in that order. Processing times are:

M1 M2 M3




Job 1 3 2 4
Job 2 2 4 3
Table 15.10: Processing times for the two jobs on the three machines.

Each machine can process only one job at a time, and jobs cannot be interrupted.

1.
Introduce start-time variables sjk for job j on machine k and write the precedence constraints within each job.
2.
For each machine k, introduce a binary variable δk and write the disjunctive pair of big- M constraints stating that either job 1 precedes job 2 on machine k or vice versa. Propose a valid value of M from the data.
3.
Minimize the makespan and solve the model. You should find an optimal makespan of 12; report which job goes first on each machine and the full schedule.

15.8, §15.7.4, §15.7.1]

Selected Solutions

Solution

(Exercise 15.20) With xi = 1 if package i is loaded, the model is

max 5x1+3x2+3x3+7x4+4x5s.t.11x1+3x2+2x3+5x4+4x5 15,xi {0,1}.

The optimal load is packages 2,3,4,5 with weight 3 + 2 + 5 + 4 = 14 15 and payout 3 + 3 + 7 + 4 = $17. The heavy package 1 never pays: taking it leaves only 4kg of room, and the best it can then achieve is 5 + 3 = $8.

Solution

(Exercise 15.21) The neighbor sets (including the district itself, as in the fire station example) are V 1 = {1,2,4}, V 2 = {1,2,3,5}, V 3 = {2,3,6}, V 4 = {1,4,5}, V 5 = {2,4,5,6}, V 6 = {3,5,6}. One station cannot cover all six districts since no set V i has more than four elements. Two stations suffice: districts 2 and 5 cover V 2 V 5 = {1,,6}, and so do districts 3 and 4, and districts 1 and 6. The optimal value is 2, and these three placements are the only optimal ones.

Solution

(Exercise 15.26) Total capacity is 40 + 25 = 65 37 = 10 + 12 + 15, so the instance is feasible; in fact center 1 alone has capacity 40 37, while center 2 alone ( 25 < 37) does not suffice. Solving the model, the optimum opens center 1 only and serves all three stores from it: cost 80 + 2(10) + 3(12) + 1(15) = 80 + 71 = $151. Opening both centers costs 140 in fixed charges plus 47 in best-case serving costs, a total of $187, so the cheaper center is not worth its $60 opening cost.

Solution

(Exercise 15.27) The chromatic number is 3. Lower bound: vertices A, B, C are pairwise adjacent (a triangle), so they need three distinct colors. Upper bound: the coloring A 1, B 2, C 3, D 1, E 2 is proper, as can be checked edge by edge. Solving the integer program confirms jwj = 3.

Solution

(Exercise 15.28) Introduce δ {0,1}, where δ = 0 selects mode A and δ = 1 selects mode B. Valid big- M values can be read from the problem: relaxing each constraint by M = 20 (any upper bound on the left-hand sides over reasonable production levels works). The formulation is

max 5x1 + 4x2 s.t. 2x1 + x2 10 + Mδ x1 + 3x2 12 + M(1 δ) x1,x2 0,δ {0,1}.

If δ = 0, mode A’s constraint is enforced and mode B’s is relaxed; if δ = 1, the roles are reversed.

Solution

(Exercise 15.29) Let x 0 be the production quantity and y {0,1} indicate whether production is started:

max 15x 8x 500y = 7x 500y s.t. x 200y x 0,y {0,1}.

The linking constraint x 200y plays two roles: if y = 0 it forces x = 0 (no production without paying the startup cost), and if y = 1 it enforces the capacity limit of 200 units. Since producing at capacity earns 7(200) 500 = 900 > 0, the optimal solution is y = 1, x = 200.

Try it out visually!

Branch-and-Bound Tree Explorer: how solvers actually solve the integer programs in this chapter; watch branching, bounding, and fathoming on small examples.

Concept Quiz: twenty quick self-check questions spanning the whole book.

15.10 Literature and Resources

Resources

Knapsack Problem

Set Cover

Facility Location

Other examples

Notes from AIMMS modeling book.

Modeling Tricks

Further Topics

© 2026 Robert Hildebrand and contributors · Licensed CC BY-SA 4.0 · Sources and attribution · Book home