Course 19.2Lesson 3 of 3
Three special cases can happen. If the rules clash, the feasible region is empty, so there is no feasible solution. If the lines are parallel to an edge, the optimum is reached at both ends of that edge and at every point between them, so there are many optimal solutions. And on an unbounded region an optimum may not exist. The function linprog in scipy solves a problem and reports which case it found, so it checks a hand solution.
Try the code and the simulations beside the lesson.
scipy.optimize.linprog to check a solution, and read its status.If the rules contradict each other, the feasible region is empty. For example, and cannot both hold. There are no corner points, so there is nothing to compare. We say the problem has no feasible solution. In a real problem this means that the demands cannot all be met at once.
Take the bakery region again, with . The values at the corners are at , at , at and at . The maximum is , and two corners give it.
The line is also the edge of the region that joins those two corners. The lines are parallel to that edge. When the sliding line reaches the edge, it lies along it. Every point of the edge gives . For example, gives .
So there are infinitely many optimal solutions, and the maximum value is . If a problem asks for "the" optimal plan, give the maximum value and say that it is reached at both corners and everywhere between them.
When does this happen? When the objective function is a multiple of the left side of one boundary line. Here is the left side of the rule .
The function linprog in the module scipy.optimize solves a linear programme. It always minimises subject to rules of the form . Three habits make it work.
res.fun.bounds=[(0, None), (0, None)].The result res has a code res.status. It is 0 when a best point was found, 2 when there is no feasible solution and 3 when the problem is unbounded. If it is 0, res.x holds the best point and res.fun the best value. When there are many optimal solutions, linprog reports only one of them.
linprog to maximise. It will then give you the minimum.res.fun as the maximum. For a maximisation it is the negative of the maximum.linprog minimises. Negate to maximise. Multiply a rule by .res.status is 0 for solved, 2 for no feasible solution and 3 for unbounded.linprog, and linprog is checked by the corners.scipy.optimize.linprog (the arguments A_ub, b_ub and bounds, and the status codes).Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
linprog for the maximum of ?linprog?linprog returns status = 3. What does it mean?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.