Modeling I: the specification, the four patterns, and the time index

Week 2 · 2105623 Optimization of Chemical Processes · one-hour session

Soorathep Kheawhom

17 August 2026

One hour today. Two hours on your own.

Today

  • 35 min The specification, and the four patterns every linear model is built from
  • 6 min The warm-up, walked end to end
  • 12 min The time index and the inventory balance, in the sheet
  • 7 min HW1, and your two hours — the self-study pack

Both classroom activities move out of the room today. They are in the pack, they have a deadline, and Week 3 opens with your answers.

Where Weeks 2 to 5 live

Recap of Week 1

1Verbalthe problem in prose

2Specificationwe are here

3Algebraand here

4CodeWeeks 7 and 8

5InterpretationWeeks 7 and 8

Week 1 established

The four parts of any problem, the standard form, the classification table, the tool stack, and one solved LP: x* = (6, 3) t/week at z* = 3,300.00 USD/week with two binding resources.

And the geometry

An LP with a finite optimum has an optimal vertex. That argument is not repeated today. Every model in this session is an LP and the same picture applies, unchanged.

The modeling block is stages 2 and 3, done four times on four kinds of structure. Weeks 2 to 5 add no new mathematics at all.

The specification, and the four patterns

Lecture block 1 · 35 minutes

One document, four patterns,
and one small model in which all four are visible at once.

Stage 2 is the real deliverable of engineering thinking

Why a document, and not algebra

  1. Index sets Each one named, with its membership stated.
  2. Parameters Symbol, meaning, unit, and the source of the number.
  3. Decision variables Symbol, unit, and bounds.
  4. One objective Stated in words, with its unit.
  5. Restrictions Numbered, in words, including the ones you assume away.

Why this and not algebra

Algebra hides assumptions. The symbol It looks precise, but it does not say whether inventory is measured at the start or the end of the period. The specification has to say so in words, where a reader can disagree with it.

A specification that requires guessing will be guessed at, and the guess will be plausible, silent and unlabeled.

The code is a translation of this document. If the specification is right, writing the algebra and then the model file is close to mechanical.

The specification template, blank

This is what Part A of the pack asks you to fill in

Section What goes in it The question it forces you to answer
Sets and indices every dimension of the problem, named, with its membership What is repeated, and over what?
Parameters symbol, meaning, unit, source of the number Which numbers are fixed before the model is solved, and who owns them?
Decision variables symbol with full index, unit, bounds What is genuinely under your control?
Objective one sentence in words, with its unit What counts as better, in what currency, over what period?
Constraints numbered, in words What must hold, and is each one hard or soft?
Assumptions numbered alongside the constraints What did you decide to ignore, and would a reviewer accept it?

Assumptions are written as numbered restrictions, not as prose. “Everything produced is sold” is a modeling decision with a cost attached, and numbering it is what lets somebody challenge it.

Parameters carry a unit and a source

Specification, row 2

Symbol Meaning Unit Where the number comes from
dt demand in period t t/month sales forecast, revision date recorded
Ct production capacity t/month line rate times available hours
ct unit production cost USD/t standard cost plus the electricity contract
h inventory holding cost USD/t/month working capital plus storage
b backlog penalty USD/t/month expedited freight plus contractual damages
I0 opening inventory t the stock ledger at the planning date
ρp reactor hours per tonne of p h/t the process, measured and not assumed

A parameter is anything fixed before the problem is solved. If you can change it, it is a variable; if you cannot, it is a parameter. Confusing the two is the commonest stage-2 error.

h and b carry per month in their unit. That is what makes a backlog charged again in every period until it is cleared — and it is exactly the modeling decision that drives the answer at half past two.

Decision variables carry a unit and bounds

Specification, row 3

  1. A symbol with its full index xp,t, not x.
  2. A unit Tonnes per month is not tonnes.
  3. Bounds At minimum: is it non-negative? Is it bounded above by something physical?
Symbol Meaning Unit
xt ≥ 0 production in period t t
It ≥ 0 inventory carried out of t t
Bt ≥ 0 backlog carried out of t t

Bounds are free performance and free safety

An unbounded variable is the commonest cause of an unbounded model, and an unbounded integer variable will cripple a solver’s presolve in Week 11. Write the physical bound even when you believe the constraints already imply it. It costs one line and it documents the physics.

A variable is not a formula

It is a variable that the balance equation ties to production and demand. Do not write it as an expression. Keeping it a variable is what lets you bound it, price it, and read its dual.

Units on every symbol: the cheapest error detector there is

Thirty seconds, every time

The check, applied to the inventory balance

It−1 [t]   −   Bt−1 [t]   +   xt [t]   −   dt [t]   =   It [t]   −   Bt [t]

Every term is a tonnage. If any one of them had carried a rate, the equation would be wrong, and it would still solve.

And to the objective

ct [USD/t] · xt [t]   +   h [USD/t/month] · It [t] · 1 [month]   ⇒   [USD]

The “one period” in the holding term is implicit. Writing it out is what stops you putting a weekly rate into a monthly model.

