Ë
    0Ò^j·  ã                   ó˜   — d Z ddlZddlmZ ddlmZ eeej                  fZ
 ej                  ej                  «      j                  Zd„ Zy)a   
This module provides the _project function that attempts to project the initial guess
onto the feasible set.

Adapted from the corresponding function in the PDFO package (https://www.pdfo.net) by
Tom M. Ragonneau (https://ragonneau.github.io) and Zaikun Zhang (https://www.zhangzk.net).
é    Né   ©ÚLinearConstraint)ÚOptimizeResultc           	      óò  ‡— d}t        | t        «      r| gŠn)t        | d«      r| Šnt        dj	                  |«      «      ‚	 t        j                  ‰t
        j                  ¬«      Št        ‰j                  «      dk7  rt        dj	                  |«      «      ‚‰j                  }t        |t        «      r|g}n)t        |d«      r|}nt        dj	                  |«      «      ‚	 t        j                  |t
        j                  ¬«      }t        |j                  «      dk7  s|j                  |k7  rt        d	j	                  |«      «      ‚t        |t        «      r|g}n)t        |d«      r|}nt        d
j	                  |«      «      ‚	 t        j                  |t
        j                  ¬«      }t        |j                  «      dk7  s|j                  |k7  rt        dj	                  |«      «      ‚t        |t        «      r6ddht        |j                  «       «      k  rt        |d   t        «      s|d   �t        dj	                  |«      «      ‚d}|d   €<t        j                  t        j                   ‰|fd¬«      |fd¬«      }	t#        |	¬«      S t%        t        j&                  t        j(                  |d   j*                  |d   j,                  z
  «      t.        «      «      rßt        j0                  |«      | k  rÆt        j2                  |«      |k\  r®|d   j4                  }
|d   j,                  |d   j*                  z   dz  }t
        j6                  j9                  |
