Defining a constraint on time when time is an index to other variables
Awaiting user inputDear Community,
I have defined the following variables.
# Binary indicator variable: 1 if bus b is leaving node i at time t, else 0
n0 = model.addVars(n_cars, n_nodes, time_steps, vtype=GRB.BINARY, name='n0')
# Binary indicator variable: 1 if bus b is arriving at node i at time t, else 0
n1 = model.addVars(n_cars, n_nodes, time_steps, vtype=GRB.BINARY, name='n1')
# Binary indicator variable: 1 if bus i is at node k at time t at node k, else 0
x = model.addVars(n_cars, n_nodes, time_steps, vtype=GRB.BINARY, name='x')
# Binary variable: 1 if bus i moves from node j to k at time t.
z = model.addVars(n_cars, n_nodes, time_steps, vtype=GRB.BINARY, name='z')
# Integer variable: Waiting time (incl. charging time) of bus b at node k, after arriving at the node at time t.
theta = model.addVars(n_cars, n_nodes, time_steps, lb=0, name="theta")
Now I want to write a constraint that says: "The departure time of any car from any node is equal to the arrival time plus the waiting time at that node".
But so far I was not able to find a way to write this, because time steps are indices to the variables I have defined.
I also cannot define a new variable for the time, e.g., Continuous variable s(n_cars, n_nodes) is the arrival time of a car at a node, or something similar.
This is because I do not know in advance how many times a vehicle might want to pass through or wait at a particular node.
Do you have any suggestions for me?
Thank you.
-
Official comment
This post is more than three 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. -
But so far I was not able to find a way to write this, because time steps are indices to the variables I have defined.
The post use a decision variable as an index discusses one possibility of defining such variables.
I also cannot define a new variable for the time, e.g., Continuous variable s(n_cars, n_nodes) is the arrival time of a car at a node, or something similar.
This is because I do not know in advance how many times a vehicle might want to pass through or wait at a particular node.I am not sure I understand the issue here. You could define a continuous variable s(n_cars, n_nodes) with some fixed upper and lower bounds defining the min/max waiting time and then let the solver decide what the optimal solution value is. Could you elaborate a bit more on this?
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments