I have a value x, which is a combination of decision variables.
I need to calculate a cost, which only triggers if x > 100. So cost = MAX(x – 100, 0) * 20.
Is there any way to do this in linear programming?
I’ve tried creating two binary variables (y1 & y2), in which y1 = 1 when x <= 100 & y2 = 1 when x > 100 & y1 + y2 = 1, from this website – https://uk.mathworks.com/matlabcentral/answers/693740-linear-programming-with-conditional-constraints. However, my excel solver is still giving non-linearity complaints…
Any advice on how I can fix this?
>Solution :
It is not possible to use linear programming to solve a problem with a cost function that has a piecewise linear structure, like the one you have described. This is because linear programming only allows for linear objective functions and constraints, and the piecewise nature of your cost function means that it is not a linear function.
One way to approach this problem would be to use a mixed integer linear programming (MILP) solver, which allows for integer variables in the objective function and constraints. In your case, you could use a binary variable to represent whether or not the cost function should be applied, and then use this binary variable to control the application of the cost function in the objective function. Here is an example of how this could work:
minimize cost = 20 * x * y
subject to:
x <= 100 * (1 - y) // x must be <= 100 if y is 0
x >= 100 * y // x must be >= 100 if y is 1
y in {0, 1} // y must be 0 or 1
In this example, the binary variable y is used to control whether or not the cost function is applied to x. When y is 0, the cost function is not applied, and the value of x is allowed to be anything less than or equal to 100. When y is 1, the cost function is applied, and the value of x must be greater than or equal to 100.
You can find more information about mixed integer linear programming and how to solve MILP problems using a solver like Gurobi or CPLEX in the documentation for those solvers.