Problem: There is an order to fabricate some products of total number, let's say 200 (all products are the same). We have some number of factories, let's say 5. Every factory has different number of production lines (every line performs differently (speed of production). One of main constraints is that all factories must finish together at the same time (there is an epsilon for some small deviation).
### [Factory ID, Number Of Lines, Performance(Products per line per month)]
factories = {
['f1', 10, 2],
['f2', 3, 5],
['f3', 4, 10],
['f4', 8, 11],
['f5', 11, 17]}
order_to_fabricate = 200 # (products)
for factory in factories:
is_factory_enabled = model.NewBoolVar(f'{factory[0]}')
lines_per_factory_enabled = model.NewIntVar(0, factory[1], f"line per factory: {factory[0]}")
products_per_factory = model.NewIntVar(0, order_to_fabricate, f"products per factory: {factory[0]}")
model.Add(products_per_factory >= lines_per_factory_enabled)
total_fab_rate = model.NewIntVar(0, factory[1]*factory[2], f"Production rate per factory: {factory[0]}") #upper bound than can be produced by factory
model.AddMultiplicationEquality(total_fab_rate, [lines_per_factory_enabled, factory[2]])
fabrication_duration = model.NewIntVar(0, int(round(order_to_fabricate / factory[2])), f"Production duration") #upper bound set like single line will serve total number of products
model.AddDivisionEquality(fabrication_duration, products_per_factory, total_fab_rate) # total_fab_rate can be zero :(
factory_enabled.append(is_factory_enabled)
number_of_lines.append(lines_per_factory_enabled)
number_of_products.append(products_per_factory)
factory_er_for_all_lines.append(total_fab_rate)
factory_er_duration.append(fabrication_duration)
# some constraints here...
The thing is that when the factory is not enabled number of lines is zero and fabricated number of products is also zero. AddDivisionEquality
gets ZERO
in the denominator and this constraint doesn't have the OnlyEnforceIf
option.
I'm really stuck on how to avoid this issue. I want the model to select specific factories (also with some other constraints), but not all of them which is why I have is_factory_enabled
.
Is there any approach to overcome such an issue?