Reputation: 11
My MIP problem requires semi-continuous variables :
Problem formulation states that all goods could be either produced at Minimum Order Quantity (MOQ) or as 0, which could be summarized as:
Xi >= MOQi or Xi = 0,
where Xi is a decision variable for the amount of "i" goods to be produced.
This is typically solved by introducing a binary variable Yi which can only take values 1 and 0:
X = solver.NumVar(lbound= MOQ, ubound = 'infinity', name = 'Xi')
Y = solver.IntVar(lbound = 0, ubound = 1, name = 'Yi')
That combination of variables is then used in all constraints and objective function:
as a product.
(e.g. X1*Y1 + ... + Xi*Yi <= 1000)
Another option is to make Xi semi-continuous, able to have values 0 or >=MOQ
I couldn't find a way to implement any of those options in current OR-Tools python wrapper. The rest of the problem (production planning) is nicely expressed as a linear problem (with option to make some of the variables Integer) and I would ideally like to have MOQ also be a parameter that could be turned on/off.
Could anyone give any suggestions on how to achieve that? May be recommend another instrument?
I obviuosly tried to just do products anyway:
x = solver.NumVar(0.0, infinity, 'x')
y = solver.IntVar(0, 1, 'y')
solver.Add(5 * x * y <= 170.5)
And got:
/usr/local/lib/python3.8/dist-packages/ortools/linear_solver/linear_solver_natural_api.py in init(self, expr, coef)
177 self.__coef = coef
178 else:
--> 179 raise TypeError
180
181 def str(self):
TypeError:
Upvotes: 1
Views: 232
Reputation: 11064
alternatively, if your problem is integral, CP-SAT supports complex domains natively.
x = model.NewIntVarFromDomain(cp_model.Domain.FromIntervals([0, 0], [5, 100]))
Upvotes: 1