
    Ti!                         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d
S )    )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dS )ConstraintType   
         N)__name__
__module____qualname__LINEAR_OBJECTNONLINEAR_OBJECTLINEAR_DICTNONLINEAR_DICT     s/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/scipy/_lib/pyprima/__init__.pyr   r      s#        MKNNNr   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## 	O
):):ASASZ^blZlZl))	J	%	% O5J+>+>TZEWEW^bfp^p^p,,	S	!	! Ogj$&?&? OGJX\D]D] O++	U	#	# O
D(A(A OgjZ^F_F_ O..MD,<,<MMMNNNr   c           	         | sdS t          | t                    s| g} g }g }| D ]}t          |          }|t          j        u r|                    |           5|t          j        u r|                    |           Y|t          j        k    r7|                    t          |d         |d         |d                              |t          j	        k    r7|                    t          |d         |d         |d                              t          d          t          |          dk    rt          |          }nd }t          |          dk    rt          |          }nt          |          dk    r	|d         }n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    z k8,, $"m ! ? ?
-j99n:::%%j1111 ???!((4444 :::%%&6z#
SWHXZdeiZj&k&kllll ===!(()<Z=NPZ[_P`blmqbr)s)stttt=>>>
 !!A%%(>?T(U(U%%(,% ""?@RSS		 	 A	%	%.q1 ;;;r   r   c                     t          |          \  }|ddin|}|                    dd          }	|V|	st          d           d}n||	st          d           d}n||	st          d           d}n|	st          d	           d
}nl|                                }|dvrt	          d| d          |dk    rt	          d          |dvr|t	          d          |dvr|t	          d          	 t          |          n1# t          $ r$ t          j        |g          } fd}
|
 dY nw xY wt          |          \  }}t          ||          }||k    t          j        ||z
            |k     z  t                    r^d|         |         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                    r+t          j                  }|<   |j        | <   ||_        |S )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R  S Nr   r   )xargsoriginal_scalar_funs    r   
scalar_funzminimize.<locals>.scalar_funw   s     &&qt3d3333r   r   g      ?c                 T    t          j                  }|<   | | <    |gR  S Nnpzeros)r?   newx
_fixed_idx_fixed_valuesr@   lenx0original_funs     r   	fixed_funzminimize.<locals>.fixed_fun   s>    8E??D,D !D*<,t,,,,r   )linear	nonlinear)NNNNc                 4     | gR  } |           }||fS rD   r   )r?   fnlconstrr@   r$   r3   s      r   calcfczminimize.<locals>.calcfc   s0    AA44Q77Hh;r   c                 F     | gR  }t          j        d          }||fS r>   rE   )r?   rQ   constrr@   r$   s      r   rS   zminimize.<locals>.calcfc   s-    AAXa[[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;7W7W44!(woogGKK&&E~(4R% QRRRFF*m% lmmmFFk% jkkkFFU% TUUUFF KKKoflooopppX"?"Kklll---2C2Ohiii777F<N\]]]
B   Xrd^^!	4 	4 	4 	4 	4 	4 FE**FB R
 
 C	r6"r'??S 	"  : zNR
^+
 zNzN
 

 ___	- 	- 	- 	- 	- 	- 	- 	- 	-
  %,"b"1BQU&V&VWWX$%ABS%T%T"dFFF%;"dFF$0	 	 	 	 	 	 	 	
	 	 	 	 	 	
 F2JJMB	'G7#H-HI


    F  : x(Z"Hj[Ms   >D +D<;D<)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      sG   H H H H H H H H H H A A A A A A        + * * * * *       % % % % % % ) ) ) ) ) ) ! ! ! ! ! !     $ $ $ $ $ $    T   
O 
O 
O'< '< '<TE E E E E Er   