- 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. ])
- 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. - 调用