The class of error units catch

Mixing a stock (tonnes) with a flow (tonnes per month), or mixing two time bases. Neither produces an error message. Both produce a plan that is confidently wrong by a factor of four or five.

Pattern 1 · the index set

The same relation repeated over a family

Template

iI     and then     xi  ⟶  xi,t

  • Name every dimension once Then index parameters, variables and constraints over it, and write the relation once. The solver expands it.
  • Growth becomes a data change Adding a product, a period or a site changes the data, not the model. The number of rows grows; the number of ideas does not.
  • Where it reappears Every week of this course. It is the reason the Pyomo Set component exists at all.
Dimension Index Set
product or grade p P
resource or operation r, s R, S
period t T, ordered
node or site i, j N
scenario ω Ω

Ordered sets matter

A time set must be ordered, because the model needs to know what t − 1 means. In Pyomo, pyo.Set(initialize=T, ordered=True), then m.T.prev(t). In a spreadsheet, “the column immediately to the left” is the same statement — and it is why periods run across columns.

Pattern 2 · the balance equation

What goes in equals what goes out plus what accumulates

Template

accumulation  =  inflow  −  outflow

It−1  +  xt  −  dt  =  It

  • It is the same law as a material balance Only the boundary moves. Draw it around a vessel and it is a mass balance; draw it around a period and it is an inventory balance.
  • It is an equality And it is the backbone of the model, not a refinement of it.
  • Where it reappears As the node balance in Week 3, as a component balance in Week 4, and as a unit balance in both.

The most expensive class of error

A missing balance is worse than a wrong one. The model still solves. It still reports a plan. It has simply stopped conserving material, and nothing on the screen says so.

Patterns 1 and 2 together

Written once, expanded over the ordered set T. One line of specification becomes six rows in the spreadsheet, and the six rows are what make it a plan rather than six unrelated decisions.

Pattern 3 · the capacity constraint

A shared resource limits a sum

Template

Σi ari xi   ≤   br    for every rR

  • One inequality per resource And one per resource per period as well, if the resource is renewed each period.
  • The sum is what makes it a constraint If only one activity used the resource, it would be a bound on a single variable and the solver would handle it for free.
  • Where it reappears Arc capacity in Week 3, pool capacity in Week 4, unit capacity in Week 5.

Renewable, or consumed once

xtCt for every t    versus    Σt xtC

Line hours that reset every month give one inequality per period. A fixed allocation of catalyst consumed once over the horizon gives one inequality summed over t.

They behave completely differently, and nothing in the English of a problem statement tells you which is meant. The specification has to say.

Pattern 4 · the linking constraint

A variable in one block constrains another

Template

any constraint whose index
spans more than one block

  • It destroys separability Which sounds like a defect and is in fact the whole point. If the blocks separated, you would not need a solver — you would need arithmetic.
  • That is where the value of optimizing lives Every dollar a planning model earns comes through a linking constraint.
  • Where it reappears Transshipment nodes in Week 3, pooling in Week 4, big-M links in Week 5.

Temporal linking · block 2

The inventory balance carries stock from t − 1 into t, so the periods cannot be planned one at a time.

Resource linking · block 3

One shared reactor is used by both products, so the products cannot be planned one at a time.

Remove both and the model falls apart into a stack of independent one-period problems that nobody needs a solver for.

The same four patterns in four unrelated domains

Why they are worth naming

1 Index set 2 Balance 3 Capacity 4 Linking
Refinery blend feedstocks c, properties q volume balance: blend = Σ components feedstock availability, over c quality specs, over q
Staff roster staff e, shifts t only if headcount carries across periods cover per shift; hours per person rest rules, over consecutive t
Battery dispatch hours t, |T| = 24 state-of-charge balance, over t power limit and energy capacity per t the state-of-charge balance itself
Warehouse network plants i, warehouses j, customers k node balance at each warehouse plant supply; warehouse throughput the warehouse node balance

The honest nuance. The roster’s balance row is arguable. If staff are simply assigned to shifts, the cover requirement is a capacity constraint with a ≥ sense and there is no balance at all. A balance appears only if a pool of people is carried across periods. Both readings are defensible — and the specification is where you say which one you chose.

The warm-up, stages 1 to 3 · the finishing shop

All four patterns, in a model small enough to hold in the head

A finishing shop attached to the electrolyte plant packages two grades for zinc-air cell assembly, a Standard grade and a HighPurity grade. Both pass through the same three operations in order: mixing, ion-exchange purification, and filling. The three operations have different weekly hour allocations because they are shared with other campaigns. HighPurity is worth more per tonne but spends four times as long in purification. Everything finished is sold.

Operation Standard, h/t HighPurity, h/t Available, h/week
Mixing 2 3 120
Ion-exchange purification 1 4 104
Filling 1 1 44
Contribution margin, USD/t 520 790