|t        j:                  |
‰«      z
  d¬«      \  }}}}t        j                  t        j                   ‰|z   |fd¬«      |fd¬«      }	t#        |	¬«      S |d   ��	 ddlm} ddlm } ddlm} |d   }t        «       t        «       }}t        j                  g g«      t        j                  g g«      c|d<   |d<   |d   jC                  d|j4                  j                  d   «      |d<   |d   jC                  d|j4                  j                  d   «      |d<   t        j                  g «      t        j                  g «      c|d<   |d<   t        j                  g «      t        j                  g «      c|d<   |d<   tE        |j,                  j                  «      D �]-  }|j,                  |   |j*                  |   k7  r†t        jF                  |d   |j4                  ||dz   …dd…f   fd¬«      |d<   t
        jH                  |d   |j,                  |   f   |d<   t
        jH                  |d   |j*                  |   f   |d<   Œ©t        jF                  |d   |j4                  ||dz   …dd…f   fd¬«      |d<   t
        jH                  |d   |j,                  |   f   |d<   t
        jH                  |d   |j*                  |   f   |d<   �Œ0 |d   j                  dkD  r5|d   j                  dkD  r#|d   j                  dkD  r |di |¤Ž |di |¤Žg}nJ|d   j                  dkD  r|d   j                  dkD  r	 |di |¤Ž}n|d   j                  dkD  r	 |di |¤Ž}nd}t        j:                  |d   ‰«      }t        j:                  |d   ‰«      }t        jJ                  ||d   «      jM                  «       s–t        jJ                  |d   |«      jM                  «       sot        jN                  ||d   «      jM                  «       sHt        jJ                  ‰|«      jM                  «       s$t        jJ                  |‰«      jM                  «       r |ˆfd„‰ˆfd„ |||«      |¬ «      S t#        ‰¬«      S t#        ‰¬«      S # t        $ r t        dj	                  |«      «      ‚w xY w# t        $ r t        dj	                  |«      «      ‚w xY w# t        $ r t        dj	                  |«      «      ‚w xY w# tP        $ r t#        ‰¬«      cY S w xY w)!a�  Projection of the initial guess onto the feasible set.

    Parameters
    ----------
    x0: ndarray, shape (n,)
        The same as in prepdfo.
    lb: ndarray, shape (n,)
        The same as in prepdfo.
    ub: ndarray, shape (n,)
        The same as in prepdfo.
    constraints: dict
        The general constraints of the problem, defined as a dictionary with
        fields:
            linear: LinearConstraint
                The linear constraints of the problem.
            nonlinear: dict
                The nonlinear constraints of the problem. When ``_project`` is called, the nonlinear constraints are
                None.

    Returns
    -------
    result: OptimizeResult
        The result of the projection.

    Authors
    -------
    Tom M. RAGONNEAU (ragonneau.github.io)
    and Zaikun ZHANG (www.zhangzk.net)

    Dedicated to the late Professor M. J. D. Powell FRS (1936--2015).
    ÚprimaÚ__len__z,{}: UNEXPECTED ERROR: x0 should be a vector.)Údtypez5{}: UNEXPECTED ERROR: x0 should contain only scalars.r   z,{}: UNEXPECTED ERROR: lb should be a vector.z5{}: UNEXPECTED ERROR: lb should contain only scalars.z={}: UNEXPECTED ERROR: the size of lb is inconsistent with x0.z,{}: UNEXPECTED ERROR: ub should be a vector.z5{}: UNEXPECTED ERROR: ub should contain only scalars.z={}: UNEXPECTED ERROR: the size of ub is inconsistent with x0.ÚlinearÚ	nonlinearNz6{}: UNEXPECTED ERROR: The constraints are ill-defined.g@Œµx¯Dr   )Úaxis)Úxé   )Úrcond)Úminimize)ÚBoundsr   ÚAÚlbÚub© c                 óB   •— t        j                  | ‰z
  | ‰z
  «      dz  S )Nr   )ÚnpÚdot©r   Úx0_cs    €úr/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/scipy/_external/pyprima/common/_project.pyú<lambda>z_project.<locals>.<lambda>¤   s   ø€ ¬"¯&©&°°T±¸1¸t¹8Ó*DÀqÑ*H€ ó    c                 ó   •— | ‰z
  S )Nr   r   s    €r   r   z_project.<locals>.<lambda>¤   s   ø€ Ð_`ÐcgÑ_g€ r   )ÚjacÚboundsÚconstraints))Ú
isinstanceÚscalar_typesÚhasattrÚ
ValueErrorÚformatr   ÚasarrayÚfloat64ÚlenÚshapeÚsizeÚdictÚsetÚkeysr   ÚnanminÚnanmaxr   ÚallÚ
less_equalÚabsr   r   ÚepsÚmaxÚminr   ÚlinalgÚlstsqr   Úscipy.optimizer   r   ÚreshapeÚrangeÚconcatenateÚr_ÚgreaterÚanyÚ	not_equalÚImportError)Úx0r   r   r"   ÚinvokerÚlenx0Úlb_cÚub_cÚmax_conÚx_projÚaÚbÚxiÚ_r   ÚScipyBoundsÚScipyLinearConstraintr   Úpc_args_ineqÚ
pc_args_eqÚiÚproject_constraintsÚax_ineqÚax_eqr   s                           @r   Ú_projectrV      s¡  ø€ ð@ €Gô �"”lÔ#Øˆt‰Ü	��YÔ	Ø‰äÐG×NÑNÈwÓWÓXÐXðbÜ�z‰z˜$¤b§j¡jÔ1ˆô ˆ4�:‰:ƒ˜!ÒÜÐG×NÑNÈwÓWÓXÐXØ�I‰I€Eô �"”lÔ#Øˆt‰Ü	��YÔ	Ø‰äÐG×NÑNÈwÓWÓXÐXðbÜ�z‰z˜$¤b§j¡jÔ1ˆô ˆ4�:‰:ƒ˜!Ò˜tŸy™y¨EÒ1ÜÐX×_Ñ_Ð`gÓhÓiÐiô �"”lÔ#Øˆt‰Ü	��YÔ	Ø‰äÐG×NÑNÈwÓWÓXÐXðbÜ�z‰z˜$¤b§j¡jÔ1ˆô ˆ4�:‰:ƒ˜!Ò˜tŸy™y¨EÒ1ÜÐX×_Ñ_Ð`gÓhÓiÐiô �k¤4Ô(°(¸KÐ1HÌCÐP[×P`ÑP`ÓPbÓLcÒ1cÜ˜K¨Ñ1Ô3CÔDÈÐT\ÑH]ÐHeäÐQ×XÑXÐY`ÓaÓbÐbà€Gð �8ÑÐ$ä—‘œBŸI™I t¨T l¸Ô;¸TÐBÈÔKˆÜ Ô'Ð'Ü	ŒR�]‰]œ2Ÿ6™6 +¨hÑ"7×":Ñ":¸[ÈÑ=R×=UÑ=UÑ"UÓVÔX[Ó\Ô	]Ü�F‰F�4‹L˜W˜HÒ$¬¯©°«¸Ò)@ð ˜Ñ!×#Ñ#ˆØ˜Ñ"×%Ñ%¨°HÑ(=×(@Ñ(@Ñ@ÀAÑEˆÜ—i‘i—o‘o a¨¬R¯V©V°A°t«_Ñ)<ÀD�oÓI‰ˆˆAˆq�!ô —‘œBŸI™I t¨b¡y°$Ð&7¸aÔ@À$ÐGÈaÔPˆä Ô'Ð'à�8ÑÑ(ð1	*å/Ý<ÝPà  Ñ*ˆFô (,£v¬t«v˜*ˆLÜ13·±¸R¸DÓ1AÄ2Ç:Á:ÈrÈdÓCSÐ.ˆL˜Ñ˜z¨#™Ø ,¨SÑ 1× 9Ñ 9¸!¸V¿X¹X¿^¹^ÈAÑ=NÓ OˆL˜ÑØ(¨™o×5Ñ5°a¸¿¹¿¹ÈÑ9JÓKˆJ�s‰OÜ35·:±:¸b³>Ä2Ç:Á:ÈbÃ>Ð0ˆL˜Ñ 
¨4Ñ 0Ü35·:±:¸b³>Ä2Ç:Á:ÈbÃ>Ð0ˆL˜Ñ 
¨4Ñ 0ä˜6Ÿ9™9Ÿ>™>Ó*ó M�Ø—9‘9˜Q‘< 6§9¡9¨Q¡<Ò/Ü(*¯©¸ÀSÑ8IÈ6Ï8É8ÐTUÐVWÐXYÑVYÐTYÒ[\ÐT\ÑK]Ð7^ÐefÔ(g�L Ñ%Ü)+¯©¨|¸DÑ/AÀ6Ç9Á9ÈQÁ<Ð/OÑ)P�L Ñ&Ü)+¯©¨|¸DÑ/AÀ6Ç9Á9ÈQÁ<Ð/OÑ)P�L Ò&ä&(§n¡n°jÀ±oÀvÇxÁxÐPQÐRSÐTUÑRUÐPUÒWXÐPXÑGYÐ5ZÐabÔ&c�J˜s‘OÜ')§u¡u¨Z¸Ñ-=¸v¿y¹yÈ¹|Ð-KÑ'L�J˜tÑ$Ü')§u¡u¨Z¸Ñ-=¸v¿y¹yÈ¹|Ð-KÑ'L�J˜tÓ$ðMð ˜CÑ ×%Ñ%¨Ò)¨l¸4Ñ.@×.EÑ.EÈÒ.IÈjÐY]ÑN^×NcÑNcÐfgÒNgÙ'<Ñ'L¸|Ñ'LÑNcÑNqÐfpÑNqÐ&rÑ#Ø˜cÑ"×'Ñ'¨!Ò+°¸TÑ0B×0GÑ0GÈ!Ò0KÙ&;Ñ&K¸lÑ&KÑ#Ø˜C‘×%Ñ%¨Ò)Ù&;Ñ&I¸jÑ&IÑ#à&(Ð#ô —f‘f˜\¨#Ñ.°Ó5ˆGÜ—F‘F˜: c™?¨DÓ1ˆEÜ�z‰z˜' <°Ñ#5Ó6×:Ñ:Ô<ÄÇ
Á
È<ÐX\ÑK]Ð_fÓ@g×@kÑ@kÔ@mÜ—L‘L ¨
°4Ñ(8Ó9×=Ñ=Ô?Ü—J‘J˜t TÓ*×.Ñ.Ô0´B·J±J¸tÀTÓ4J×4NÑ4NÔ4PÙÓ HÈ$ÓThÙ'2°4¸Ó'>ÐL_ôað aô &¨Ô-Ð-ô
 ˜DÔ!Ð!øôc ò bÜÐP×WÑWÐX_Ó`ÓaÐaðbûô ò bÜÐP×WÑWÐX_Ó`ÓaÐaðbûô ò bÜÐP×WÑWÐX_Ó`ÓaÐaðbûôb ò 	*Ü! DÔ)Ò)ð	*ús=   Á%_) Ã#%` Æ%`7 Ï	Pa ßa ß)$`à$`4à7$aáa6á5a6)Ú__doc__Únumpyr   Ú_linear_constraintsr   r:   r   ÚintÚfloatÚgenericr$   Úfinfor)   r5   rV   r   r   r   ú<module>r^      sG   ðñó Ý 1Ý )ð �U˜BŸJ™JÐ'€Ø€b‡h�hˆr�z‰zÓ×Ñ€ó\"r   