line1 | line2 | line3 | line4 | |
---|---|---|---|---|
A | 2.3 | 0 | 3.1 | 0 |
B | 0 | 4 | 2.2 | 0 |
C | 1.1 | 0 | 0 | 4.6 |
Let's say after optimization with certain constraints, my model will generate an optimal production allocation table similar to above. A, B, C are the three product types and the matrix displays the number of hours needed for each production line in order to finish the demand.
I need to add another constraint which allows only one non-integer hour amount for each of the products. what is the easiest way or logic to do this? Please show by model.addVars() and model.addConstrs() if possible.
Update: This is what I wrote according to the answer by Rob:
y = edm.addVars(lines, products, vtype=GRB.INTEGER)
z = edm.addVars(lines, products, vtype=GRB.BINARY)
for line in lines:
for product in products:
constraint1_1 = edm.addConstr(
(
#blocks[line, product] - y[line, product] >= - z[line, product]
y[line, product] - blocks[line, product] <= z[line, product]
),
name = 'constraint 1.1'
)
constraint1_2 = edm.addConstr(
(
blocks[line, product] - y[line, product] <= z[line, product]
),
name = 'constraint 1.2'
)
constraint2 = edm.addConstrs(
(
quicksum(z[line, product] for line in lines) <= 1 for product in products
),
name = 'constraint 2'
)
But my model optimization keeps running and has not given a solution for 2 hours. Any ideas what could be the issue? Thanks