0
$\begingroup$

i'm starting my studies of Operational Research with Mathematica and i'm stuck on a problem with 12 variables. In fact, I was able to solve the problem using LinearProgramming, but NMaximize is a different animal:

eq = {30, 20, 24, 18, 12, 36, 30, 24, 8, 15, 25, 20}
res1 = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}
res2 = {0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0}
res3 = {0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0}
res4 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}
res = {res1, res2, res3, res4}
par = {{5, 0}, {8, 0}, {4, 0}, {10, 0}}
LinearProgramming[eq, res, par]
{5, 0, 0, 0, 0, 8, 4, 0, 0, 0, 10, 0}

But using NMaximize, wont work:

EQUATION = {30*P1L1 + 12*P2L1 + 8*P3L1 + 20*P1L2 + 36*P2L2 + 
   15*P3L2 + 24*P1L3 + 30*P2L3 + 25*P3L3 + 18*P1L4 + 24*P2L4 + 
   20*P3L4}
RESTRICTIONS = {P1L1 + P2L1 + P3L1 == 5.0 && 
   P1L2 + P2L2 + P3L2 == 8.0 && P1L3 + P2L3 + P3L3 == 4.0 && 
   P1L4 + P2L4 + P3L4 == 10.0}
NMaximize[EQUATION, RESTRICTIONS, {P1L1, P1L2, P1L3, P1L4, P2L1, P2L2,
   P2L3, P2L4, P3L1, P3L2, P3L3, P3L4}]

The result was:

NMaximize::vdom: "Variable domain {P1L1,P1L2,P1L3,P1L4,P2L1,P2L2,P2L3,P2L4,P3L1,P3L2,P3L3,P3L4} should be either Reals or Integers. "

Perhaps a trick here?

$\endgroup$
  • $\begingroup$ You can use phpsimplex to solve that problem. $\endgroup$ – user24806 Jan 19 '15 at 0:27
3
$\begingroup$

Your use of NMaximize has a couple syntax errors. According to the documentation, the restrictions and equations should be given as a list as the first argument, not as the first and second arguments. Also, you have an extraneous {} around your equation and restrictions, so remove those. Finally, remember that LinearProgramming assumes all quantities are positive, so you need to add a constraint to enforce that.

After the preceding three corrections are made, NMaximize finds the solution instantly:

NMaximize[{EQUATION[[1]], 
    RESTRICTIONS[[1]] && And @@ (Thread[# > 0])}, #] &@{P1L1, P1L2, 
  P1L3, P1L4, P2L1, P2L2, P2L3, P2L4, P3L1, P3L2, P3L3, P3L4}

producing

{798., {P1L1 -> 5., P1L2 -> 0., P1L3 -> 0., P1L4 -> 0., P2L1 -> 0., 
  P2L2 -> 8., P2L3 -> 4., P2L4 -> 10., P3L1 -> 0., P3L2 -> 0., 
  P3L3 -> 0., P3L4 -> 0.}}

which agrees with the result of LinearProgramming.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.