§
    fŠtjöB  ã                   óœ   — d Z ddlZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZmZ ddlmZmZmZ d	„ Zd
„ Zd„ Z	 	 	 	 	 	 	 	 dd„ZdS )a^  HiGHS Linear Optimization Methods

Interface to HiGHS linear optimization software.
https://highs.dev/

.. versionadded:: 1.5.0

References
----------
.. [1] Q. Huangfu and J.A.J. Hall. "Parallelizing the dual revised simplex
           method." Mathematical Programming Computation, 10 (1), 119-142,
           2018. DOI: 10.1007/s12532-017-0130-5

é    Né   )ÚOptimizeWarningÚOptimizeResult)Úwarn)Ú_highs_wrapper)Ú	kHighsInfÚHighsDebugLevelÚObjSenseÚHighsModelStatusÚsimplex_constants)Ú	csc_arrayÚvstackÚissparsec                 ó  — i dd“t           j        d“t           j        d“t           j        d“t           j        d“t           j        d“t           j        d“t           j        d“t           j        d“t           j	        d“t           j
        d“t           j        d“t           j        d“t           j        d“t           j        d	“t           j        d
“}d}|                     | |¦  «        \  }}| �t#          | ¦  «        nd}|› d|› d|› d�}||fS )zCConverts HiGHS status number/message to SciPy status number/messageN)é   z%HiGHS did not provide a status code. )r   Ú )é   r   )r   z&Optimization terminated successfully. )r   zTime limit reached. )r   zIteration limit reached. )r   zThe problem is infeasible. )é   zThe problem is unbounded. )r   z(The problem is unbounded or infeasible. )r   z*The HiGHS status code was not recognized. z(HiGHS Status z: ú))r   ÚkNotsetÚ
kLoadErrorÚkModelErrorÚkPresolveErrorÚkSolveErrorÚkPostsolveErrorÚkModelEmptyÚkObjectiveBoundÚkObjectiveTargetÚkOptimalÚ
kTimeLimitÚkIterationLimitÚkInfeasibleÚ
kUnboundedÚkUnboundedOrInfeasibleÚgetÚint)Úhighs_statusÚhighs_messageÚscipy_statuses_messagesÚunrecognizedÚscipy_statusÚscipy_messageÚhstats          ú[/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/optimize/_linprog_highs.pyÚ_highs_to_scipy_status_messager/   "   s‰  € ðFØÐ:ðFåÔ  'ðFõ 	Ô# WðFõ 	Ô$ gð	Fõ
 	Ô'¨ðFõ 	Ô$ gðFõ 	Ô(¨'ðFõ 	Ô$ gðFõ 	Ô(¨'ðFõ 	Ô)¨7ðFõ 	Ô!Ð#PðFõ 	Ô#Ð%@ðFõ 	Ô(Ð*JðFõ 	Ô$Ð&HðFõ 	Ô#Ð%FðFõ  	Ô/ð 2Eð!FÐð$ E€Là×#Ò# L°,Ñ?Ô?ñ  €L�-à!-Ð!9�C�ÑÔÐ¸t€EØ%ð @ð @Ø&+ð@ð @Ø/<ð@ð @ð @€Mà˜Ð&Ð&ó    c                 óÒ   — t          j        | ¦  «        }t          j        d¬¦  «        5  t          j        | |         ¦  «        t          z  | |<   d d d ¦  «         n# 1 swxY w Y   | S )NÚignore©Úinvalid)ÚnpÚisinfÚerrstateÚsignr   )ÚxÚinfss     r.   Ú_replace_infr;   @   s˜   € åŒ8�A‰;Œ;€DÝ	Œ˜XÐ	&Ñ	&Ô	&ð -ð -Ý”'˜!˜Dœ'Ñ"Ô"¥9Ñ,ˆˆ$‰ð-ð -ð -ñ -ô -ð -ð -ð -ð -ð -ð -øøøð -ð -ð -ð -à€Hs   ª&AÁA Á#A c                 ój  — 	 ||                       ¦   «                  S # t          $ r ||          cY S t          $ ry t          j        t
          ¦  «        }|j        |         j        }t          d|› d| › dt          | 
                    ¦   «         ¦  «        › d|› d�	t          d¬¦  «         ||         cY S w xY w)NzOption z is z, but only values in z are allowed. Using default: ú.r   ©Ú
