While the number of options is small, a choice can be made "by eye": try a few combinations and keep the best one. When a budget, a time limit, the indivisibility of objects, and the client's wishes all act at once, such enumeration stops being a proof. You do not know whether you have gone through all feasible combinations, whether you missed the best one, or whether you violated a condition you forgot about. Formalization does not abolish this, but it makes every assumption explicit and checkable.
Below, one end-to-end example is worked through. Its numbers are made up specifically for illustration: they are neither enterprise data nor industry recommendations.
From a verbal problem to a model
According to the NEOS Guide, an optimization model consists of variables, an objective, and constraints. Translating a practical question into this form is conveniently done step by step:
- What exactly is being decided. These are the decision variables, for example how many units of each option to choose.
- What data and units are known. Scores, resource consumption, limits. The units of measurement should be written down at once: an error in them distorts the model in the least noticeable way.
- What counts as best. The objective must be a number that is minimized or maximized.
- What is mandatory. Constraints define the admissible values, and the domain of the variables (non-negativity, integrality) is also part of the model.
The University of Washington lecture notes distinguish two concepts. A feasible solution satisfies all the hard constraints. An optimal solution is a feasible one whose objective value is the best among the feasible ones. Hence the order of checking: first feasibility, then comparison of quality.
An end-to-end example
Let x and y be non-negative integer quantities of two options. The conditional scores are 7 and 5. We need to maximize
7x + 5y
subject to the constraints
3x + 2y ≤ 11.5 and x + y ≤ 5.
The first constraint can be read as a limit on some resource, the second as a limit on the total number of chosen units. These are assumptions of the example, not facts about a real situation.
Since the variables are integers and x does not exceed 3 (at x = 4 already 3·4 = 12 > 11.5), the solution can be checked by full enumeration over x. For each x we take the largest admissible y: the scores of y are positive, so a smaller y gives no gain.
| x | largest admissible y | 3x + 2y | x + y | 7x + 5y |
|---|---|---|---|---|
| 0 | 5 | 10 | 5 | 25 |
| 1 | 4 | 11 | 5 | 27 |
| 2 | 2 | 10 | 4 | 24 |
| 3 | 1 | 11 | 4 | 26 |
| 4 | none admissible | — | — | — |
The maximum among admissible integer solutions is 27 at (x, y) = (1, 4). Substitution confirms feasibility: 3·1 + 2·4 = 11 ≤ 11.5 and 1 + 4 = 5 ≤ 5. The objective value: 7·1 + 5·4 = 27.
Feasibility as a separate stage
The set of feasible solutions may turn out to be empty. Then the question "which solution is better" makes no sense: there is no solution satisfying all the written constraints. According to the same lecture notes, even a small change in the constraints can lead to infeasibility.
In our example this is easy to reproduce. Add the hard condition x ≥ 4. From 3x + 2y ≤ 11.5 with y ≥ 0 it follows that x ≤ 11.5/3 ≈ 3.83, so the requirement x ≥ 4 and the original constraint are incompatible. This is my calculation for illustration.
Infeasibility does not say which condition is wrong. The data, the units, and the meaning of each condition need to be checked. Choosing the solution with the smallest violation and calling it feasible is not allowed: it violates a hard constraint. If a violation is acceptable, the condition is in fact soft and must be written differently.
Continuous and discrete choice
NEOS distinguishes continuous variables, which take values from a range of real numbers, and discrete ones, for example integer variables. The IBM Decision Optimization documentation also identifies models with mixed integer and continuous variables. The type of a variable must be chosen by meaning: indivisible objects and counts of actions require integer values.
Let us see what ignoring this requirement leads to. If fractional x and y are temporarily allowed, the optimum lies at the intersection of the boundaries 3x + 2y = 11.5 and x + y = 5. Substituting y = 5 − x gives 3x + 10 − 2x = 11.5, whence x = 1.5 and y = 3.5. The objective value: 7·1.5 + 5·3.5 = 28.
The fractional solution is better than the integer one (28 versus 27), but for the original problem it is infeasible. Rounding guarantees neither a feasible nor an optimal solution. The pair (2, 4) gives 3·2 + 2·4 = 14 > 11.5 and violates the constraint. The pair (2, 3) violates it as well: 6 + 6 = 12 > 11.5. Another way of rounding, x down to 1 and y up to 4, leads to (1, 4), that is, to the optimum found above. But this is a coincidence in this example, not a proof: the optimality of (1, 4) was confirmed by enumeration. An admissible integer optimum has to be sought as the solution of a problem with integer variables, not by relying on rounding of the continuous one.
Hard constraints and soft preferences
A hard constraint must hold in all feasible solutions. A soft one allows violation, but a penalty is assigned for it. GAMS describes this construction and the role of penalty weights. In a minimization problem the penalty is added to the objective, in a maximization problem it is subtracted.
Add the preference x ≥ 2 with the penalty 2·max(0, 2 − x). The conditions 3x + 2y ≤ 11.5 and x + y ≤ 5 remain hard. The new objective: 7x + 5y − 2·max(0, 2 − x).
| x | y | 7x + 5y | penalty | objective after penalty |
|---|---|---|---|---|
| 0 | 5 | 25 | 4 | 21 |
| 1 | 4 | 27 | 2 | 25 |
| 2 | 2 | 24 | 0 | 24 |
| 3 | 1 | 26 | 0 | 26 |
Now the optimum is (3, 1) with the value 26 after the penalty. The preference x ≥ 2 is satisfied, but the price is a drop in the original score from 27 to 26.
The penalty weight here is chosen for demonstration only, and it affects the result. Denote the weight by w and assume w ≥ 0, that is, violating the preference is not encouraged. Then the penalty equals w·max(0, 2 − x), and in the table above w = 2. For x = 1 the objective after the penalty equals 27 − w, for x = 3 it remains 26, for x = 0 it is 25 − 2w, and for x = 2 it is 24. Comparing, we get: for w < 1 the choice remains (1, 4), for w = 1 two solutions are equal in value (26), for w > 1 (3, 1) wins. This is my calculation for this example, not a general rule.
It is important that a soft constraint stops being a guarantee. A solution with x = 1 can still turn out to be optimal if the penalty is smaller than the gain. The claim "we took the preference into account" can only be made together with the weight and its justification. The sources do not offer a universal way to choose the numerical value of the weight: it has to be reconciled with the scale of the objective and with what the client is prepared to trade off.
How to check the result
A reliable check is not "the solver returned an answer" but several independent actions:
- substitute the found values into all hard constraints and make sure they hold;
- for each soft constraint, recompute the magnitude of the violation and the penalty separately, to see which preference is violated and at what cost;
- recompute the objective by hand or with separate code;
- check the units of measurement and the meaning of each constraint;
- compare with the relaxed model (such as the fractional solution with the value 28), to understand what the integrality requirement costs;
- change the input data and the penalty weights and see whether the choice changes.
The last point is especially important. According to the NEOS description, deterministic optimization assumes the data are exactly known, while for uncertain parameters there exist, in particular, stochastic and robust formulations. A single computation on fixed values does not describe uncertainty.
A separate caveat concerns nonlinear problems. Our example is linear and small, so its optimum is confirmed by enumeration. For nonlinear models a particular solver may return a local rather than a global optimum, and then one has to find out what exactly the chosen method guarantees.
What "optimal" means
Optimality is defined only relative to the given variables, objective, constraints, and input data. It does not prove that these premises describe the real problem correctly. If the scores are chosen arbitrarily, a hard condition in fact admits a compromise, or an important factor did not make it into the model, a mathematically impeccable optimum will remain an answer to a different question. Therefore both the solution and the model itself must be checked: the sources provide the foundations of formalization, but they do not replace domain expertise.