_linprog_doc.py 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Aug 22 19:49:17 2020
  4. @author: matth
  5. """
  6. def _linprog_highs_doc(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
  7. bounds=None, method='highs', callback=None,
  8. maxiter=None, disp=False, presolve=True,
  9. time_limit=None,
  10. dual_feasibility_tolerance=None,
  11. primal_feasibility_tolerance=None,
  12. ipm_optimality_tolerance=None,
  13. simplex_dual_edge_weight_strategy=None,
  14. mip_rel_gap=None,
  15. **unknown_options):
  16. r"""
  17. Linear programming: minimize a linear objective function subject to linear
  18. equality and inequality constraints using one of the HiGHS solvers.
  19. Linear programming solves problems of the following form:
  20. .. math::
  21. \min_x \ & c^T x \\
  22. \mbox{such that} \ & A_{ub} x \leq b_{ub},\\
  23. & A_{eq} x = b_{eq},\\
  24. & l \leq x \leq u ,
  25. where :math:`x` is a vector of decision variables; :math:`c`,
  26. :math:`b_{ub}`, :math:`b_{eq}`, :math:`l`, and :math:`u` are vectors; and
  27. :math:`A_{ub}` and :math:`A_{eq}` are matrices.
  28. Alternatively, that's:
  29. minimize::
  30. c @ x
  31. such that::
  32. A_ub @ x <= b_ub
  33. A_eq @ x == b_eq
  34. lb <= x <= ub
  35. Note that by default ``lb = 0`` and ``ub = None`` unless specified with
  36. ``bounds``.
  37. Parameters
  38. ----------
  39. c : 1-D array
  40. The coefficients of the linear objective function to be minimized.
  41. A_ub : 2-D array, optional
  42. The inequality constraint matrix. Each row of ``A_ub`` specifies the
  43. coefficients of a linear inequality constraint on ``x``.
  44. b_ub : 1-D array, optional
  45. The inequality constraint vector. Each element represents an
  46. upper bound on the corresponding value of ``A_ub @ x``.
  47. A_eq : 2-D array, optional
  48. The equality constraint matrix. Each row of ``A_eq`` specifies the
  49. coefficients of a linear equality constraint on ``x``.
  50. b_eq : 1-D array, optional
  51. The equality constraint vector. Each element of ``A_eq @ x`` must equal
  52. the corresponding element of ``b_eq``.
  53. bounds : sequence, optional
  54. A sequence of ``(min, max)`` pairs for each element in ``x``, defining
  55. the minimum and maximum values of that decision variable. Use ``None``
  56. to indicate that there is no bound. By default, bounds are
  57. ``(0, None)`` (all decision variables are non-negative).
  58. If a single tuple ``(min, max)`` is provided, then ``min`` and
  59. ``max`` will serve as bounds for all decision variables.
  60. method : str
  61. This is the method-specific documentation for 'highs', which chooses
  62. automatically between
  63. :ref:`'highs-ds' <optimize.linprog-highs-ds>` and
  64. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`.
  65. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  66. :ref:`'revised simplex' <optimize.linprog-revised_simplex>`, and
  67. :ref:`'simplex' <optimize.linprog-simplex>` (legacy)
  68. are also available.
  69. integrality : 1-D array or int, optional
  70. Indicates the type of integrality constraint on each decision variable.
  71. ``0`` : Continuous variable; no integrality constraint.
  72. ``1`` : Integer variable; decision variable must be an integer
  73. within `bounds`.
  74. ``2`` : Semi-continuous variable; decision variable must be within
  75. `bounds` or take value ``0``.
  76. ``3`` : Semi-integer variable; decision variable must be an integer
  77. within `bounds` or take value ``0``.
  78. By default, all variables are continuous.
  79. For mixed integrality constraints, supply an array of shape `c.shape`.
  80. To infer a constraint on each decision variable from shorter inputs,
  81. the argument will be broadcasted to `c.shape` using `np.broadcast_to`.
  82. This argument is currently used only by the ``'highs'`` method and
  83. ignored otherwise.
  84. Options
  85. -------
  86. maxiter : int
  87. The maximum number of iterations to perform in either phase.
  88. For :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`, this does not
  89. include the number of crossover iterations. Default is the largest
  90. possible value for an ``int`` on the platform.
  91. disp : bool (default: ``False``)
  92. Set to ``True`` if indicators of optimization status are to be
  93. printed to the console during optimization.
  94. presolve : bool (default: ``True``)
  95. Presolve attempts to identify trivial infeasibilities,
  96. identify trivial unboundedness, and simplify the problem before
  97. sending it to the main solver. It is generally recommended
  98. to keep the default setting ``True``; set to ``False`` if
  99. presolve is to be disabled.
  100. time_limit : float
  101. The maximum time in seconds allotted to solve the problem;
  102. default is the largest possible value for a ``double`` on the
  103. platform.
  104. dual_feasibility_tolerance : double (default: 1e-07)
  105. Dual feasibility tolerance for
  106. :ref:`'highs-ds' <optimize.linprog-highs-ds>`.
  107. The minimum of this and ``primal_feasibility_tolerance``
  108. is used for the feasibility tolerance of
  109. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`.
  110. primal_feasibility_tolerance : double (default: 1e-07)
  111. Primal feasibility tolerance for
  112. :ref:`'highs-ds' <optimize.linprog-highs-ds>`.
  113. The minimum of this and ``dual_feasibility_tolerance``
  114. is used for the feasibility tolerance of
  115. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`.
  116. ipm_optimality_tolerance : double (default: ``1e-08``)
  117. Optimality tolerance for
  118. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`.
  119. Minimum allowable value is 1e-12.
  120. simplex_dual_edge_weight_strategy : str (default: None)
  121. Strategy for simplex dual edge weights. The default, ``None``,
  122. automatically selects one of the following.
  123. ``'dantzig'`` uses Dantzig's original strategy of choosing the most
  124. negative reduced cost.
  125. ``'devex'`` uses the strategy described in [15]_.
  126. ``steepest`` uses the exact steepest edge strategy as described in
  127. [16]_.
  128. ``'steepest-devex'`` begins with the exact steepest edge strategy
  129. until the computation is too costly or inexact and then switches to
  130. the devex method.
  131. Curently, ``None`` always selects ``'steepest-devex'``, but this
  132. may change as new options become available.
  133. mip_rel_gap : double (default: None)
  134. Termination criterion for MIP solver: solver will terminate when the
  135. gap between the primal objective value and the dual objective bound,
  136. scaled by the primal objective value, is <= mip_rel_gap.
  137. unknown_options : dict
  138. Optional arguments not used by this particular solver. If
  139. ``unknown_options`` is non-empty, a warning is issued listing
  140. all unused options.
  141. Returns
  142. -------
  143. res : OptimizeResult
  144. A :class:`scipy.optimize.OptimizeResult` consisting of the fields:
  145. x : 1D array
  146. The values of the decision variables that minimizes the
  147. objective function while satisfying the constraints.
  148. fun : float
  149. The optimal value of the objective function ``c @ x``.
  150. slack : 1D array
  151. The (nominally positive) values of the slack,
  152. ``b_ub - A_ub @ x``.
  153. con : 1D array
  154. The (nominally zero) residuals of the equality constraints,
  155. ``b_eq - A_eq @ x``.
  156. success : bool
  157. ``True`` when the algorithm succeeds in finding an optimal
  158. solution.
  159. status : int
  160. An integer representing the exit status of the algorithm.
  161. ``0`` : Optimization terminated successfully.
  162. ``1`` : Iteration or time limit reached.
  163. ``2`` : Problem appears to be infeasible.
  164. ``3`` : Problem appears to be unbounded.
  165. ``4`` : The HiGHS solver ran into a problem.
  166. message : str
  167. A string descriptor of the exit status of the algorithm.
  168. nit : int
  169. The total number of iterations performed.
  170. For the HiGHS simplex method, this includes iterations in all
  171. phases. For the HiGHS interior-point method, this does not include
  172. crossover iterations.
  173. crossover_nit : int
  174. The number of primal/dual pushes performed during the
  175. crossover routine for the HiGHS interior-point method.
  176. This is ``0`` for the HiGHS simplex method.
  177. ineqlin : OptimizeResult
  178. Solution and sensitivity information corresponding to the
  179. inequality constraints, `b_ub`. A dictionary consisting of the
  180. fields:
  181. residual : np.ndnarray
  182. The (nominally positive) values of the slack variables,
  183. ``b_ub - A_ub @ x``. This quantity is also commonly
  184. referred to as "slack".
  185. marginals : np.ndarray
  186. The sensitivity (partial derivative) of the objective
  187. function with respect to the right-hand side of the
  188. inequality constraints, `b_ub`.
  189. eqlin : OptimizeResult
  190. Solution and sensitivity information corresponding to the
  191. equality constraints, `b_eq`. A dictionary consisting of the
  192. fields:
  193. residual : np.ndarray
  194. The (nominally zero) residuals of the equality constraints,
  195. ``b_eq - A_eq @ x``.
  196. marginals : np.ndarray
  197. The sensitivity (partial derivative) of the objective
  198. function with respect to the right-hand side of the
  199. equality constraints, `b_eq`.
  200. lower, upper : OptimizeResult
  201. Solution and sensitivity information corresponding to the
  202. lower and upper bounds on decision variables, `bounds`.
  203. residual : np.ndarray
  204. The (nominally positive) values of the quantity
  205. ``x - lb`` (lower) or ``ub - x`` (upper).
  206. marginals : np.ndarray
  207. The sensitivity (partial derivative) of the objective
  208. function with respect to the lower and upper
  209. `bounds`.
  210. Notes
  211. -----
  212. Method :ref:`'highs-ds' <optimize.linprog-highs-ds>` is a wrapper
  213. of the C++ high performance dual revised simplex implementation (HSOL)
  214. [13]_, [14]_. Method :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`
  215. is a wrapper of a C++ implementation of an **i**\ nterior-\ **p**\ oint
  216. **m**\ ethod [13]_; it features a crossover routine, so it is as accurate
  217. as a simplex solver. Method :ref:`'highs' <optimize.linprog-highs>` chooses
  218. between the two automatically. For new code involving `linprog`, we
  219. recommend explicitly choosing one of these three method values instead of
  220. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  221. :ref:`'revised simplex' <optimize.linprog-revised_simplex>`, and
  222. :ref:`'simplex' <optimize.linprog-simplex>` (legacy).
  223. The result fields `ineqlin`, `eqlin`, `lower`, and `upper` all contain
  224. `marginals`, or partial derivatives of the objective function with respect
  225. to the right-hand side of each constraint. These partial derivatives are
  226. also referred to as "Lagrange multipliers", "dual values", and
  227. "shadow prices". The sign convention of `marginals` is opposite that
  228. of Lagrange multipliers produced by many nonlinear solvers.
  229. References
  230. ----------
  231. .. [13] Huangfu, Q., Galabova, I., Feldmeier, M., and Hall, J. A. J.
  232. "HiGHS - high performance software for linear optimization."
  233. https://highs.dev/
  234. .. [14] Huangfu, Q. and Hall, J. A. J. "Parallelizing the dual revised
  235. simplex method." Mathematical Programming Computation, 10 (1),
  236. 119-142, 2018. DOI: 10.1007/s12532-017-0130-5
  237. .. [15] Harris, Paula MJ. "Pivot selection methods of the Devex LP code."
  238. Mathematical programming 5.1 (1973): 1-28.
  239. .. [16] Goldfarb, Donald, and John Ker Reid. "A practicable steepest-edge
  240. simplex algorithm." Mathematical Programming 12.1 (1977): 361-371.
  241. """
  242. pass
  243. def _linprog_highs_ds_doc(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
  244. bounds=None, method='highs-ds', callback=None,
  245. maxiter=None, disp=False, presolve=True,
  246. time_limit=None,
  247. dual_feasibility_tolerance=None,
  248. primal_feasibility_tolerance=None,
  249. simplex_dual_edge_weight_strategy=None,
  250. **unknown_options):
  251. r"""
  252. Linear programming: minimize a linear objective function subject to linear
  253. equality and inequality constraints using the HiGHS dual simplex solver.
  254. Linear programming solves problems of the following form:
  255. .. math::
  256. \min_x \ & c^T x \\
  257. \mbox{such that} \ & A_{ub} x \leq b_{ub},\\
  258. & A_{eq} x = b_{eq},\\
  259. & l \leq x \leq u ,
  260. where :math:`x` is a vector of decision variables; :math:`c`,
  261. :math:`b_{ub}`, :math:`b_{eq}`, :math:`l`, and :math:`u` are vectors; and
  262. :math:`A_{ub}` and :math:`A_{eq}` are matrices.
  263. Alternatively, that's:
  264. minimize::
  265. c @ x
  266. such that::
  267. A_ub @ x <= b_ub
  268. A_eq @ x == b_eq
  269. lb <= x <= ub
  270. Note that by default ``lb = 0`` and ``ub = None`` unless specified with
  271. ``bounds``.
  272. Parameters
  273. ----------
  274. c : 1-D array
  275. The coefficients of the linear objective function to be minimized.
  276. A_ub : 2-D array, optional
  277. The inequality constraint matrix. Each row of ``A_ub`` specifies the
  278. coefficients of a linear inequality constraint on ``x``.
  279. b_ub : 1-D array, optional
  280. The inequality constraint vector. Each element represents an
  281. upper bound on the corresponding value of ``A_ub @ x``.
  282. A_eq : 2-D array, optional
  283. The equality constraint matrix. Each row of ``A_eq`` specifies the
  284. coefficients of a linear equality constraint on ``x``.
  285. b_eq : 1-D array, optional
  286. The equality constraint vector. Each element of ``A_eq @ x`` must equal
  287. the corresponding element of ``b_eq``.
  288. bounds : sequence, optional
  289. A sequence of ``(min, max)`` pairs for each element in ``x``, defining
  290. the minimum and maximum values of that decision variable. Use ``None``
  291. to indicate that there is no bound. By default, bounds are
  292. ``(0, None)`` (all decision variables are non-negative).
  293. If a single tuple ``(min, max)`` is provided, then ``min`` and
  294. ``max`` will serve as bounds for all decision variables.
  295. method : str
  296. This is the method-specific documentation for 'highs-ds'.
  297. :ref:`'highs' <optimize.linprog-highs>`,
  298. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`,
  299. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  300. :ref:`'revised simplex' <optimize.linprog-revised_simplex>`, and
  301. :ref:`'simplex' <optimize.linprog-simplex>` (legacy)
  302. are also available.
  303. Options
  304. -------
  305. maxiter : int
  306. The maximum number of iterations to perform in either phase.
  307. Default is the largest possible value for an ``int`` on the platform.
  308. disp : bool (default: ``False``)
  309. Set to ``True`` if indicators of optimization status are to be
  310. printed to the console during optimization.
  311. presolve : bool (default: ``True``)
  312. Presolve attempts to identify trivial infeasibilities,
  313. identify trivial unboundedness, and simplify the problem before
  314. sending it to the main solver. It is generally recommended
  315. to keep the default setting ``True``; set to ``False`` if
  316. presolve is to be disabled.
  317. time_limit : float
  318. The maximum time in seconds allotted to solve the problem;
  319. default is the largest possible value for a ``double`` on the
  320. platform.
  321. dual_feasibility_tolerance : double (default: 1e-07)
  322. Dual feasibility tolerance for
  323. :ref:`'highs-ds' <optimize.linprog-highs-ds>`.
  324. primal_feasibility_tolerance : double (default: 1e-07)
  325. Primal feasibility tolerance for
  326. :ref:`'highs-ds' <optimize.linprog-highs-ds>`.
  327. simplex_dual_edge_weight_strategy : str (default: None)
  328. Strategy for simplex dual edge weights. The default, ``None``,
  329. automatically selects one of the following.
  330. ``'dantzig'`` uses Dantzig's original strategy of choosing the most
  331. negative reduced cost.
  332. ``'devex'`` uses the strategy described in [15]_.
  333. ``steepest`` uses the exact steepest edge strategy as described in
  334. [16]_.
  335. ``'steepest-devex'`` begins with the exact steepest edge strategy
  336. until the computation is too costly or inexact and then switches to
  337. the devex method.
  338. Curently, ``None`` always selects ``'steepest-devex'``, but this
  339. may change as new options become available.
  340. unknown_options : dict
  341. Optional arguments not used by this particular solver. If
  342. ``unknown_options`` is non-empty, a warning is issued listing
  343. all unused options.
  344. Returns
  345. -------
  346. res : OptimizeResult
  347. A :class:`scipy.optimize.OptimizeResult` consisting of the fields:
  348. x : 1D array
  349. The values of the decision variables that minimizes the
  350. objective function while satisfying the constraints.
  351. fun : float
  352. The optimal value of the objective function ``c @ x``.
  353. slack : 1D array
  354. The (nominally positive) values of the slack,
  355. ``b_ub - A_ub @ x``.
  356. con : 1D array
  357. The (nominally zero) residuals of the equality constraints,
  358. ``b_eq - A_eq @ x``.
  359. success : bool
  360. ``True`` when the algorithm succeeds in finding an optimal
  361. solution.
  362. status : int
  363. An integer representing the exit status of the algorithm.
  364. ``0`` : Optimization terminated successfully.
  365. ``1`` : Iteration or time limit reached.
  366. ``2`` : Problem appears to be infeasible.
  367. ``3`` : Problem appears to be unbounded.
  368. ``4`` : The HiGHS solver ran into a problem.
  369. message : str
  370. A string descriptor of the exit status of the algorithm.
  371. nit : int
  372. The total number of iterations performed. This includes iterations
  373. in all phases.
  374. crossover_nit : int
  375. This is always ``0`` for the HiGHS simplex method.
  376. For the HiGHS interior-point method, this is the number of
  377. primal/dual pushes performed during the crossover routine.
  378. ineqlin : OptimizeResult
  379. Solution and sensitivity information corresponding to the
  380. inequality constraints, `b_ub`. A dictionary consisting of the
  381. fields:
  382. residual : np.ndnarray
  383. The (nominally positive) values of the slack variables,
  384. ``b_ub - A_ub @ x``. This quantity is also commonly
  385. referred to as "slack".
  386. marginals : np.ndarray
  387. The sensitivity (partial derivative) of the objective
  388. function with respect to the right-hand side of the
  389. inequality constraints, `b_ub`.
  390. eqlin : OptimizeResult
  391. Solution and sensitivity information corresponding to the
  392. equality constraints, `b_eq`. A dictionary consisting of the
  393. fields:
  394. residual : np.ndarray
  395. The (nominally zero) residuals of the equality constraints,
  396. ``b_eq - A_eq @ x``.
  397. marginals : np.ndarray
  398. The sensitivity (partial derivative) of the objective
  399. function with respect to the right-hand side of the
  400. equality constraints, `b_eq`.
  401. lower, upper : OptimizeResult
  402. Solution and sensitivity information corresponding to the
  403. lower and upper bounds on decision variables, `bounds`.
  404. residual : np.ndarray
  405. The (nominally positive) values of the quantity
  406. ``x - lb`` (lower) or ``ub - x`` (upper).
  407. marginals : np.ndarray
  408. The sensitivity (partial derivative) of the objective
  409. function with respect to the lower and upper
  410. `bounds`.
  411. Notes
  412. -----
  413. Method :ref:`'highs-ds' <optimize.linprog-highs-ds>` is a wrapper
  414. of the C++ high performance dual revised simplex implementation (HSOL)
  415. [13]_, [14]_. Method :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`
  416. is a wrapper of a C++ implementation of an **i**\ nterior-\ **p**\ oint
  417. **m**\ ethod [13]_; it features a crossover routine, so it is as accurate
  418. as a simplex solver. Method :ref:`'highs' <optimize.linprog-highs>` chooses
  419. between the two automatically. For new code involving `linprog`, we
  420. recommend explicitly choosing one of these three method values instead of
  421. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  422. :ref:`'revised simplex' <optimize.linprog-revised_simplex>`, and
  423. :ref:`'simplex' <optimize.linprog-simplex>` (legacy).
  424. The result fields `ineqlin`, `eqlin`, `lower`, and `upper` all contain
  425. `marginals`, or partial derivatives of the objective function with respect
  426. to the right-hand side of each constraint. These partial derivatives are
  427. also referred to as "Lagrange multipliers", "dual values", and
  428. "shadow prices". The sign convention of `marginals` is opposite that
  429. of Lagrange multipliers produced by many nonlinear solvers.
  430. References
  431. ----------
  432. .. [13] Huangfu, Q., Galabova, I., Feldmeier, M., and Hall, J. A. J.
  433. "HiGHS - high performance software for linear optimization."
  434. https://highs.dev/
  435. .. [14] Huangfu, Q. and Hall, J. A. J. "Parallelizing the dual revised
  436. simplex method." Mathematical Programming Computation, 10 (1),
  437. 119-142, 2018. DOI: 10.1007/s12532-017-0130-5
  438. .. [15] Harris, Paula MJ. "Pivot selection methods of the Devex LP code."
  439. Mathematical programming 5.1 (1973): 1-28.
  440. .. [16] Goldfarb, Donald, and John Ker Reid. "A practicable steepest-edge
  441. simplex algorithm." Mathematical Programming 12.1 (1977): 361-371.
  442. """
  443. pass
  444. def _linprog_highs_ipm_doc(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
  445. bounds=None, method='highs-ipm', callback=None,
  446. maxiter=None, disp=False, presolve=True,
  447. time_limit=None,
  448. dual_feasibility_tolerance=None,
  449. primal_feasibility_tolerance=None,
  450. ipm_optimality_tolerance=None,
  451. **unknown_options):
  452. r"""
  453. Linear programming: minimize a linear objective function subject to linear
  454. equality and inequality constraints using the HiGHS interior point solver.
  455. Linear programming solves problems of the following form:
  456. .. math::
  457. \min_x \ & c^T x \\
  458. \mbox{such that} \ & A_{ub} x \leq b_{ub},\\
  459. & A_{eq} x = b_{eq},\\
  460. & l \leq x \leq u ,
  461. where :math:`x` is a vector of decision variables; :math:`c`,
  462. :math:`b_{ub}`, :math:`b_{eq}`, :math:`l`, and :math:`u` are vectors; and
  463. :math:`A_{ub}` and :math:`A_{eq}` are matrices.
  464. Alternatively, that's:
  465. minimize::
  466. c @ x
  467. such that::
  468. A_ub @ x <= b_ub
  469. A_eq @ x == b_eq
  470. lb <= x <= ub
  471. Note that by default ``lb = 0`` and ``ub = None`` unless specified with
  472. ``bounds``.
  473. Parameters
  474. ----------
  475. c : 1-D array
  476. The coefficients of the linear objective function to be minimized.
  477. A_ub : 2-D array, optional
  478. The inequality constraint matrix. Each row of ``A_ub`` specifies the
  479. coefficients of a linear inequality constraint on ``x``.
  480. b_ub : 1-D array, optional
  481. The inequality constraint vector. Each element represents an
  482. upper bound on the corresponding value of ``A_ub @ x``.
  483. A_eq : 2-D array, optional
  484. The equality constraint matrix. Each row of ``A_eq`` specifies the
  485. coefficients of a linear equality constraint on ``x``.
  486. b_eq : 1-D array, optional
  487. The equality constraint vector. Each element of ``A_eq @ x`` must equal
  488. the corresponding element of ``b_eq``.
  489. bounds : sequence, optional
  490. A sequence of ``(min, max)`` pairs for each element in ``x``, defining
  491. the minimum and maximum values of that decision variable. Use ``None``
  492. to indicate that there is no bound. By default, bounds are
  493. ``(0, None)`` (all decision variables are non-negative).
  494. If a single tuple ``(min, max)`` is provided, then ``min`` and
  495. ``max`` will serve as bounds for all decision variables.
  496. method : str
  497. This is the method-specific documentation for 'highs-ipm'.
  498. :ref:`'highs-ipm' <optimize.linprog-highs>`,
  499. :ref:`'highs-ds' <optimize.linprog-highs-ds>`,
  500. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  501. :ref:`'revised simplex' <optimize.linprog-revised_simplex>`, and
  502. :ref:`'simplex' <optimize.linprog-simplex>` (legacy)
  503. are also available.
  504. Options
  505. -------
  506. maxiter : int
  507. The maximum number of iterations to perform in either phase.
  508. For :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`, this does not
  509. include the number of crossover iterations. Default is the largest
  510. possible value for an ``int`` on the platform.
  511. disp : bool (default: ``False``)
  512. Set to ``True`` if indicators of optimization status are to be
  513. printed to the console during optimization.
  514. presolve : bool (default: ``True``)
  515. Presolve attempts to identify trivial infeasibilities,
  516. identify trivial unboundedness, and simplify the problem before
  517. sending it to the main solver. It is generally recommended
  518. to keep the default setting ``True``; set to ``False`` if
  519. presolve is to be disabled.
  520. time_limit : float
  521. The maximum time in seconds allotted to solve the problem;
  522. default is the largest possible value for a ``double`` on the
  523. platform.
  524. dual_feasibility_tolerance : double (default: 1e-07)
  525. The minimum of this and ``primal_feasibility_tolerance``
  526. is used for the feasibility tolerance of
  527. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`.
  528. primal_feasibility_tolerance : double (default: 1e-07)
  529. The minimum of this and ``dual_feasibility_tolerance``
  530. is used for the feasibility tolerance of
  531. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`.
  532. ipm_optimality_tolerance : double (default: ``1e-08``)
  533. Optimality tolerance for
  534. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`.
  535. Minimum allowable value is 1e-12.
  536. unknown_options : dict
  537. Optional arguments not used by this particular solver. If
  538. ``unknown_options`` is non-empty, a warning is issued listing
  539. all unused options.
  540. Returns
  541. -------
  542. res : OptimizeResult
  543. A :class:`scipy.optimize.OptimizeResult` consisting of the fields:
  544. x : 1D array
  545. The values of the decision variables that minimizes the
  546. objective function while satisfying the constraints.
  547. fun : float
  548. The optimal value of the objective function ``c @ x``.
  549. slack : 1D array
  550. The (nominally positive) values of the slack,
  551. ``b_ub - A_ub @ x``.
  552. con : 1D array
  553. The (nominally zero) residuals of the equality constraints,
  554. ``b_eq - A_eq @ x``.
  555. success : bool
  556. ``True`` when the algorithm succeeds in finding an optimal
  557. solution.
  558. status : int
  559. An integer representing the exit status of the algorithm.
  560. ``0`` : Optimization terminated successfully.
  561. ``1`` : Iteration or time limit reached.
  562. ``2`` : Problem appears to be infeasible.
  563. ``3`` : Problem appears to be unbounded.
  564. ``4`` : The HiGHS solver ran into a problem.
  565. message : str
  566. A string descriptor of the exit status of the algorithm.
  567. nit : int
  568. The total number of iterations performed.
  569. For the HiGHS interior-point method, this does not include
  570. crossover iterations.
  571. crossover_nit : int
  572. The number of primal/dual pushes performed during the
  573. crossover routine for the HiGHS interior-point method.
  574. ineqlin : OptimizeResult
  575. Solution and sensitivity information corresponding to the
  576. inequality constraints, `b_ub`. A dictionary consisting of the
  577. fields:
  578. residual : np.ndnarray
  579. The (nominally positive) values of the slack variables,
  580. ``b_ub - A_ub @ x``. This quantity is also commonly
  581. referred to as "slack".
  582. marginals : np.ndarray
  583. The sensitivity (partial derivative) of the objective
  584. function with respect to the right-hand side of the
  585. inequality constraints, `b_ub`.
  586. eqlin : OptimizeResult
  587. Solution and sensitivity information corresponding to the
  588. equality constraints, `b_eq`. A dictionary consisting of the
  589. fields:
  590. residual : np.ndarray
  591. The (nominally zero) residuals of the equality constraints,
  592. ``b_eq - A_eq @ x``.
  593. marginals : np.ndarray
  594. The sensitivity (partial derivative) of the objective
  595. function with respect to the right-hand side of the
  596. equality constraints, `b_eq`.
  597. lower, upper : OptimizeResult
  598. Solution and sensitivity information corresponding to the
  599. lower and upper bounds on decision variables, `bounds`.
  600. residual : np.ndarray
  601. The (nominally positive) values of the quantity
  602. ``x - lb`` (lower) or ``ub - x`` (upper).
  603. marginals : np.ndarray
  604. The sensitivity (partial derivative) of the objective
  605. function with respect to the lower and upper
  606. `bounds`.
  607. Notes
  608. -----
  609. Method :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`
  610. is a wrapper of a C++ implementation of an **i**\ nterior-\ **p**\ oint
  611. **m**\ ethod [13]_; it features a crossover routine, so it is as accurate
  612. as a simplex solver.
  613. Method :ref:`'highs-ds' <optimize.linprog-highs-ds>` is a wrapper
  614. of the C++ high performance dual revised simplex implementation (HSOL)
  615. [13]_, [14]_. Method :ref:`'highs' <optimize.linprog-highs>` chooses
  616. between the two automatically. For new code involving `linprog`, we
  617. recommend explicitly choosing one of these three method values instead of
  618. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  619. :ref:`'revised simplex' <optimize.linprog-revised_simplex>`, and
  620. :ref:`'simplex' <optimize.linprog-simplex>` (legacy).
  621. The result fields `ineqlin`, `eqlin`, `lower`, and `upper` all contain
  622. `marginals`, or partial derivatives of the objective function with respect
  623. to the right-hand side of each constraint. These partial derivatives are
  624. also referred to as "Lagrange multipliers", "dual values", and
  625. "shadow prices". The sign convention of `marginals` is opposite that
  626. of Lagrange multipliers produced by many nonlinear solvers.
  627. References
  628. ----------
  629. .. [13] Huangfu, Q., Galabova, I., Feldmeier, M., and Hall, J. A. J.
  630. "HiGHS - high performance software for linear optimization."
  631. https://highs.dev/
  632. .. [14] Huangfu, Q. and Hall, J. A. J. "Parallelizing the dual revised
  633. simplex method." Mathematical Programming Computation, 10 (1),
  634. 119-142, 2018. DOI: 10.1007/s12532-017-0130-5
  635. """
  636. pass
  637. def _linprog_ip_doc(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
  638. bounds=None, method='interior-point', callback=None,
  639. maxiter=1000, disp=False, presolve=True,
  640. tol=1e-8, autoscale=False, rr=True,
  641. alpha0=.99995, beta=0.1, sparse=False,
  642. lstsq=False, sym_pos=True, cholesky=True, pc=True,
  643. ip=False, permc_spec='MMD_AT_PLUS_A', **unknown_options):
  644. r"""
  645. Linear programming: minimize a linear objective function subject to linear
  646. equality and inequality constraints using the interior-point method of
  647. [4]_.
  648. .. deprecated:: 1.9.0
  649. `method='interior-point'` will be removed in SciPy 1.11.0.
  650. It is replaced by `method='highs'` because the latter is
  651. faster and more robust.
  652. Linear programming solves problems of the following form:
  653. .. math::
  654. \min_x \ & c^T x \\
  655. \mbox{such that} \ & A_{ub} x \leq b_{ub},\\
  656. & A_{eq} x = b_{eq},\\
  657. & l \leq x \leq u ,
  658. where :math:`x` is a vector of decision variables; :math:`c`,
  659. :math:`b_{ub}`, :math:`b_{eq}`, :math:`l`, and :math:`u` are vectors; and
  660. :math:`A_{ub}` and :math:`A_{eq}` are matrices.
  661. Alternatively, that's:
  662. minimize::
  663. c @ x
  664. such that::
  665. A_ub @ x <= b_ub
  666. A_eq @ x == b_eq
  667. lb <= x <= ub
  668. Note that by default ``lb = 0`` and ``ub = None`` unless specified with
  669. ``bounds``.
  670. Parameters
  671. ----------
  672. c : 1-D array
  673. The coefficients of the linear objective function to be minimized.
  674. A_ub : 2-D array, optional
  675. The inequality constraint matrix. Each row of ``A_ub`` specifies the
  676. coefficients of a linear inequality constraint on ``x``.
  677. b_ub : 1-D array, optional
  678. The inequality constraint vector. Each element represents an
  679. upper bound on the corresponding value of ``A_ub @ x``.
  680. A_eq : 2-D array, optional
  681. The equality constraint matrix. Each row of ``A_eq`` specifies the
  682. coefficients of a linear equality constraint on ``x``.
  683. b_eq : 1-D array, optional
  684. The equality constraint vector. Each element of ``A_eq @ x`` must equal
  685. the corresponding element of ``b_eq``.
  686. bounds : sequence, optional
  687. A sequence of ``(min, max)`` pairs for each element in ``x``, defining
  688. the minimum and maximum values of that decision variable. Use ``None``
  689. to indicate that there is no bound. By default, bounds are
  690. ``(0, None)`` (all decision variables are non-negative).
  691. If a single tuple ``(min, max)`` is provided, then ``min`` and
  692. ``max`` will serve as bounds for all decision variables.
  693. method : str
  694. This is the method-specific documentation for 'interior-point'.
  695. :ref:`'highs' <optimize.linprog-highs>`,
  696. :ref:`'highs-ds' <optimize.linprog-highs-ds>`,
  697. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`,
  698. :ref:`'revised simplex' <optimize.linprog-revised_simplex>`, and
  699. :ref:`'simplex' <optimize.linprog-simplex>` (legacy)
  700. are also available.
  701. callback : callable, optional
  702. Callback function to be executed once per iteration.
  703. Options
  704. -------
  705. maxiter : int (default: 1000)
  706. The maximum number of iterations of the algorithm.
  707. disp : bool (default: False)
  708. Set to ``True`` if indicators of optimization status are to be printed
  709. to the console each iteration.
  710. presolve : bool (default: True)
  711. Presolve attempts to identify trivial infeasibilities,
  712. identify trivial unboundedness, and simplify the problem before
  713. sending it to the main solver. It is generally recommended
  714. to keep the default setting ``True``; set to ``False`` if
  715. presolve is to be disabled.
  716. tol : float (default: 1e-8)
  717. Termination tolerance to be used for all termination criteria;
  718. see [4]_ Section 4.5.
  719. autoscale : bool (default: False)
  720. Set to ``True`` to automatically perform equilibration.
  721. Consider using this option if the numerical values in the
  722. constraints are separated by several orders of magnitude.
  723. rr : bool (default: True)
  724. Set to ``False`` to disable automatic redundancy removal.
  725. alpha0 : float (default: 0.99995)
  726. The maximal step size for Mehrota's predictor-corrector search
  727. direction; see :math:`\beta_{3}` of [4]_ Table 8.1.
  728. beta : float (default: 0.1)
  729. The desired reduction of the path parameter :math:`\mu` (see [6]_)
  730. when Mehrota's predictor-corrector is not in use (uncommon).
  731. sparse : bool (default: False)
  732. Set to ``True`` if the problem is to be treated as sparse after
  733. presolve. If either ``A_eq`` or ``A_ub`` is a sparse matrix,
  734. this option will automatically be set ``True``, and the problem
  735. will be treated as sparse even during presolve. If your constraint
  736. matrices contain mostly zeros and the problem is not very small (less
  737. than about 100 constraints or variables), consider setting ``True``
  738. or providing ``A_eq`` and ``A_ub`` as sparse matrices.
  739. lstsq : bool (default: ``False``)
  740. Set to ``True`` if the problem is expected to be very poorly
  741. conditioned. This should always be left ``False`` unless severe
  742. numerical difficulties are encountered. Leave this at the default
  743. unless you receive a warning message suggesting otherwise.
  744. sym_pos : bool (default: True)
  745. Leave ``True`` if the problem is expected to yield a well conditioned
  746. symmetric positive definite normal equation matrix
  747. (almost always). Leave this at the default unless you receive
  748. a warning message suggesting otherwise.
  749. cholesky : bool (default: True)
  750. Set to ``True`` if the normal equations are to be solved by explicit
  751. Cholesky decomposition followed by explicit forward/backward
  752. substitution. This is typically faster for problems
  753. that are numerically well-behaved.
  754. pc : bool (default: True)
  755. Leave ``True`` if the predictor-corrector method of Mehrota is to be
  756. used. This is almost always (if not always) beneficial.
  757. ip : bool (default: False)
  758. Set to ``True`` if the improved initial point suggestion due to [4]_
  759. Section 4.3 is desired. Whether this is beneficial or not
  760. depends on the problem.
  761. permc_spec : str (default: 'MMD_AT_PLUS_A')
  762. (Has effect only with ``sparse = True``, ``lstsq = False``, ``sym_pos =
  763. True``, and no SuiteSparse.)
  764. A matrix is factorized in each iteration of the algorithm.
  765. This option specifies how to permute the columns of the matrix for
  766. sparsity preservation. Acceptable values are:
  767. - ``NATURAL``: natural ordering.
  768. - ``MMD_ATA``: minimum degree ordering on the structure of A^T A.
  769. - ``MMD_AT_PLUS_A``: minimum degree ordering on the structure of A^T+A.
  770. - ``COLAMD``: approximate minimum degree column ordering.
  771. This option can impact the convergence of the
  772. interior point algorithm; test different values to determine which
  773. performs best for your problem. For more information, refer to
  774. ``scipy.sparse.linalg.splu``.
  775. unknown_options : dict
  776. Optional arguments not used by this particular solver. If
  777. `unknown_options` is non-empty a warning is issued listing all
  778. unused options.
  779. Returns
  780. -------
  781. res : OptimizeResult
  782. A :class:`scipy.optimize.OptimizeResult` consisting of the fields:
  783. x : 1-D array
  784. The values of the decision variables that minimizes the
  785. objective function while satisfying the constraints.
  786. fun : float
  787. The optimal value of the objective function ``c @ x``.
  788. slack : 1-D array
  789. The (nominally positive) values of the slack variables,
  790. ``b_ub - A_ub @ x``.
  791. con : 1-D array
  792. The (nominally zero) residuals of the equality constraints,
  793. ``b_eq - A_eq @ x``.
  794. success : bool
  795. ``True`` when the algorithm succeeds in finding an optimal
  796. solution.
  797. status : int
  798. An integer representing the exit status of the algorithm.
  799. ``0`` : Optimization terminated successfully.
  800. ``1`` : Iteration limit reached.
  801. ``2`` : Problem appears to be infeasible.
  802. ``3`` : Problem appears to be unbounded.
  803. ``4`` : Numerical difficulties encountered.
  804. message : str
  805. A string descriptor of the exit status of the algorithm.
  806. nit : int
  807. The total number of iterations performed in all phases.
  808. Notes
  809. -----
  810. This method implements the algorithm outlined in [4]_ with ideas from [8]_
  811. and a structure inspired by the simpler methods of [6]_.
  812. The primal-dual path following method begins with initial 'guesses' of
  813. the primal and dual variables of the standard form problem and iteratively
  814. attempts to solve the (nonlinear) Karush-Kuhn-Tucker conditions for the
  815. problem with a gradually reduced logarithmic barrier term added to the
  816. objective. This particular implementation uses a homogeneous self-dual
  817. formulation, which provides certificates of infeasibility or unboundedness
  818. where applicable.
  819. The default initial point for the primal and dual variables is that
  820. defined in [4]_ Section 4.4 Equation 8.22. Optionally (by setting initial
  821. point option ``ip=True``), an alternate (potentially improved) starting
  822. point can be calculated according to the additional recommendations of
  823. [4]_ Section 4.4.
  824. A search direction is calculated using the predictor-corrector method
  825. (single correction) proposed by Mehrota and detailed in [4]_ Section 4.1.
  826. (A potential improvement would be to implement the method of multiple
  827. corrections described in [4]_ Section 4.2.) In practice, this is
  828. accomplished by solving the normal equations, [4]_ Section 5.1 Equations
  829. 8.31 and 8.32, derived from the Newton equations [4]_ Section 5 Equations
  830. 8.25 (compare to [4]_ Section 4 Equations 8.6-8.8). The advantage of
  831. solving the normal equations rather than 8.25 directly is that the
  832. matrices involved are symmetric positive definite, so Cholesky
  833. decomposition can be used rather than the more expensive LU factorization.
  834. With default options, the solver used to perform the factorization depends
  835. on third-party software availability and the conditioning of the problem.
  836. For dense problems, solvers are tried in the following order:
  837. 1. ``scipy.linalg.cho_factor``
  838. 2. ``scipy.linalg.solve`` with option ``sym_pos=True``
  839. 3. ``scipy.linalg.solve`` with option ``sym_pos=False``
  840. 4. ``scipy.linalg.lstsq``
  841. For sparse problems:
  842. 1. ``sksparse.cholmod.cholesky`` (if scikit-sparse and SuiteSparse are
  843. installed)
  844. 2. ``scipy.sparse.linalg.factorized`` (if scikit-umfpack and SuiteSparse
  845. are installed)
  846. 3. ``scipy.sparse.linalg.splu`` (which uses SuperLU distributed with SciPy)
  847. 4. ``scipy.sparse.linalg.lsqr``
  848. If the solver fails for any reason, successively more robust (but slower)
  849. solvers are attempted in the order indicated. Attempting, failing, and
  850. re-starting factorization can be time consuming, so if the problem is
  851. numerically challenging, options can be set to bypass solvers that are
  852. failing. Setting ``cholesky=False`` skips to solver 2,
  853. ``sym_pos=False`` skips to solver 3, and ``lstsq=True`` skips
  854. to solver 4 for both sparse and dense problems.
  855. Potential improvements for combatting issues associated with dense
  856. columns in otherwise sparse problems are outlined in [4]_ Section 5.3 and
  857. [10]_ Section 4.1-4.2; the latter also discusses the alleviation of
  858. accuracy issues associated with the substitution approach to free
  859. variables.
  860. After calculating the search direction, the maximum possible step size
  861. that does not activate the non-negativity constraints is calculated, and
  862. the smaller of this step size and unity is applied (as in [4]_ Section
  863. 4.1.) [4]_ Section 4.3 suggests improvements for choosing the step size.
  864. The new point is tested according to the termination conditions of [4]_
  865. Section 4.5. The same tolerance, which can be set using the ``tol`` option,
  866. is used for all checks. (A potential improvement would be to expose
  867. the different tolerances to be set independently.) If optimality,
  868. unboundedness, or infeasibility is detected, the solve procedure
  869. terminates; otherwise it repeats.
  870. Whereas the top level ``linprog`` module expects a problem of form:
  871. Minimize::
  872. c @ x
  873. Subject to::
  874. A_ub @ x <= b_ub
  875. A_eq @ x == b_eq
  876. lb <= x <= ub
  877. where ``lb = 0`` and ``ub = None`` unless set in ``bounds``. The problem
  878. is automatically converted to the form:
  879. Minimize::
  880. c @ x
  881. Subject to::
  882. A @ x == b
  883. x >= 0
  884. for solution. That is, the original problem contains equality, upper-bound
  885. and variable constraints whereas the method specific solver requires
  886. equality constraints and variable non-negativity. ``linprog`` converts the
  887. original problem to standard form by converting the simple bounds to upper
  888. bound constraints, introducing non-negative slack variables for inequality
  889. constraints, and expressing unbounded variables as the difference between
  890. two non-negative variables. The problem is converted back to the original
  891. form before results are reported.
  892. References
  893. ----------
  894. .. [4] Andersen, Erling D., and Knud D. Andersen. "The MOSEK interior point
  895. optimizer for linear programming: an implementation of the
  896. homogeneous algorithm." High performance optimization. Springer US,
  897. 2000. 197-232.
  898. .. [6] Freund, Robert M. "Primal-Dual Interior-Point Methods for Linear
  899. Programming based on Newton's Method." Unpublished Course Notes,
  900. March 2004. Available 2/25/2017 at
  901. https://ocw.mit.edu/courses/sloan-school-of-management/15-084j-nonlinear-programming-spring-2004/lecture-notes/lec14_int_pt_mthd.pdf
  902. .. [8] Andersen, Erling D., and Knud D. Andersen. "Presolving in linear
  903. programming." Mathematical Programming 71.2 (1995): 221-245.
  904. .. [9] Bertsimas, Dimitris, and J. Tsitsiklis. "Introduction to linear
  905. programming." Athena Scientific 1 (1997): 997.
  906. .. [10] Andersen, Erling D., et al. Implementation of interior point
  907. methods for large scale linear programming. HEC/Universite de
  908. Geneve, 1996.
  909. """
  910. pass
  911. def _linprog_rs_doc(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
  912. bounds=None, method='interior-point', callback=None,
  913. x0=None, maxiter=5000, disp=False, presolve=True,
  914. tol=1e-12, autoscale=False, rr=True, maxupdate=10,
  915. mast=False, pivot="mrc", **unknown_options):
  916. r"""
  917. Linear programming: minimize a linear objective function subject to linear
  918. equality and inequality constraints using the revised simplex method.
  919. .. deprecated:: 1.9.0
  920. `method='revised simplex'` will be removed in SciPy 1.11.0.
  921. It is replaced by `method='highs'` because the latter is
  922. faster and more robust.
  923. Linear programming solves problems of the following form:
  924. .. math::
  925. \min_x \ & c^T x \\
  926. \mbox{such that} \ & A_{ub} x \leq b_{ub},\\
  927. & A_{eq} x = b_{eq},\\
  928. & l \leq x \leq u ,
  929. where :math:`x` is a vector of decision variables; :math:`c`,
  930. :math:`b_{ub}`, :math:`b_{eq}`, :math:`l`, and :math:`u` are vectors; and
  931. :math:`A_{ub}` and :math:`A_{eq}` are matrices.
  932. Alternatively, that's:
  933. minimize::
  934. c @ x
  935. such that::
  936. A_ub @ x <= b_ub
  937. A_eq @ x == b_eq
  938. lb <= x <= ub
  939. Note that by default ``lb = 0`` and ``ub = None`` unless specified with
  940. ``bounds``.
  941. Parameters
  942. ----------
  943. c : 1-D array
  944. The coefficients of the linear objective function to be minimized.
  945. A_ub : 2-D array, optional
  946. The inequality constraint matrix. Each row of ``A_ub`` specifies the
  947. coefficients of a linear inequality constraint on ``x``.
  948. b_ub : 1-D array, optional
  949. The inequality constraint vector. Each element represents an
  950. upper bound on the corresponding value of ``A_ub @ x``.
  951. A_eq : 2-D array, optional
  952. The equality constraint matrix. Each row of ``A_eq`` specifies the
  953. coefficients of a linear equality constraint on ``x``.
  954. b_eq : 1-D array, optional
  955. The equality constraint vector. Each element of ``A_eq @ x`` must equal
  956. the corresponding element of ``b_eq``.
  957. bounds : sequence, optional
  958. A sequence of ``(min, max)`` pairs for each element in ``x``, defining
  959. the minimum and maximum values of that decision variable. Use ``None``
  960. to indicate that there is no bound. By default, bounds are
  961. ``(0, None)`` (all decision variables are non-negative).
  962. If a single tuple ``(min, max)`` is provided, then ``min`` and
  963. ``max`` will serve as bounds for all decision variables.
  964. method : str
  965. This is the method-specific documentation for 'revised simplex'.
  966. :ref:`'highs' <optimize.linprog-highs>`,
  967. :ref:`'highs-ds' <optimize.linprog-highs-ds>`,
  968. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`,
  969. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  970. and :ref:`'simplex' <optimize.linprog-simplex>` (legacy)
  971. are also available.
  972. callback : callable, optional
  973. Callback function to be executed once per iteration.
  974. x0 : 1-D array, optional
  975. Guess values of the decision variables, which will be refined by
  976. the optimization algorithm. This argument is currently used only by the
  977. 'revised simplex' method, and can only be used if `x0` represents a
  978. basic feasible solution.
  979. Options
  980. -------
  981. maxiter : int (default: 5000)
  982. The maximum number of iterations to perform in either phase.
  983. disp : bool (default: False)
  984. Set to ``True`` if indicators of optimization status are to be printed
  985. to the console each iteration.
  986. presolve : bool (default: True)
  987. Presolve attempts to identify trivial infeasibilities,
  988. identify trivial unboundedness, and simplify the problem before
  989. sending it to the main solver. It is generally recommended
  990. to keep the default setting ``True``; set to ``False`` if
  991. presolve is to be disabled.
  992. tol : float (default: 1e-12)
  993. The tolerance which determines when a solution is "close enough" to
  994. zero in Phase 1 to be considered a basic feasible solution or close
  995. enough to positive to serve as an optimal solution.
  996. autoscale : bool (default: False)
  997. Set to ``True`` to automatically perform equilibration.
  998. Consider using this option if the numerical values in the
  999. constraints are separated by several orders of magnitude.
  1000. rr : bool (default: True)
  1001. Set to ``False`` to disable automatic redundancy removal.
  1002. maxupdate : int (default: 10)
  1003. The maximum number of updates performed on the LU factorization.
  1004. After this many updates is reached, the basis matrix is factorized
  1005. from scratch.
  1006. mast : bool (default: False)
  1007. Minimize Amortized Solve Time. If enabled, the average time to solve
  1008. a linear system using the basis factorization is measured. Typically,
  1009. the average solve time will decrease with each successive solve after
  1010. initial factorization, as factorization takes much more time than the
  1011. solve operation (and updates). Eventually, however, the updated
  1012. factorization becomes sufficiently complex that the average solve time
  1013. begins to increase. When this is detected, the basis is refactorized
  1014. from scratch. Enable this option to maximize speed at the risk of
  1015. nondeterministic behavior. Ignored if ``maxupdate`` is 0.
  1016. pivot : "mrc" or "bland" (default: "mrc")
  1017. Pivot rule: Minimum Reduced Cost ("mrc") or Bland's rule ("bland").
  1018. Choose Bland's rule if iteration limit is reached and cycling is
  1019. suspected.
  1020. unknown_options : dict
  1021. Optional arguments not used by this particular solver. If
  1022. `unknown_options` is non-empty a warning is issued listing all
  1023. unused options.
  1024. Returns
  1025. -------
  1026. res : OptimizeResult
  1027. A :class:`scipy.optimize.OptimizeResult` consisting of the fields:
  1028. x : 1-D array
  1029. The values of the decision variables that minimizes the
  1030. objective function while satisfying the constraints.
  1031. fun : float
  1032. The optimal value of the objective function ``c @ x``.
  1033. slack : 1-D array
  1034. The (nominally positive) values of the slack variables,
  1035. ``b_ub - A_ub @ x``.
  1036. con : 1-D array
  1037. The (nominally zero) residuals of the equality constraints,
  1038. ``b_eq - A_eq @ x``.
  1039. success : bool
  1040. ``True`` when the algorithm succeeds in finding an optimal
  1041. solution.
  1042. status : int
  1043. An integer representing the exit status of the algorithm.
  1044. ``0`` : Optimization terminated successfully.
  1045. ``1`` : Iteration limit reached.
  1046. ``2`` : Problem appears to be infeasible.
  1047. ``3`` : Problem appears to be unbounded.
  1048. ``4`` : Numerical difficulties encountered.
  1049. ``5`` : Problem has no constraints; turn presolve on.
  1050. ``6`` : Invalid guess provided.
  1051. message : str
  1052. A string descriptor of the exit status of the algorithm.
  1053. nit : int
  1054. The total number of iterations performed in all phases.
  1055. Notes
  1056. -----
  1057. Method *revised simplex* uses the revised simplex method as described in
  1058. [9]_, except that a factorization [11]_ of the basis matrix, rather than
  1059. its inverse, is efficiently maintained and used to solve the linear systems
  1060. at each iteration of the algorithm.
  1061. References
  1062. ----------
  1063. .. [9] Bertsimas, Dimitris, and J. Tsitsiklis. "Introduction to linear
  1064. programming." Athena Scientific 1 (1997): 997.
  1065. .. [11] Bartels, Richard H. "A stabilization of the simplex method."
  1066. Journal in Numerische Mathematik 16.5 (1971): 414-434.
  1067. """
  1068. pass
  1069. def _linprog_simplex_doc(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
  1070. bounds=None, method='interior-point', callback=None,
  1071. maxiter=5000, disp=False, presolve=True,
  1072. tol=1e-12, autoscale=False, rr=True, bland=False,
  1073. **unknown_options):
  1074. r"""
  1075. Linear programming: minimize a linear objective function subject to linear
  1076. equality and inequality constraints using the tableau-based simplex method.
  1077. .. deprecated:: 1.9.0
  1078. `method='simplex'` will be removed in SciPy 1.11.0.
  1079. It is replaced by `method='highs'` because the latter is
  1080. faster and more robust.
  1081. Linear programming solves problems of the following form:
  1082. .. math::
  1083. \min_x \ & c^T x \\
  1084. \mbox{such that} \ & A_{ub} x \leq b_{ub},\\
  1085. & A_{eq} x = b_{eq},\\
  1086. & l \leq x \leq u ,
  1087. where :math:`x` is a vector of decision variables; :math:`c`,
  1088. :math:`b_{ub}`, :math:`b_{eq}`, :math:`l`, and :math:`u` are vectors; and
  1089. :math:`A_{ub}` and :math:`A_{eq}` are matrices.
  1090. Alternatively, that's:
  1091. minimize::
  1092. c @ x
  1093. such that::
  1094. A_ub @ x <= b_ub
  1095. A_eq @ x == b_eq
  1096. lb <= x <= ub
  1097. Note that by default ``lb = 0`` and ``ub = None`` unless specified with
  1098. ``bounds``.
  1099. Parameters
  1100. ----------
  1101. c : 1-D array
  1102. The coefficients of the linear objective function to be minimized.
  1103. A_ub : 2-D array, optional
  1104. The inequality constraint matrix. Each row of ``A_ub`` specifies the
  1105. coefficients of a linear inequality constraint on ``x``.
  1106. b_ub : 1-D array, optional
  1107. The inequality constraint vector. Each element represents an
  1108. upper bound on the corresponding value of ``A_ub @ x``.
  1109. A_eq : 2-D array, optional
  1110. The equality constraint matrix. Each row of ``A_eq`` specifies the
  1111. coefficients of a linear equality constraint on ``x``.
  1112. b_eq : 1-D array, optional
  1113. The equality constraint vector. Each element of ``A_eq @ x`` must equal
  1114. the corresponding element of ``b_eq``.
  1115. bounds : sequence, optional
  1116. A sequence of ``(min, max)`` pairs for each element in ``x``, defining
  1117. the minimum and maximum values of that decision variable. Use ``None``
  1118. to indicate that there is no bound. By default, bounds are
  1119. ``(0, None)`` (all decision variables are non-negative).
  1120. If a single tuple ``(min, max)`` is provided, then ``min`` and
  1121. ``max`` will serve as bounds for all decision variables.
  1122. method : str
  1123. This is the method-specific documentation for 'simplex'.
  1124. :ref:`'highs' <optimize.linprog-highs>`,
  1125. :ref:`'highs-ds' <optimize.linprog-highs-ds>`,
  1126. :ref:`'highs-ipm' <optimize.linprog-highs-ipm>`,
  1127. :ref:`'interior-point' <optimize.linprog-interior-point>` (default),
  1128. and :ref:`'revised simplex' <optimize.linprog-revised_simplex>`
  1129. are also available.
  1130. callback : callable, optional
  1131. Callback function to be executed once per iteration.
  1132. Options
  1133. -------
  1134. maxiter : int (default: 5000)
  1135. The maximum number of iterations to perform in either phase.
  1136. disp : bool (default: False)
  1137. Set to ``True`` if indicators of optimization status are to be printed
  1138. to the console each iteration.
  1139. presolve : bool (default: True)
  1140. Presolve attempts to identify trivial infeasibilities,
  1141. identify trivial unboundedness, and simplify the problem before
  1142. sending it to the main solver. It is generally recommended
  1143. to keep the default setting ``True``; set to ``False`` if
  1144. presolve is to be disabled.
  1145. tol : float (default: 1e-12)
  1146. The tolerance which determines when a solution is "close enough" to
  1147. zero in Phase 1 to be considered a basic feasible solution or close
  1148. enough to positive to serve as an optimal solution.
  1149. autoscale : bool (default: False)
  1150. Set to ``True`` to automatically perform equilibration.
  1151. Consider using this option if the numerical values in the
  1152. constraints are separated by several orders of magnitude.
  1153. rr : bool (default: True)
  1154. Set to ``False`` to disable automatic redundancy removal.
  1155. bland : bool
  1156. If True, use Bland's anti-cycling rule [3]_ to choose pivots to
  1157. prevent cycling. If False, choose pivots which should lead to a
  1158. converged solution more quickly. The latter method is subject to
  1159. cycling (non-convergence) in rare instances.
  1160. unknown_options : dict
  1161. Optional arguments not used by this particular solver. If
  1162. `unknown_options` is non-empty a warning is issued listing all
  1163. unused options.
  1164. Returns
  1165. -------
  1166. res : OptimizeResult
  1167. A :class:`scipy.optimize.OptimizeResult` consisting of the fields:
  1168. x : 1-D array
  1169. The values of the decision variables that minimizes the
  1170. objective function while satisfying the constraints.
  1171. fun : float
  1172. The optimal value of the objective function ``c @ x``.
  1173. slack : 1-D array
  1174. The (nominally positive) values of the slack variables,
  1175. ``b_ub - A_ub @ x``.
  1176. con : 1-D array
  1177. The (nominally zero) residuals of the equality constraints,
  1178. ``b_eq - A_eq @ x``.
  1179. success : bool
  1180. ``True`` when the algorithm succeeds in finding an optimal
  1181. solution.
  1182. status : int
  1183. An integer representing the exit status of the algorithm.
  1184. ``0`` : Optimization terminated successfully.
  1185. ``1`` : Iteration limit reached.
  1186. ``2`` : Problem appears to be infeasible.
  1187. ``3`` : Problem appears to be unbounded.
  1188. ``4`` : Numerical difficulties encountered.
  1189. message : str
  1190. A string descriptor of the exit status of the algorithm.
  1191. nit : int
  1192. The total number of iterations performed in all phases.
  1193. References
  1194. ----------
  1195. .. [1] Dantzig, George B., Linear programming and extensions. Rand
  1196. Corporation Research Study Princeton Univ. Press, Princeton, NJ,
  1197. 1963
  1198. .. [2] Hillier, S.H. and Lieberman, G.J. (1995), "Introduction to
  1199. Mathematical Programming", McGraw-Hill, Chapter 4.
  1200. .. [3] Bland, Robert G. New finite pivoting rules for the simplex method.
  1201. Mathematics of Operations Research (2), 1977: pp. 103-107.
  1202. """
  1203. pass