stacklevel)ÚlowerÚAttributeErrorÚKeyErrorÚinspectÚ	signatureÚ_linprog_highsÚ
parametersÚdefaultr   ÚsetÚkeysr   )ÚoptionÚ
option_strÚchoicesÚsigÚdefault_strs        r.   Ú_convert_to_highs_enumrO   H   só   € ð$Ø�v—|’|‘~”~Ô&Ð&øÝð ð ð Ø�vŒÐÐÐÝð $ð $ð $ÝÔ¥Ñ/Ô/ˆØ”n ZÔ0Ô8ˆÝð �zð ð  vð ð Ý�G—L’L‘N”NÑ#Ô#ðð àðð ð õ ¨ð	,ñ 	,ô 	,ð 	,ð �{Ô#Ð#Ð#Ð#ð$øøøs   ‚ œB2°A?B2Â1B2TFc                 óR
  — |rd|› d�}t          |t          d¬¦  «         t          |	dt          j        j        t          j        j        t          j        j        t          j        j        ddœ¬¦  «        }| \  }}}}}}}}|j	         
                    ¦   «         \  }}t          j        d	¬
¦  «        5  t          j        |¦  «         t          j        z  }ddd¦  «         n# 1 swxY w Y   |}|}|}t          j        ||f¦  «        }t          j        ||f¦  «        }t!          |¦  «        st!          |¦  «        rt#          ||f¦  «        }nt          j        ||f¦  «        }t%          |¦  «        }i d|“dt&          j        “d|“d|“dt*          j        “d|“d|“d|“d|“d|“d|“d|“dt          j        j        “d|“d|“d|
“} |                      |¦  «         t5          |¦  «        }t5          |¦  «        }t5          |¦  «        }t5          |¦  «        }|�t          j        |¦  «        dk    rt          j        d¦  «        }nt          j        |¦  «        }t=          ||j        |j         |j!        ||||| "                    t          j#        ¦  «        | ¦
  «
        }!d|!v r[|!d         }"t          j        |"tI          |¦  «        d…         ¦  «        }#t          j        |"dtI          |¦  «        …         ¦  «        }"nd\  }"}#d|!v r£|!d         }$t          j        |$dtI          |¦  «        …         ¦  «        }%t          j        |$tI          |¦  «        d…         ¦  «        }&t          j        |!d         ddd…f         ¦  «        }'t          j        |!d         ddd…f         ¦  «        }(n
