为什么运行时间看起来太长了?
Why does the runtime seems too long?
我正在尝试 运行 我在 Jupyter notebook 中的代码,但 运行 时间似乎无穷无尽,然后我的笔记本电脑突然挂起。你能告诉我我的代码有什么问题吗? (这里为了更好理解,我把数据弄得非常小)
customers = [1,2,3]
nodes = [3,5,6,8,10,14,18]
edges = [(3,6),(8,18),(8,3),(8,10),(8,7),(14,3),(14,5),(14,7),(18,3),(18,8),(18,14)]
demands = {1:200, 2:300, 3:500}
origins = {1:18, 2:8, 3:14}
destinations = {1:6, 2:10, 3:5}
prio_start = {1: [3, 7, 1, 2, 5, 4, 6], 2: [6, 4, 2, 3, 7, 1, 5], 3: [1, 2, 3, 4, 6, 7, 5]}
y_set_init = []
dict_path_nodes = {}
for k in customers:
currentnode = origins[k]
path_nodes = [currentnode]
path_edges = []
prio_init = prio_start[k]
stop = False
while not stop:
for (e, g) in edges:
if e == currentnode:
max_value = max(prio_init)
max_index = prio_init.index(max_value) + 1
nextnode = max_index
path_nodes.append(nextnode)
path_edges.append((currentnode, nextnode))
if (currentnode, nextnode) not in y_set_init:
y_set_init.append((currentnode, nextnode))
currentnode = nextnode
if currentnode == destinations[k]:
stop = True
dict_path_nodes[k]= path_nodes
print(dict_path_nodes)
我是否可能错过了循环的一些“中断”?
如果 currentnode = 2,则循环变为无限循环(因为 e 永远不会等于 2)。而 currentnode 可能是 2,因为它被设置为 prios 的索引,而不是它们的值?请验证您的逻辑,可能您想在某处获取此列表的值。
我正在尝试 运行 我在 Jupyter notebook 中的代码,但 运行 时间似乎无穷无尽,然后我的笔记本电脑突然挂起。你能告诉我我的代码有什么问题吗? (这里为了更好理解,我把数据弄得非常小)
customers = [1,2,3]
nodes = [3,5,6,8,10,14,18]
edges = [(3,6),(8,18),(8,3),(8,10),(8,7),(14,3),(14,5),(14,7),(18,3),(18,8),(18,14)]
demands = {1:200, 2:300, 3:500}
origins = {1:18, 2:8, 3:14}
destinations = {1:6, 2:10, 3:5}
prio_start = {1: [3, 7, 1, 2, 5, 4, 6], 2: [6, 4, 2, 3, 7, 1, 5], 3: [1, 2, 3, 4, 6, 7, 5]}
y_set_init = []
dict_path_nodes = {}
for k in customers:
currentnode = origins[k]
path_nodes = [currentnode]
path_edges = []
prio_init = prio_start[k]
stop = False
while not stop:
for (e, g) in edges:
if e == currentnode:
max_value = max(prio_init)
max_index = prio_init.index(max_value) + 1
nextnode = max_index
path_nodes.append(nextnode)
path_edges.append((currentnode, nextnode))
if (currentnode, nextnode) not in y_set_init:
y_set_init.append((currentnode, nextnode))
currentnode = nextnode
if currentnode == destinations[k]:
stop = True
dict_path_nodes[k]= path_nodes
print(dict_path_nodes)
我是否可能错过了循环的一些“中断”?
如果 currentnode = 2,则循环变为无限循环(因为 e 永远不会等于 2)。而 currentnode 可能是 2,因为它被设置为 prios 的索引,而不是它们的值?请验证您的逻辑,可能您想在某处获取此列表的值。