
    Di                        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 d dlmZ d d	lmZ 	 	 	 	 	 	 	 	 dd
ZddZdd	 	 	 	 	 ddZy)    )annotations)SequenceN)optuna_warn)_CONSTRAINTS_KEY)StudyDirection)
_dominates)FrozenTrial)
TrialStatec                   | 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     t/home/ubuntu/crypto_trading_bot/.venv/lib/python3.12/site-packages/optuna/samplers/nsgaii/_constraints_evaluation.py	<genexpr>z)_constrained_dominates.<locals>.<genexpr>C        <!qAv<   c              3  &   K   | ]	  }|d k    ywr   r   r   s     r   r   z)_constrained_dominates.<locals>.<genexpr>D   r   r   c              3  ,   K   | ]  }|d kD  s	|  ywr   r   r   s     r   r   z)_constrained_dominates.<locals>.<genexpr>S        61AQ6   
c              3  ,   K   | ]  }|d kD  s	|  ywr   r   r   s     r   r   z)_constrained_dominates.<locals>.<genexpr>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_dominatesr3      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>e   s     ?QQq?r   )r   r   r   appendnpnanr)   array)
populationpenaltytrialconstraintss       r   _evaluate_penaltyr?   X   so     G A((,,-=>NN266"NN3?+??@A 88Gr4   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    r8   anyisnanr:   r%   )r;   r@   tnum_constraints_trial_constraintss         r   _validate_constraintsrJ   i   s    
 @JK1Q^^ 0"5	6KUVO  a**../?@ (= = 66"((288L123IJJ/1_``a 	Ls   0C()r*   r	   r+   r	   r,   zSequence[StudyDirection]returnbool)r;   zSequence[FrozenTrial]rK   z
np.ndarray)r;   zlist[FrozenTrial]r@   rL   rK   None)
__future__r   collections.abcr   numpyr8   optuna._warningsr   optuna.samplers._baser   optuna.studyr   optuna.study._multi_objectiver   optuna.trialr	   r
   r3   r?   rJ   r   r4   r   <module>rV      sz    " $  ( 2 ' 4 $ #F#F#!,F#:RF#	F#R( !a!a a 
	ar4   