Learn
Lesson · Integer Programming · Modelling with binaries

Either–Or Constraints

“Constraint A or constraint B” cannot be written by writing both, because writing both is the conjunction — and on a sequencing pair the conjunction is infeasible. It is written by relaxing each row with a big-M term that a single binary switches off, so that one value of the binary enforces A and makes B vacuous and the other value does the reverse.

A or B A relaxed by M_A(1 − y) B relaxed by M_B y y = 1 enforces A and makes B vacuous; y = 0 does the reverse x₁ − x₂ ≤ −4 + 14(1 − y) −x₁ + x₂ ≤ −3 + 13y y = 1 start at (0, 4) cost 4 y = 0 start at (3, 0) cost 3 y free → y = 3/13, both jobs at 0, cost 0 — a bound, not a schedule both rows at once → 0 ≤ −7, infeasible
One binary, two rows, and what each value does to them

Core ideas

What this lesson establishes

One hard idea: “or” is not something you can write by writing more constraints, because constraints accumulate as “and”.

1

Writing both rows writes the conjunction

Constraints in a model are simultaneous. Adding a row never creates a choice; it removes plans. So writing A and writing B asks for both, and on two jobs competing for one machine that asks job one to finish before job two starts and job two to finish before job one starts. Add the two rows and you get 0 ≤ −7.

2

A big-M term, switched by one binary, is what or costs

Relax A by M_A(1 − y) and B by M_B y. At y = 1 the first term vanishes and A binds, while B has M_B added to its right-hand side and nothing in the region can break it. At y = 0 the roles swap. The binary is not a variable in the problem; it is the choice the problem contains.

3

A fractional binary describes nothing

The relaxation may set y = 3/13. Both rows are then half-relaxed at once, both jobs start at time zero on one machine, and the cost is 0 — below either real branch, which is what a bound looks like. There is no schedule here at all: “job one is three-thirteenths before job two” is not a sentence about machines.

The material

Or, written with one binary and two constants

Why the conjunction is infeasible, what each branch is, and what the relaxation says instead.

Two jobs share one machine. Job one takes four hours, job two takes three, and neither can run while the other is on the machine. Let x₁ and x₂ be the start times. Either job one finishes before job two starts, which is x₁ + 4 ≤ x₂, or job two finishes before job one starts, which is x₂ + 3 ≤ x₁. Exactly one of those must hold.

Definition · Either-or pair

Given two rows A(x) ≤ a and B(x) ≤ b of which at least one must hold, the disjunctive formulation introduces one binary y and writes A(x) ≤ a + M_A(1 − y) together with B(x) ≤ b + M_B y, where each M is large enough to make its own row vacuous over the rest of the feasible region.

Written as ≤ rows, the pair above is x₁ − x₂ ≤ −4 and −x₁ + x₂ ≤ −3. With deadlines putting both start times in [0, 10], the most the first left-hand side can exceed its right-hand side is 10 − 0 − (−4) = 14, so M_A = 14; by the mirror argument M_B = 13. Each constant is the slack its own row needs to become harmless, and not one unit more.

Example · Both branches, solved

Minimise x₁ + x₂. Fixing y = 1 enforces “job one first” and the model starts the jobs at (0, 4), costing 4. Fixing y = 0 enforces “job two first” and starts them at (3, 0), costing 3. Both are genuine schedules, the second is cheaper, and the integer problem wants the better of exactly these two — which is what the binary means.

What the conjunction does, and what the relaxation does

Write both original rows together and add them: the left-hand sides cancel to 0 and the right-hand sides give −7, so the model asserts 0 ≤ −7 and is infeasible. That is the diagnosis to recognise, because the symptom is a solver reporting infeasibility on data that is perfectly consistent, and the usual response is to go looking for a typo in the processing times.

Now leave y continuous. The relaxation sets y = 3/13, starts both jobs at time zero, and reports 0. Every row is satisfied: y is large enough to relax the second row by 3 and small enough to relax the first by 4, so both are half-off at once. The value 0 is a perfectly good lower bound on the integer answer of 3. It is not a schedule, and the machine cannot run two jobs at once because a variable took a value between 0 and 1.

The two constants need not be equal and each must be valid for its own row: here 14 and 13. One M used for both, unchecked, is how a disjunction quietly becomes an implication — if the shared value is big enough for one row and too small for the other, then one branch of the “or” is partially enforced even when the binary says it should be off, and the model answers a question with one alternative half-deleted.

The same pair, repeated over every pair of jobs on every machine, is what makes a job shop an integer programme rather than a linear one. That is why “Scheduling” can prove single-machine rules by exchange arguments and still needs this course the moment two jobs contend for one resource: the sequencing decision is a binary, and there is no linear model of it.

The device generalises past two alternatives. Three rows of which exactly one must hold need three binaries summing to 1, each relaxing its own row by M(1 − y_k); and a two-level capacity — either run at the small size or at the large one — is the same pattern with the two rows being the two capacity limits. What does not generalise is guessing the constants: each one is sized against its own row, every time.

Interactive

Either-or constraints

