How to add a contraint which limits the product of two tuples?
OngoingHi I have a production planning problem. I have durations and an assignment variable x to it. My indexes are i for station, j for types and k for tasks. What is important is that the assignment variable x is fractional number between [0,1]. I now want to add a contraint which says the duration for e.g. tuple (1,1,1) is 100 but the assignment x(1,1,1) is only 0.5 so that the task with exact this combination of tuple lasts 50 seconds. On the Right side I now want to say that all of these combinations are bigger than at least a value Z. How can I do that? My code below:
stations = [1,2]
C = 200
Z = 50
tasks = ['w01','w02','w03']
durations = {(1,'TC','w01'):150, (1,'TC','w02'):115, (1,'TC','w03'):135,
(1,'OC','w01'):150, (1,'OC','w02'):115, (1,'OC','w03'):135,
(2,'TC','w01'):150, (2,'TC','w02'):115, (2,'TC','w03'):135,
(2,'OC','w01'):150, (2,'OC','w02'):115, (2,'OC','w03'):135}
successors = {'w01':[],'w02':['w01'],'w03':['w02']}
types = ['TC','OC']
f_cost = {(1,'TC'): 50000,(1,'OC'): 40000,
(2,'TC'): 50000,(2,'OC'): 40000}
edges, v_cost = gp.multidict({
(1,'TC','w01'): [15],
(1,'TC','w02'): [30],
(1,'TC','w03'): [45],
(2,'TC','w01'): [15],
(2,'TC','w02'): [30],
(2,'TC','w03'): [45],
(1,'OC','w01'): [50],
(1,'OC','w02'): [80],
(1,'OC','w03'): [110],
(2,'OC','w01'): [50],
(2,'OC','w02'): [80],
(2,'OC','w03'): [110]
})
x_arcs = [(i,j,k) for i in stations for j in types for k in tasks]
y_arcs = [(i,j) for i in stations for j in types]
m = gp.Model()
y = m.addVars(y_arcs, vtype = GRB.BINARY, name = 'y')
x = m.addVars(x_arcs, vtype = GRB.CONTINUOUS, name = 'x',ub=1)
m.addConstrs(quicksum(x[i,j,k] for i in stations for j in types) == 1 for k in tasks)
m.addConstrs(quicksum(durations[i,j,k]*x[i,j,k] for j in types for k in tasks) <= C for i in stations)
m.addConstrs(quicksum(y[i,j] for j in types) == 1 for i in stations)
m.addConstrs(quicksum(i*x[i,j,k] for i in stations for j in types) >=
quicksum(i*x[i,j,l] for i in stations for j in types)
for k in tasks for l in successors[k] if k!= 'w01')
And than the objective function etc. I tried to implement this with that constraint:
m.addConstrs(quicksum(durations[i,j,k]*x[i,j,k] for j in types) >= Z*x[i,j,k] for i in stations for k in tasks)
And also with all kind of variations on the indexes, but it clearly doenst do the thing I want to if I look up at the .sol data. Could anyone help out with this? Thanks

Looking from afar it seems to me that there is a problem with your \(j\) index  perhaps the forloop is in the wrong place?
Could you show the mathematical formulation of the constraint you would like to implement?
Best regards
Jonasz0 
Jonasz Staszek that is the mathematical formulation. Maybe I could also just say >= Z I am not really sure about that. What I want is that no durations that are made at once (so on one specific combination of (i,j,k) ) are shorter than the value of Z. Thanks
0 
How do you know which \(j\) index is to be used for the \(x\)variable on the righthand side of your constraint? This is probably the reason for your difficulties.
I am not sure if I understood the context of your problem correctly, but it seems to me that the righthand side of your inequality should be just \(Z^{min}\). You will then ensure that the same righthand side term is applied to all the constraints which you mention.
Best regards
Jonasz0 
If I write just Z^min for the RHS, how can I avoid the case for the tuple x beeing 0, than the statement will be 0 >= Z^min which will be false so the model will be infeasible. I tried to do something like
m.addConstrs(quicksum(durations[i,j,k]*x[i,j,k] for j in types for i in stations for k in tasks) >= Z_min for x[i,j,k] != 0)
That doesnt work and gives syntax error. The problem is that x is a tupledict and I dont want the tupledict itself but only the value on the specific points. How can I tell the program that the constraint is only valid when x is not 0
0
Please sign in to leave a comment.
Comments
4 comments