Practice: Driving a Linear Programming Solver

Construction · Direct application · Explanation

A workshop makes two products. Each unit of A takes 2 machine-hours and 1 labour-hour and contributes £30; each unit of B takes 1 machine-hour and 1 labour-hour and contributes £20. There are 100 machine-hours and 80 labour-hours available, and at most 40 units of A can be sold.

Using Excel Solver, or by hand against its documented behaviour if you do not have Excel:

(a) Describe the sheet: which cells hold the decision variables, which cell holds the objective, and how each constraint is expressed. State what each cell means.

(b) Two settings in the Solver dialog materially affect whether the answer is trustworthy. Name them, say what each should be for this model, and say what goes wrong if each is left at a value that does not suit a linear program.

(c) Report the plan and contribution Solver returns, and confirm which constraints bind.

(d) A colleague's sheet gives a different, higher contribution for the same data. Name two errors in a spreadsheet model that would produce a larger answer while still solving cleanly, and say how you would find each.

(e) Compare this entry route with passing arrays to a routine such as linprog. Name one error each form makes easier, and one it makes harder.

Write your answer, then compare it with the worked solution.

3 hints available, least help first.

Hint 1: Retrieval cue

The objective and every constraint left-hand side must be formulas referring to the changing cells, never typed values.

Hint 2: Concept cue

Two defaults in the dialog do not suit a linear program. One concerns the method, the other concerns the sign of the variables.

Hint 3: Strategy cue

For part (d), ask what a model would have to believe in order to report a contribution above £1,800.

Compare with the worked solution

Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.

(a) The sheet. Two changing cells hold the decision variables: one for a , units of product A per week, one for b , units of B. A third cell holds the objective as a formula, = 30 a + 20 b referring to those two cells. A formula, never a typed number, so it recomputes as Solver varies the plan. Three further formula cells hold the left-hand side of each constraint: = 2 a + b for machine-hours, = a + b for labour-hours, = a for the sales limit. Each appears in the dialog as a row naming that cell, the relation ≤ , and a bound of 100, 80 and 40 respectively. Because the direction is chosen explicitly in the dialog as Max, no negation is needed: unlike an array interface that only minimises, Solver takes the maximisation as stated. That is the conversion this route avoids. (b) The two settings. The solving method. It must be set to the linear option. The default is a nonlinear method, which may terminate at a point it cannot certify as globally optimal and may report a different answer on different runs from different starting cells. For a genuinely linear model the linear method is both correct and faster, and it certifies optimality. The nonnegativity option. Unconstrained variables are not assumed nonnegative, so this must either be checked or entered as explicit ≥ 0 constraint rows. Left off, Solver may return a negative quantity of one product, arithmetically optimal, physically meaningless, and easy to miss because the cell simply shows a negative number. (c) The answer. Solver reports an optimal solution: make 20 units of A and 60 units of B, for a contribution of £1,800 per week. Checking against the model as written: - Machine-hours: 2 ( 20 ) + 60 = 100 ≤ 100 ✓ binding
- Labour-hours: 20 + 60 = 80 ≤ 80 ✓ binding
- Sales limit: 20 ≤ 40 ✓ slack of 20
- Objective: 30 ( 20 ) + 20 ( 60 ) = 1800 ✓ Both resources bind and demand does not, so the plan is capacity-limited rather than demand-limited. (d) Two errors giving a larger answer. A constraint cell referring to the wrong cells. If the machine-hours formula reads = 2 a , the reference to b lost in an edit, the model believes B consumes no machine time, and the reported contribution rises above 1,800. Finding it: read each constraint formula back as a sentence and check it against the description, or substitute the reported plan into the constraints by hand, where the true machine-hour usage would exceed 100. A missing constraint row. If the labour-hours row was never added to the dialog, the model is unconstrained in labour and again returns more than 1,800. Finding it: count the rows in the dialog against the restrictions in the description, and check the reported plan against every stated restriction rather than the ones on the sheet. Both produce a clean optimal status, because each yields a valid program. The check that catches them is verification against the original description, not anything inside the tool. (e) The two entry routes. A spreadsheet makes reference errors easier: a formula can point at the wrong cell and still compute, and the sheet displays values rather than the relationships between them, so the error is invisible on screen. It makes direction errors harder, since the objective sense is an explicit choice in the dialog rather than a convention to remember. An array interface inverts this. It makes convention errors easier, forgetting that the routine only minimises, or that bounds are not assumed, and makes reference errors harder, since the arrays are written out in one place and their shapes must agree or the call fails.

