How to write an if condition for my variable in GLPK?

Here is my complete problem:

enter image description here

information:

* Max. total investment: $ 125

* Payout is the sum of units purchased x pay-off / unit

* Investment cost: purchase price + cost / unit x number of units if you buy at least one unit

* Cost is the sum of investment costs

Limitations:

* You cannot invest in 2 and 5.

* You can invest in 1 only if you invest at least one of 2 and 3.

* You must invest at least two out of 3,4,5.

* You may not invest more than the maximum number of units.

Problem: Maximize Profit: Payback -

 xi: # of units i ∈ {1,2,3,4,5}
 yi=1 if xi>0 else yi=0
 cost = sum{i in I} buyInCost_i * yi + cost-unit_i*xi
 pay-off = sum{i in I} (pay-off/unit)_i*xi
 profit = pay-off - cost

 Maximize profit

 Subject to

 y2+y5 <= 1
 y1<= y2+y3
 y3+y4+y5 >= 2
 x1<=5, x2<=4, x3<=5, x4<=7, x5<=3
 cost<=125

Here is my question:

For example, I have this binary variable y

 yi=1 if xi>0 else yi=0  and i ∈ {1,2,3,4,5}

I declared I as a data set

 set I;

 data;

 set I := 1 2 3 4 5;

, if else y glpk. ?

:

 set I;

 /*if x[i]>0 y[i]=1 else y[i]=0 ?????*/
 var y{i in I}, binary;

 param a{i in I};
 /* buy-in cost of investment i */

 param b{i in I};
 /* cost per unit of investment i */

 param c{i in I};
 /* pay-off per unit of investment i */

 param d{i in I};
 /* max number of units of investment i */

 var x{i in I} >=0;
 /* Number of units that is bought of investment i */

 var po := sum{i in I} c[i]*x[i];

 var cost := sum{i in I} a[i]*y[i] + b[i]*x[i];

 maximize profit: po-cost;

 s.t. c1: y[2]+y[5]<=1;
 s.t. c2: y[1]<y[2]+y[3];
 s.t. c3: y[3]+y[4]+y[5]>=2;
 s.t. c4: x[1]<=5 
     x[2]<=4
     x[3]<=5
     x[4]<=7
     x[5]<=3;

 s.t. c5: cost <=125;
 s.t. c6{i in I}: M * y[i] > x[i];   // if condition of y[i] 

 set I := 1 2 3 4 5;
 param a :=
1 25
2 35
3 28
4 20
5 40;

 param b :=
1 5
2 7
3 6
4 4
5 8;

 param c :=
1 15
2 25
3 17
4 13
5 18;

 param d :=
1 5
2 4
3 5
4 7
5 3;

 param M := 10000;

:

      problem.mod:21: syntax error in variable statement 
      Context: ...I } ; param d { i in I } ; var x { i in I } >= 0 ; var po :=
      MathProg model processing error
+5
1

( "" if LP).

. , :

M * yi > xi

M - ( xi).

:

  • if xi > 0, yi > 0, yi == 1, yi ( M ).
  • if xi == 0, , yi 0, yi, .

if.

+8

All Articles