Creating model takes too much time
Ongoing
Hi All
I have a problem in a big scale network modeling.
I write the sets as
S = [s for s in range(1, 7)]
S_ = [s_ for s_ in range(1, 7)]
T = [t for t in range(0, 145)]
T_ = [t_ for t_ in range(0, 145)]
T1 = [t1 for t1 in range(0, 145)]
T1_ = [t1_ for t1_ in range(0, 145)]
P = [p for p in range(1, 3)]
P_ = [p_ for p_ in range(1, 3)]
K = [k for k in range(0, 17)]
K_ = [k_ for k_ in range(0, 17)]
L = [l for l in range(1, 14)]
L_ = [l_ for l_ in range(1, 14)]
I write the variables as
x = m.addVars(L, P, K, arc_set.keys(), vtype=GRB.BINARY, name="x")
I write the constraints as
for s in S:
for s_ in S_:
for t in T:
if s_ == s + 1:
m.addConstr(
gp.quicksum(x[l, p, kt, s, s_, t1, t1_] for l in L for p in P for kt in KT for t1 in T1 for t1_ in T1_
if stop_pattern[kt, s] == 1 and t1_ == t1 + real_runtime[p, kt, s, s_] and (s, s_, t1, t1_) in segment_arc.keys() and t <= t1 < t + ff_headway[s]),
GRB.LESS_EQUAL,
1,
'fafa_headway')
It takes 2000 seconds for Gurobi to creat these constraints and I dont know why. Is there any faster way?
1

Hi,
These are many for loops that you have and a lot of conditions. Unfortunately, your code is not selfcontained so I could not run it to do some tests. However, you should some small improvement by changing this
for s in S:
for s_ in S_:
for t in T:
if s_ == s + 1:into this
for s in S:
for s_ in S_:
if s_ == s + 1:
for t in T:Additionally, the conditions for the quicksum seem to be quite complicated. Are you sure you have the best data structures for what you want to do? Is there any chance you can come up with a model that does not have a variable with 7 indices? How many x variables do you have? This seems to be something about arcs? So is this a dense network, do all arcs between two nodes exist? Can you represent this in a sparse way?
Best,
Sonja
0
Please sign in to leave a comment.
Comments
1 comment