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. enter image description here

  • $\begingroup$ 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. $\endgroup$
    – A.Omidi
    Mar 6, 2023 at 12:59
  • $\begingroup$ 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? $\endgroup$
    – Sam
    Mar 6, 2023 at 13:18
  • $\begingroup$ Please, modify your question to get the right advice. $\endgroup$
    – A.Omidi
    Mar 6, 2023 at 13:38
  • $\begingroup$ I just edit the question. Sorry for getting you confused $\endgroup$
    – Sam
    Mar 6, 2023 at 13:43
  • $\begingroup$ 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!! $\endgroup$
    – A.Omidi
    Mar 6, 2023 at 13:49

1 Answer 1


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\}$

  • $\begingroup$ As the $\alpha$ is a parameter one can easily restrict the values of the variables on it by using an if-then/else statement. $\endgroup$
    – A.Omidi
    Mar 6, 2023 at 13:29
  • $\begingroup$ 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? $\endgroup$
    – Sam
    Mar 6, 2023 at 13:34
  • $\begingroup$ @Sam please check the answer if it works. $\endgroup$ Mar 6, 2023 at 13:57
  • $\begingroup$ 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? $\endgroup$
    – Sam
    Mar 6, 2023 at 14:18
  • $\begingroup$ Yes that's correct $\endgroup$ Mar 6, 2023 at 14:19

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.