我使用 docplex 包创建了一个优化模型。
这就是我定义决策变量的方式。
x = {(i.supply,i.demand,i.product): tm.integer_var(name='x_{0}_{1}_{2}'.format(i.supply,i.demand,i.product),ub=10000000) for i in cost_list}
使用tms = tm.solve()
我设法得到结果。
type
的 tms 是<class 'docplex.mp.solution.SolveSolution'>
. 我的输出如下。
solution for: transportation
objective: 60
x_1_3_a = 1
x_1_3_b = 3
我需要将其放入x_1_3_a = 1 & x_1_3_b = 3
数据框中(x,1,3,a,1
结果位于不同的列中)。有人可以建议我如何做到这一点。
---After the edit---
预期的输出熊猫数据框如下。
Var,supply,demand,product,qty
x,1,3,a,1
x,1,3,b,3