从PuLP迁移到Scipy

2024-09-29 23:15:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我用纸浆来解决一些最小化问题 有约束,上下界。 它非常简单和干净。在

但我只需要用小精灵和小精灵 模块。在

我在读: http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html

Constrained minimization of multivariate scalar functions

但我有点迷路了。。。一些优秀的灵魂可以发布一个小例子 这是西皮的肉酱吗?在

提前谢谢。 毫米

from pulp import *

'''
Minimize        1.800A + 0.433B + 0.180C
Constraint      1A + 1B + 1C = 100
Constraint      0.480A + 0.080B + 0.020C >= 24
Constraint      0.744A + 0.800B + 0.142C >= 76
Constraint                            1C <= 2
'''

...

Tags: 模块orghttpdocsdochtmlscipytutorial
1条回答
网友
1楼 · 发布于 2024-09-29 23:15:56

考虑以下因素:

^{1}$

需要注意的是,eq条件应该等于零,而ineq函数对于大于零的任何值都将返回true。在

我们获得:

^{pr2}$

再次检查等式:

output = np.array([ 40.3,  57.7,   2. ])

np.sum(output) == 100
True
round(np.sum(p*output),8) >= 24
True
round(np.sum(e*output),8) >= 76
True

舍入来自两点精度误差:

np.sum(p*output)
23.999999999999996

相关问题 更多 >

    热门问题