0
$\begingroup$

Please help me...

S = 100;
hv[1] = 3.5; hv[2] = 4;
c[1] = 10; c[2] = 50;
Cv[1] = 2.4; Cv[2] = 3;
Cf[1] = 3; Cf[2] = 1.2;
s[1] = 0.3; s[2] = 0.1;
th[1] = 0.01; th[2] = 0.03;
A[1, 1] = 3; A[2, 1] = 2; A[1, 2] = 1; A[2, 2] = 1.1;
d[1, 1] = 1850; d[2, 1] = 2000; d[1, 2] = 2100; d[2, 2] = 1300;
k[1, 1] = d[1, 1]*0.05 ; k[1, 2] = d[1, 2]*0.05 ; 
k[2, 1] = d[2, 1]*0.05 ; k[2, 2] = d[2, 2]*0.05 ;
so[1, 1] = 3.5; so[2, 1] = 1.5; so[1, 2] = 0.3; so[2, 2] = 0.6;
t[1, 1] = 1; t[2, 1] = 1; t[1, 2] = 1; t[2, 2] = 1;
e[1, 1] = 2; e[2, 1] = 2; e[1, 2] = 2; e[2, 2] = 2;
Y[1, 1] = 3; Y[2, 1] = 3; Y[1, 2] = 3; Y[2, 2] = 3;
hb[1, 1] = 2.4; hb[2, 1] = 1.3; hb[1, 2] = 4.5; hb[2, 2] = 3.6;
W[1] = 500; W[2] = 1000;
w[1] = 12; w[2] = 2; w[3] = 3;
P[1] = 8000; P[2] = 10000; P[3] = 6000;

NMinimize[{Sum[(S*de[i])/(m[i]*Q[i])+(hv[i]*Q[i])/2*((m[i]-1)*(1-de[i]/P[i])
+de[i]/P[i])+de[i]/(m[i]*Q[i])*(m[i]*c[i]+m[i]*Q[i]*Cv[i]+Cf[i])
+(m[i]*s[i]*de[i]*Q[i]*th[i])/2, {i, 1, 2}]
+Sum[(A[i, j]*d[i, j])/q[i, j]+(hb[i, j]*(1 - k[i, j])^2*q[i, j])/2
+(k[i, j]^2*so[i, j]*q[i, j])/2+(m[i]*t[i, j]*d[i, j])/q[i, j]
+(m[i]*e[i, j]*d[i, j])/q[i, j] + Y[i, j]*d[i, j], {i,1, 2}, {j, 1, 2}],
Table[{Table[1000 > q[i, j] > 0, {j, 1, 2}],Element[m[i], Integers], 1000 > m[i] >= 1,
Q[i] == Sum[q[i, j], {j, 2}] > 0, de[i] == Sum[d[i, j], {j, 2}],
Sum[(q[i, 1]*w[i]/m[i]), {i, 2}] <= W[1],Sum[(q[i, 2]*w[i]/m[i]), {i, 2}] <= W[2]}, {i, 1, 2}]}, 
Join[Flatten@{Table[{m[i], Table[q[i, j], {j, 1, 2}]}, {i, 1,2}]}, {Q[1], Q[2], de[1], de[2]}], MaxIterations -> 100]

I made this code for solving the problem. When i run, i got a message.

NMinimize::lvar: Variables {{{m[1],{q[1,1],q[1,2]}},{m[2],{q[2,1],q[2,2]}}}} should be a list of variables, with each element being a variable, or a list containing a variable and lower and upper bounds for the starting region for that variable. >>

I followed the tutorial of Nminimize, however, it happened. What am i wrong with this code?

$\endgroup$
3
  • 1
    $\begingroup$ There are missing closing brackets. Please give code by correcting those first. $\endgroup$
    – Lotus
    Commented May 19, 2016 at 12:33
  • $\begingroup$ "{{{m[1],{q[1,1],q[1,2]}},{m[2],{q[2,1],q[2,2]}}}} should be a list of variables, with each element being a variable". This error message is one of the more clear ones you will encounter in any programming language: you need a list where the elements are variables. You have a nested list of variables. Replace {Table[{m[i], Table[q[i, j], {j, 1, 2}]}, {i, 1, 2}]} with Flatten@{Table[{m[i], Table[q[i, j], {j, 1, 2}]}, {i, 1, 2}]}. (But also fix your mismatched brackets.) $\endgroup$
    – march
    Commented May 19, 2016 at 15:19
  • $\begingroup$ Now, i update my code. plz check one more OTL $\endgroup$
    – user26674
    Commented May 20, 2016 at 1:56

1 Answer 1

1
$\begingroup$

If you see the Mathematica message, it is clear that the variable list is incomplete. It should also include Q[1],Q[2], de[1],de[2], P[1] and P[2]. The syntax therefore becomes:

Timing[NMinimize[{Sum[(S*de[i])/(m[i]*Q[i]) + (hv[i]*Q[i])/
        2*((m[i] - 1)*(1 - de[i]/P[i]) + de[i]/P[i]) + 
      de[i]/(m[i]*Q[i])*(m[i]*c[i] + m[i]*Q[i]*Cv[i] + Cf[i]) + (m[i]*
         s[i]*de[i]*Q[i]*th[i])/2, {i, 1, 2}] + 
    Sum[(A[i, j]*d[i, j])/
       q[i, j] + (hb[i, j]*(1 - k[i, j])^2*q[i, j])/
       2 + (k[i, j]^2*so[i, j]*q[i, j])/2 + (m[i]*t[i, j]*d[i, j])/
       q[i, j] + (m[i]*e[i, j]*d[i, j])/q[i, j] + Y[i, j]*d[i, j], {i,
       1, 2}, {j, 1, 2}], 
   Table[{Table[q[i, j] > 0, {j, 1, 2}], Element[m[i], Integers], 
     m[i] > 0, Q[i] == Sum[q[i, j], {j, 2}], 
     de[i] == Sum[d[i, j], {j, 2}]}, {i, 1, 2}]}, 
  Join[Flatten@{Table[{m[i], Table[q[i, j], {j, 1, 2}]}, {i, 1, 
       2}]}, {Q[1], Q[2], de[1], de[2], P[1], P[2]}]]]

Now we get an answer from NMinimize, but with a warning that at a specific point it encountered 1/0. Indeed, if you substitute the values given out by the message into the function we get 1/0. You have to therefore check if this is a valid answer, or if you need to add more constraints to your problem to skip this singularity.

Hope this helps. (I do not consider this to be complete answer to this question, but comments does not allow for proper code formatting. So I put this in as an answer)

$\endgroup$
1
  • $\begingroup$ Thanks! it works. I forgot add P[i] value... it was not decision variable. lol. And, can i ask one more question? i add W[1] = 500; W[2] = 1000; w[1] = 12; w[2] = 2; w[3] = 3; and i put this code -> Sum[(q[i, 1]*w[i]/m[i]), {i, 2}] <= W[1], Sum[(q[i, 2]*w[i]/m[i]), {i, 2}] <= W[2] in the constraints part, but it is not working.. Non-linear constraints are not available in Nminimize? $\endgroup$
    – user26674
    Commented May 20, 2016 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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