
    (ph                         S SK Jr  S SKJr  S SKrS SKrS SKJrJ	r	J
r
Jr  S SKJr  SSKJrJr  SSKJrJr  SS	KJr   " S
 S5      r " S S5      r " S S5      r " S S5      r " S S5      rg)    )suppress)	signatureN)BoundsLinearConstraintNonlinearConstraintOptimizeResult)PreparedConstraint   )PRINT_OPTIONSBARRIER)CallbackSuccessget_arrays_tol)exact_1d_arrayc                   D    \ rS rSrSrS rS r\S 5       r\S 5       r	Sr
g)	ObjectiveFunction   z!
Real-valued objective function.
c                     U(       aC  Ub  [        U5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   eXl        X l        X@l        SU l        g)a  
Initialize the objective function.

Parameters
----------
fun : {callable, None}
    Function to evaluate, or None.

        ``fun(x, *args) -> float``

    where ``x`` is an array with shape (n,) and `args` is a tuple.
verbose : bool
    Whether to print the function evaluations.
debug : bool
    Whether to make debugging tests during the execution.
*args : tuple
    Additional arguments to be passed to the function.
Nr   )callable
isinstancebool_fun_verbose_args_n_eval)selffunverbosedebugargss        L/var/www/html/venv/lib/python3.13/site-packages/scipy/_lib/cobyqa/problem.py__init__ObjectiveFunction.__init__   sV    & ;(3--//gt,,,,eT****	
    c                    [         R                  " U[        S9nU R                  c  SnU$ [        [         R                  " U R                  " U/U R
                  Q76 5      5      nU =R                  S-  sl        U R                  (       aB  [         R                  " S0 [        D6   [        U R                   SU SU 35        SSS5        U$ U$ ! , (       d  f       U$ = f)z
Evaluate the objective function.

Parameters
----------
x : array_like, shape (n,)
    Point at which the objective function is evaluated.

Returns
-------
float
    Function value at `x`.
dtypeN        r
   () =  )nparrayfloatr   squeezer   r   r   printoptionsr   printname)r   xfs      r    __call__ObjectiveFunction.__call__6   s     HHQe$99A  bjj1!:tzz!:;<ALLAL}}__5}5TYYKq4s34 6q 65s   %C
Cc                     U R                   $ Z
Number of function evaluations.

Returns
-------
int
    Number of function evaluations.
)r   r   s    r    n_evalObjectiveFunction.n_evalO        ||r#   c                 |    SnU R                   b   U R                   R                  nU$ U$ ! [         a    Sn U$ f = f)Z
Name of the objective function.

Returns
-------
str
    Name of the objective function.
 r   )r   __name__AttributeError)r   r1   s     r    r1   ObjectiveFunction.name[   sM     99 yy)) t " s   + ;;)r   r   r   r   N)r@   