Stage 2, restrictions in words. R1. On each operation, the hours consumed cannot exceed the hours allocated. R2. Production cannot be negative. R3. There is no demand limit, because everything finished is sold — and R3 is an assumption, numbered so that it can be challenged.   Stage 3. max Σp cp xp subject to Σp asp xpbs for every s, with xp ≥ 0 and [h/t]·[t/week] = [h/week] on every row.

The warm-up, stages 4 and 5 · the answer and what it says

Busiest and binding are different words

Operation Used, h Avail., h Slack, h Dual, USD/h
Mixing 108 120 12 0
Purification 104 104 0 90
Filling 44 44 0 430

The answer

24 t of Standard and 20 t of HighPurity, for 28,280.00 USD of contribution margin in the week.

Verified two ways in the notebook: vertex enumeration in NumPy, and a finite-difference check on every dual.

The engineering reading

Buy an overtime shift on filling first, not on the operation that looks busiest.

Mixing consumes 108 hours, more than either other operation in absolute terms, and it is worth exactly zero at the margin.

And the limitation we spend the rest of the day removing

This plans one week in isolation. It has no memory. It cannot build stock now for a peak later, and it cannot say that a shortfall this week must be delivered next week.

A time index turns one decision into a plan

Pattern 4, drawn

t = 1t = 2t = 3t = 4t = 5t = 6 Iₜ, BₜIₜ, BₜIₜ, BₜIₜ, BₜIₜ, Bₜ xₜ produced dₜ shipped the amber arrows are the only place consecutive periods meet cover them and six independent problems are left

Without the amber arrows these are six independent problems. Each would be solved on its own, and nothing at all would be gained by solving them together. The optimization would be arithmetic.

The amber arrows are the linking constraint of pattern 4. Everything a multiperiod model can do about seasonality, a demand spike or a cost profile passes through them.

The inventory balance

Pattern 2, with the boundary drawn around a period

period t Iₜ₋₁ − Bₜ₋₁ Iₜ − Bₜ xₜ produced dₜ shipped same law, new boundary

Accumulation equals inflow minus outflow, around a period

It−1Bt−1 + xtdt  =  ItBt    for every tT

with I0 given and B0 = 0.

  • The net stock position Positive means stock on hand at the close of the period, negative means stock owed to a customer.
  • The same law, a new boundary Drawn around a period rather than around a vessel.
  • Patterns 1 and 2 together Written once, and expanded over the ordered set of periods.

The same model in the spreadsheet: periods across columns

The sheet you are about to complete

BCDEFGH 123456 period, row 5 demand dₜ · row 6capacity Cₜ · row 7unit cost cₜ · row 8 120150180210160130170 in every period424245484643 production xₜ · row 16inventory Iₜ · row 17backlog Bₜ · row 18 C16:H18 — 18 changing cells balance C28:C33 = E28:E33capacity C34:C39 ≤ E34:E39 C40: B₆ = 0 · the only scalar row C24: objective, Min, sum of C21:C23 t − 1 is the column to the left
Algebraic symbol Range Pyomo component
tT C5:H5 Set(..., ordered=True)
dt, Ct, ct C6:H8 Param(m.T, ...)
h, b, I0, B0 C9:H10, C11:C12 scalar Param
x, I, B ≥ 0 C16:H18 three Var(m.T, ...)
balance ∀ t C28:C33 Constraint(m.T, rule=...)
xtCt C34:C39 Constraint(m.T, ...)
objective C24 Objective(sense=minimize)

The transposition. In Week 1 the model ran down the rows. Here periods run across columns, so each constraint family becomes a block of rows. Only the layout changed.

HW1 is released today

Due Week 4

  1. Released today, Week 2. Due Week 4. On myCourseVille at the end of this session.
  2. Linear and network model construction. The linear half rests on today; the network half needs Week 3, so start with the linear half now.
  3. Every question that asks for a model asks for the structured specification first, exactly as in Part A of the pack, and marks it separately.
  4. One question asks for a multiperiod plan built in OpenSolver and reproduced in Pyomo, with the two answers compared.

The instruction that carries the most marks

Write the specification before any algebra.

A correct model with no specification loses marks. A specification that states its assumptions and its start-versus-end convention earns them even where the algebra slips.

Two habits to carry into it

A unit on every symbol, and a bound on every variable. Both are checkable by a reader in thirty seconds, and both catch the errors a solver never reports.

Your two hours, and what to hand in

Before we meet again

  • 35 min A Aurora Specialty Chemicals — write the specification table. No algebra, no formulas
  • 30 min B Read the rest of the Week 2 slides — the convention, backlog, the complete model — and answer three questions
  • 40 min C Complete the multiperiod sheet, predict one number before you re-solve, then check it in Pyomo
  • 15 min D Open HW1 and start the linear half

One PDF, on myCourseVille, before midnight this Friday, 21 August. Week 3 opens with the ambiguities you found in Part A.

 

Before you go · 45 seconds

How was today?

Five questions. Anonymous — no name, no email, no login.

The fourth question is the one I actually use.

The two most common answers open next week’s session.

oxidized-challenge-ed9.notion.site

QR code linking to the weekly feedback form

Scan now — I will wait