Python PULP排序结果

问题描述 投票:0回答:1

我出于线性优化的原因而使用PULP。一切正常,我正在获得结果,并且正在打印每个结果:

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()函数对结果进行排序,但出现错误:

'

我也尝试过这个opt_P.sort(key=lambda s: s[1]),这个也:opt_P.sort(key=lambda s: s["name"])但出现错误:

'LpVariable'对象不可下标

您能支持我解决这个问题吗?

python sorting pulp
1个回答
0
投票

您可以指定要使用的键功能。

© www.soinside.com 2019 - 2024. All rights reserved.