Message Boards Message Boards

1
|
8956 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Maximize option for LinearProgramming function?

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.
POSTED BY: Betty Love
3 Replies
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} *)
POSTED BY: Ilian Gachevski
Thanks!  I know about the Maximize function.  Really wanted LinearProgramming to work for either max or min!
POSTED BY: Betty Love
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.
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract