
    Q-jR                        d dl mZ d dlmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ erd dlmZ d d	lmZ d d
lmZ 	 	 	 	 	 	 	 	 ddZddZdd	 	 	 	 	 ddZy)    )annotations)TYPE_CHECKINGN)optuna_warn)_CONSTRAINTS_KEY)
_dominates)
TrialState)Sequence)StudyDirection)FrozenTrialc                   | j                   j                  t              }|j                   j                  t              }|t        d| j                   d       |t        d|j                   d       ||t        | ||      S ||y||yt        |t        t        f      sJ t        |t        t        f      sJ t        |      t        |      k7  rt        d      | j                  t        j                  k7  ry|j                  t        j                  k7  ryt        d |D              }t        d |D              }|r|rt        | ||      S |ry|ryt        d |D              }t        d	 |D              }||k  S )
af  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  &   K   | ]	  }|d k    ywr   N .0vs     |/Users/jameslopez/projects/TradingBot25/.venv/lib/python3.12/site-packages/optuna/samplers/nsgaii/_constraints_evaluation.py	<genexpr>z)_constrained_dominates.<locals>.<genexpr>H        <|!qAv|   c              3  &   K   | ]	  }|d k    ywr   r   r   s     r   r   z)_constrained_dominates.<locals>.<genexpr>I   r   r   c              3  ,   K   | ]  }|d kD  s	|  ywr   r   r   s     r   r   z)_constrained_dominates.<locals>.<genexpr>X        61AQ   
c              3  ,   K   | ]  }|d kD  s	|  ywr   r   r   s     r   r   z)_constrained_dominates.<locals>.<genexpr>Y   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lT5M222
<C--[\\||z***||z***<|<<<|<< 4&&*55 666J666J
""    c                   g }| D ]d  }|j                   j                  t              }| |j                  t        j
                         D|j                  t        d |D                     f t	        j                  |      S )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  ,   K   | ]  }|d kD  s	|  ywr   r   r   s     r   r   z$_evaluate_penalty.<locals>.<genexpr>j   s     ?+QQq+r   )r   r    r   appendnpnanr*   array)
populationpenaltytrialconstraintss       r   _evaluate_penaltyr@   ]   sh     G((,,-=>NN266"NN3?+??@  88Gr5   F)is_constrainedc                  |sy t        | D cg c]+  }t        |j                  j                  t        g             - c}d      }| D ]  }|j                  j                  t              }|t        d|j                   d       >t        j                  t        j                  t        j                  |                  rt        d      t        |      |k7  st        d       y c c}w )Nr   )defaultr   r   z*NaN is not acceptable as constraint value.r   )maxr%   r   r    r   r   r!   r9   anyisnanr;   r&   )r<   rA   tnum_constraints_trial_constraintss         r   _validate_constraintsrK   n   s    
 @JK
1Q^^ 0"5	6
KUVO **../?@ (= = 66"((288L123IJJ/1_``  	Ls   0C()r+   r   r,   r   r-   zSequence[StudyDirection]returnbool)r<   zSequence[FrozenTrial]rL   z
np.ndarray)r<   zlist[FrozenTrial]rA   rM   rL   None)
__future__r   typingr   numpyr9   optuna._warningsr   optuna.samplers._baser   optuna.study._multi_objectiver   optuna.trialr   collections.abcr	   optuna.studyr
   r   r4   r@   rK   r   r5   r   <module>rX      s    "    ( 2 4 # (+(F#F#!,F#:RF#	F#R( !a!a a 
	ar5   