A complete answer does each of these:

  • converts to solver form
  • states the correspondence
  • reverses the conversion
  • scopes the status

Construction · Direct application · Explanation

A dairy blends two feeds. Each tonne of feed X costs £180 and supplies 40 kg protein and 20 kg fibre; each tonne of feed Y costs £240 and supplies 30 kg protein and 60 kg fibre. A batch must supply at least 240 kg protein and at least 240 kg fibre. No more than 8 tonnes of X is available.

Using MATLAB's linprog, or by hand against its documented argument form if you do not have MATLAB:

(a) Write the model, then state which of linprog's arrays each part belongs in, consulting its documentation for the form it expects.

(b) Give the arrays you would pass, including bounds, and state what each column index means. Say which constraints needed rewriting to fit the expected form, and why.

(c) Report the status, the point and the objective value you obtain, then reverse every conversion you applied and state the answer in the dairy's terms.

(d) Verify the reported point against the model as you first wrote it, and say which constraints bind.

(e) Name one thing the exit flag establishes and one thing it does not.

Write your answer, then compare it with the worked solution.

3 hints available, least help first.

Hint 1: Retrieval cue

Check the documented form before converting anything: which direction does it optimise, and how are inequality directions expressed?

Hint 2: Concept cue

Multiplying an inequality by − 1 reverses its direction. Apply it to the whole row, right-hand side included.

Hint 3: Strategy cue

Before reporting, list every conversion you made and check that each has been reversed or shown not to need reversing.

Compare with the worked solution

Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.

(a) The model, and where each part goes. Let x and y be tonnes of feed X and feed Y.

min 180 x + 240 y subject to 40 x + 30 y ≥ 240 , 20 x + 60 y ≥ 240 , x ≤ 8 , x , y ≥ 0 .

linprog solves a minimisation with inequalities as A x ≤ b , equalities in a separate array, and bounds given separately. So: the objective is already a minimisation and needs no negation; the two ≥ rows must be rewritten as ≤ by negating them; the limit on x is either a third inequality row or an upper bound, and appears exactly once either way; there are no equalities; nonnegativity is stated as a lower bound of zero, not assumed. (b) The arrays. Column 1 is x , tonnes of feed X per batch; column 2 is y , tonnes of feed Y.

f = ( 180 240 ) , A = ( − 40 − 30 − 20 − 60 ) , b = ( − 240 − 240 ) ,

with bounds ℓ = ( 0 , 0 ) T and u = ( 8 , ∞ ) T , taking the availability limit as an upper bound. Row 1 is the protein requirement, row 2 the fibre requirement. The rewriting to record: both constraint rows were negated to turn ≥ into ≤ . Multiplying an inequality by − 1 reverses its direction, so 40 x + 30 y ≥ 240 becomes − 40 x − 30 y ≤ − 240 . The objective was not negated, since the model already minimises. Negating it out of habit would invert the question. (c) The result, and reversing. The solver reports an optimum found, at x = ( 4 , 8 / 3 ) , that is, 4 and approximately 2.667 , with objective value 1360 . The only conversions applied were to the constraint rows, which do not affect how the point or the objective value are read. The objective was not negated, so the reported value stands as it is. In the dairy's terms: blend 4 tonnes of feed X with 8/3 tonnes of feed Y, at a cost of £1,360 per batch. The fractional quantity is ordinary. Nothing in a linear program makes its optimum integral, and a tonnage is divisible, so 8 / 3 tonnes is an implementable answer rather than something to round. Rounding it to 2.7 would raise the cost; rounding to 2.6 would breach the fibre requirement. (d) Verification against the original model. - Protein: 40 ( 4 ) + 30 ( 8 / 3 ) = 160 + 80 = 240 ≥ 240 ✓, binding
- Fibre: 20 ( 4 ) + 60 ( 8 / 3 ) = 80 + 160 = 240 ≥ 240 ✓, binding
- Availability: 4 ≤ 8 ✓, slack of 4 tonnes
- Nonnegativity: both positive ✓
- Objective: 180 ( 4 ) + 240 ( 8 / 3 ) = 720 + 640 = 1360 ✓ matches Both nutrient requirements bind and the availability limit does not. This is the covering shape behaving as expected: every unit of slack above a floor is paid for and not required, so the cheapest blend meets its minima exactly. The feed X limit is not scarce at this solution, so negotiating more of it would buy nothing. What would change the cost is relaxing either nutrient floor. Both are active, so each has a price attached, and a sensitivity run would report what a kilogram of either requirement is worth. (e) What the exit flag says. It establishes that the routine terminated having found a point it certifies as optimal for the arrays it received, as opposed to stopping at an iteration limit, or concluding the constraints were unsatisfiable. It does not establish that those arrays are the dairy's model. The negations in part (b) are exactly where that could fail: negating a row's coefficients but not its right-hand side yields a valid program describing a requirement nobody stated, and the flag would report success on it.

