我使用纸浆的线性优化的原因。一切正常,我正在得到结果,我正在打印每一个结果:
for i in range (0, len(opt_P)):
print (opt_P[i].name + " = " + str(opt_P[i].varValue))
输出如下所示:
0 = 20.0
1 = 20.0
10 = 1200.0
11 = 1200.0
2 = 20.0
3 = 20.0
4 = 20.0
5 = 20.0
6 = 1200.0
7 = 1200.0
8 = 45.895992
9 = 1200.0
我想用opt_P.sort()
函数对结果进行排序,但得到错误:
'<' not supported between instances of 'LpVariable' and 'LpVariable'
我还尝试了这个opt_P.sort(key=lambda s: s[1])
,这个也:opt_P.sort(key=lambda s: s["name"])
,但出现了错误:
'LpVariable' object is not subscriptable
你能支持我解决这个问题吗
您可以指定要使用的键函数
例如:
或者如果你想把它们作为整数排序
相关问题 更多 >
编程相关推荐