
    Џkh!                         d dl mZmZmZ ddlmZ ddlmZmZ ddl	m
Z
 d dlmZ ddlmZ ddlmZ dd	lmZ d d
lZd dlmZ  G d de      Zd Zd ZddZy
)    )NonlinearConstraintLinearConstraintBounds   )process_nl_constraints)#combine_multiple_linear_constraintsseparate_LC_into_eq_and_ineq)process_bounds)Enum)_project)get_arrays_tol)cobylaN)Iterablec                       e Zd ZdZdZdZdZy)ConstraintType   
         N)__name__
__module____qualname__LINEAR_OBJECTNONLINEAR_OBJECTLINEAR_DICTNONLINEAR_DICT     W/var/www/teggl/fontify/venv/lib/python3.12/site-packages/scipy/_lib/pyprima/__init__.pyr   r      s    MKNr   r   c                    t        | t              rd| v rd| v rd| v rt        j                  S t        | t              rd| v rd| v rd| v rt        j                  S t        | d      r(t        | d      rt        | d      rt        j                  S t        | d      r(t        | d      rt        | d      rt        j                  S t        dt        |        d      )NAlbubfunzConstraint type z not recognized)

isinstancedictr   r   r   hasattrr   r   
ValueErrortype)
constraints    r   get_constraint_typer+      s    *d#
):ASZ^blZl)))	J	%5J+>TZEW^bfp^p,,,	S	!gj$&?GJX\D]+++	U	#
D(AgjZ^F_...+D,<+=_MNNr   c           	         | syt        | t              s| g} g }g }| D ]  }t        |      }|t        j                  u r|j                  |       2|t        j                  u r|j                  |       V|t        j                  k(  r&|j                  t        |d   |d   |d                |t        j                  k(  r&|j                  t        |d   |d   |d                t        d       t        |      dkD  rt        |      }nd }t        |      dkD  rt        |      }||fS t        |      dk(  r	|d   }||fS d }||fS )	N)NNr!   r"   r#   r$   zConstraint type not recognizedr   r   )r%   r   r+   r   r   appendr   r   r   r   r   r(   lenr   r   )constraintslinear_constraintsnonlinear_constraintsr*   constraint_typenonlinear_constraint_functionlinear_constraints          r   process_constraintsr5   %   s    k8,"m ! ?
-j9n:::%%j1 ? ??!((4 : ::%%&6z#
SWHXZdeiZj&kl = ==!(()<Z=NPZ[_P`blmqbr)st=>>?  !A%(>?T(U%(,% "?@RS ;;; 
	 A	%.q1 ;;; !;;;r   c                     t        |      \  }|ddin|}|j                  dd      }	|F|	st        d       d}n||	st        d       d}ny||	st        d       d}ng|	st        d	       d
}nW|j                         }|dvrt	        d| d      |dk7  rt	        d      |dvr|t	        d      |dvr|t	        d      	 t        |      t        |      \  }}t        ||      }||k  t        j                  ||z
        |k  z  t              rJd|   |   z   z  t        j                  |   |         |    }|    }|    } fd}| t        ||||d d      }|j                  }|t!        |      \  }}}}nd\  }}}} fd}n fd} ||      \  }}d|v r|d= d|v r|d   |d<   |d= t#        |t        |      |||||||f	|||d|}t              r1t        j$                        }|<   |j                  | <   ||_        |S # t        $ r& t        j                  |g      } fd}
|
 dY w xY w)NquietTz/Nonlinear constraints detected, applying COBYLAr   zJLinear constraints detected without nonlinear constraints, applying LINCOAlincoazHBounds without linear or nonlinear constraints detected, applying BOBYQAbobyqaz2No bounds or constraints detected, applying NEWUOAnewuoa)r:   uobyqar9   r   r8   zFMethod must be one of NEWUOA, UOBYQA, BOBYQA, COBYLA, or LINCOA, not ''zLNonlinear constraints were provided for an algorithm that cannot handle them)r   r8   zILinear constraints were provided for an algorithm that cannot handle them)r   r9   r8   z=Bounds were provided for an algorithm that cannot handle themc                      | d   g S Nr   r   )xargsoriginal_scalar_funs    r   
scalar_funzminimize.<locals>.scalar_funw   s    &qt3d33r   r   g      ?c                 V    t        j                        }|<   | | <    |g S Nnpzeros)r?   newx
_fixed_idx_fixed_valuesr@   lenx0original_funs     r   	fixed_funzminimize.<locals>.fixed_fun   s6    88E?D,D !D*,t,,r   )linear	nonlinear)NNNNc                 .     | g } |       }||fS rD   r   )r?   fnlconstrr@   r$   r3   s      r   calcfczminimize.<locals>.calcfc   s$    AA4Q7Hh;r   c                 H     | g }t        j                  d      }||fS r>   rE   )r?   rQ   constrr@   r$   s      r   rS   zminimize.<locals>.calcfc   s'    AAXXa[Ff9r   maxfevmaxfun)f0	nlconstr0callback)r5   getprintlowerr(   r.   	TypeErrorrF   arrayr
   r   absanyclipr   r?   r	   r   rG   )r$   x0r@   methodboundsr/   rZ   optionsr4   r7   rB   r"   r#   tolrM   resultA_eqb_eqA_ineqb_ineqrS   rX   rY   rH   rI   rJ   rK   r3   rL   rA   s   ` `                     @@@@@@r   minimizerm   O   s*   7J;7W44!(wogGKK&E~(4% QRF*% lmF% jkF% TUF KKeflemmnoppX"?"Kkll--2C2Ohii77F<N\]]
B FE*FB R
 C	r66"r'?S 	"  :zNR
^+
 zNzN

 ___	- 	-
  %,"b"1BQU&VWXX$%ABS%T"dFF%;"dFF$0	
	
 2JMB	'G7#H-HI


  F  :xx(Z"HHj[MA  XXrd^!	4s   H6 6+I%$I%)r   NNr   NN)scipy.optimizer   r   r   common._nonlinear_constraintsr   common._linear_constraintsr   r	   common._boundsr
   enumr   common._projectr   common.linalgr   cobyla.cobylar   numpyrF   collections.abcr   r   r+   r5   rm   r   r   r   <module>rx      sH    H H A +  % ) !  $T 
O'<TEr   