10. python的优化算法包

  1. sciPy优化算法包
    sciPy中的optimize中的函数linprog使用simplex方法来求解线性规划问题,但是这个算法包不能求解整数规划问题。
    官方例子:
from scipy import optimize as op
import numpy as np
c=np.array([2,3,-5])
A_ub=np.array([[-2,5,-1],[1,3,1]])
B_ub=np.array([-10,12])
A_eq=np.array([[1,1,1]])
B_eq=np.array([7])
x1=(0,7)
x2=(0,7)
x3=(0,7)
res=op.linprog(-c,A_ub,B_ub,A_eq,B_eq,bounds=(x1,x2,x3))
print(res)

输出结果为:

     fun: -14.571428571428571
 message: 'Optimization terminated successfully.'
     nit: 2
   slack: array([3.85714286, 0.57142857, 6.42857143, 7.        , 0.        ])
  status: 0
 success: True
       x: array([6.42857143, 0.57142857, 0.        ])
  1. pulp算法包
    参考https://pythonhosted.org/PuLP/index.html。PuLP is an LP modeler written in python. PuLP can generate MPS or LP files and call GLPK[1], COIN CLP/CBC[2], CPLEX[3], and GUROBI[4] to solve linear problems.
  2. 调用
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容