One binary relaxes one row and enforces the other, and a fractional y describes nothing

Either, orwriting both constraints writes the conjunction, and on a sequencing pair that is infeasible
the branch y = 1 allowsthe branch y = 0 allowswhere the relaxation stopswriting both

Method

Writing a disjunction you can check

The check at the end is two re-solves rather than eight rows, and it is the same discipline.

1

Write each alternative on its own, as a ≤ row

x₁ − x₂ ≤ −4 and −x₁ + x₂ ≤ −3. Getting both into the same relation first makes the relaxation term easy to place and makes the sign errors visible while they are still cheap.

2

Decide which alternative y = 1 enforces

Then write M_A(1 − y) on that row and M_B y on the other. Writing the convention down is not ceremony: the two rows look alike, and a swapped pair gives a model that solves and means the opposite.

3

Size each M against its own row

The most that row's left-hand side can exceed its right-hand side anywhere the other constraints allow. Here 14 and 13, from the deadlines. Two rows, two constants, two reasons.

4

Fix y to each value and re-solve

y = 1 should give a schedule with job one first; y = 0 one with job two first. If either branch is infeasible or describes the wrong order, the fault is in the signs or in an M that is too small, and you have just found out which.

5

Leave y continuous and read what it says

A fractional y is the relaxation's bound and it is not a plan. Looking at it once, and naming the impossible schedule it describes, is what stops it being reported later as an answer.

Or, and, and the binary between them

Score 0 / 0

Two jobs, one machine, and the three things you can write

One instance, three formulations: the conjunction, the two fixed branches, and the relaxation. Only the middle one describes a machine.

job one takes 4 hours, job two takes 3; one machine; both start by 10 x₁, x₂ = start times, minimise x₁ + x₂ the two alternatives, as ≤ rows A job one first x₁ + 4 ≤ x₂ x₁ − x₂ ≤ −4 B job two first x₂ + 3 ≤ x₁ −x₁ + x₂ ≤ −3 WRONG: write both add them: (x₁ − x₂) + (−x₁ + x₂) ≤ −4 − 3 0 ≤ −7 infeasible RIGHT: one binary, two constants M_A = 10 − 0 − (−4) = 14 M_B = 10 − 0 − (−3) = 13 x₁ − x₂ ≤ −4 + 14(1 − y) −x₁ + x₂ ≤ −3 + 13y y = 1 A binds: x₁ − x₂ ≤ −4 B reads −x₁ + x₂ ≤ 10 optimum (0, 4) cost 4 y = 0 B binds: −x₁ + x₂ ≤ −3 A reads x₁ − x₂ ≤ 10 optimum (3, 0) cost 3 ← the answer y continuous: y = 3/13 14(1 − 3/13) = 140/13 ≥ 4 and 13(3/13) = 3 ≥ 3 so (0, 0) satisfies both rows cost 0 — a bound

The 0 ≤ −7 line is the one to memorise, because it is what the model says rather than what the solver says. A solver reports “infeasible” and a reader goes looking for bad data; adding the two rows takes ten seconds and names the real cause, which is that “or” was written as “and”.

The relaxation's y = 3/13 is worth reading arithmetically once. It is the smallest y that relaxes row B by the three hours it needs; and it is small enough that row A is still relaxed by 140/13, comfortably more than the four hours it needs. Both alternatives are switched most of the way off at the same time, which is precisely the plan that does not exist.

For a faded rehearsal, use the lab's second instance — a seven-hour job against a two-hour one, with the short job weighted twice as heavily in the objective. The supplied first move is that the tightest constants are now 19 and 14, from the same deadline argument. Work out both branches before opening the quiz and say which order wins, and by how much.

Common mistakes

1
Writing both constraintsIt is the conjunction, it forces both alternatives, and on a sequencing pair it makes the model infeasible. The reason this one is expensive is the diagnosis: infeasibility on consistent data sends readers looking for a data error, and the fault is in the formulation.
2
Using one M for both rows without checking itThe two rows need not need the same slack — here 14 and 13. A shared value that is valid for one row and short for the other leaves part of one alternative enforced when the binary says it is off, so the disjunction has quietly become an implication and the model is answering a narrower question.
3
Reading a fractional y as mostly one ordery = 3/13 is not “job one goes first about a quarter of the time”, and there is no probability in a linear programme. It is a point at which both rows are partly relaxed, describing a schedule that cannot be run. Its value is a bound; its coordinates are not a plan.

Check your understanding

✓
Finish when writing both rows for an either-or reads as a category error rather than a near miss.

You should be able to write a disjunctive pair with one binary and two separately sized constants, say what each value of the binary enforces and what it makes vacuous, show in one line why writing both rows is infeasible, and read a fractional binary as a bound with an impossible plan behind it.

Note: The two constants need not be equal and each must be valid for its own side; one M used for both, unchecked, is how a disjunction quietly becomes an implication. Sequencing two jobs on one machine is exactly this pair of rows, which is why the job shop of “Scheduling” is an integer programme and its single-machine rules are not — and this lesson is where that boundary is drawn.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.