title: How can I write an if condition for my variable in GLPK?
body: <p>Here is my full problem:</p>
  
  <p><img src="https://i.stack.imgur.com/AZKEg.png" alt="enter image description here"></p>
  
  <p>Information:</p>
  
  <p>*Max. total investment: $125</p>
  
  <p>*Pay-off is the sum of the units bought x pay-off/unit</p>
  
  <p>*Cost per investment: Buy-in cost + cost/unit x number of units if you buy at least one unit</p>
  
  <p>*The cost is sum of the costs per investment</p>
  
  <p>Constraints:</p>
  
  <p>*You may not invest in both 2 and 5.</p>
  
  <p>*You may invest in 1 only if you invest at least one of 2 and 3.</p>
  
  <p>*You must invest at least two of 3,4,5.</p>
  
  <p>*You may not invest more than max number of units.</p>
  
  <p>Problem: Maximize profit : pay-off - cost</p>
  
  <pre><code> xi: # of units i ∈ {1,2,3,4,5}
   yi=1 if xi&gt;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 &lt;= 1
   y1&lt;= y2+y3
   y3+y4+y5 &gt;= 2
   x1&lt;=5, x2&lt;=4, x3&lt;=5, x4&lt;=7, x5&lt;=3
   cost&lt;=125
  </code></pre>
  
  <p>Here is my question:</p>
  
  <p>For example I have this binary variable y</p>
  
  <pre><code> yi=1 if xi&gt;0 else yi=0  and i ∈ {1,2,3,4,5}
  </code></pre>
  
  <p>I declared i as a data set</p>
  
  <pre><code> set I;
  
   data;
  
   set I := 1 2 3 4 5;
  </code></pre>
  
  <p>I don't know how to add if else condition to y variable in glpk. Can you please help me out?</p>
  
  <p>My modelling :</p>
  
  <pre><code> set I;
  
   /*if x[i]&gt;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} &gt;=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]&lt;=1;
   s.t. c2: y[1]&lt;y[2]+y[3];
   s.t. c3: y[3]+y[4]+y[5]&gt;=2;
   s.t. c4: x[1]&lt;=5 
       x[2]&lt;=4
       x[3]&lt;=5
       x[4]&lt;=7
       x[5]&lt;=3;
  
   s.t. c5: cost &lt;=125;
   s.t. c6{i in I}: M * y[i] &gt; 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;
  </code></pre>
  
  <p>I am getting this syntax error:</p>
  
  <pre><code>      problem.mod:21: syntax error in variable statement 
        Context: ...I } ; param d { i in I } ; var x { i in I } &gt;= 0 ; var po :=
        MathProg model processing error
  </code></pre>