
    -ji                        S SK Jr  S SKJr  S SKrS SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S S	KJr          SS
 jrSS jrSS.     SS jjrg)    )annotations)SequenceN)optuna_warn)_CONSTRAINTS_KEY)StudyDirection)
_dominates)FrozenTrial)
TrialStatec                P   U R                   R                  [        5      nUR                   R                  [        5      nUc  [        SU R                   S35        Uc  [        SUR                   S35        Uc  Uc  [        XU5      $ Ub  Uc  gUc  Ub  g[        U[        [        45      (       d   e[        U[        [        45      (       d   e[        U5      [        U5      :w  a  [        S5      eU R                  [        R                  :w  a  gUR                  [        R                  :w  a  g[        S U 5       5      n[        S U 5       5      nU(       a  U(       a  [        XU5      $ U(       a  gU(       a  g[        S U 5       5      n[        S	 U 5       5      nXx:  $ )
aJ  Checks constrained-domination.

A trial x is said to constrained-dominate a trial y, if any of the following conditions is
true:
1) Trial x is feasible and trial y is not.
2) Trial x and y are both infeasible, but solution x has a smaller overall constraint
violation.
3) Trial x and y are feasible and trial x dominates trial y.
Trial K does not have constraint values. It will be dominated by the other trials.TF@Trials with different numbers of constraints cannot be compared.c              3  *   #    U  H	  oS :*  v   M     g7fr   N .0vs     h/home/james-whalen/.local/lib/python3.13/site-packages/optuna/samplers/nsgaii/_constraints_evaluation.py	<genexpr>)_constrained_dominates.<locals>.<genexpr>C        <|!Av|   c              3  *   #    U  H	  oS :*  v   M     g7fr   r   r   s     r   r   r   D   r   r   c              3  4   #    U  H  oS :  d  M
  Uv   M     g7fr   r   r   s     r   r   r   S        61AQQ   		c              3  4   #    U  H  oS :  d  M
  Uv   M     g7fr   r   r   s     r   r   r   T   r   r   )system_attrsgetr   r   numberr   
isinstancelisttuplelen
ValueErrorstater
   COMPLETEallsum)	trial0trial1
directionsconstraints0constraints1satisfy_constraints0satisfy_constraints1
violation0
violation1s	            r   _constrained_dominatesr4      s    &&**+;<L&&**+;<LV]]O $9 9	

 V]]O $9 9	

  4&*55L$8 8lT5M2222lT5M2222
<C--[\\||z***||z***<|<<<|<< 4&*55 666J666J""    c                   / nU  Hg  nUR                   R                  [        5      nUc!  UR                  [        R
                  5        MF  UR                  [        S U 5       5      5        Mi     [        R                  " U5      $ )zEvaluate feasibility of trials in population.
Returns:
    A list of feasibility status T/F/None of trials in population, where T/F means
    feasible/infeasible and None means that the trial does not have constraint values.
c              3  4   #    U  H  oS :  d  M
  Uv   M     g7fr   r   r   s     r   r   $_evaluate_penalty.<locals>.<genexpr>e   s     ?+QQqq+r   )r   r    r   appendnpnanr*   array)
populationpenaltytrialconstraintss       r   _evaluate_penaltyrA   X   sh     G((,,-=>NN266"NN3?+??@  88Gr5   F)is_constrainedc                  U(       d  g [        U  Vs/ s H,  n[        UR                  R                  [        / 5      5      PM.     snSS9nU  H  nUR                  R                  [        5      nUc  [        SUR                   S35        M@  [        R                  " [        R                  " [        R                  " U5      5      5      (       a  [        S5      e[        U5      U:w  d  M  [        S5      e   g s  snf )Nr   )defaultr   r   z*NaN is not acceptable as constraint value.r   )maxr%   r   r    r   r   r!   r:   anyisnanr<   r&   )r=   rB   tnum_constraints_trial_constraintss         r   _validate_constraintsrL   i   s    
 @JK
1Q^^ 0"5	6
KUVO **../?@ (= = 66"((288L1233IJJ/1_``  	Ls   3C:)r+   r	   r,   r	   r-   zSequence[StudyDirection]returnbool)r=   zSequence[FrozenTrial]rM   z
np.ndarray)r=   zlist[FrozenTrial]rB   rN   rM   None)
__future__r   collections.abcr   numpyr:   optuna._warningsr   optuna.samplers._baser   optuna.studyr   optuna.study._multi_objectiver   optuna.trialr	   r
   r4   rA   rL   r   r5   r   <module>rX      sz    " $  ( 2 ' 4 $ #F#F#!,F#:RF#	F#R( !a!a a 
	ar5   