Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 49 · Modelling Decisions

Decision Variables, Objectives and Constraints

Learn the three building blocks of every optimization model, how to choose variables and units, write objectives and constraints, and check linear assumptions.

Every optimization model, from a two-variable classroom example to a nationwide airline schedule, is built from the same three blocks: decision variables, an objective function and constraints. If you can write these three clearly, you can hand the model to a solver. If any of them is vague, no solver can rescue you. In this lesson you take each block apart, learn the rules for writing it well, and build a complete model for a small plant nursery.

A model written out line by line with arrows pointing to its parts: objective, space constraint, labor constraint, contract minimum and sign restrictions
The anatomy of a model: variables first, then one objective, then constraints for space, labor, contract and signs.

What you will learn

  • How to define decision variables with clear units and the right type.
  • How to turn a goal into an objective function.
  • The common kinds of constraints and how to write them.
  • The four assumptions behind linear models, and when they fail.

Key terms

Parameter: a known number in the model, such as a price or a capacity.

Continuous variable: a variable that can take any value in a range, such as kilograms of flour.

Integer variable: a variable restricted to whole numbers, such as trucks.

Binary variable: an integer variable that is 0 or 1, used for yes/no choices.

Feasible region: the set of all decisions that satisfy every constraint.

Non-negativity: the rule that a quantity cannot be below zero.

Decision variables: what can you choose?

A decision variable is a number that the model is free to choose. Everything else is a parameter, a number that someone hands you. In the bakery, the oven capacity of 16 hours is a parameter; the number of cake batches x is a decision variable.

Good variables follow four rules.

  1. State the meaning and the unit exactly. Write "r = number of trays of roses planted this season", not just "r = roses". A variable that could mean trays, plants or dollars causes silent mistakes.
  2. Choose the type that matches reality. Kilograms, liters and money are naturally continuous. Trucks, employees and machines are integers. Whether to open a warehouse is binary.
  3. Use the smallest set that describes the decision. If you know that y = 10 - x, do not add y as a second unknown.
  4. Think about what the plan sheet will show. If a manager must receive "how many trays of each plant", then those are the variables.

The objective function: what do you want?

The objective function turns a decision into a single score. Write it as a formula in the variables and say whether you maximize or minimize it. Typical objectives: maximize profit, minimize cost, minimize total travel time, maximize the number of customers served.

Profit is usually revenue minus cost. If a tray of roses sells for $20 and costs $8 to grow, its contribution to profit is $12 per tray, and the objective term is 12r. Be careful to count only costs that change with the decision. Rent, which is paid whatever you plant, does not influence the choice and can be left out.

Real organizations often want several things at once (low cost and high quality). Two common ways to cope are to combine the measures into one weighted score, or to optimize one measure and turn the others into constraints ("minimize cost, but quality must be at least 90%"). Later chapters return to this idea.

Constraints: what limits you?

A constraint is a statement that must be true for a decision to be allowed. Written as an inequality or an equation, it has three parts: a formula in the variables on the left, a comparison (≤, ≥ or =) and a number on the right.

Kind Meaning Example
Capacity (≤) Do not use more than you have 1.5r + t ≤ 60 square meters
Requirement (≥) Meet at least a minimum t ≥ 10 tulip trays by contract
Balance (=) Things must match exactly stock in = stock out
Sign Quantities cannot be negative r ≥ 0, t ≥ 0

Check units in every constraint: each term on the left must be measured in the same unit as the right side. If one term is in hours and another in minutes, convert first.

Do not forget the obvious ones. Models without sign restrictions often "discover" that making -5 trays of something frees up space, a silly answer that a solver will happily return.

Linear models and their four assumptions

If the objective and every constraint are sums of variables multiplied by constants, the model is linear, and fast methods apply (Chapter 3). A linear model quietly assumes four things.

  1. Proportionality. Doubling a variable doubles its effect. Two trays use twice the space of one tray.
  2. Additivity. Effects add up with no interaction. Total labor is the sum of the labor of each product.
  3. Divisibility. Variables may take fractional values. (If not, you need integer variables, covered in Chapter 3.)
  4. Certainty. All parameters are known exactly. (They are not; that is why we test sensitivity.)

These assumptions are often reasonable and sometimes not. Volume discounts break proportionality: the 100th unit costs less than the first. The plot below shows a cost with a discount compared with the straight line a linear model would assume.

Python When does linearity break?

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When the gap matters, a linear model can still work for small ranges or be refined with integer variables (see Binary Variables and Logic).

Worked example: Green Garden Nursery

A nursery grows roses and tulips in trays. A tray of roses earns $12 of profit and a tray of tulips $9. The greenhouse has 60 m² of bench space; a rose tray needs 1.5 m² and a tulip tray 1 m². The staff has 120 hours of labor per season; a rose tray needs 2 hours and a tulip tray 3 hours. A contract requires at least 10 trays of tulips. How many trays of each should the nursery grow? (All numbers are invented for the example.)

Step 1, variables. r = trays of roses, t = trays of tulips, both continuous for now.

Step 2, objective. Maximize 12r + 9t dollars.

Step 3, constraints.

TEXT
1.5r +  t ≤ 60    (bench space, m²)
  2r + 3t ≤ 120   (labor, hours)
         t ≥ 10   (contract)
     r, t ≥ 0

Step 4, check by hand. Try r = 24 and t = 24. Space: 36 + 24 = 60, exactly full. Labor: 48 + 72 = 120, exactly full. Contract: 24 ≥ 10. Profit: 288 + 216 = 504. Now try r = 40, t = 0: it breaks the contract (t ≥ 10), so it is not allowed even though its profit of $480 is easy to calculate. Checking a few plans by hand is the fastest way to catch a wrongly written constraint.

Python Solve the nursery model

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that a constraint on a single variable, such as t ≥ 10, can be given to the solver as a bound instead of a row of the matrix. The result is the same.

Testing a formulation

Before you trust a model, run three quick tests.

  1. Unit test. Does every term in every constraint have consistent units?
  2. Extreme test. Set a variable to zero or to a huge value. Does the model respond sensibly?
  3. Known plan test. Take a plan you understand and compute its objective and constraint values by hand. They should agree with the model.

Common misconceptions

"The objective can have several goals joined by 'and'." An optimizer needs one number to compare plans. Combine goals with weights or turn some into constraints.

"A constraint that is not binding is useless." It may not matter for this data, but it can start to matter if the data change. Keep every real rule in the model.

"Variables and parameters are the same." A parameter is given; a variable is chosen. Mixing them up leads to models that cannot be solved or answer the wrong question.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. In the nursery model, which is a decision variable?

    Decision variables are chosen by the planner; the others are given data.
  2. 2. Which type of variable is best for "build the new factory or not"?

    A yes/no choice is modelled with a binary variable that takes the value 0 or 1.
  3. 3. A volume discount mainly breaks which assumption of linear models?

    With a discount, doubling the quantity does not double the cost, so proportionality fails.
  4. 4. What does the constraint t ≥ 10 express in the nursery model?

    It requires at least 10 trays of tulips, as the contract says.
  5. 5. Why include sign restrictions such as r ≥ 0?

    Real quantities cannot be negative, and the solver will not know that unless the model says so.

Summary

  • A model has decision variables (chosen), parameters (given), one objective and constraints.
  • Define variables with clear meaning and units; match the type (continuous, integer, binary) to reality.
  • The objective is one formula to maximize or minimize; constraints are capacities, requirements, balances and sign rules.
  • Linear models assume proportionality, additivity, divisibility and certainty; test whether these are reasonable.
  • Check a formulation with unit, extreme and known-plan tests.

Next: The Product-Mix Model