文章目录

  • 线性规划
    • scipy
    • 例子

线性规划

线性规划(Linear programming,简称LP),是运筹学中研究较早、发展较快、应用广泛、方法较成熟的一个重要分支,它是辅助人们进行科学管理的一种数学方法。研究线性约束条件下线性目标函数的极值问题的数学理论和方法。英文缩写LP。

线性规划模型的一般形式:

建立线性规划模型的一般步骤:

1.根据问题所要达到目的的因素找到决策变量;
2.由决策变量和所要达到目的之间的函数关系确定目标函数;
3.由决策变量所受的限制条件确定决策变量所要满足的约束条件。

scipy

scipy.optimize.linprog(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None, bounds=None, method=‘simplex’, callback=None, options=None)

  • c : array_like
    Coefficients of the linear objective function to be minimized.
    最小化的线性目标函数的系数。

  • A_ub :
    2-D array which, when matrix-multiplied by x, gives the values of the upper-bound inequality constraints at x.
    上限不等式约束的值

  • b_ub : array_like
    1-D array of values representing the upper-bound of each inequality constraint (row) in A_ub.
    表示 A_ub 中每个不等式约束(行)的上限的一维值数组。

  • A_eq : array_like
    2-D array which, when matrix-multiplied by x, gives the values of the equality constraints at x.

  • b_eq : array_like
    1-D array of values representing the RHS of each equality constraint (row) in A_eq.

  • bounds : sequence, optional
    (min, max) pairs for each element in x, defining the bounds on that parameter. Use None for one of min or max when there is no bound in that direction. By default bounds are (0, None) (non-negative) If a sequence containing a single tuple is provided, then min and max will be applied to all variables in the problem.

  • method : str, optional
    Type of solver. At this time only ‘simplex’ is supported.

  • callback : callable, optional
    If a callback function is provide, it will be called within each iteration of the simplex algorithm. The callback must have the signature callback(xk, **kwargs) where xk is the current solution vector and kwargs is a dictionary containing the following:

“tableau” : The current Simplex algorithm tableau
“nit” : The current iteration.
“pivot” : The pivot (row, column) used for the next iteration.
“phase” : Whether the algorithm is in Phase 1 or Phase 2.
“basis” : The indices of the columns of the basic variables.

  • options : dict, optional
    A dictionary of solver options. All methods accept the following generic options:

  • maxiter : int
    Maximum number of iterations to perform.

  • disp : bool
    Set to True to print convergence messages.

例子

from scipy import optimize as op
import math
import numpy as np#系数
beta=[3,5,4]
c=np.array(beta)
#设置约束
a1=[2,3,0]
a2=[0,2,4]
a3=[3,2,5]#不等式约束
A_ub=np.array([a1,a2,a3])
#约束上限,默认为非负
B_ub=np.array([1500,800,2000])
#线性规划
res=op.linprog(-c,A_ub,B_ub)
#输出结果
print(res)

Python解决线性规划问题相关推荐

  1. python引入包pulp_用python的pulp库解决线性规划问题

    本文会介绍怎么用python解决线性规划问题,为什么要用python而不是matlab和lingo呢?因为matlab的函数写法不太符合正常的思维方式,编起来很复杂.而lingo虽然编写容易,但报错不 ...

  2. 万字教你如何用 Python 实现线性规划

    摘要:线性规划是一组数学和计算工具,可让您找到该系统的特定解,该解对应于某些其他线性函数的最大值或最小值. 本文分享自华为云社区<实践线性规划:使用 Python 进行优化>,作者: Yu ...

  3. 只需一步,轻松用Python实现线性规划

    线性规划说明 什么是线性规划? 想象一下,您有一个线性方程组和不等式系统.这样的系统通常有许多可能的解决方案.线性规划是一组数学和计算工具,可让您找到该系统的特定解,该解对应于某些其他线性函数的最大值 ...

  4. Python使用PuLP第三方库解决线性规划问题

    假设我们考虑投资两种证券X和Y.若投资X证券的数量为xxx,投资Y证券的数量为yyy, 试求3x+2y3x+2y3x+2y的最大值.限制条件如下: 投资2倍的X证券数量与投资Y证券数量之和不超过100 ...

  5. python线性整数规划求解_实例详解:用Python解决整数规划问题!

    我们将使用整数规划来做出最佳决策 整数规划(IP)问题是所有变量都被限制为整数的优化问题(指规划中的变量(全部或部分)限制为整数,若在线性模型中,变量限制为整数,则称为整数线性规划).IP问题是有关于 ...

  6. 最优解问题——PuLP解决线性规划问题(一)

    文章目录 1 PuLP介绍 1.1 理论.流程介绍 1.2 主函数介绍 1.2.1 LpProblem类 1.2.2 LpVariable类 1.2.3 lpSum(vector) 1.3 一些函数写 ...

  7. 高德API+Python解决租房问题

    项目简介:编写Python脚本爬取某租房网站的房源信息,利用高德的 js API 在地图上标出房源地点,划出距离工作地点1小时内可到达的范围,附上公交路径规划功能查看不同路径的用时. 本教程由ekCi ...

  8. Python版本的数据结构书_《用Python解决数据结构与算法问题》

    源于经典 数据结构作为计算机从业人员的必备基础,Java, c 之类的语言有很多这方面的书籍,Python 相对较少, 其中比较著名的一本 problem-solving-with-algorithm ...

  9. Python解决The truth value of a Series is ambiguous.md

    Python解决The truth value of a Series is ambiguous.md import pandas as pd data = pd.read_csv('x.csv') ...

最新文章

  1. 致谢 开源开发者的贡献_对开源做出的贡献如何使我成为更好的开发人员,以及如何做到这一点...
  2. SQL Sever索引
  3. SAP软件项目实施要点
  4. python中的单下划线和双下划线_python 里面的单下划线与双下划线的区别(私有和保护)...
  5. windows 系统nginx做反向代理实例
  6. .rdlc 文件设置方向_在Word里面怎么设置把字竖着打出来?
  7. linux bttrack服务,使用Docker安装OpenTracker,自建BT Tracker服务器
  8. 东北大学计算机 大一物理考试题,2010-2011东北大学物理考试题及答案
  9. 数据库工作笔记005---You have an error in your SQL syntax; check the manual that corresponds to y
  10. 区块链的一些名词解释
  11. 解决vim编译后的乱码问题
  12. 【渝粤教育】电大中专建筑力学 (2)作业 题库
  13. Eighth season eighth episode,Monica got a stripper in her bachelorette party??????
  14. 在浏览器中打开shell,连接linux
  15. C语言经典编程282例01
  16. transition(过渡)
  17. MA、EMA、MACD、BOLL、KDJ指标计算
  18. React 中同构(SSR)原理脉络梳理
  19. C# HttpUtility.UrlEncode 与 Java URLEncoder.encode的转换方法,李逵与李鬼
  20. python面向对象基础_python面向对象基础

热门文章

  1. 树莓派超级水冷主机!!!
  2. android 渠道方案,Android 不同渠道差异代码
  3. PHP+MySQL编程100个案例(建议收藏)
  4. logitech摄像头 linux,logitech webcam linux 驱动安装
  5. java中workFlowEvent_关于WorkFlow的使用以及例子
  6. 9.HTML基础——列表标签
  7. Java正则表达式匹配一句英文句子(大写字母开头,结尾有句号)
  8. 可穿戴在线展首日巡礼:剖析产业痛点 直击黑科技新品
  9. 醋在生活中的83种妙用
  10. 相机标定(2): 单目相机标定总结