Optimization Toolbox: Worked examples

Detailed formulations and walkthroughs for the nine optimization models included with the workbook.

← Optimization Toolbox overview · Getting started · Modeling guide · Solver guide · Reference

Why the workbook includes multiple examples

Each fixture is intentionally small enough to audit in Excel. Together they exercise the common model compiler across fundamentally different mathematical structures.

They are not nine hard-coded Python programs. The notebook reads the same tables and determines which model is active from the shared Model ID.

Example matrix

Model ID Example Family Main concept
product_mix Product Mix LP Linear objective, resource constraints, LP marginals
workforce Workforce Scheduling MILP Integer decisions and covering constraints
portfolio Portfolio Allocation QP Quadratic risk objective and return constraint
marketing Marketing Allocation NLP Diminishing-return nonlinear objective with budget constraint
parameter_fit Parameter Estimation Least squares Nonlinear residual fitting
equations Nonlinear Equations Equations Bounded nonlinear system
goal_plan Goal-Based Planning Multiobjective Cost/emissions Pareto frontier
multimodal Multimodal Design Global Local versus global search
infeasible Infeasible Capacity Plan LP diagnostics Explicit infeasibility

1. Product Mix — linear programming

Business question

How many chairs and desks should be produced to maximize contribution margin under labor, material, and desk-demand limits?

Decision variables

  • chairs >= 0
  • 0 <= desks <= 50

Objective

\[\max 45\,chairs + 80\,desks\]

Constraints

\[2\,chairs + 4\,desks \le 240\]

\[3\,chairs + 5\,desks \le 300\]

Expected baseline

The validated baseline returns:

  • Chairs ≈ 16.6667
  • Desks = 50
  • Objective = 4,750
  • Status = OPTIMAL

What to inspect

  • Which resource constraint is binding?
  • What marginal value does HiGHS report for relaxing a binding resource?
  • Is the desk upper bound active?

Scenario

High margin desks changes the desk objective coefficient from 80 to 95 without rewriting the base model.

MATLAB analogue

This corresponds to the LP modeling territory served by MATLAB linprog, while the workbook uses SciPy/HiGHS and a tabular model definition.

2. Workforce Scheduling — mixed-integer linear programming

Business question

How many workers should start on each day of the week so daily staffing requirements are covered with the fewest total starts?

Decision variables

Seven nonnegative integer start variables:

  • start_mon
  • start_tue
  • start_wed
  • start_thu
  • start_fri
  • start_sat
  • start_sun

Objective

Minimize the sum of all weekly shift starts.

Constraints

Each day has a minimum staffing requirement. Constraint terms encode which start days contribute coverage to each calendar day.

The long-form coefficient table is important here: the model is sparse and readable without a manually constructed matrix in Python.

Expected result

The validation contract requires:

  • detected class MILP;
  • solver HiGHS MILP;
  • status OPTIMAL;
  • integral decision values;
  • all daily coverage constraints independently feasible.

What to change

Increase one daily requirement and observe whether the integer schedule changes discretely rather than smoothly.

MATLAB analogue

Comparable problem family: intlinprog.

3. Portfolio Allocation — quadratic objective

Business question

Allocate a portfolio across equity, bonds, and cash to minimize modeled variance while remaining fully invested and meeting a minimum expected return.

Decision variables

  • equity
  • bonds
  • cash

Each is bounded between 0 and 1.

Linear constraints

Full investment:

\[equity + bonds + cash = 1\]

Minimum expected return:

\[0.11\,equity + 0.055\,bonds + 0.02\,cash \ge 0.07\]

Quadratic risk terms

The Quadratic sheet contains diagonal and cross terms representing a small covariance-style risk objective.

Solver semantics

The current beta uses SLSQP rather than a dedicated QP solver. The validated status is therefore LOCAL_OPTIMUM, not a generic claim that every authored quadratic problem has a convex-QP certificate.

Scenario

Higher return target raises the return lower bound to 8.5%.

What to inspect

  • Which assets hit bounds?
  • How does the allocation shift when the return floor rises?
  • Does independent feasibility still show full investment and return compliance?

MATLAB analogue

Comparable mathematical territory: quadprog, but with a different current backend and weaker QP-specific diagnostics.

4. Marketing Allocation — constrained nonlinear optimization

Business question

