线性优化不遵守约束

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

我有一个简单的线性问题,需要遵守特定的边界和约束,但是在运行 scipy.linprog 时不遵守约束。

对于我的目标函数,我使用列中的值作为我的系数。

c = [-df['A'][0], 
              -df['A'][1],
              -df['A'][2],
              -df['A'][3],
              -df['A'][4],
              -df['A'][5],
              -df['A'][6],
              -df['A'][7],
              -df['A'][8],
              -df['A'][9]
              ]

对于我的约束,我使用另一列的值作为我的系数

A = [df['B'][0], 
              df['B'][1],
              df['B'][2],
              df['B'][3],
              df['B'][4],
              df['B'][5],
              df['B'][6],
              df['B'][7],
              df['B'][8],
              df['B'][9]
              ]

不等式值就是这个除法

b = [np.sum(df2['C'] * df2['D'] * df2['E']) / (9.12*12)]
res = linprog(c=c, A_ub=A, b_ub=b, bounds=bounds, options={'dips': True, 'tol': 1e-8})

我的目标函数是找到最大化

df['A']*vector
总和的最佳向量,同时我尊重
df['B']*vector = b
的总和。

我也试过使用“单纯形”和“内点”。

When i tried this implementation using simplex i got the result:
 message: Optimization terminated successfully.
 success: True
  status: 0
     fun: -104315467.86366615
       x: [ 1.000e+00  1.000e+00  1.000e+00  1.000e+00  1.000e+00
            1.000e+00  1.000e+00  1.000e+00  1.000e+00  1.000e+00]
     nit: 11

哪个不是最优的,也不尊重我的约束。

python optimization scipy linear-programming
© www.soinside.com 2019 - 2024. All rights reserved.