Sub topic 8
Writing constraints and bounds that reflect the business
This chapter assumes you can already set up Solver with an objective cell and variable cells, as covered in the setup chapter. It also assumes you can write formulas with absolute references and read basic financial statements. Here the focus is the constraints: how to translate business rules into Solver rows, and how to avoid models that are infeasible or that find answers no manager would accept.
Why constraints decide the answer
Without constraints, Solver maximizes profit by making infinite units. The objective cell says what you want. The constraints say what is possible and acceptable. In most financial models, the constraints carry more business knowledge than the objective does.
Every constraint has three parts: a cell reference on the left, an operator, and a right-hand side that is a number or a cell. Solver's constraint dialog offers these operators:
| Operator | Meaning | Typical business use |
|---|---|---|
| `<=` | At most | Capacity, budget, maximum leverage |
| `>=` | At least | Contract minimums, interest cover, minimum cash |
| `=` | Exactly | Weights summing to 100%, balanced flows |
| `int` | Whole number | Trucks, machines, staff |
| `bin` | 0 or 1 | Fund this project or not |
| `dif` | All different | Assigning distinct slots or ranks |
The int, bin, and dif operators apply only to variable cells. You cannot force a calculated output cell to be an integer.
Bounds versus constraints on outputs
There are two kinds of constraint, and mixing them up causes most confusion.
- Bounds on variable cells. These limit a decision directly, such as
B2 >= 5orB3 <= 40. They describe what you are allowed to choose. - Constraints on calculated cells. These limit a result of the model, such as total machine hours
<= 100or net debt to EBITDA<= 3.5. They describe what must remain true after the formulas run.
The left side of a constraint must be a cell or range, not a typed formula. If you need B2 - 40*B3 <= 0, build a helper cell that holds that expression and constrain the helper. This keeps the logic visible on the sheet, which helps reviewers.
The option Make Unconstrained Variables Non-Negative adds a lower bound of zero to any variable cell without its own lower bound. Leave it on for quantities such as units and amounts. Turn it off, or set explicit bounds, for variables that can be legitimately negative, such as a cash flow adjustment or a short position.
Keep the right-hand sides in cells
Put each limit in a labeled assumption cell and point the constraint at it. A constraint such as $C$10 <= 100 hides the number 100 inside the Solver dialog, where nobody sees it when the capacity changes. With $C$10 <= $F$3, the limit is visible, documented, and changeable like any other input.
Assumptions (inputs)
F3 Machine hours available 100
F4 Market demand cap (units) 40
F5 Contract minimum, product y 15
Variable cells
B2 Units of x
B3 Units of y
Calculated cells
C2 Hours used =2*B2+4*B3
C3 Units produced =B2+B3
C4 Profit =20*B2+30*B3
Solver
Set objective: C4 (Max)
By changing: B2:B3
Subject to: C2 <= F3
C3 <= F4
B3 >= F5
B2 >= 5When capacity changes next quarter, you edit F3 and re-run Solver. You do not reopen the constraint list.
Translating business rules
Most business rules map to one of a few patterns.
| Business rule | Constraint |
|---|---|
| Plant has 100 machine hours | Hours used `<=` hours available |
| We cannot sell more than 40 units | Units produced `<=` demand cap |
| A customer contract requires 15 units of y | Units of y `>=` 15 |
| Debt covenant: net debt/EBITDA below 3.5 | Leverage cell `<=` 3.5 |
| Funding weights must total 100% | Sum of weights `=` 1 |
| No single source exceeds 60% of funding | Each weight `<=` 0.6 |
| Whole machines only | Variable `int` |
| Fund project or not | Variable `bin` |
For covenants, constrain the ratio cell itself instead of its inputs. Solver can then trade off debt, cash, and earnings freely, as long as the covenant holds.
Integer, binary, and minimum-batch rules
Adding int or bin constraints turns a smooth problem into a combinatorial one. Solver has to search through many whole-number combinations, so the run takes longer, and the final answer may be within a tolerance of the true best. In Solver's options, Integer Optimality (%) controls that tolerance. A value of 1 means Solver stops when it has proven the answer is within 1% of the best possible. For a final answer, reduce it to 0.
A common business rule is a minimum batch: you either produce nothing or at least 5 units, but never 2. Solver has no operator for this, so you build it with a binary switch b for each product, using two helper cells.
Variable cells: B2 = units of x (>= 0), B4 = run flag for x (bin)
Helper cells: C5 = B2 - 40*B4 constrain C5 <= 0 (no output unless flag is 1)
C6 = B2 - 5*B4 constrain C6 >= 0 (at least 5 if flag is 1)If the flag is 0, the first helper forces B2 <= 0. If the flag is 1, B2 must be between 5 and 40. The number 40 only needs to be as large as the biggest quantity that could ever make sense.
Slack, binding constraints, and what they tell you
After Solver finds a solution, each constraint is either binding or not. A binding constraint holds with equality. A non-binding constraint has slack, meaning room to spare. Binding constraints are where the business is limited. If only machine hours bind, then an extra machine hour is worth money, and an extra unit of demand is worth nothing.
Solver's Sensitivity Report gives that value as a shadow price for linear models. The reports chapter covers how to read it. For now, the point is that adding a constraint that turns out non-binding changes nothing, while one that binds changes the answer.
A checked example
The setup above has a profit of 20x + 30y, machine hours 2x + 4y <= 100, and demand x + y <= 40. Without the extra rules, the best plan is 30 units of x and 10 of y, for a profit of 900. Now add the contract minimums y >= 15 and x >= 5. The y contract forces Solver away from that plan. The following code reproduces the model outside Excel so you can verify what Solver returns.
from scipy.optimize import linprog
# Maximize 20*x + 30*y, so minimize the negative.
c = [-20, -30]
A_ub = [[2, 4], # machine hours per unit
[1, 1]] # total units, demand cap
b_ub = [100, 40]
# Bounds on the variable cells: x >= 5, y >= 15 (contract minimum)
bounds = [(5, None), (15, None)]
res = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds)
print(res.x.round(2), round(-res.fun, 2))
print(-res.ineqlin.marginals.round(2)) # value of one more hour, one more unit of demandThe expected output is a plan of 20 units of x and 15 of y, with a profit of 850, and shadow prices of 10 for machine hours and 0 for the demand cap. The contract minimum costs 50 of profit compared with the unconstrained optimum of 900. The demand cap is no longer binding, since only 35 units are produced, so extra demand has no value. Machine hours are the binding limit, and one more hour adds 10 of profit.
When Solver says the problem is infeasible
"Solver could not find a feasible solution" means no combination of variables satisfies every constraint at once. This is usually a modeling error and sometimes a real business conflict. Work through these checks in order:
- Remove all constraints except the bounds, then add the rest back one at a time and re-run. The one that triggers the message is part of the conflict.
- Check units. A limit in thousands compared against a value in units, or a percentage typed as 60 instead of 0.6, makes the problem impossible.
- Check equalities. A requirement like
=on a calculated cell is often too strict. Use a range with two inequalities instead when a small tolerance is acceptable. - Check that the minimums can coexist. If contracts require 30 units of y at 4 hours each, that is 120 hours, which exceeds the 100 available, so no plan works.
Common errors
- Hardcoded limits inside the dialog. They go stale and nobody sees them. Reference assumption cells.
- A missing non-negativity bound. The solution shows negative units because a negative production plan scores well on paper.
- Constraining the wrong cell. The constraint points at last year's total instead of the current one, so it never binds.
- Strict equalities on rounded values. A cell that shows 100% may be 99.9999%. Equalities then fail on tolerance. Constraint Precision in Solver's options defaults to 0.000001, so a tiny mismatch matters.
- Redundant rules. Constraints that can never bind add clutter and slow integer problems.
- Treating a bound as an objective. If a rule is a preference, not a requirement, such as "try to keep leverage low," put it in the objective with a penalty or run the model at several limits and compare.
Exercise
A funding model has three sources with weights in B2:B4. The weights must total 100%, no source may exceed 60%, and the cheapest source cannot fall below 10%. List the Solver constraints, and say which are bounds on variable cells and which are on a calculated cell.
Show answer
Bounds on variable cells: B2:B4 <= 0.6 (maximum for each source), the cheapest source's cell >= 0.1 (for example B2 >= 0.1), and B2:B4 >= 0 (non-negativity, from the checkbox or explicit). Constraint on a calculated cell: a helper cell with =SUM(B2:B4) constrained to = 1. Put 0.6 and 0.1 in assumption cells and refer to them instead of typing them into the dialog.
Exercise
Solver returns "no feasible solution" after you add a contract requiring at least 30 units of product y, which uses 4 machine hours per unit, with 100 hours available. What is the cause, and what are two business responses?
Show answer
The y contract alone needs 30 x 4 = 120 hours, which exceeds the 100 available, so the constraints conflict. Responses: add capacity (raise the hours available), or renegotiate the contract minimum down to 25 units or fewer. Either one is a business decision, not a Solver setting.