
    Џkh,                     T    d dl mZ d dlZd dlmc mc mZ d dl	m
Z d dlmZ d Zd Zy)    )warnN)_highs_options)OptimizeWarningc
                    | j                   }
|j                   }|duxr t        j                  |      dkD  }ddd}t        j                         }|
|_        ||_        |
|j                  _        ||j                  _        t        j                  j                  |j                  _
        | |_        ||_        ||_        ||_        ||_        ||j                  _        ||j                  _        ||j                  _        |j                   dkD  r(|D cg c]  }t        j&                  |       c}|_        t        j*                         }t        j,                         }t/        j0                         }|	j3                         D ]
  \  }}||dv r|j5                  |      }d|k(  r!t7        dt9        ||i       t:        d       E|d	v r1t=        |t>              r|rd
nd}nt7        d| d| dt:        d       zt        j@                  |      }tC        |||      \  }}|t        j@                  jD                  k(  r*t=        |t>              st7        d| d| dt:        d       |dk7  rt7        |t:        d       tG        |||        |jI                  |      }|t        jJ                  jL                  k(  rA|jO                  |jQ                         |jS                  |jQ                               d       |S |jU                  |      }|t        jJ                  jL                  k(  r?t        jV                  jX                  }|jO                  ||jS                  |      d       |S |j[                         }|t        jJ                  jL                  k(  rA|jO                  |jQ                         |jS                  |jQ                               d       |S |jQ                         }|j]                         }|t        jV                  j^                  t        jV                  j`                  t        jV                  jb                  t        jV                  jd                  fvxsn |t        jV                  j`                  t        jV                  jb                  t        jV                  jd                  hv xr |jf                  t        jh                  k(  }|t        jV                  j^                  k7  }|r|s|sg|re|jO                  |d|jS                  |       d|jk                  |jl                         |jn                  |jp                  |jr                  d       |S |ju                         } |jw                         }!t        jx                  d|
f      }"|!jz                  }#| j|                  }$t        |
      D ]X  }%|#|%   t        j                  j                  k(  r|$|%   |"d|%f<   .|#|%   t        j                  j                  k(  sO|$|%   |"d|%f<   Z |jO                  ||jS                  |      t        j                  | j                        || j                  z
  t        j                  | j                        |"|jf                  |jn                  |jp                  |jr                  d
       |r3|jO                  |j                  |j                  |j                  d       |S c c}w )a
  Solve linear programs using HiGHS [1]_.

    Assume problems of the form:

        MIN c.T @ x
        s.t. lhs <= A @ x <= rhs
             lb <= x <= ub

    Parameters
    ----------
    c : 1-D array, (n,)
        Array of objective value coefficients.
    astart : 1-D array
        CSC format index array.
    aindex : 1-D array
        CSC format index array.
    avalue : 1-D array
        Data array of the matrix.
    lhs : 1-D array (or None), (m,)
        Array of left hand side values of the inequality constraints.
        If ``lhs=None``, then an array of ``-inf`` is assumed.
    rhs : 1-D array, (m,)
        Array of right hand side values of the inequality constraints.
    lb : 1-D array (or None), (n,)
        Lower bounds on solution variables x.  If ``lb=None``, then an
        array of all `0` is assumed.
    ub : 1-D array (or None), (n,)
        Upper bounds on solution variables x.  If ``ub=None``, then an
        array of ``inf`` is assumed.
    options : dict
        A dictionary of solver options

    Returns
    -------
    res : dict

        If model_status is one of kOptimal,
        kObjectiveBound, kTimeLimit,
        kIterationLimit:

            - ``status`` : HighsModelStatus
                Model status code.

            - ``message`` : str
                Message corresponding to model status code.

            - ``x`` : list
                Solution variables.

            - ``slack`` : list
                Slack variables.

            - ``lambda`` : list
                Lagrange multipliers associated with the constraints
                Ax = b.

            - ``s`` : list
                Lagrange multipliers associated with the constraints
                x >= 0.

            - ``fun``
                Final objective value.

            - ``simplex_nit`` : int
                Number of iterations accomplished by the simplex
                solver.

            - ``ipm_nit`` : int
                Number of iterations accomplished by the interior-
                point solver.

        If model_status is not one of the above:

            - ``status`` : HighsModelStatus
                Model status code.

            - ``message`` : str
                Message corresponding to model status code.

    Notes
    -----
    If ``options['write_solution_to_file']`` is ``True`` but
    ``options['solution_file']`` is unset or ``''``, then the solution
    will be printed to ``stdout``.

    If any iteration limit is reached, no solution will be
    available.

    ``OptimizeWarning`` will be raised if any option value set by
    the user is found to be incorrect.

    References
    ----------
    .. [1] https://highs.dev/
    .. [2] https://www.maths.ed.ac.uk/hall/HiGHS/HighsOptions.html
    Nr   )xfun)sensezUnrecognized options detected:    )
