# Need help with a linear programming problem

Consider

$$1\rightarrow{}x+2y\leq{500}$$,

$$2\rightarrow{}2x +y \leq{520}$$,

$$3\rightarrow{}2x+5y \leq{}1200$$,

$$4\rightarrow{}x \geq{}0$$,

$$5\rightarrow{}y \geq{}0$$,

The above is the set of inequalities that generates a linear programming problem whose objective function is

$$f(x,y)=9x +12y$$,

I need to maximize the objective function, but the graphics are unclear when it comes to the points,

a) The problem to be solved is to produce a plot with enough detail with the coordinates of the solution polygon, drawn it by hand, with geogebra, symbolab and it is not possible to appreciate it well

b) I have never solved a linear programming problem with Mathematica and I would like to know how it can be done using mathematical syntax.

If you can help me, I would appreciate it very much

Notes

I do not know the symplex method.
This is not homework or a work assignment, it is for personal knowledge.

Update

error corrected

• Look at the condition: x,y <=0 and you want to maximize the objective function . The largest value the objective function can have under this assumption is zero. Therefore, I think there is something wrong with your question. Nov 7 '20 at 21:03
• @Daniel Hube see correction above Nov 7 '20 at 21:27
• There is a function LinearProgamming" in MMA for minimization. In your case for maximization you would define: c= -{..},m=-{{},{},..}; b=- {..}. Note the minus signs. Nov 8 '20 at 8:38

obj = 9 x + 12 y;
c1 = x + 2 y <= 500;
c2 = 2 x + y <= 520;
c3 = 2 x + 5 y <= 1200;
c4 = x >= 0;
c5 = y >= 0;

{max, argmax} = {#[], {x, y} /. #[]} & @
NMaximize[{obj, And[c1, c2, c3, c4, c5]}, {x, y}]

 {3540., {180., 160.}}

Show[RegionPlot[And[c1, c2, c3, c4, c5], {x, 0, 300}, {y, 0, 300},
ColorFunction -> (ColorData[{"TemperatureMap", {0, max}}][9 # + 12 #2] &),
ColorFunctionScaling -> False],
Normal[ContourPlot[obj, {x, 0, 300}, {y, 0, 300},
ContourShading -> None, Contours -> Subdivide[0, max, 5]]] /.
Tooltip[l : {__, Line[x_, ___]}, t_] :> {l, Text[t, Mean[x]]},
ListPlot[{Callout[argmax, argmax]}, PlotStyle -> Directive[Red, PointSize[Large]]]] A variation: You can add a legend showing objective function value over the feasible region and use custom arrowheads to place and orient the contour labels along the contour lines:

Show[RegionPlot[And[c1, c2, c3, c4, c5], {x, 0, 300}, {y, 0, 300},
ColorFunction -> (ColorData[{"TemperatureMap", {0, max}}][
9 # + 12 #2] &), ColorFunctionScaling -> False,
PlotLegends ->
BarLegend[{ColorData[{"TemperatureMap", {0, max}}], {0, max}},
LegendMarkerSize -> 400, LegendFunction -> "Frame",
LegendLabel -> "obj"]],
Normal[ContourPlot[obj, {x, 0, 300}, {y, 0, 300},
ContourShading -> None, Contours -> Subdivide[0, max, 5]]] /.
Tooltip[{dir__, Line[x_, ___]}, t_] :> {dir,
Graphics @ Text[Framed[Style[t, 16, Bold, Opacity, Black],
Background -> White, FrameStyle -> None]]}}],
Arrow[Line @ SortBy[First] @ x]},
ListPlot[{Callout[argmax, Style[argmax, 16, Bold]]},
PlotStyle -> Directive[Red, PointSize[Large]]], ImageSize -> 500] • kglr__wow your first code works very well the second and third send me these errors, the graph appears but not with the color variation) "Part::partd: Part specification nmax[]] is longer than depth of object. ColorData::notent: {TemperatureMap,{0,nmax[]}} is not a known entity, class, or tag for ColorData. Use ColorData[] for a list of entities. (use MMA 12.1).What does the value 3540 mean in the first result? Nov 7 '20 at 21:53
• @rpujadas, sorry, nmax[] should be max . Fixed now.
– kglr
Nov 7 '20 at 21:57
• @kglr_What does the value 3540 mean in the first result? Nov 7 '20 at 22:19
• @rpujadas - The 3540 is the maximum value of the objective function subject to the given constraints. The system can be solved exactly {max, argmax} = {#[], {x, y} /. #[]} &@Maximize[{obj, c1, c2, c3, c4, c5}, {x, y}] Nov 7 '20 at 22:34
• @Bob Hanlon ,I had not understood the result format of the code. Thank you Nov 7 '20 at 22:36