Skip to main content

Decision Variables, Objectives, and Constraints

A useful optimization model is a typed argument: variables name controllable actions, the objective ranks feasible actions, and constraints encode declared boundaries. Units expose many modeling errors before a solver does.

Prerequisites​

Complete from prediction to decision and the linked linear-programming introduction.

Learning goals​

  • Give every variable, coefficient, bound, objective, and right-hand side a unit.
  • Distinguish a hard constraint from a preference or soft target.
  • Compute resource use and slack independently from solver fields.
  • Recognize sign, scale, and default-bound mistakes.

A unit ledger​

QuantityMeaningUnit
xW,xCx_W,x_Cworkshop and clinic decisionsbatches per week
8,68,6predicted benefit coefficientbenefit points per batch
first row of AAstaff usestaff-hours per batch
second row of AAroom useroom-hours per batch
40,5040,50weekly capacitiesstaff-hours per week; room-hours per week

Thus AxAx has hours per week and can be compared with bb. The objective cTxc^Tx has benefit points per week. Both variables have explicit lower bounds of zero and no upper bounds beyond shared resources. Negative batches would be nonsensical, while silent default bounds make a model harder to review.

The two capacity inequalities are hard constraints: the model declares violations unacceptable. A goal such as “offer at least 22 clinic batches” may instead be a soft target with an explicit shortfall variable and penalty; lesson 5 shows that construction.

Worked example​

import numpy as np
from scipy.optimize import linprog

c = np.array([-8.0, -6.0]) # negate benefit because linprog minimizes
A = np.array([[2.0, 1.0], [1.0, 2.0]])
b = np.array([40.0, 50.0])
bounds = [(0.0, None), (0.0, None)]
result = linprog(c, A_ub=A, b_ub=b, bounds=bounds, method="highs")
if result.status != 0:
raise RuntimeError(result.message)

used = A @ result.x
slack = b - used
print(f"variables={len(result.x)} units=batches_per_week lower_bounds={[bound[0] for bound in bounds]}")
print(f"staff_used_hours={used[0]:.1f} staff_slack_hours={slack[0]:.1f}")
print(f"room_used_hours={used[1]:.1f} room_slack_hours={slack[1]:.1f} objective_points={-result.fun:.1f}")

Expected output:

variables=2 units=batches_per_week lower_bounds=[0.0, 0.0]
staff_used_hours=40.0 staff_slack_hours=0.0
room_used_hours=50.0 room_slack_hours=0.0 objective_points=200.0

Zero slack means both capacities bind at this solution. It does not mean either capacity is measured perfectly or should automatically be expanded.

Limitations and common mistakes​

  • Adding unlike units in one row makes the inequality meaningless.
  • Reversing <= or negating only one side changes the feasible set.
  • A negative objective for SciPy is an API transformation, not a claim that benefit is negative.
  • Very different coefficient scales can worsen numerical conditioning; rescale meaningfully and preserve the unit map.
  • A bound, policy, or fairness requirement left in prose is not enforced.

Practice​

Add a declared upper bound of 18 workshop batches per week. Predict whether it binds, solve again, and report every slack with its unit. Explain whether the cap is physical, contractual, or chosen.

Next steps​

Learn what solver statuses and mathematical evidence do—and do not—certify in feasibility, optimality, and certificates.

Primary sources​

Checked 2026-10-18: SciPy 1.18.1, linprog parameter and result contract and linprog(method="highs"); HiGHS, official documentation; Stanford EE364A, Linear Programming.