d\  }%}&d\  }'}(|! %                    d d¦  «        })|! %                    d!d¦  «        }*tM          |)|*¦  «        \  }+}|!d"         },|,|"|#tO          |"|%d#œ¦  «        tO          |#|&d#œ¦  «        tO          |,€dn|,|z
  |(d#œ¦  «        tO          |,€dn||,z
  |'d#œ¦  «        |! %                    d$¦  «        |+|!d          tP          j)        k    ||! %                    d%d¦  «        p|! %                    d&d¦  «        |! %                    d'¦  «        d(œ}-t          j*        |,¦  «        rW|�U|-                     |! %                    d)d¦  «        |! %                    d*d+¦  «        |! %                    d,d+¦  «        d-œ¦  «         |-S ).aý  
    Solve the following linear programming problem using one of the HiGHS
    solvers:

    User-facing documentation is in _linprog_doc.py.

    Parameters
    ----------
    lp :  _LPProblem
        A ``scipy.optimize._linprog_util._LPProblem`` ``namedtuple``.
    solver : "ipm" or "simplex" or None
        Which HiGHS solver to use.  If ``None``, "simplex" will be used.

    Options
    -------
    maxiter : int
        The maximum number of iterations to perform in either phase. For
        ``solver='ipm'``, this does not include the number of crossover
        iterations.  Default is the largest possible value for an ``int``
        on the platform.
    disp : bool
        Set to ``True`` if indicators of optimization status are to be printed
        to the console each iteration; default ``False``.
    time_limit : float
        The maximum time in seconds allotted to solve the problem; default is
        the largest possible value for a ``double`` on the platform.
    presolve : bool
        Presolve attempts to identify trivial infeasibilities,
        identify trivial unboundedness, and simplify the problem before
        sending it to the main solver. It is generally recommended
        to keep the default setting ``True``; set to ``False`` if presolve is
        to be disabled.
    dual_feasibility_tolerance : double
        Dual feasibility tolerance.  Default is 1e-07.
        The minimum of this and ``primal_feasibility_tolerance``
        is used for the feasibility tolerance when ``solver='ipm'``.
    primal_feasibility_tolerance : double
        Primal feasibility tolerance.  Default is 1e-07.
        The minimum of this and ``dual_feasibility_tolerance``
        is used for the feasibility tolerance when ``solver='ipm'``.
    ipm_optimality_tolerance : double
        Optimality tolerance for ``solver='ipm'``.  Default is 1e-08.
        Minimum possible value is 1e-12 and must be smaller than the largest
        possible value for a ``double`` on the platform.
    simplex_dual_edge_weight_strategy : str (default: None)
        Strategy for simplex dual edge weights. The default, ``None``,
        automatically selects one of the following.

        ``'dantzig'`` uses Dantzig's original strategy of choosing the most
        negative reduced cost.

        ``'devex'`` uses the strategy described in [15]_.

        ``steepest`` uses the exact steepest edge strategy as described in
        [16]_.

        ``'steepest-devex'`` begins with the exact steepest edge strategy
        until the computation is too costly or inexact and then switches to
        the devex method.

        Currently, using ``None`` always selects ``'steepest-devex'``, but this
        may change as new options become available.

    mip_max_nodes : int
        The maximum number of nodes allotted to solve the problem; default is
        the largest possible value for a ``HighsInt`` on the platform.
        Ignored if not using the MIP solver.
    unknown_options : dict
        Optional arguments not used by this particular solver. If
        ``unknown_options`` is non-empty, a warning is issued listing all
        unused options.

    Returns
    -------
    sol : dict
        A dictionary consisting of the fields:

            x : 1D array
                The values of the decision variables that minimizes the
                objective function while satisfying the constraints.
            fun : float
                The optimal value of the objective function ``c @ x``.
            slack : 1D array
                The (nominally positive) values of the slack,
                ``b_ub - A_ub @ x``.
            con : 1D array
                The (nominally zero) residuals of the equality constraints,
                ``b_eq - A_eq @ x``.
            success : bool
                ``True`` when the algorithm succeeds in finding an optimal
                solution.
            status : int
                An integer representing the exit status of the algorithm.

                ``0`` : Optimization terminated successfully.

                ``1`` : Iteration or time limit reached.

                ``2`` : Problem appears to be infeasible.

                ``3`` : Problem appears to be unbounded.

                ``4`` : The HiGHS solver ran into a problem.

            message : str
                A string descriptor of the exit status of the algorithm.
            nit : int
                The total number of iterations performed.
                For ``solver='simplex'``, this includes iterations in all
                phases. For ``solver='ipm'``, this does not include
                crossover iterations.
            crossover_nit : int
                The number of primal/dual pushes performed during the
                crossover routine for ``solver='ipm'``.  This is ``0``
                for ``solver='simplex'``.
            ineqlin : OptimizeResult
                Solution and sensitivity information corresponding to the
                inequality constraints, `b_ub`. A dictionary consisting of the
                fields:

                residual : np.ndnarray
                    The (nominally positive) values of the slack variables,
                    ``b_ub - A_ub @ x``.  This quantity is also commonly
                    referred to as "slack".

                marginals : np.ndarray
                    The sensitivity (partial derivative) of the objective
                    function with respect to the right-hand side of the
                    inequality constraints, `b_ub`.

            eqlin : OptimizeResult
                Solution and sensitivity information corresponding to the
                equality constraints, `b_eq`.  A dictionary consisting of the
                fields:

                residual : np.ndarray
                    The (nominally zero) residuals of the equality constraints,
                    ``b_eq - A_eq @ x``.

                marginals : np.ndarray
                    The sensitivity (partial derivative) of the objective
                    function with respect to the right-hand side of the
                    equality constraints, `b_eq`.

            lower, upper : OptimizeResult
                Solution and sensitivity information corresponding to the
                lower and upper bounds on decision variables, `bounds`.

                residual : np.ndarray
                    The (nominally positive) values of the quantity
                    ``x - lb`` (lower) or ``ub - x`` (upper).

                marginals : np.ndarray
                    The sensitivity (partial derivative) of the objective
                    function with respect to the lower and upper
                    `bounds`.

            mip_node_count : int
                The number of subproblems or "nodes" solved by the MILP
                solver. Only present when `integrality` is not `None`.

            mip_dual_bound : float
                The MILP solver's final estimate of the lower bound on the
                optimal solution. Only present when `integrality` is not
                `None`.

            mip_gap : float
                The difference between the final objective function value
                and the final dual bound, scaled by the final objective
                function value. Only present when `integrality` is not
                `None`.

    Notes
    -----
    The result fields `ineqlin`, `eqlin`, `lower`, and `upper` all contain
    `marginals`, or partial derivatives of the objective function with respect
    to the right-hand side of each constraint. These partial derivatives are
    also referred to as "Lagrange multipliers", "dual values", and
    "shadow prices". The sign convention of `marginals` is opposite that
    of Lagrange multipliers produced by many nonlinear solvers.

    References
    ----------
    .. [15] Harris, Paula MJ. "Pivot selection methods of the Devex LP code."
            Mathematical programming 5.1 (1973): 1-28.
    .. [16] Goldfarb, Donald, and John Ker Reid. "A practicable steepest-edge
            simplex algorithm." Mathematical Programming 12.1 (1977): 361-371.
    zUnrecognized options detected: z). These will be passed to HiGHS verbatim.r   r>   Ú!simplex_dual_edge_weight_strategyN)ÚdantzigÚdevexzsteepest-devexÚsteepestN)rL   r2   r3   ÚpresolveÚsenseÚsolverÚ
