Modeling problem about using variable value for indexing and conditional summation
AnsweredDear all,
Please have a look at the example below. This is not programmatically correct, but I want to show the idea and get your thoughts on implementing it in Gurobi.
start_time = {n: t for n, t in the schedule.items()} # dictionary containing action start times at various nodes
tx = m.addVars(nodes, lb=0) # Decision variable takes the duration of activity at each node
cx = m.addVars(time_horizon, vtype=GRB.BINARY) # An activity takes place at time t
Now I want to write a constraint for cx. Nodes is the set of all nodes.
for j in nodes:
start = time[j]
for t in range(start, start + tx[j]):
m.addConstr[cx[t] == 1]
Of course, this does not work because I cannot have a variable for index subsetting like this. But do you have any idea as to how I can make it work? A pseudo-example might be super helpful. Thank you.
0
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
I solved this problem based on the answer given in Adding Consecutive Shifts COnstraint – Gurobi Help Center.
0
Post is closed for comments.
Comments
2 comments