基于统一api的python线性规划求解器
lpsolvers的Python项目详细描述
此模块提供单个函数solve_lp(c, G, h, A, b, solver=X) 使用solver关键字参数选择后端解算器。线性的 它解决的程序采用标准格式:
min. c^T x s.t. G x <= h A x == b
其中向量不等式按坐标表示。
示例
要求解线性程序,只需构建定义它的矩阵并调用 solve_lp函数:
fromnumpyimportarrayfromlpsolversimportsolve_lpc=array([1.,2.,3.])G=array([[1.,2.,-1.],[2.,0.,1.],[1.,2.,1.],[-1.,-1.,-1.]])h=array([4.,1.,3.,2.])print"LP solution:",solve_lp(c,G,h)
此示例输出解决方案[2.2 -0.8-3.4]。