time_limitÚhighs_debug_levelÚdual_feasibility_toleranceÚipm_optimality_toleranceÚlog_to_consoleÚmip_max_nodesÚoutput_flagÚprimal_feasibility_toleranceÚsimplex_strategyÚipm_iteration_limitÚsimplex_iteration_limitÚmip_rel_gapr   Úslack)NNÚlambdaÚ	marg_bndsr   ÚstatusÚmessager9   )ÚresidualÚ	marginalsÚfunÚsimplex_nitÚipm_nitÚcrossover_nit)r9   rd   ÚconÚineqlinÚeqlinr@   Úupperrk   rg   Úsuccessrh   Únitrn   Úmip_node_countÚmip_dual_boundg        Úmip_gap)ru   rv   rw   )+r   r   rO   Ús_cÚSimplexEdgeWeightStrategyÚ!kSimplexEdgeWeightStrategyDantzigÚkSimplexEdgeWeightStrategyDevexÚ kSimplexEdgeWeightStrategyChooseÚ&kSimplexEdgeWeightStrategySteepestEdgeÚTÚcopyr5   r7   Ú	ones_likeÚinfÚconcatenater   r   r   r
   Ú	kMinimizer	   ÚkHighsDebugLevelNoneÚSimplexStrategyÚkSimplexStrategyDualÚupdater;   ÚsumÚemptyÚarrayr   ÚindptrÚindicesÚdataÚastypeÚuint8Úlenr%   r/   r   r   r   Úany).ÚlprW   rX   rU   ÚdispÚmaxiterrZ   r_   r[   rQ   rc   r]   Úunknown_optionsrh   Ú&simplex_dual_edge_weight_strategy_enumÚcÚA_ubÚb_ubÚA_eqÚb_eqÚboundsÚx0ÚintegralityÚlbÚubÚlhs_ubÚrhs_ubÚlhs_eqÚrhs_eqÚlhsÚrhsÚAÚoptionsÚresrd   ro   ÚlamdaÚmarg_ineqlinÚ