Allocate a fixed marketing budget across Search, Social, and Email when each channel has diminishing returns.

Variables

  • search
  • social
  • email

Each is bounded from 0 to 100.

Objective

The safe worksheet expression is:

120*log(1+search) + 90*sqrt(social) + 60*log(1+email)

The supplied fixture maximizes this response.

Constraint

\[search + social + email \le 100\]

Scenario

Tight budget changes the budget upper bound from 100 to 75.

Why it is useful

This fixture demonstrates that an Excel user can inspect the actual nonlinear formula without granting worksheet text arbitrary Python execution.

Solver semantics

SLSQP returns a local constrained result. The notebook then recomputes the budget and bounds before accepting LOCAL_OPTIMUM.

MATLAB analogue

Comparable problem class: constrained nonlinear optimization with fmincon.

5. Parameter Estimation — nonlinear least squares

Business question

Fit saturation parameters to six observations.

Parameters as decisions

  • vmax — maximum response
  • km — half-saturation parameter

Data

The observed x/y pairs are stored as scalar Parameters so the residual formulas remain readable.

Residual form

For observation \(i\):

\[r_i = \frac{vmax\,x_i}{km+x_i} - y_i\]

The solver minimizes the sum of squared residuals subject to parameter bounds.

What to inspect

  • fitted vmax and km;
  • residual objective;
  • whether the solution hits parameter bounds;
  • whether different sensible starting values reach a similar fit.

MATLAB analogue

Comparable territory: lsqnonlin / lsqcurvefit.

6. Nonlinear Equations

Business question

Find bounded values of x and y satisfying:

\[x^2 + y = 5\]

\[x + y^2 = 5\]

with both variables between 0 and 5.

Implementation

The Expressions sheet stores two Equation rows:

x**2 + y - 5
x + y**2 - 5

The notebook solves the residual system with least_squares and checks the residual norm.

Status

The correct semantic result is FEASIBLE_SOLUTION when the residuals are sufficiently close to zero. The workbook does not call an equation root an optimization optimum.

MATLAB analogue

Comparable system-solving territory: fsolve.

7. Goal-Based Planning — multiobjective optimization

Business question

Choose standard and green supply to satisfy demand while exposing the tradeoff between cost and emissions.

Variables

  • standard
  • green

Constraint

\[standard + green \ge 100\]

Objective 1: Cost

\[70\,standard + 90\,green\]

Objective 2: Emissions

\[6\,standard + 2\,green\]

Method

The Toolbox does not hide the tradeoff in one arbitrary weighted sum. It:

  1. finds the endpoint that minimizes Cost;
  2. finds the endpoint that minimizes Emissions;
  3. sweeps an emissions epsilon bound;
  4. minimizes Cost at each bound;
  5. publishes the nondominated frontier.

What to inspect

  • the shape of the Pareto tradeoff;
  • which frontier points materially improve emissions for modest cost;
  • whether the selected representative solution is actually the organization’s preferred point.

MATLAB analogue

This is multiobjective capability, but the method differs from MATLAB fgoalattain, fminimax, gamultiobj, or paretosearch.

9. Infeasible Capacity Plan — failure diagnostics

Model

Variables x and y are nonnegative.

Constraints require both:

\[x+y \ge 10\]

and:

\[x+y \le 5\]

Why ship an infeasible example

Operational optimization models regularly become infeasible because constraints are authored by different stakeholders or because a scenario makes targets mutually inconsistent.

A proper workbench should demonstrate that it:

  • reports infeasibility clearly;
  • does not publish a fabricated optimal decision vector;
  • preserves solver termination evidence;
  • gives reviewers a reproducible failure case.

MATLAB analogue

The problem family is still LP, but the pedagogical focus is result interpretation and diagnostics rather than successful optimization.

Turn an example into an operational model

The supplied fixtures are deliberately compact. To adapt one:

  1. Preserve the schema, not the sample business labels.
  2. Create a new Model ID rather than overwriting an acceptance fixture when you want both to remain available.
  3. Add your domain-specific constraints and scenarios.
  4. Set objective direction explicitly.
  5. Add offline expectations for at least a baseline and a meaningful changed-input case.
  6. Add an infeasible/stressed case when operational rules can conflict.
  7. Benchmark runtime using realistic row counts and nonlinear evaluation cost.

See the Modeling guide for the exact schema and Reference for input-band limits.