linprog优化失败。无法找到可行的起点

时间:2018-08-29 14:56:32

标签: optimization scipy

import numpy as np
from scipy.optimize import linprog
c.shape, c.dtype, c.sort(), c

它显示如下:

((108,),
 dtype('int64'),
 None,
 array([38093, 38100, 38101, 38103, 38105, 38108, 38110, 38114, 38116,
        38116, 38117, 38118, 38118, 38119, 38120, 38124, 38127, 38129,
        38131, 38132, 38133, 38135, 38141, 38141, 38142, 38145, 38146,
        38147, 38148, 38149, 38149, 38149, 38150, 38150, 38151, 38151,
        38152, 38152, 38153, 38154, 38156, 38157, 38157, 38160, 38163,
        38163, 38166, 38167, 38167, 38168, 38168, 38169, 38169, 38169,
        38170, 38172, 38174, 38175, 38177, 38178, 38178, 38178, 38178,
        38180, 38180, 38182, 38182, 38183, 38183, 38184, 38184, 38185,
        38188, 38188, 38189, 38191, 38192, 38192, 38193, 38195, 38196,
        38197, 38197, 38197, 38202, 38203, 38204, 38204, 38204, 38205,
        38206, 38209, 38211, 38211, 38213, 38214, 38216, 38218, 38218,
        38224, 38225, 38227, 38229, 38230, 38234, 38236, 38240, 38242]))
A_ub = np.array([c, -c])
b_ub = [np.ceil(np.mean(c) * 6), -np.floor(np.mean(c) * 6)]
A_eq = np.array([np.ones_like(c)])
b_eq = 6
res = linprog(c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=[0, 1], method='simplex', options={"disp": True})

它显示如下:

Optimization failed. Unable to find a feasible starting point.

感谢您运行并帮助我!

代码有什么问题?

我将linprog的方法更改为内点,然后显示打击:

res = linprog(c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=[0, 1], method='interior-point', options={"disp": True})
print(res)
con: array([-1.97238315e-09])
     fun: 229016.000075321
 message: 'Optimization terminated successfully.'
     nit: 4
   slack: array([9.99924679e-01, 7.53210043e-05])
  status: 0
 success: True
       x: array([0.05594776, 0.05591185, 0.05590681, 0.05589631, 0.05588602,
       0.05587049, 0.05586021, 0.05583966, 0.05582939, 0.05582939,
       0.05582415, 0.05581912, 0.05581912, 0.05581366, 0.05580886,
       0.05578811, 0.05577283, 0.05576257, 0.05575232, 0.05574708,
       0.05574185, 0.0557316 , 0.05570086, 0.05570086, 0.05569585,
       0.05568016, 0.05567537, 0.05567014, 0.05566492, 0.05565969,
       0.05565969, 0.05565969, 0.05565468, 0.05565468, 0.05564968,
       0.05564968, 0.05564445, 0.05564445, 0.05563945, 0.05563422,
       0.055624  , 0.05561899, 0.05561899, 0.05560333, 0.05558811,
       0.05558811, 0.05557267, 0.05556768, 0.05556768, 0.05556268,
       0.05556268, 0.05555746, 0.05555746, 0.05555746, 0.05555225,
       0.05554226, 0.05553183, 0.05552662, 0.05551664, 0.05551143,
       0.05551143, 0.05551143, 0.05551143, 0.05550122, 0.05550122,
       0.05549103, 0.05549103, 0.05548604, 0.05548604, 0.05548083,
       0.05548083, 0.05547562, 0.05546044, 0.05546044, 0.05545524,
       0.05544527, 0.05544007, 0.05544007, 0.05543486, 0.05542468,
       0.05541992, 0.0554145 , 0.0554145 , 0.0554145 , 0.05538916,
       0.05538396, 0.05537899, 0.05537899, 0.05537899, 0.05537357,
       0.05536882, 0.05535345, 0.0553435 , 0.0553435 , 0.05533312,
       0.05532793, 0.05531799, 0.0553076 , 0.0553076 , 0.05527736,
       0.05527195, 0.05526202, 0.05525165, 0.05524669, 0.0552264 ,
       0.05521626, 0.05519599, 0.05518585])

但是结果不是我的需要。我只希望x数组为1或0。

1 个答案:

答案 0 :(得分:0)

cvxopt解决了我的问题。这么快