__module____qualname____firstlineno____doc__r!   r4   propertyr:   r1   __static_attributes__r*   r#   r    r   r      s9    :2 	 	  r#   r   c                   P    \ rS rSrSrS r\S 5       r\S 5       rS r	S r
S rS	rg
)BoundConstraintsn   z&
Bound constraints ``xl <= x <= xu``.
c                 $   [         R                  " UR                  [        5      U l        [         R                  " UR
                  [        5      U l        [         R                  * U R                  [         R                  " U R                  5      '   [         R                  U R                  [         R                  " U R                  5      '   [         R                  " U R                  U R                  :*  5      =(       aj    [         R                  " U R                  [         R                  :  5      =(       a2    [         R                  " U R                  [         R                  * :  5      U l        [         R                  " U R                  [         R                  * :  5      [         R                  " U R                  [         R                  :  5      -   U l        [        U[         R                   " UR                  R"                  5      5      U l        g)zp
Initialize the bound constraints.

Parameters
----------
bounds : scipy.optimize.Bounds
    Bound constraints.
N)r+   r,   lbr-   _xlub_xuinfxlisnanxuallis_feasiblecount_nonzeromr	   onessizepcs)r   boundss     r    r!   BoundConstraints.__init__s   s9    88FIIu-88FIIu- ')ffW!"%'VV!" FF477dgg%& *tww'(*tww"&&() 	
 !!$''RVVG"34r7G7GGGbff8
 
 &fbggfiinn.EFr#   c                     U R                   $ )zL
Lower bound.

Returns
-------
`numpy.ndarray`, shape (n,)
    Lower bound.
)rN   r9   s    r    rR   BoundConstraints.xl        xxr#   c                     U R                   $ )zL
Upper bound.

Returns
-------
`numpy.ndarray`, shape (n,)
    Upper bound.
)rP   r9   s    r    rT   BoundConstraints.xu   r`   r#   c                 V    [         R                  " U[        S9nU R                  U5      $ )
Evaluate the maximum constraint violation.

Parameters
----------
x : array_like, shape (n,)
    Point at which the maximum constraint violation is evaluated.

Returns
-------
float
    Maximum constraint violation at `x`.
r%   )r+   asarrayr-   	violationr   r2   s     r    maxcvBoundConstraints.maxcv   s#     JJq&~~a  r#   c                     U R                   (       a  [        R                  " S/5      $ U R                  R	                  U5      $ )Nr   )rV   r+   r,   r[   rf   rg   s     r    rf   BoundConstraints.violation   s0    88QC= 88%%a((r#   c                 ~    U R                   (       a+  [        R                  " XR                  U R                  5      $ U$ )z
Project a point onto the feasible set.

Parameters
----------
x : array_like, shape (n,)
    Point to be projected.

Returns
-------
`numpy.ndarray`, shape (n,)
    Projection of `x` onto the feasible set.
)rV   r+   cliprR   rT   rg   s     r    projectBoundConstraints.project   s*     04/?/?rwwq''477+FQFr#   )rN   rP   rV   rX   r[   N)r@   rC   rD   rE   rF   r!   rG   rR   rT   rh   rf   rn   rH   r*   r#   r    rJ   rJ   n   sE    G4 	 	 	 	!")Gr#   rJ   c                       \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
 rS rSrg)LinearConstraints   zC
Linear constraints ``a_ub @ x <= b_ub`` and ``a_eq @ x == b_eq``.
c           	         U(       aN  [        U[        5      (       d   eU H  n[        U[        5      (       a  M   e   [        U[        5      (       d   e[        R
                  " SU45      U l        [        R
                  " S5      U l        [        R
                  " SU45      U l        [        R
                  " S5      U l	        U GH  n[        R                  " UR                  UR                  -
  5      [        UR                  UR                  5      :*  n[        R                  " U5      (       a{  [        R                  " U R                   UR"                  U   45      U l        [        R$                  " U R&                  SUR                  U   UR                  U   -   -  45      U l	        [        R(                  " U5      (       a  GM  [        R                  " U R*                  UR"                  U)    UR"                  U)    * 45      U l        [        R$                  " U R,                  UR                  U)    UR                  U)    * 45      U l        GM     SU R*                  [        R.                  " U R*                  5      '   SU R                   [        R.                  " U R                   5      '   [        R.                  " U R,                  5      [        R0                  " U R,                  5      -  n[        R.                  " U R&                  5      nU R*                  U) SS24   U l        U R,                  U)    U l        U R                   U) SS24   U l        U R&                  U)    U l	        U Vs/ s H?  oR"                  R2                  (       d  M  [5        U[        R6                  " U5      5      PMA     snU l        gs  snf )z
Initialize the linear constraints.

Parameters
----------
constraints : list of LinearConstraint
    Linear constraints.
n : int
    Number of variables.
debug : bool
    Whether to make debugging tests during the execution.
r         ?r'   N)r   listr   r   r+   empty_a_ub_b_ub_a_eq_b_eqabsrO   rM   r   anyvstacka_eqAconcatenateb_eqrU   a_ubb_ubrS   isinfrZ   r	   rY   r[   )	r   constraintsnr   
constraintis_equalityundef_ubundef_eqcs	            r    r!   LinearConstraints.__init__   s    k40000)
!*.>???? *eT****XXq!f%
XXa[
XXq!f%
XXa[
%J&&
-
z}}=>K vvk""YY		:<<3L'MN
^^		&MM+6(mmK89	
 66+&&YY		"k\2#{l33
  ^^		"{l3#|44
1 &B *-		"((499%&),		"((499%&88DII&$)))<<88DII&YYy!|,
YYy)
YYy!|,
YYy)
7B
7B!cchh-q"''!*-{
 
s   8O$Oc                     U R                   $ )z
Left-hand side matrix of the linear inequality constraints.

Returns
-------
`numpy.ndarray`, shape (m, n)
    Left-hand side matrix of the linear inequality constraints.
)rw   r9   s    r    r   LinearConstraints.a_ub       zzr#   c                     U R                   $ )z
Right-hand side vector of the linear inequality constraints.

Returns
-------
`numpy.ndarray`, shape (m, n)
    Right-hand side vector of the linear inequality constraints.
)rx   r9   s    r    r   LinearConstraints.b_ub#  r   r#   c                     U R                   $ )z
Left-hand side matrix of the linear equality constraints.

Returns
-------
`numpy.ndarray`, shape (m, n)
    Left-hand side matrix of the linear equality constraints.
)ry   r9   s    r    r~   LinearConstraints.a_eq/  r   r#   c                     U R                   $ )z
Right-hand side vector of the linear equality constraints.

Returns
-------
`numpy.ndarray`, shape (m, n)
    Right-hand side vector of the linear equality constraints.
)rz   r9   s    r    r   LinearConstraints.b_eq;  r   r#   c                 .    U R                   R                  $ zl
Number of linear inequality constraints.

Returns
-------
int
    Number of linear inequality constraints.
)r   rZ   r9   s    r    m_ubLinearConstraints.m_ubG       yy~~r#   c                 .    U R                   R                  $ zh
Number of linear equality constraints.

Returns
-------
int
    Number of linear equality constraints.
)r   rZ   r9   s    r    m_eqLinearConstraints.m_eqS  r   r#   c                 J    [         R                  " U R                  U5      SS9$ )rd   r'   initialr+   maxrf   rg   s     r    rh   LinearConstraints.maxcv_  s     vvdnnQ'55r#   c                     [        U R                  5      (       a?  [        R                  " U R                   Vs/ s H  o"R	                  U5      PM     sn5      $ [        R
                  " / 5      $ s  snf N)lenr[   r+   r   rf   r,   )r   r2   pcs      r    rf   LinearConstraints.violationo  sK    txx==>>TXX"FXr<<?X"FGGxx| #Gs   A0)ry   rw   rz   rx   r[   N)r@   rC   rD   rE   rF   r!   rG   r   r   r~   r   r   r   rh   rf   rH   r*   r#   r    rq   rq      s    B
H 	 	 	 	 	 	 	 	 	 	 	 	6 r#   rq   c                   h    \ rS rSrSrS rS r\S 5       r\S 5       r	\S 5       r
SS	 jrSS
 jrSrg)NonlinearConstraintsiu  zA
Nonlinear constraints ``c_ub(x) <= 0`` and ``c_eq(x) == b_eq``.
c                 :   U(       ae  [        U[        5      (       d   eU H  n[        U[        5      (       a  M   e   [        U[        5      (       d   e[        U[        5      (       d   eXl        / U l        X l        SU l        SU l        S=U l	        U l
        g)z
Initialize the nonlinear constraints.

Parameters
----------
constraints : list
    Nonlinear constraints.
verbose : bool
    Whether to print the function evaluations.
debug : bool
    Whether to make debugging tests during the execution.
N)r   ru   r   r   _constraintsr[   r   _map_ub_map_eq_m_ub_m_eq)r   r   r   r   r   s        r    r!   NonlinearConstraints.__init__z  s     k40000)
!*.ABBBB *gt,,,,eT****' "&&
TZr#   c           
      	   [        U R                  5      (       d:  S=U l        U l        [        R
                  " / 5      [        R
                  " / 5      4$ [        R
                  " U[        S9n[        U R                  5      (       Gd  / U l        / U l	        SU l        SU l        U R                   GH  n[        UR                  5      (       d2  [        R                  " U5      nS Ul        S Ul        [        X15      nO[        X!5      nSUR                  l        U R                  R#                  U5        [        R$                  " UR                  R&                  5      nUR(                  S   UR(                  S   pv[+        Xg5      n[        R,                  " Xv-
  5      U:*  n	U R                  R#                  XY   5        U R                  R#                  XY)    5        U =R                  [        R.                  " U	5      -  sl        U =R                  [        R.                  " U	) 5      -  sl        GM     / n
/ n[1        U R                  5       GH  u  pUR                  R                  U5      nU R2                  (       aq  [        R4                  " S0 [6        D6   [9        [:        5         U R                  U   R                  R<                  n[?        U SU SU 35        S	S	S	5        S	S	S	5        U R                  U   nU R                  U   nUU   n[        U5      (       a  UR(                  S   U   nUR(                  S   U   nU[        R@                  * :  nUU   UU   -
  nU
R#                  U5        U[        R@                  :  nUU   UU   -
  nU
R#                  U5        X   n[        U5      (       a-  S
UR(                  S   U   UR(                  S   U   -   -  nUU-  nUR#                  U5        GM     U R                  (       a  [        RB                  " U5      nO[        R
                  " / 5      nU R                  (       a  [        RB                  " U
5      n
O[        R
                  " / 5      n
U
RD                  U l        URD                  U l        X4$ ! , (       d  f       GN= f! , (       d  f       GN= f)a_  
Calculates the residual (slack) for the constraints.

Parameters
----------
x : array_like, shape (n,)
    Point at which the constraints are evaluated.

Returns
-------
`numpy.ndarray`, shape (m_nonlinear_ub,)
    Nonlinear inequality constraint slack values.
`numpy.ndarray`, shape (m_nonlinear_eq,)
    Nonlinear equality constraint slack values.
r   r%   c                     U $ r   r*   )x0s    r    <lambda>/NonlinearConstraints.__call__.<locals>.<lambda>  s    rr#   c                     g)Nr'   r*   )r   vs     r    r   r     s    3r#   Tr
   r(   r)   Nrt   r*   )#r   r   r   r   r+   r,   r-   r[   r   r   r   jaccopyhessr	   r   	f_updatedappendarangerX   r\   r   r{   rW   	enumerater   r/   r   r   rA   r@   r0   rQ   r   rZ   )r   r2   r   r   r   idxrM   rO   arr_tolr   c_ubc_eqivalfun_nameeq_idxub_idxub_valrR   rT   	finite_xl_v	finite_xueq_valmidpoints                            r    r4   NonlinearConstraints.__call__  s     4$$%%&''DJ88B<"--HHQe$488}}DLDLDJDJ"//

// 		*-A)AE.AF+A1B+J:B $( #ii) 1ryy|B(0 ffRWo8##C$45##C$56 

b..{;;


b..|<<

7 0: txx(EA&&**Q-C}}__5}5!.1#'#4#4Q#7#;#;#D#D
!A3d3%89 2 6 \\!_F\\!_F[F6{{YYq\&)YYq\&) "&&L		]VI%66B K	I&I6B [F6{{"))A,v"61f9M"MN("KKA )D ::>>$'D88B<D::>>$'D88B<DYY
YY
zW 21 65s$   R4-7R"$R4"
R1,R44
S	c                 J    U R                   c  [        S5      eU R                   $ )z
Number of nonlinear inequality constraints.

Returns
-------
int
    Number of nonlinear inequality constraints.

Raises
------
ValueError
    If the number of nonlinear inequality constraints is unknown.
z:The number of nonlinear inequality constraints is unknown.)r   
ValueErrorr9   s    r    r   NonlinearConstraints.m_ub  s*     ::L  ::r#   c                 J    U R                   c  [        S5      eU R                   $ )z
Number of nonlinear equality constraints.

Returns
-------
int
    Number of nonlinear equality constraints.

Raises
------
ValueError
    If the number of nonlinear equality constraints is unknown.
z8The number of nonlinear equality constraints is unknown.)r   r   r9   s    r    r   NonlinearConstraints.m_eq  s*     ::J  ::r#   c                 ~    [        U R                  5      (       a#  U R                  S   R                  R                  $ g)r8   r   )r   r[   r   nfevr9   s    r    r:   NonlinearConstraints.n_eval/  s,     txx==88A;??'''r#   Nc                 H    [         R                  " U R                  XUS9SS9$ aT  
Evaluate the maximum constraint violation.

Parameters
----------
x : array_like, shape (n,)
    Point at which the maximum constraint violation is evaluated.
cub_val : array_like, shape (m_nonlinear_ub,), optional
    Values of the nonlinear inequality constraints. If not provided,
    the nonlinear inequality constraints are evaluated at `x`.
ceq_val : array_like, shape (m_nonlinear_eq,), optional
    Values of the nonlinear equality constraints. If not provided,
    the nonlinear equality constraints are evaluated at `x`.

Returns
-------
float
    Maximum constraint violation at `x`.
)cub_valceq_valr'   r   r   )r   r2   r   r   s       r    rh   NonlinearConstraints.maxcv>  s'    ( vvNN1wN?
 	
r#   c                     [         R                  " U R                   Vs/ s H  oDR                  U5      PM     sn5      $ s  snf r   )r+   r   r[   rf   )r   r2   r   r   r   s        r    rf   NonlinearConstraints.violationV  s-    ~~B2||ABCCBs   A )r   r   r   r   r   r   r[   NN)r@   rC   rD   rE   rF   r!   r4   rG   r   r   r:   rh   rf   rH   r*   r#   r    r   r   u  sZ    ':jX  *  *  
0Dr#   r   c                   H   \ rS rSrSrS rSS jr\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rSS jrSS jrS rSrg)ProblemiZ  z
Optimization problem.
c           
         U(       a  [        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[        5      (       d   e[        U[
        5      (       d   e[        U[        5      (       d   e[        U	[        5      (       d   e[        U
[        5      (       d   eU	(       a  U
S:  d   e[        U[        5      (       d   eUS:  d   e[        U[        5      (       d   eXl        X@l	        XPl
        Ub  [        U5      (       d  [        S5      eX`l        [        US5      nUR                  nUR                   R                  U:w  a  [#        SU S35      eUR$                  R&                  S   U:w  a  [#        SU S	35      e[)        UR                   UR*                  5      nUR                   UR*                  :*  [,        R.                  " UR                   UR*                  -
  5      U:  -  U l        S
UR                   U R0                     UR*                  U R0                     -   -  U l        [,        R4                  " U R2                  UR                   U R0                     UR*                  U R0                     5      U l        X0l        [        [9        UR                   U R0                  )    UR*                  U R0                  )    5      5      U l        U R:                  R=                  X R0                  )    5      U l        UR@                  URB                  SS2U R0                  4   U R2                  -  -
  n[        [E        UR$                  SS2U R0                  ) 4   [,        RF                  * URH                  UR$                  SS2U R0                  4   U R2                  -  -
  5      [E        URB                  SS2U R0                  ) 4   X5      /U RJ                  U5      U l	        U=(       a    U R:                  RL                  =(       a    [,        RN                  " [,        RP                  " U R:                  R                   5      5      =(       a>    [,        RN                  " [,        RP                  " U R:                  R*                  5      5      nU(       Ga  S
U R:                  R*                  U R:                  R                   -
  -  U l)        S
U R:                  R*                  U R:                  R                   -   -  U l*        [        [9        [,        RV                  " U RJ                  5      * [,        RV                  " U RJ                  5      5      5      U l        U R                  R@                  U R                  RB                  U RT                  -  -
  n[        [E        U R                  R$                  [,        RX                  " U RR                  5      -  [,        RF                  * U R                  RH                  U R                  R$                  U RT                  -  -
  5      [E        U R                  RB                  [,        RX                  " U RR                  5      -  UU5      /U RJ                  U5      U l	        U R>                  U RT                  -
  U RR                  -  U l        OJ[,        RV                  " U RJ                  5      U l)        [,        RZ                  " U RJ                  5      U l*        Xpl.        Xl/        / U l0        / U l1        / U l2        Xl3        Xl4        / U l5        / U l6        / U l7        g)ai  
Initialize the nonlinear problem.

The problem is preprocessed to remove all the variables that are fixed
by the bound constraints.

Parameters
----------
obj : ObjectiveFunction
    Objective function.
x0 : array_like, shape (n,)
    Initial guess.
bounds : BoundConstraints
    Bound constraints.
linear : LinearConstraints
    Linear constraints.
nonlinear : NonlinearConstraints
    Nonlinear constraints.
callback : {callable, None}
    Callback function.
feasibility_tol : float
    Tolerance on the constraint violation.
scale : bool
    Whether to scale the problem according to the bounds.
store_history : bool
    Whether to store the function evaluations.
history_size : int
    Maximum number of function evaluations to store.
filter_size : int
    Maximum number of points in the filter.
debug : bool
    Whether to make debugging tests during the execution.
r   Nz)The callback must be a callable function.z#The initial guess must be a vector.zThe bounds must have z
 elements.r
   z@The left-hand side matrices of the linear constraints must have z	 columns.rt   )8r   r   rJ   rq   r   r-   r   int_obj_linear
_nonlinearr   	TypeError	_callbackr   rZ   rR   r   r   shaper   rT   r+   r{   
_fixed_idx
_fixed_valrm   _orig_boundsr   _boundsrn   _x0r   r~   r   rQ   r   r   rV   rU   isfinite_scaling_factor_scaling_shiftrY   diagzeros_feasibility_tol_filter_size_fun_filter_maxcv_filter	_x_filter_store_history_history_size_fun_history_maxcv_history
_x_history)r   objr   r\   linear	nonlinearcallbackfeasibility_tolscalestore_historyhistory_sizefilter_sizer   r   tolr   s                   r    r!   Problem.__init___  s   ` c#45555f&67777f&78888i)=>>>>ou5555eT****mT2222lC0000#a'''k3////?"?eT****	#H%% KLL! B EFGG99>>Q4QCzBCC;;Q1$s)%  VYY		2!99		1FF699vyy()C/
 IIdoo&4??)CC
 ''OOIIdoo&IIdoo&
 #'699doo-.		4??:J0KL

 <<''OO+;(<= {{V[[DOO);<tNN( KKDOO#3 34VVGKKkk!T__"45GH !Q0@-@!A4N FF
   5((5r{{4<<??345 r{{4<<??34	 	 #&$,,//DLLOO*K#LD "%4<<??)J"KD+'9DL <<$$t||'8'84;N;N'NND,$))BGGD4H4H,II)),,++d.A.AAB %))BGGD4H4H,II DL" 4#6#66$:N:NNDH#%77466?D "$((466"2D !0' ,) r#   c                 t  ^^ [         R                  " U[        S9nU R                  U5      nU R	                  U5      mU R                  U5      u  pEU R                  XU5      mU R                  (       a  U R                  R                  T5        U R                  R                  T5        U R                  R                  U5        [        U R                  5      U R                  :  aQ  U R                  R                  S5        U R                  R                  S5        U R                  R                  S5        [         R                  " T5      (       a4  [         R                  " T5      (       a  [        U R                   5      S:H  nO[         R                  " T5      (       a4  [#        U4S j[%        U R                   U R&                  5       5       5      nO[         R                  " T5      (       a4  [#        U4S j[%        U R                   U R&                  5       5       5      nO4[#        UU4S j[%        U R                   U R&                  5       5       5      nU(       GaI  U R                   R                  T5        U R&                  R                  T5        U R(                  R                  U5        [+        [        U R                   5      S-
  SS5       GH\  n[         R                  " T5      (       a$  [         R                  " U R                   U   5      nO[         R                  " T5      (       a$  [         R                  " U R&                  U   5      nO[         R                  " U R                   U   5      =(       dU    [         R                  " U R&                  U   5      =(       d+    TU R                   U   :*  =(       a    TU R&                  U   :*  nU(       d  GM  U R                   R                  U5        U R&                  R                  U5        U R(                  R                  U5        GM_     [        U R                   5      U R,                  :  aQ  U R                   R                  S5        U R&                  R                  S5        U R(                  R                  S5        U R.                  b  [1        U R.                  5      n	 U R3                  U5      u  pnU R                  U
5      n
[5        U	R6                  5      S	1:X  a  [9        U
US
9nU R/                  US9  OU R/                  U
5         [         R                  " T5      (       a  [>        m[>        U[         R                  " U5      '   [>        U[         R                  " U5      '   [A        [C        T[>        5      [>        * 5      m[         RD                  " [         RF                  " U[>        5      [>        * 5      n[         RD                  " [         RF                  " U[>        5      [>        * 5      nTXE4$ ! [:         a  n[<        UeSnAff = f)at  
Evaluate the objective and nonlinear constraint functions.

Parameters
----------
x : array_like, shape (n,)
    Point at which the functions are evaluated.
penalty : float, optional
    Penalty parameter used to select the point in the filter to forward
    to the callback function.

Returns
-------
float
    Objective function value.
`numpy.ndarray`, shape (m_nonlinear_ub,)
    Nonlinear inequality constraint function values.
`numpy.ndarray`, shape (m_nonlinear_eq,)
    Nonlinear equality constraint function values.

Raises
------
`cobyqa.utils.CallbackSuccess`
    If the callback function raises a ``StopIteration``.
r%   r   c              3      >#    U  HF  u  p[         R                  " U5      =(       a    TU:  =(       d    [         R                  " U5      v   MH     g 7fr   r+   rS   ).0
fun_filtermaxcv_filter	maxcv_vals      r    	<genexpr>#Problem.__call__.<locals>.<genexpr>7  sK       1,J $ -,*88L)*1   AAc              3      >#    U  HF  u  p[         R                  " U5      =(       a    TU:  =(       d    [         R                  " U5      v   MH     g 7fr   r  )r  r  r  fun_vals      r    r  r  A  sK       1,J & )j((88J'(1r  c              3   J   >#    U  H  u  pTU:  =(       d    TU:  v   M     g 7fr   r*   )r  r  r  r  r  s      r    r  r  K  s1       1,J *$@	L(@@1s    #   Nintermediate_result)r2   r   )r  )$r+   re   r-   build_xr   r   rh   r   r   r   r   r   r   r   poprS   r   rU   zipr   r   ranger   r   r   	best_evalset
parametersr   StopIterationr   r   r   minmaximumminimum)r   r2   penaltyx_fullr   r   include_pointkremove_pointsigx_bestfun_best_r  excr  r  s                  @@r    r4   Problem.__call__
  s   6 JJq&a))F#??62JJq73	$$W-&&y1OO""1%4$$%(:(::!!%%a(##''*##A& 88G)!4!4 0 01Q6MXXg   14$$&&1	  M XXi     14$$&&1	  M    03$$&&1  M ##G,%%i0NN!!!$
 3t//014b"=88G$$#%88D,<,<Q,?#@LXXi((#%88D,>,>q,A#BL !1!1!!45 ?88D$6$6q$9:?"d&6&6q&99 ?%););A)>>	 !  <$$((+&&**1-NN&&q) >$ 4##$t'8'88  $$Q'""&&q)""1% >>%DNN+C/&*nnW&=#!f-s~~&+@*AA*8 $+'
 NN7JNKNN6*
 88GG%,!"%,!"c'7+gX6**RZZ9G8D**RZZ9G8D(( ! /%3./s   AX! 'X! !
X7+X22X7c                 .    U R                   R                  $ )zD
Number of variables.

Returns
-------
int
    Number of variables.
)r   rZ   r9   s    r    r   	Problem.n  s     ww||r#   c                 .    U R                   R                  $ )z
Number of variables in the original problem (with fixed variables).

Returns
-------
int
    Number of variables in the original problem (with fixed variables).
)r   rZ   r9   s    r    n_origProblem.n_orig  s     ###r#   c                     U R                   $ )zP
Initial guess.

Returns
-------
`numpy.ndarray`, shape (n,)
    Initial guess.
)r   r9   s    r    r   
Problem.x0  r`   r#   c                 .    U R                   R                  $ r7   )r   r:   r9   s    r    r:   Problem.n_eval  s     yyr#   c                 .    U R                   R                  $ )r>   )r   r1   r9   s    r    r   Problem.fun_name  r   r#   c                     U R                   $ )zM
Bound constraints.

Returns
-------
BoundConstraints
    Bound constraints.
)r   r9   s    r    r\   Problem.bounds  r<   r#   c                     U R                   $ )zP
Linear constraints.

Returns
-------
LinearConstraints
    Linear constraints.
)r   r9   s    r    r   Problem.linear  r<   r#   c                 .    U R                   R                  $ )zT
Number of bound constraints.

Returns
-------
int
    Number of bound constraints.
)r\   rX   r9   s    r    m_boundsProblem.m_bounds  s     {{}}r#   c                 .    U R                   R                  $ r   )r   r   r9   s    r    m_linear_ubProblem.m_linear_ub       {{r#   c                 .    U R                   R                  $ r   )r   r   r9   s    r    m_linear_eqProblem.m_linear_eq  rE  r#   c                 .    U R                   R                  $ )z
Number of nonlinear inequality constraints.

Returns
-------
int
    Number of nonlinear inequality constraints.

Raises
------
ValueError
    If the number of nonlinear inequality constraints is not known.
)r   r   r9   s    r    m_nonlinear_ubProblem.m_nonlinear_ub       ###r#   c                 .    U R                   R                  $ )z
Number of nonlinear equality constraints.

Returns
-------
int
    Number of nonlinear equality constraints.

Raises
------
ValueError
    If the number of nonlinear equality constraints is not known.
)r   r   r9   s    r    m_nonlinear_eqProblem.m_nonlinear_eq  rL  r#   c                 H    [         R                  " U R                  [        S9$ )z
History of objective function evaluations.

Returns
-------
`numpy.ndarray`, shape (n_eval,)
    History of objective function evaluations.
r%   )r+   r,   r   r-   r9   s    r    fun_historyProblem.fun_history(  s     xx))77r#   c                 H    [         R                  " U R                  [        S9$ )z
History of maximum constraint violations.

Returns
-------
`numpy.ndarray`, shape (n_eval,)
    History of maximum constraint violations.
r%   )r+   r,   r   r-   r9   s    r    maxcv_historyProblem.maxcv_history4  s     xx++599r#   c                      U R                   S:  d  U R                  S:  a  gU R                  S:  d  U R                  S:  a  gU R                  S:  a  gg! [
         a     gf = f)z
Type of the problem.

The problem can be either 'unconstrained', 'bound-constrained',
'linearly constrained', or 'nonlinearly constrained'.

Returns
-------
str
    Type of the problem.
r   znonlinearly constrainedzlinearly constrainedzbound-constrainedunconstrained)rJ  rN  rC  rG  r@  r   r9   s    r    typeProblem.type@  si    	-""Q&$*=*=*A0!!A%)9)9A)=-"*& 	- -	-s    A  A A 
A#"A#c                      U R                   S:H  $ )zw
Whether the problem is a feasibility problem.

Returns
-------
bool
    Whether the problem is a feasibility problem.
r?   )r   r9   s    r    is_feasibilityProblem.is_feasibility^  s     }}""r#   c                     [         R                  " U R                  5      nU R                  X R                  '   XR
                  -  U R                  -   X R                  ) '   U R                  R                  U5      $ )z
