代码和运行结果如下所示
from network_graph import graph_list_2
import time
start =time.clock()
graph_list = graph_list_2
n = 10
workload = np.random.randint(0,30,size=n)
x = [0]*n
best_x = [0]*n
min_cost = n+1
def conflict(k):
global n,x,bext_x,min_cost
cap = [80]*n
for i in range(len(x[:k+1])):
cap[x[i]] = cap[x[i]]-workload[i]
for i in range(n):
if cap[i] < 0:
return True
cost = len(set(x[:k+1]))
if 0 < min_cost <= cost:
return True
return False
def mec_pla(k):
global n,graph_list,x,min_cost,best_x
if k>=n:
cost = len(set(x[:k]))
if cost <= min_cost:
best_x = x[:]
min_cost = cost
print(x)
else:
for node in graph_list[k]:
x[k] = node
if not conflict(k):
mec_pla(k+1)
mec_pla(0)
print(best_x)
print(min_cost)
end = time.clock()
print('Running time: %s Seconds'%(end-start))
请问该如何修改呢
错误提示比较清楚,类型错误,generator对象不能用下标
对象不是迭代器,生成器不能直接迭代获取
先找这个文件,错误在这里报的