I’m teaching an OR course and my university recently purchased a site license for Mathematica. I’d like for my OR students to use it to solve LPs and IPs. I’m trying to learn how to use it for this myself (previously I used Maple or other specific LP software). As far as I can tell from the documentation, the Mathematica LinearProgramming command assumes a Minimization problem. Is there a way to tell it to Maximize? I realize that I can negate the cost coefficients, but I really would prefer not to have to add that layer to what I’m teaching on day 1 of class.
I think for LinearProgramming the only way would be to reformulate the problem of maximizing c.x as minimizing -c.x as mentioned.
However, note Maximize will also handle linear problems.
Thanks! I know about the Maximize function. Really wanted LinearProgramming to work for either max or min!
I guess that depends on the way it will be used, but what about a definition like the following (of course, the “new” function can be named as desired)
lpMaximize[c_, rest___] := LinearProgramming[-c, rest]
lpMaximize[{1, 1}, {{1, 2}}, {3}, {{-1, 2}, {-1, 1}}]
(* Out[3]= {2, 1} *)
We could also let LinearProgramming automatically do the above if the last argument is “Max”, for example:
Unprotect[LinearProgramming];
LinearProgramming[c_, rest___ /; Last[{rest}] === "Max"] := LinearProgramming[-c, Sequence @@ Most[{rest}]]
Protect[LinearProgramming];
LinearProgramming[{1, 1}, {{1, 2}}, {3}, {{-1, 2}, {-1, 1}}]
(* Out[11]= {1, 1} *)
LinearProgramming[{1, 1}, {{1, 2}}, {3}, {{-1, 2}, {-1, 1}}, "Max"]
(* Out[12] = {2, 1} *)