如何保存linprog解决方案的部分内容

时间:2016-10-15 16:12:00

标签: scipy

我通过索引for循环中的每个问题来解决使用linprog的一系列线性编程问题:

>>> def gen1():
...     t = (yield)[0]
...     print 'Received: {!r}'.format(t)
...     yield False
...
>>> g = gen1()
>>> next(g)
>>> g.send('foo')
Received: 'f'
False

我想保存一个列表(仍然在i上索引)函数最小化结果和显示变量值的数组。我想我需要在for-loop中添加像minfval [i] = ???和xval [i] = ???,但实际上我不知道如何从linprog提供的结果中提取这些值。有什么建议?非常感谢。

1 个答案:

答案 0 :(得分:0)

考虑阅读docs,因为它非常清楚地解释了linprog究竟返回的内容。

好处是,您实际上已经将这些值与代码一起存储,因为您存储的是整个 scipy.optimize.OptimizeResult

现在只需要访问它:

if (!req.body["task"]) {
    res.sendStatus(403);
} else {
    fs.appendFile("tasks.json", JSON.stringify(req.body));
}  

您还应该查看字段var your_object = {"task":"","important":"true","urgent":"false","quadrant":"2"}; console.log(!JSON.stringify(your_object["task"])); var your_object = {"task":"hello","important":"true","urgent":"false","quadrant":"2"}; console.log(!JSON.stringify(your_object["task"])); var your_object = {"task":"","important":"true","urgent":"false","quadrant":"2"}; console.log(!your_object["task"]); var your_object = {"task":"hello","important":"true","urgent":"false","quadrant":"2"}; console.log(!your_object["task"]);,以确保安全!

提取linprog结果中包含的文档(上面的链接):

from scipy.optimize import linprog
for i in range(1,N):
    sol[i] = linprog(coa3[N][0], A_ub = coa4[i], b_ub = chvneg[i],  options=      {"disp": True})

# iterate over solution-vectors
for i in range(1,N):
    print(sol[i].x)

# iterate over objectives
for i in range(1,N):
    print(sol[i].fun)