# Converting a piecewise function to a linear equation as a constraint

The value of one of the variable of my model (alpha_1) is given by a piecewise function. Each element of the piecewise depends on the value of some other binary decision variables (X1, x2, x3).

I'd like to know how I can express this piecewise function as some linear equations within the constraints to make sure that the right value has been chosen. Please below find the piecewise function.

• Are you sure $\alpha_{1}$ is a parameter? A parameter is pre-defined while the value of the variables depends on the problem-solving process. Mar 6 at 12:59
• You are right. what a stupid error. Alpha then counts as variable. So, if I use big-M to convert this piecewise function into some equations, then the whole model wold become non-linear. Right?
– Sam
Mar 6 at 13:18
• I just edit the question. Sorry for getting you confused
– Sam
Mar 6 at 13:43
• Just out of curiosity, are you sure the above picture adopts your below comment? Basically, the right hand side of the second and third statements at the if statement was not correct. i.e., x1 +x2 =2 and x1+x2+x3=1.. It seems the modified picture does not change!! Mar 6 at 13:49

For the if statements try this
$$x_1-(x_2+x_3) \le w_1$$
$$x_2-x_3 \le w_2$$
$$x_3 \le w_3$$
$$w_1 +w_2+w_3 =1$$
where $$w$$ are binary. $$\alpha = 100w_1 +200w_2 + 300w_3$$

As question now stands I d modify answer as
$$x_1 +x_2+x_3 = w_1+2w_2+3w_3$$
$$\sum_i w_i =1$$
You may also need
$$\sum_{i=k+1}^n x_i \le Mx_k$$ for $$k=\{1,2,...n-1\}$$

• As the $\alpha$ is a parameter one can easily restrict the values of the variables on it by using an if-then/else statement. Mar 6 at 13:29
• Many thanks for the answer. I made a mistake in the if statement. Basically, the right hand side of the second and third statements at the if statement was not correct. i.e., x1 +x2 =2 and x1+x2+x3=1. May I ask you how this affect on the formula you provided earlier?
– Sam
Mar 6 at 13:34
• @Sam please check the answer if it works. Mar 6 at 13:57
• Many thanks Sutanu. As far as I see, there might be one situation that these constraints could not handle. That is, the situation where x1 and x3 would take the value of 1. The last constraint you added(sum of xi<= Mx_k) is to take care of this issue?
– Sam
Mar 6 at 14:18
• Yes that's correct Mar 6 at 14:19