- sciPy優(yōu)化算法包
sciPy中的optimize中的函數(shù)linprog使用simplex方法來求解線性規(guī)劃問題玉控,但是這個算法包不能求解整數(shù)規(guī)劃問題。
官方例子:
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. - 調用