A complete answer does each of these:

  • converts to solver form
  • states the correspondence
  • reverses the conversion
  • scopes the status

Recognition · Interpretation

A colleague enters a production model into a solver. It returns status optimal, a point, and an objective value. What has been established?

2 hints available, least help first.

Hint 1: Retrieval cue

What information does the solver have about what you meant to write?

Hint 2: Concept cue

Consider a model entered with one coefficient mistyped. What status would the solver report?

Direct application

A solver accepts inequality constraints only in the form A x ≤ b . A model contains the requirement

40 x + 30 y ≥ 240 .

Rewritten for that interface, the row's coefficients become ( − 40 , − 30 ) .

What is the corresponding entry of b ?

Enter the value. It is checked against the answer and the precision this task asks for.

2 hints available, least help first.

Hint 1: Retrieval cue

What must be done to an inequality to reverse its direction, and to which parts of it?

Hint 2: Concept cue

Test your rewritten row at ( 0 , 0 ) . The original requirement is not met there, so the rewritten one must not be satisfied there either.

Direct application

A maximisation of weekly contribution is entered into a minimising solver by negating the objective coefficients. The solver reports an optimal point and an objective value of − 2450 .

What is the weekly contribution of the reported plan, in pounds?

Enter the value. It is checked against the answer and the precision this task asks for.

2 hints available, least help first.

Hint 1: Retrieval cue

What conversion was applied to the objective before the program was entered?

Hint 2: Concept cue

The point is unchanged by the negation; only the sign of the objective value differs.

Recognition · Error diagnosis

A solver minimises c T x subject to A x ≤ b , x ≥ 0 .

A profit model is to maximise 3 x 1 + 5 x 2 , whose optimal plan earns 36 .

A learner enters c = ( 3 , 5 ) unchanged, receives an objective value of 0 at x = ( 0 , 0 ) , and reports that the model makes no profit.

Which response identifies the error?

2 hints available, least help first.

Hint 1: Retrieval cue

In which direction does this solver optimise, whatever the model intended?

Hint 2: Concept cue

Maximising f and minimising − f have the same argmax. What does that imply for the value the solver reports?

Practice data

Your practice record is stored in this browser only. Clearing it removes every answer and every scheduled review, and cannot be undone.

Results update as you type. Use the up and down arrow keys to move between results, Enter to open one, and Escape to close.

Type to search.

Settings

Appearance

Interface density

Your record

Your progress is stored in this browser and nowhere else: an identifier, the answers you have given, the mastery states and review schedule derived from them, and the lesson you last opened. Clearing it makes you a new learner on this device. It cannot be undone, and it will not affect your appearance or density settings.

Focus timer

Focus--minutes remaining

Phase

Kept in this browser only, and used to label the session in your own history.

Today

Nothing recorded yet. Finish a focus session and it will appear here.

Settings

Focus sessions between long breaks.

Sessions you are aiming for in a day.

Notifications

Your history

Sessions are stored in this browser and nowhere else. They are not evidence and never reach your mastery record.