marg_eqlinÚ
marg_upperÚ
marg_lowerr'   r(   rg   r9   Úsols.                                                 r.   rE   rE   Y   s  € ðJ ð 5ð=°_ð =ð =ð =ˆåˆW•o°!Ð4Ñ4Ô4Ð4õ .DØ)Ø+åÔ.ÔPåÔ.ÔNåÔ.ÔOåÔ.ÔUØðð ð.ñ .ô .Ð*ð :<Ñ6€A€tˆT�4˜˜v r¨;àŒX�]Š]‰_Œ_�F€Bˆå	Œ˜XÐ	&Ñ	&Ô	&ð ,ð ,Ý”,˜tÑ$Ô$Ð$¥R¤VÑ+ˆð,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,à€FØ€FØ€FÝ
Œ.˜& &Ð)Ñ
*Ô
*€CÝ
Œ.˜& &Ð)Ñ
*Ô
*€Cå��~„~ð $� $™œð $Ý�D˜$�<Ñ Ô ˆˆåŒI�t˜T�lÑ#Ô#ˆÝ�!‰Œ€AðØ�Hðà•Ô#ðð 	�&ðð 	�jð	ð
 	�_ÔAðð 	%Ð&@ðð 	#Ð$<ðð 	˜$ðð 	˜ðð 	�tðð 	'Ð(Dðð 	,Ø2ðð 	�CÔ/ÔDðð 	˜wðð  	" 7ð!ð" 	�{ð#€Gð& ‡N‚N�?Ñ#Ô#Ð#õ �sÑ
Ô
€CÝ
�sÑ
Ô
€CÝ	�bÑ	Ô	€BÝ	�bÑ	Ô	€BàÐ�bœf [Ñ1Ô1°QÒ6Ð6Ý”h˜q‘k”kˆˆå”h˜{Ñ+Ô+ˆå
˜˜AœH a¤i°´¸¸cØ˜R ×!3Ò!3µB´HÑ!=Ô!=¸wñHô H€Cð �#€~€~Ø�G”ˆÝŒh�u�S ™YœY˜Z˜ZÔ(Ñ)Ô)ˆÝ”˜˜z¥ D¡	¤	˜zÔ*Ñ+Ô+ˆˆà‰
ˆˆsð �3€€Ø�H”ˆÝ”x  j¥s¨4¡y¤y jÔ 1Ñ2Ô2ˆÝ”X˜e¥C¨¡I¤I J JÔ/Ñ0Ô0ˆ
Ý”X˜c +Ô.¨q°!°!°!¨tÔ4Ñ5Ô5ˆ
Ý”X˜c +Ô.¨q°!°!°!¨tÔ4Ñ5Ô5ˆ
ˆ
à#-Ñ ˆ�jØ!+Ñˆ
�Jð
 —7’7˜8 TÑ*Ô*€LØ—G’G˜I tÑ,Ô,€MÝ4°\Ø5BñDô D�O€FˆGð 	ˆCŒ€AØØØÝ$Ø Ø(ð&ð &ñ ô õ #ØØ&ð$ð $ñ ô õ #Ø#$ 9˜4˜4°!°b±&Ø&ð$ð $ñ ô õ #Ø#$ 9˜4˜4°"°q±&Ø&ð$ð $ñ ô ð —'’'˜%‘.”.ØØ˜(”mÕ'7Ô'@Ò@ØØ—'’'˜-¨Ñ+Ô+ÐD¨s¯wªw°yÀ!Ñ/DÔ/DØŸGšG OÑ4Ô4ð1ð €Cõ6 
„vˆa�y„yð �[Ð,Ø�
Š
Ø!ŸgšgÐ&6¸Ñ:Ô:Ø!ŸgšgÐ&6¸Ñ<Ô<Ø—w’w˜y¨#Ñ.Ô.ð
ð 
ñ 	ô 	ð 	ð €Js   Â0#CÃC#Ã&C#)
NTFNNNNNNN)Ú__doc__rC   Únumpyr5   Ú	_optimizer   r   Úwarningsr   Ú_highspy._highs_wrapperr   Ú_highspy._corer   r	   r
   r   r   rx   Úscipy.sparser   r   r   r/   r;   rO   rE   © r0   r.   ú<module>r¸      s3  ððð ð €€€Ø Ð Ð Ð Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø Ð Ð Ð Ð Ð Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 5Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4ð'ð 'ð 'ð<ð ð ð$ð $ð $ð" :>Ø'+Ø.2Ø04Ø,0Ø59Ø#Ø!%ðMð Mð Mð Mð Mð Mr0   