Build the full vector of variables from the reduced vector.

Parameters
----------
x : array_like, shape (n,)
    Reduced vector of variables.

Returns
-------
`numpy.ndarray`, shape (n_orig,)
    Full vector of variables.
)	r+   rv   r3  r   r   r   r   r   rn   )r   r2   r&  s      r    r  Problem.build_xj  sc     $++&"&//$%(<(<$<&*&9&9%:   ((00r#   Nc                     U R                  XUS9n[        R                  " U5      (       a  [        R                  " USS9$ gr   )rf   r+   rW   r   )r   r2   r   r   rf   s        r    rh   Problem.maxcv~  s;    ( NN1wNG	I&&66)S11r#   c                 $   / nU R                   R                  (       d,  U R                   R                  U5      nUR                  U5        [	        U R
                  R                  5      (       a,  U R
                  R                  U5      nUR                  U5        [	        U R                  R                  5      (       a-  U R                  R                  XU5      nUR                  U5        [	        U5      (       a  [        R                  " U5      $ g r   )
r\   rV   rf   r   r   r   r[   r   r+   r   )r   r2   r   r   rf   blcnlcs           r    rf   Problem.violation  s    	{{&&%%a(AQt{{&&q)BR t""##//++A@CS!y>>>>),, r#   c                    [        U R                  5      S:X  a  U " U R                  5        [        R                  " U R                  5      n[        R                  " U R
                  5      n[        R                  " U R                  5      n[        R                  " U5      n[        R                  " U5      (       Ga7  X0R                  :*  n[        R                  " U5      (       a  [        R                  " [        R                  " X&   5      5      (       dp  UU[        R                  " X&   5      :*  -  n[        R                  " U5      S:  a  Xs[        R                  " X7   5      :*  -  n[        R                  " U5      S   nGO[        R                  " U5      (       a  [        R                  " U5      S   nGO[        R                   " U[        R"                  5      n	X%   XU   -  -   X'   [        R                  " [        R                  " U	5      5      (       a4  U[        R                  " U5      :*  n
[        R                  " U
5      S   nGOU	[        R                  " U	5      :*  n[        R                  " U5      S:  a  X[        R                  " X;   5      :*  -  n[        R                  " U5      S:  a  X[        R                  " X+   5      :*  -  n[        R                  " U5      S   nOp[        R                  " [        R                  " U5      5      (       d3  U[        R                  " U5      :*  n[        R                  " U5      S   nO[        U5      S-
  nU R$                  R'                  XHSS24   5      X(   X8   4$ )aV  
Return the best point in the filter and the corresponding objective and
nonlinear constraint function evaluations.

Parameters
----------
penalty : float
    Penalty parameter

Returns
-------
`numpy.ndarray`, shape (n,)
    Best point.
float
    Corresponding objective function value.
float
    Corresponding maximum constraint violation.
r   r
   r  N)r   r   r   r+   r,   r   r   r   r|   r   rU   rS   nanminrW   r"  flatnonzero	full_likenanr\   rn   )r   r%  r  r  x_filter
finite_idxfeasible_idxfun_min_idxr   merit_filtermin_maxcv_idxmerit_min_idxs               r    r  Problem.best_eval  s   , t A%M XXd../
xx 2 2388DNN+[[.
66*'+@+@@Lvvl##BFF12- - +"))J,D"EE ##K014266$14 $ K NN;/3%% NN<04  "||J?*WJ7O-OO ( 66"((<011 %1BIIl4K$KM}5b9A %1BIIl4K$KM''6:%(7: *  ''6:%rvv&58 *  }5b9A,--
 %		*(==K{+B/A J!#AKKA/MO
 	
r#   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r'   r   )r@   rC   rD   rE   rF   r!   r4   rG   r   r3  r   r:   r   r\   r   r@  rC  rG  rJ  rN  rQ  rT  rX  r[  r  rh   rf   r  rH   r*   r#   r    r   r   Z  sj   iVB)H 	 	 	$ 	$ 	 	 	  	  	 	 	 	 	 	 	 	 	  	  	  	  $ $  $ $  	8 	8 	: 	: - -: 	# 	#1(4- h
r#   r   )
contextlibr   inspectr   r   numpyr+   scipy.optimizer   r   r   r   scipy.optimize._constraintsr	   settingsr   r   utilsr   r   r   r   rJ   rq   r   r   r*   r#   r    <module>rz     so         ; - 2 !W Wt]G ]G@d dNbD bDJv

 v

r#   