stacklevel)presolveparallelonoffz	Option f"z" is "z4", but only True or False is allowed. Using default.)statusmessagezmodel_status is z; primal_status is )r   r   simplex_nitipm_nitcrossover_nit   )
r   r   r   slacklambda	marg_bndsr   r   r   r   )mip_node_countmip_dual_boundmip_gap)Jsizenpsum_hHighsLpnum_col_num_row_	a_matrix_MatrixFormatkColwiseformat_	col_cost_
col_lower_
col_upper_
row_lower_
row_upper_start_index_value_HighsVarTypeintegrality__HighsHighsOptionshoptHighsOptionsManageritemsget_option_typer   dictr   
isinstanceboolHighsOptionTypecheck_optionkBoolsetattrpassOptionsHighsStatuskErrorupdategetModelStatusmodelStatusToString	passModelHighsModelStatuskModelErrorrungetInfokOptimal
kTimeLimitkIterationLimitkSolutionLimitobjective_function_value	kHighsInfsolutionStatusToStringprimal_solution_statussimplex_iteration_countipm_iteration_countcrossover_iteration_countgetSolutiongetBasiszeros
col_statuscol_dualrangeHighsBasisStatuskLowerkUpperarray	col_value	row_valuerow_dualr   r   r   )&cindptrindicesdatalhsrhslbubintegralityoptionsnumcolnumrowisMipreslpihighshighs_optionshoptmanagerkeyvalopt_typer   msg
opt_statusinit_statuserr_model_status
run_statusmodel_statusinfomipFailConditionlpFailConditionsolutionbasisr   basis_col_statussolution_col_dualiis&                                         b/var/www/teggl/fontify/venv/lib/python3.12/site-packages/scipy/optimize/_highspy/_highs_wrapper.py_highs_wrapperr   	   s9   B VVFXXFt#?{(;a(?E C 
BBKBK"BLL"BLL??33BLLBLBMBMBMBM BLL!BLLBLL!7BC!2??1-C IIKEOO%M**,KMMO +1S;#+ ..s3>1$Sz2B1CD
 ..c4("%$5C#C5se 42 3'#$	 ))(3H&uc37KFC2--333!#t,#C5se 42 3'#$	  {S/a8sC0W+1Z ""=1JR^^***

..0 44U5I5I5KL	
 
//"%Kbnn+++..::

* 445EF	
 
 JR^^***

..0 44U5I5I5KL	
 
 '')L ==?D $
$$
&&
++
**	,   	**//..
	
 	< **bll:  #b&9&9&B&BBO"Eo

&-,,\:; <$//0K0KLMO  $;;33!%!?!?		
 
   "HNNE !V%I'' ))Fm 5B2#6#6#=#==04Iaeb!R%8%8%?%??04Iae	5 JJ"00>(,,- 8---hhx001"0077//!;;	
& 

"&"5"5"&"5"5<<	
 JW Ds   ["c                    | j                  |      \  }}t        j                         }|t        j                  j
                  k7  ryt        j                  j                  t        t        j                  j                  t        t        j                  j                  t        t        j                  j                  t        i}|j                  |d       }|t        u r|j!                  ||      sy|t        u r|j#                  ||      sy|t        u r|j%                  ||      sy|y| j'                  |      \  }}|t        j                  j
                  k7  ryy)N)r
   zInvalid option name.)r
   zInvalid option value.)   zUnknown option type.)   z Failed to validate option value.)r   zCheck option succeeded.)getOptionTyper4   r5   r    r@   kOkr;   r=   r:   kIntintkDoublefloatkStringstrgetcheck_string_optioncheck_double_optioncheck_int_optiongetOptionValue)	
highs_instoptionvaluer   option_typert   valid_typesexpected_typecurrent_values	            r   r<   r<   2  s    $226:FK**,K###) 	  $

""E
""C	K  OOK6M..vu=...vu=.++FE:.(&55f=FM###4'    )warningsr   numpyr   scipy.optimize._highspy._coreoptimize_highspy_corer    scipy.optimize._highspyr   r4   scipy.optimizer   r   r<    r   r   <module>r      s#      * * : *fR	 (r   