
    (phO                         S r SSKrSSKJr  SSKJr  SSKJ	r	  SSK
JrJrJrJr  SSKJr  \" SS	5      rS
\R$                  l        S\l         S rSS jrS rS rSS jrS rS rS rS rS rS rSS jrS r g)z:
Method agnostic utility functions for linear programming
    N)warn   )OptimizeWarning)_remove_redundancy_svd_remove_redundancy_pivot_sparse_remove_redundancy_pivot_dense_remove_redundancy_id)
namedtuple
_LPProblemz+c A_ub b_ub A_eq b_eq bounds x0 integrality)NNNNNNNa   Represents a linear-programming problem.

    Attributes
    ----------
    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : various valid formats, optional
        The bounds of ``x``, as ``min`` and ``max`` pairs.
        If bounds are specified for all N variables separately, valid formats
        are:
        * a 2D array (N x 2);
        * a sequence of N sequences, each with 2 values.
        If all variables have the same bounds, the bounds can be specified as
        a 1-D or 2-D array or sequence with 2 scalar values.
        If all variables have a lower bound of 0 and no upper bound, the bounds
        parameter can be omitted (or given as None).
        Absent lower and/or upper bounds can be specified as -numpy.inf (no
        lower bound), numpy.inf (no upper bound) or None (both).
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.
    integrality : 1-D array or int, optional
        Indicates the type of integrality constraint on each decision variable.

        ``0`` : Continuous variable; no integrality constraint.

        ``1`` : Integer variable; decision variable must be an integer
        within `bounds`.

        ``2`` : Semi-continuous variable; decision variable must be within
        `bounds` or take value ``0``.

        ``3`` : Semi-integer variable; decision variable must be an integer
        within `bounds` or take value ``0``.

        By default, all variables are continuous.

        For mixed integrality constraints, supply an array of shape `c.shape`.
        To infer a constraint on each decision variable from shorter inputs,
        the argument will be broadcast to `c.shape` using `np.broadcast_to`.

        This argument is currently used only by the ``'highs'`` method and
        ignored otherwise.

    Notes
    -----
    This namedtuple supports 2 ways of initialization:
    >>> lp1 = _LPProblem(c=[-1, 4], A_ub=[[-3, 1], [1, 2]], b_ub=[6, 4])
    >>> lp2 = _LPProblem([-1, 4], [[-3, 1], [1, 2]], [6, 4])

    Note that only ``c`` is a required argument here, whereas all other arguments
    ``A_ub``, ``b_ub``, ``A_eq``, ``b_eq``, ``bounds``, ``x0`` are optional with
    default values of None.
    For example, ``A_eq`` and ``b_eq`` can be set without ``A_ub`` or ``b_ub``:
    >>> lp3 = _LPProblem(c=[-1, 4], A_eq=[[2, 1]], b_eq=[10])
    c                    U R                  SS5      nU(       a  Ub  [        R                  " U5      nU(       a  Ub  [        R                  " U5      n[        R                  " U5      =(       d    [        R                  " U5      n1 SknSS1nX;   a  U(       a  [	        SU SU S35      eU R                  S	S5      nU(       d!  U(       a  US
:X  a  SU S	'   [        S[        SS9  XU4$ )ay  
Check the provided ``A_ub`` and ``A_eq`` matrices conform to the specified
optional sparsity variables.

Parameters
----------
A_ub : 2-D array, optional
    2-D array such that ``A_ub @ x`` gives the values of the upper-bound
    inequality constraints at ``x``.
A_eq : 2-D array, optional
    2-D array such that ``A_eq @ x`` gives the values of the equality
    constraints at ``x``.
options : dict
    A dictionary of solver options. All methods accept the following
    generic options:

        maxiter : int
            Maximum number of iterations to perform.
        disp : bool
            Set to True to print convergence messages.

    For method-specific options, see :func:`show_options('linprog')`.
method : str, optional
    The algorithm used to solve the standard form problem.

Returns
-------
A_ub : 2-D array, optional
    2-D array such that ``A_ub @ x`` gives the values of the upper-bound
    inequality constraints at ``x``.
A_eq : 2-D array, optional
    2-D array such that ``A_eq @ x`` gives the values of the equality
    constraints at ``x``.
options : dict
    A dictionary of solver options. All methods accept the following
    generic options:

        maxiter : int
            Maximum number of iterations to perform.
        disp : bool
            Set to True to print convergence messages.

    For method-specific options, see :func:`show_options('linprog')`.
_sparse_presolveF>   highshighs-ds	highs-ipmsimplexzrevised simplexzMethod 'zL' does not support sparse constraint matrices. Please consider using one of .sparsezinterior-pointTz9Sparse constraint matrix detected; setting 'sparse':True.   
stacklevel)popsps
coo_matrixissparse
ValueErrorgetr   r   )	optionsmethA_ubA_eqr   sparse_constraintpreferred_methodsdense_methodsr   s	            O/var/www/html/venv/lib/python3.13/site-packages/scipy/optimize/_linprog_util.py_check_sparse_inputsr%   [   s    \ {{#5u=D,~~d#D,~~d#T*@cll4.@: 12M!28D6 *N-.a1 2 	2 [[5)F'D4D,D H	,$    c                     U(       a!  [         R                  " U c  SU4OU [        SS9$ U c  [        R                  " SU4[        S9$ [        R
                  " U [        SS9$ )a5  Format the left hand side of the constraints to a 2-D array

Parameters
----------
A : 2-D array
    2-D array such that ``A @ x`` gives the values of the upper-bound
    (in)equality constraints at ``x``.
n_x : int
    The number of variables in the linear programming problem.
sparse_lhs : bool
    Whether either of `A_ub` or `A_eq` are sparse. If true return a
    coo_matrix instead of a numpy array.

Returns
-------
np.ndarray or sparse.coo_matrix
    2-D array such that ``A @ x`` gives the values of the upper-bound
    (in)equality constraints at ``x``.

r   Tdtypecopyr)   )r   r   floatnpzerosarray)An_x
sparse_lhss      r$   _format_A_constraintsr3      sX    * ~~	QHqD
 	
 
xxC..xxT22r&   c                     U c  [         R                  " / [        S9$ [         R                  " U [        SS9R                  5       n U R                  S:w  a  U $ U R                  S5      $ )aP  Format the upper bounds of the constraints to a 1-D array

Parameters
----------
b : 1-D array
    1-D array of values representing the upper-bound of each (in)equality
    constraint (row) in ``A``.

Returns
-------
1-D np.array
    1-D array of values representing the upper-bound of each (in)equality
    constraint (row) in ``A``.

r+   Tr(   r   )r-   r/   r,   squeezesizereshape)bs    r$   _format_b_constraintsr:      sR      	yxx%((
%d+335A!1.2.r&   c           
         U u  pp4pVpxUc  [         e [        R                  " U[        R                  SS9R	                  5       nUR
                  S:X  a  UR                  S5      n[        U5      n	U	S:X  d  [        UR                  5      S:w  a  [        S5      e[        R                  " U5      R                  5       (       d  [        S5      e [        R                  " U5      =(       d    [        R                  " U5      n [        X)US
9nUR                  S   n[        UR                  5      S:w  d  UR                  S   U	:w  a  [        S5      e[        R                  " U5      (       a3  [        R                  " UR                  5      R                  5       (       aD  [        R                  " U5      (       d4  [        R                  " U5      R                  5       (       d  [        S5      e [!        U5      nUR                  U4:w  a  [        S5      e[        R                  " U5      R                  5       (       d  [        S5      e  [        XIUS
9nUR                  S   n[        UR                  5      S:w  d  UR                  S   U	:w  a  [        S5      e[        R                  " U5      (       a3  [        R                  " UR                  5      R                  5       (       aD  [        R                  " U5      (       d4  [        R                  " U5      R                  5       (       d  [        S5      e [!        U5      nUR                  U4:w  a  [        S5      e[        R                  " U5      R                  5       (       d  [        S5      e Ub   [        R                  " U["        SS9R	                  5       nUR$                  S:X  a  UR                  S5      n[        U5      S:X  d  UR$                  S:w  a  [        S5      eUR
                  UR
                  :X  d  [        S5      e[        R                  " U5      R                  5       (       d  [        S5      e[        R&                  " U	S4["        S9nUb9  [        R(                  " U/ 5      (       d  [        R(                  " U/ /5      (       a  S[        R*                  4n [        R,                  " [        R                  " U["        S95      nUR                  n[        U5      S:  a  [        S[        U5      S S 35      e[        R                  " UU	S4:H  5      (       a  UnO[        R                  " US!:H  5      (       d  [        R                  " US":H  5      (       a)  UR1                  5       nUS   USS2S4'   US   USS2S4'   OC[        R                  " USU	4:H  5      (       a  [        S#U	S S$U	S S%35      e[        S&U S'35      e[        R2                  " USS2S4   5      n[        R*                  * UUS4'   [        R2                  " USS2S4   5      n[        R*                  UUS4'   [5        XX4X^Xx5      $ ! [         a  n
[        S	5      U
eSn
A
ff = f! [         a  n
[        S5      U
eSn
A
ff = f! [         a  n
[        S5      U
eSn
A
ff = f! [         a  n
[        S5      U
eSn
A
ff = f! [         a  n
[        S5      U
eSn
A
ff = f! [         a  n
[        S5      U
eSn
A
ff = f! [         a!  n
[        SU
R.                  S   -   5      U
eSn
A
f[          a!  n
[        SU
R.                  S   -   5      U
eSn
A
ff = f)(aZ  
Given user inputs for a linear programming problem, return the
objective vector, upper bound constraints, equality constraints,
and simple bounds in a preferred format.

Parameters
----------
lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : various valid formats, optional
        The bounds of ``x``, as ``min`` and ``max`` pairs.
        If bounds are specified for all N variables separately, valid formats are:
        * a 2D array (2 x N or N x 2);
        * a sequence of N sequences, each with 2 values.
        If all variables have the same bounds, a single pair of values can
        be specified. Valid formats are:
        * a sequence with 2 scalar values;
        * a sequence with a single element containing 2 scalar values.
        If all variables have a lower bound of 0 and no upper bound, the bounds
        parameter can be omitted (or given as None).
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

Returns
-------
lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : 2D array
        The bounds of ``x``, as ``min`` and ``max`` pairs, one for each of the N
        elements of ``x``. The N x 2 array contains lower bounds in the first
        column and upper bounds in the 2nd. Unbounded variables have lower
        bound -np.inf and/or upper bound np.inf.
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

NTr(   r   r5   r   zhInvalid input for linprog: c must be a 1-D array and must not have more than one non-singleton dimensionzFInvalid input for linprog: c must not contain values inf, nan, or NonezJInvalid input for linprog: c must be a 1-D array of numerical coefficients)r2      zInvalid input for linprog: A_ub must have exactly two dimensions, and the number of columns in A_ub must be equal to the size of czIInvalid input for linprog: A_ub must not contain values inf, nan, or NonezGInvalid input for linprog: A_ub must be a 2-D array of numerical valueszInvalid input for linprog: b_ub must be a 1-D array; b_ub must not have more than one non-singleton dimension and the number of rows in A_ub must equal the number of values in b_ubzIInvalid input for linprog: b_ub must not contain values inf, nan, or NonezInvalid input for linprog: b_ub must be a 1-D array of numerical values, each representing the upper bound of an inequality constraint (row) in A_ubzInvalid input for linprog: A_eq must have exactly two dimensions, and the number of columns in A_eq must be equal to the size of czIInvalid input for linprog: A_eq must not contain values inf, nan, or NonezGInvalid input for linprog: A_eq must be a 2-D array of numerical valueszInvalid input for linprog: b_eq must be a 1-D array; b_eq must not have more than one non-singleton dimension and the number of rows in A_eq must equal the number of values in b_eqzIInvalid input for linprog: b_eq must not contain values inf, nan, or NonezInvalid input for linprog: b_eq must be a dense, 1-D array of numerical values, each representing the right hand side of an equality constraint (row) in A_eqzKInvalid input for linprog: x0 must be a 1-D array of numerical coefficientszkInvalid input for linprog: x0 should be a 1-D array; it must not have more than one non-singleton dimensionzNInvalid input for linprog: x0 and c should contain the same number of elementszGInvalid input for linprog: x0 must not contain values inf, nan, or Noner+   zTInvalid input for linprog: unable to interpret bounds, check values and dimensions: zAInvalid input for linprog: provide a 2-D array for bounds, not a dz	-D array.)r<   r   )r   r<   z%Invalid input for linprog: provide a z! x 2 array for bounds, not a 2 x z array.zQInvalid input for linprog: unable to interpret bounds with this dimension tuple: r   )	TypeErrorr-   r/   float64r6   r7   r8   lenshaper   isfiniteallr   r   r3   datar:   r,   ndimr.   array_equalinf
atleast_2dargsflattenisnanr   )lpcr   b_ubr    b_eqboundsx0integralityr1   er2   n_ubn_eqbounds_cleanbounds_convbshbounds_flati_nones                      r$   _clean_inputsr[      s   N :<6ATry%HHQbjjt4<<> 66Q;		"A!f!8s177|q(AB B {{1~!!##$% % $
 d#9s||D'9J%$T:F zz!}tzz?a4::a=C#7)* * LLr{{499'='A'A'C'C||D))"++d2C2G2G2I2I$% %%$T* ::$  
 {{4 $$&&$% % '
%$T:F zz!}tzz?a4::a=C#7)* *
 LLr{{499'='A'A'C'C||D))"++d2C2G2G2I2I$% %%$T* ::$  
 {{4 $$&&$% % ' 
~	1"E5==?B
 77a<BBr7a<277a<FG G ww!&& *+ + {{2""$$$% % 88S!HE2L ~33r~~frd7S7SRVV	@mmBHHV5$AB 

C
3x!|XaL	+, 	, 
Qx	 	 "
&&

266#-#8#8!))+(^QT(^QT	3x	 	 3C7 ;Qw() 	)   #uA'( 	( XXl1a4()F!vvgLXXl1a4()F ffLat4rOOo  #!"	##,  *"#()	**&  :23 9:	::&  *"#()	**(  801 78	88,  	1)*/01	1N  @,./ffQi89>?	@  @,./ffQi89>?	@@s   2Y1 
Z 1Z- 
[ <[) (\ -\% 1
Z;ZZ
Z*Z%%Z*-
[7[[
[&[!![&)
\3[??\
\"\\"%
]9/]]9]44]9c           
        ^/^0 U u  pEpgpp/ nSnSn[         R                  " UR                  5      nSnSnU	SS2S4   R                  5       nU	SS2S4   R                  5       nUR                  u  nnUR                  u  nnUb0  UR	                  5       S;  a  S[        U5      -   S-   n[        U5      e[        R                  " U5      (       a4  UR                  5       nUR                  5       nS	 n[        R                  nO [         R                  n[         R                  n[         R                  " UU:  5      (       dY  [         R                  " U[         R                  :H  5      (       d-  [         R                  " U[         R                  * :H  5      (       a  S
nSnSn[        XEXgXU
5      XXUU4$ [         R                  " [         R                   " US:g  SS9S:H  5      R#                  5       n[         R                  " U5      (       a  [         R                  " [         R$                  " U[         R&                  " U5      U:  5      5      (       a  S
nSnSn[        XEXgXU
5      XXUU4$ U[         R(                  " U5      SS24   nU[         R(                  " U5         n[         R                  " [         R                   " US:g  SS9S:H  5      R#                  5       n[         R                  " U5      (       a  [         R                  " [         R$                  " UXc* :  5      5      (       a  S
nSnSn[        XEXgXU
5      XXUU4$ U[         R(                  " U5      SS24   nU[         R(                  " U5         nU" Xu45      nUR                  S   S:  Gae  [         R                  " [         R                   " US:g  SS9S:H  5      R#                  5       nU[         R$                  " UUS:  5         U[         R$                  " UUS:  5      '   U[         R$                  " UUS:  5         U[         R$                  " UUS:  5      '   [         R                  " [         R*                  " U5      5      (       a  SnSnSn[        XEXgXU
5      XXUU4$ U[         R$                  " UUS:  5         U[         R$                  " UUS:  5      '   U[         R$                  " UUS:  5         U[         R$                  " UUS:  5      '   [         R                  " [         R                   " US:g  SS9S:H  5      R#                  5       nU" U5      S   nU" UUSS24   5      S   n[-        U5      S:  a  [/        UU5       HS  u  nn UU   UUU 4   -  n!UU    U-
  U!s=::  a  UU    U-   ::  d  O  S
nSnSn[        XEXgXU
5      XXUU4s  $ U!UU '   U!UU '   MU     U[         R(                  " U5      SS24   nU[         R(                  " U5         n[         R                  " [         R                   " US:g  SS9S:H  5      R#                  5       nU" UUSS24   5      S   nU" U5      S   n[-        U5      S:  a  [/        UU5       Hy  u  nn UU   UUU 4   -  n!UUU 4   S:  a  U!UU    U-
  :  a  SnO,U!UU    :  a  U!UU '   OU!UU    U-   :  a  SnOU!UU    :  a  U!UU '   U(       d  Mb  S
nSn[        XEXgXU
5      XXUU4s  $    U[         R(                  " U5      SS24   nU[         R(                  " U5         n[         R&                  " UU-
  5      U:  m/[         R(                  " T/5      n"[         R0                  " T/5      (       a  XR3                  U5      -
  n#XeR3                  U5      -
  n$UR4                  S:  a  [         R                  " U$S:  5      (       d,  UR4                  S:  a5  [         R6                  " U#S5      (       d  S
nSnSn[        XEXgXU
5      XXUU4$ Un%Un&[         R                  " T/5      (       a  XT/   R3                  UT/   5      -  nXSS2T/4   R3                  UT/   5      -
  nXeSS2T/4   R3                  UT/   5      -
  nUU"   nUT/   m0UU"   nU
b  U
U"   n
USS2U"4   nUSS2U"4   nUU"   n&UU"   n%U/U04S jn'UR9                  U'5        UR4                  S:X  Ga^  UR4                  S:X  GaM  [         R                  " / 5      n[         R                  " / 5      nUR4                  S:X  a  SnSnO[         R                  " [         R$                  " US:  U%[         R                  :H  5      5      (       dE  [         R                  " [         R$                  " US:  U&[         R                  * :H  5      5      (       a  SnSnOSnSnSnU%US:     XS:  '   U&US:     XS:  '   U%US:H     n(U%US:H     [         R*                  " U(5         U([         R*                  " U(5      '   SU([         R*                  " U(5      '   U(XS:H  '   [         R:                  " U&SS2[         R<                  4   U%SS2[         R<                  4   45      n	UR                  S   n)Sn*[        R                  " U5      (       ae  U(       aK  UR4                  S:  a;  [?        Xx5      n+U+u  pxnnUR                  S   U):  a  [A        U*[B        SS9  US:w  a  Sn[        XEXgXU
5      XXUU4$ Sn,U(       a0  UR4                  S:  a    [         RD                  RG                  U5      n-U(       a  UR4                  S:  a  W-UR                  S   :  a  [A        U*[B        SS9  UR                  S   U--
  n.Uc5  U.U,::  a  [K        Xx5      n+U+u  pxnnU.U,:  d  US:X  a  [M        Xx5      n+U+u  pxnnOZUR	                  5       nUS:X  a  [K        Xx5      n+U+u  pxnnO2US:X  a  [M        Xx5      n+U+u  pxnnOUS:X  a  [O        XxU-5      n+U+u  pxnnO UR                  S   U-:  a  SnSnUS:w  a  Sn[        XEXgXU
5      XXUU4$ ! [H         a    Sn- GNf = f) a  
Given inputs for a linear programming problem in preferred format,
presolve the problem: identify trivial infeasibilities, redundancies,
and unboundedness, tighten bounds where possible, and eliminate fixed
variables.

Parameters
----------
lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : 2D array
        The bounds of ``x``, as ``min`` and ``max`` pairs, one for each of the N
        elements of ``x``. The N x 2 array contains lower bounds in the first
        column and upper bounds in the 2nd. Unbounded variables have lower
        bound -np.inf and/or upper bound np.inf.
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

rr : bool
    If ``True`` attempts to eliminate any redundant rows in ``A_eq``.
    Set False if ``A_eq`` is known to be of full row rank, or if you are
    looking for a potential speedup (at the expense of reliability).
rr_method : string
    Method used to identify and remove redundant rows from the
    equality constraint matrix after presolve.
tol : float
    The tolerance which determines when a solution is "close enough" to
    zero in Phase 1 to be considered a basic feasible solution or close
    enough to positive to serve as an optimal solution.

Returns
-------
lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : 2D array
        The bounds of ``x``, as ``min`` and ``max`` pairs, possibly tightened.
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

c0 : 1D array
    Constant term in objective function due to fixed (and eliminated)
    variables.
x : 1D array
    Solution vector (when the solution is trivial and can be determined
    in presolve)
revstack: list of functions
    the functions in the list reverse the operations of _presolve()
    the function signature is x_org = f(x_mod), where x_mod is the result
    of a presolve step and x_org the value at the start of the step
    (currently, the revstack contains only one function)
complete: bool
    Whether the solution is complete (solved or determined to be infeasible
    or unbounded in presolve)
status : int
    An integer representing the exit status of the optimization::

     0 : Optimization terminated successfully
     1 : Iteration limit reached
     2 : Problem appears to be infeasible
     3 : Problem appears to be unbounded
     4 : Serious numerical difficulties encountered

message : str
    A string descriptor of the exit status of the optimization.

References
----------
.. [5] Andersen, Erling D. "Finding all linearly dependent rows in
       large-scale linear programming." Optimization Methods and Software
       6.3 (1995): 219-227.
.. [8] Andersen, Erling D., and Knud D. Andersen. "Presolving in linear
       programming." Mathematical Programming 71.2 (1995): 221-245.

r   F Nr   >   idsvdpivot'z[' is not a valid option for redundancy removal. Valid options are 'SVD', 'pivot', and 'ID'.c                 "    U R                  5       $ N)nonzero)r0   s    r$   where_presolve.<locals>.wheres  s    99;r&   r<   zThe problem is (trivially) infeasible since one or more upper bounds are smaller than the corresponding lower bounds, a lower bound is np.inf or an upper bound is -np.inf.TaxiszThe problem is (trivially) infeasible due to a row of zeros in the equality constraint matrix with a nonzero corresponding constraint value.zThe problem is (trivially) infeasible due to a row of zeros in the equality constraint matrix with a nonzero corresponding  constraint value.   zIf feasible, the problem is (trivially) unbounded due  to a zero column in the constraint matrices. If you wish to check whether the problem is infeasible, turn presolve off.zzThe problem is (trivially) infeasible because a singleton row in the equality constraints is inconsistent with the bounds.z}The problem is (trivially) infeasible because a singleton row in the upper bound constraints is inconsistent with the bounds.zvThe problem is (trivially) infeasible because the bounds fix all variables to values inconsistent with the constraintsc                    > [         R                  " T5      n[        U5      n[         R                  " U5      nX-
  n[         R                  " U R                  [        5      UT5      nU$ rc   )r-   flatnonzeror@   arangeinsertastyper,   )x_modiNindex_offsetinsert_indicesx_revi_fx_undos         r$   rev_presolve.<locals>.rev   sQ    
 s#AAA99Q<L-NIIell51>6JELr&   zPThe solution was determined in presolve as there are no non-trivial constraints.a  The problem is (trivially) unbounded because there are no non-trivial constraints and a) at least one decision variable is unbounded above and its corresponding cost is negative, or b) at least one decision variable is unbounded below and its corresponding cost is positive. zA_eq does not appear to be of full row rank. To improve performance, check the problem formulation for redundant equality constraints.r      r   r_   r`   r^   zDue to numerical issues, redundant equality constraints could not be removed automatically. Try providing your constraint matrices as sparse matrices to activate sparse presolve, try turning off redundancy removal, or try turning off presolve altogether.)(r-   r.   rA   r*   lowerstrr   r   r   tocsrvstackre   anyrG   r   r/   sumrJ   logical_andabslogical_notisinfr@   ziprC   dotr7   allcloseappendhstacknewaxisr   r   r   linalgmatrix_rank	Exceptionr   r   r	   )1rL   rr	rr_methodtolrM   r   rN   r    rO   rP   rQ   _revstackc0completexstatusmessagelbubm_eqnm_ubre   r}   zero_rowr0   zero_colsingleton_rowrowscolsrowcolvali_nfresidualslackub_modlb_modrw   x_zero_cn_rows_Aredundancy_warningrr_ressmall_nullspacerankdim_row_nullspaceru   rv   s1                                                  @@r$   	_presolver     s   r 02,ATrH	
BH
AFG 
1			B	1			BjjGD!jjGD!!)??Y' +( ( !!
||Dzz|zz|	  
vvb2g"&&rvv.."&&w2G2G! 1DbAx67< 	< xxtqyq1Q67??AH	vvh66NNts"$% %
 FAG HqD"E8vw@ @ x0!34Dx01D xxtqyq1Q67??AH	vvh66"..4$;788FBG HqD"E8vw@ @ x0!34Dx01D 	|AwwqzA~88BFF162a78@@B-/NN8QU+.-"..1q5
)*-/NN8QU+.-"..1q5
)*66"((1+F,G HqD"E8vw@ @ /1NN8QU+/-2>>(AE*+.0NN8QU+/-2>>(AE*+
 HHRVVDAIA6!;<DDFM"DdAg"D
4y1}D$HCs)d38n,Cc7S=C82c7S=8;  "1DbIx67D D
 33 (  BNN=1145BNN=12 HHRVVDAIA6!;<DDFMmQ&'(+D"D
4y1}D$HCs)d38n,CCH~!C3&#H2c7]!BsGC3&#H2c7]!BsGx; #1DbIx67D D# (& BNN=1145BNN=12 &&b/C
C>>#D 
vvc{{((2,&xx|#YY]rvveai00Qr{{8Q'?'?F)G HqD"E8vw@ @ FF	vvc{{
fjjC!!1c6l&&r#w//1c6l&&r#w//dGCdG>DBAtG}AtG}DD	 	 yyA~$))q.xx|xx|66Q;F5GffR^^AE6RVV+;<==ffR^^AE6bffW+<=>> FBG F5G!a%=a%!a%=a%!q&>'-a1f~bhhx6H'I(#$'((#$q&	
 YYq"**}-vam/DEFF zz!}H@ 	T$))a-4T@F*0'Dzz!}x''QG{1DbAx67< 	<
 O	dii!m	99((.D 
dii!mtzz!} 4Q? JJqM$. O3/;.4+FG ?2fk7C.4+FG ")IE!/;.4+FGg%7C.4+FGd".t4@.4+FG::a=4%G FQ;HqD"=8vw8 8I  	D	s   %q q#"q#c                     Uc  0 nUR                  5        VVs0 s H  u  p4X4_M	     nnn[        XRU R                  U R                  5      u  pVn[	        U R                  XgS95      n X4$ s  snnf )a;  
Parse the provided linear programming problem

``_parse_linprog`` employs two main steps ``_check_sparse_inputs`` and
``_clean_inputs``. ``_check_sparse_inputs`` checks for sparsity in the
provided constraints (``A_ub`` and ``A_eq) and if these match the provided
sparsity optional values.

``_clean inputs`` checks of the provided inputs. If no violations are
identified the objective vector, upper bound constraints, equality
constraints, and simple bounds are returned in the expected format.

Parameters
----------
lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : various valid formats, optional
        The bounds of ``x``, as ``min`` and ``max`` pairs.
        If bounds are specified for all N variables separately, valid formats are:
        * a 2D array (2 x N or N x 2);
        * a sequence of N sequences, each with 2 values.
        If all variables have the same bounds, a single pair of values can
        be specified. Valid formats are:
        * a sequence with 2 scalar values;
        * a sequence with a single element containing 2 scalar values.
        If all variables have a lower bound of 0 and no upper bound, the bounds
        parameter can be omitted (or given as None).
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

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

        maxiter : int
            Maximum number of iterations to perform.
        disp : bool
            Set to True to print convergence messages.

    For method-specific options, see :func:`show_options('linprog')`.

Returns
-------
lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : 2D array
        The bounds of ``x``, as ``min`` and ``max`` pairs, one for each of the N
        elements of ``x``. The N x 2 array contains lower bounds in the first
        column and upper bounds in the 2nd. Unbounded variables have lower
        bound -np.inf and/or upper bound np.inf.
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

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

        maxiter : int
            Maximum number of iterations to perform.
        disp : bool
            Set to True to print convergence messages.

    For method-specific options, see :func:`show_options('linprog')`.

)r   r    )itemsr%   r   r    r[   _replace)rL   r   r   kvsolver_optionsr   r    s           r$   _parse_linprogr     sq    H '.}}7tqadN7!5n68ggrww"HN$ 
r{{{8	9B 8s   A)c                    U u  p#pEpgp[         R                  " U5      (       aU  Sn
[         R                  " U5      n[         R                  " U5      nS nS n[         R                  n[         R                  nOBSn
[        R
                  n[        R                  n[        R                  n[        R                  n[        R                  " USS9nUSS2S4   nUSS2S4   nUR                  u  nn[        R                  " U[        R                  * 5      n[        R                  " U[        R                  5      n[        R                  " U5      n[        R                  " U5      n[        R                  " UU5      n[        R                  " U5      S   nUU   * UU   * sUU'   UU'   [        R                  " U[        R                  * 5      n[        R                  " U[        R                  5      n[        R                  " U5      n[        R                  " U5      nUU==   S	-  ss'   Ub  UU==   S	-  ss'   [        U5      S:  aH  UR                  S   S:  a  USS2U4==   S	-  ss'   UR                  S   S:  a  USS2U4==   S	-  ss'   UR                  5       u  nUU   n[        U5      nUS:  a  UUR                  S   4nU
(       aL  [        R                   " U5      U4nU" U[         R                  " [        R"                  " U5      U4US
945      nOGU" U[        R                  " U5      45      nSU[        R                   " UUR                  S   5      U4'   [        R$                  " U[        R                  " U5      45      nUUUS& U" X545      n[        R$                  " XF45      n[        R$                  " U[        R                  " UR                  S   45      45      nUb:  [        R$                  " U[        R                  " UR                  S   45      45      n[        R                  " UU5      n [        R                  " U 5      S   n![        U!5      n"[        R$                  " U[        R                  " U"5      45      nUb,  [        R$                  " U[        R                  " U"5      45      nU" USS2SU24   USS2U!4   * 45      nUU!   * UUUU"-   & UbA  UU!   S:  n#UU!U#      * U[        R                   " UUR                  S   5      U#   '   SUU!U#   '   U" U" UR                  S   5      U" UR                  S   UR                  S   45      /5      n$U" UU$/5      n%[        R                  " U5      S   n&UU   R'                  [(        5      n'U[        R*                  " U'UU&   -  5      -  nU
(       ac  UR-                  S	S5      nU%R/                  5       n%UU%SS2U&4   [         R0                  " U'5      -  R+                  SS9-  nUR3                  5       nOUU%SS2U&4   U'-  R+                  SS9-  nUb  UU&==   U'-  ss'   U%UX!U4$ )a

  
Given a linear programming problem of the form:

Minimize::

    c @ x

Subject to::

    A_ub @ x <= b_ub
    A_eq @ x == b_eq
     lb <= x <= ub

where ``lb = 0`` and ``ub = None`` unless set in ``bounds``.

Return the problem in standard form:

Minimize::

    c @ x

Subject to::

    A @ x == b
        x >= 0

by adding slack variables and making variable substitutions as necessary.

Parameters
----------
lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : 2D array
        The bounds of ``x``, lower bounds in the 1st column, upper
        bounds in the 2nd column. The bounds are possibly tightened
        by the presolve procedure.
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

c0 : float
    Constant term in objective function due to fixed (and eliminated)
    variables.

Returns
-------
A : 2-D array
    2-D array such that ``A`` @ ``x``, gives the values of the equality
    constraints at ``x``.
b : 1-D array
    1-D array of values representing the RHS of each equality constraint
    (row) in A (for standard form problem).
c : 1-D array
    Coefficients of the linear objective function to be minimized (for
    standard form problem).
c0 : float
    Constant term in objective function due to fixed (and eliminated)
    variables.
x0 : 1-D array
    Starting values of the independent variables, which will be refined by
    the optimization algorithm

References
----------
.. [9] Bertsimas, Dimitris, and J. Tsitsiklis. "Introduction to linear
       programming." Athena Scientific 1 (1997): 997.

Tc                 ,    [         R                  " U SS9$ Ncsr)format)r   r   blockss    r$   r   _get_Abc.<locals>.hstackb      ::fU33r&   c                 ,    [         R                  " U SS9$ r   )r   r}   r   s    r$   r}   _get_Abc.<locals>.vstacke  r   r&   F)r*   Nr   r   r5   )rA   rg   )r   r   
csr_matrixeyer-   r   r}   r.   r/   rA   equalrG   r   r   rd   r@   rl   onesconcatenatern   r,   r   r8   tocscdiagsravel)(rL   r   rM   r   rN   r    rO   rP   rQ   rR   r   r   r}   r.   r   lbsubsr   rT   lb_noneub_nonelb_someub_somel_nolb_someubi_nolbi_newubub_newubn_boundsrA   idxsA1r9   l_freei_freen_free
i_free_negA2r0   i_shiftlb_shifts(                                           r$   _get_Abcr     sz   j :<6ATr
||D~~d#~~d#	4	4 ggff XXf4(F A,C
A,CJD$hhsRVVG$GhhsBFF#GnnW%GnnW%G NN7G4MZZ&q)F	]	c-00 +CM*hhsRVVG$GhhsBFF#GnnW%GnnW%GfIOI	~
6
b

6{Q::a=1FOr!O::a=1FOr!O  HG7|H7|H!|4::a=)IIh'1D41BD0I6;"= > ?D 4%12D<=D4A/89~~tRXXh%789TU		B
|$A
288TZZ]$4567A	~^^R4::a=*:!;<=^^GW-FZZ"F[F
288F+,-A	~^^R&!123	AuuH1f9~.	/BV9*Ad4;	~Z!^
8:6*;M8N7N299T288A;'
34!"6* 
TZZ]#UDJJqM4::a=+I%JK	LBBxA jj!!$G7|""5)H"&&AgJ&
''BIIb!GGI	a7
mcii1166A6>>GGI	a7
mh&+++33	~
7xa?r&   c                 \    S[         R                  " [         R                  " U 5      5      -  $ )z:
Round elements of the array to the nearest power of two.
r<   )r-   aroundlog2)r   s    r$   _round_to_power_of_twor     s      bii
###r&   c                    U R                   u  pESnSnU R                  S:  Gav  [        R                  " [        R                  " U 5      SS9n[
        R                  " U 5      (       a  UR                  5       R                  5       nSXwS:H  '   S[        U5      -  n[
        R                  " U 5      (       a  [
        R                  " U5      U -  OXR                  US5      -  n X-  n[        R                  " [        R                  " U 5      SS9n[
        R                  " U 5      (       a  UR                  5       R                  5       nSXfS:H  '   S[        U5      -  n[
        R                  " U 5      (       a  U [
        R                  " U5      -  OX-  n X&-  nUR                  S:  a*  [        R                  " [        R                  " U5      5      OSnUS:X  a  SnX-  nUb
  X8-  SU-  -  nXX#Xh4$ )z}
Scales the problem according to equilibration from [12].
Also normalizes the right hand side vector by its maximum element.
r   r   rg   g      ?)rA   r7   r-   maxr   r   r   toarrayrJ   r   r   r8   )	r0   r9   rM   rQ   mr   CRb_scales	            r$   
_autoscaler     s~   
 77DA	A	AvvzFF266!91%<<??		##%Aq&	$Q''!ll1ooCIIaLN1YYq!_3DCFF266!91%<<??		##%Aq&	$Q''!ll1ooAciilN13C#$66A:bffRVVAY1G!|		A	~Z1""r&   c                 f     [        U5      nU SU U-  U-  $ ! [         a    [        U 5      n N"f = f)zJ
Converts solution to _autoscale problem -> solution to original problem.
N)r@   r>   )r   r   r   r   s       r$   _unscaler     s@    
F Ra5=?  Fs    00c                 b    [        U 5        US;   a  [        SUS 35        [        SUS 35        g)aW  
Print the termination summary of the linear program

Parameters
----------
message : str
        A string descriptor of the exit status of the optimization.
status : int
    An integer representing the exit status of the optimization::

            0 : Optimization terminated successfully
            1 : Iteration limit reached
            2 : Problem appears to be infeasible
            3 : Problem appears to be unbounded
            4 : Serious numerical difficulties encountered

fun : float
    Value of the objective function.
iteration : iteration
    The number of iterations performed.
)r   r   z!         Current function value: z <12.6fz         Iterations: r=   N)print)r   r   fun	iterations       r$   _display_summaryr     s7    , 
'N1#g?@	!)A
/0r&   c                    US   u  p4pVpxpUSS u  pn[        XU5      n UR                  S   nU(       d  Ub  Sn[        U5       H  u  nnUS   nUS   nU[        R                  * :X  a.  U[        R                  :X  a  US-  nU U   XU-   S-
     -
  U U'   MS  U[        R                  * :X  a  UU U   -
  U U'   Mu  U U==   U-  ss'   M     U SU n [        U5       H  nU" U 5      n M     U R                  U5      n[        R                  " SS9   XTR                  U 5      -
  nXvR                  U 5      -
  nSSS5        U UWW4$ ! , (       d  f       N= f)a"
  
Given solution x to presolved, standard form linear program x, add
fixed variables back into the problem and undo the variable substitutions
to get solution to original linear program. Also, calculate the objective
function value, slack in original upper bound constraints, and residuals
in original equality constraints.

Parameters
----------
x : 1-D array
    Solution vector to the standard-form problem.
postsolve_args : tuple
    Data needed by _postsolve to convert the solution to the standard-form
    problem into the solution to the original problem, including:

lp : A `scipy.optimize._linprog_util._LPProblem` consisting of the following fields:

    c : 1D array
        The coefficients of the linear objective function to be minimized.
    A_ub : 2D array, optional
        The inequality constraint matrix. Each row of ``A_ub`` specifies the
        coefficients of a linear inequality constraint on ``x``.
    b_ub : 1D array, optional
        The inequality constraint vector. Each element represents an
        upper bound on the corresponding value of ``A_ub @ x``.
    A_eq : 2D array, optional
        The equality constraint matrix. Each row of ``A_eq`` specifies the
        coefficients of a linear equality constraint on ``x``.
    b_eq : 1D array, optional
        The equality constraint vector. Each element of ``A_eq @ x`` must equal
        the corresponding element of ``b_eq``.
    bounds : 2D array
        The bounds of ``x``, lower bounds in the 1st column, upper
        bounds in the 2nd column. The bounds are possibly tightened
        by the presolve procedure.
    x0 : 1D array, optional
        Guess values of the decision variables, which will be refined by
        the optimization algorithm. This argument is currently used only by the
        'revised simplex' method, and can only be used if `x0` represents a
        basic feasible solution.

revstack: list of functions
    the functions in the list reverse the operations of _presolve()
    the function signature is x_org = f(x_mod), where x_mod is the result
    of a presolve step and x_org the value at the start of the step
complete : bool
    Whether the solution is was determined in presolve (``True`` if so)

Returns
-------
x : 1-D array
    Solution vector to original linear programming problem
fun: float
    optimal objective value for original problem
slack : 1-D array
    The (non-negative) slack in the upper bound constraints, that is,
    ``b_ub - A_ub @ x``
con : 1-D array
    The (nominally zero) residuals of the equality constraints, that is,
    ``b - A_eq @ x``
r   r   Nignore)invalid)r   rA   	enumerater-   rG   reversedr   errstate)r   postsolve_argsr   rM   r   rN   r    rO   rP   rQ   rR   r   r   r   r1   n_unboundedrp   bilbiubirw   r   r   cons                           r$   
_postsolver   $  sc   B :H9J6ATr)!"-HwA ,,q/C*v&EArQ%CQ%Crvvg~#-q tak 1A 566!266'>1:AaDaDCKD ' 	
$3A
 !F " %%(C	X	&xx{"XXa[  
'
 c5# 
'	&s   'E
Ec	                    [         R                  " U5      S-  nU c  US:X  a  SnSnX'4$ [         R                  " U 5      R                  5       =(       dl    [         R                  " U5      =(       dO    [         R                  " U5      R                  5       =(       d$    [         R                  " U5      R                  5       n	U	(       a  Sn
OUc  SnXSS2S4   U-
  :  XSS2S4   U-   :*  -  nXS:  [         R                  " U SUS9-  -  n[         R
                  " U5      (       + nUS	:g  =(       a    X6* :  R                  5       nUS	:g  =(       a'    [         R                  " U5      U:  R                  5       nU=(       d    U=(       d    U(       + n
US:X  a  U
(       d  SnS
US -   S-   nX'4$ US:X  a  U
(       a  SnSnX'4$ )a-  
Check the validity of the provided solution.

A valid (optimal) solution satisfies all bounds, all slack variables are
negative and all equality constraint residuals are strictly non-zero.
Further, the lower-bounds, upper-bounds, slack and residuals contain
no nan values.

Parameters
----------
x : 1-D array
    Solution vector to original linear programming problem
fun: float
    optimal objective value for original problem
status : int
    An integer representing the exit status of the optimization::

         0 : Optimization terminated successfully
         1 : Iteration limit reached
         2 : Problem appears to be infeasible
         3 : Problem appears to be unbounded
         4 : Serious numerical difficulties encountered

slack : 1-D array
    The (non-negative) slack in the upper bound constraints, that is,
    ``b_ub - A_ub @ x``
con : 1-D array
    The (nominally zero) residuals of the equality constraints, that is,
    ``b - A_eq @ x``
bounds : 2D array
    The bounds on the original variables ``x``
message : str
    A string descriptor of the exit status of the optimization.
tol : float
    Termination tolerance; see [1]_ Section 4.5.

Returns
-------
status : int
    An integer representing the exit status of the optimization::

         0 : Optimization terminated successfully
         1 : Iteration limit reached
         2 : Problem appears to be infeasible
         3 : Problem appears to be unbounded
         4 : Serious numerical difficulties encountered

message : str
    A string descriptor of the exit status of the optimization.

   Nr   r   z^The solver did not provide a solution nor did it report a failure. Please submit a bug report.Fr   )atolri   zOThe solution does not satisfy the constraints within the required tolerance of z.2Ea,  , yet no errors were raised and there is no certificate of infeasibility or unboundedness. Check whether the slack and constraint residuals are acceptable; if not, consider enabling presolve, adjusting the tolerance option(s), and/or using a different method. Please consider submitting a bug report.r<   zuThe solution is feasible, but the solver did not report that the solution was optimal. Please try a different method.)r-   sqrtrK   r~   iscloserC   r   )r   r   r   r   r   rP   r   r   rR   contains_nansis_feasiblevalid_boundsinvalid_boundsinvalid_slackinvalid_cons                  r$   _check_resultr    s   j ''#,
CyQ;FGG 	 	88C=	88E? 	 88C=	  KAqD\C//A19K4KLqBJJq!#,FFFVVL11!<(:(:(<k?rvvc{S'8&=&=&?)I]IkJ{;,14S	;>>>" ? 
1  ?r&   )F)g&.>)!__doc__numpyr-   scipy.sparser   r   warningsr   	_optimizer   !scipy.optimize._remove_redundancyr   r   r   r	   collectionsr
   r   __new____defaults__r%   r3   r:   r[   r   r   r   r   r   r   r   r   r   r&   r$   <module>r     s       &  #EG
"-
   E  RBJ3>/,EPPw8tl^CL$##L18ePgr&   