_linprog_doc.py 60 KB

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