# How to convert this if-clause condition to a linear programming optimization problem

Let’s consider the following conditional constraint. w is a set of input data. x,y(1:3),d(1:3) are the decision variables.

``x= 3.9         % optimization variable (one can iterate over it 0<x<5 ) for i=1:3     if w[i]-x <=0          d[i]=x-w[i];         y[i]= w[i]     else         d[i]=0         y[i]=w[i]     end end ``

The linear expression of the above constraint can be expressed as follows:

Max $$40𝑥+15𝑦_1−30𝑑_1+15𝑦_2−30𝑑_2+15𝑦_3−30𝑑_3$$

$$x_i – y_i <= d_i, i=1:3$$

$$y_i = w_i , i=1:3$$

$$0 <= x <= 5$$

$$y,d_i>= 0, i=1:3$$

However, I want to change the conditional constraint as follows:

``for i=1:3         if w[i]-x <=0              d[i]=x-w[i];             y[i]= w[i]         else             d[i]=0             y[i]=x    % The change         end end ``

How can I modify the linear optimization problem to satisfy the new condition?!