
    ,YHhx                        d dl mZ d dlZd dlZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZy)	    )annotationsNc                   | j                   d   dk(  r|| j                   d   k  sJ | j                   d   }t        j                  | j                   d         }| j                         }t        j                  |t        j
                  d d f   |d      }t        j                  |t              }t        |      D ]  }	t        j                  ||z
  d      }
t        j                  |
      }|||      ||	<   ||   j                         }t        j                  ||	z
  t              }d||<   ||   }||   }||   }t        j                  |d   |d |df         |d |df<   t        j                  |d   ||d df         ||d df<    |S )N   r   axisdtypeF   )shapenparangecopyrepeatnewaxiszerosintrangeprodargmaxonesboolminimum)rank_i_loss_valsrank_i_indicessubset_sizereference_pointn_trialssorted_indicessorted_loss_vals
rect_diagsselected_indicesicontribs	max_index	loss_valskeeps                 Q/var/www/html/planif/env/lib/python3.12/site-packages/optuna/_hypervolume/hssp.py_solve_hssp_2dr)      s    !!"%*{>N>T>TUV>W/WWW%%a(HYY/55a89N',,.?2::q=98!LJxx37; X77:(88rBIIh'	,^I-FG$Y/446	wwx!|40Y'-%
+D1$&JJy|Z

TU=V$W
:I:q=!$&JJy|Z	
TU=V$W
9:q=!X      c                   t         j                  j                  |dd |d      }d}t        j                  |        }|D ]  }| |   |k  r||   j                         |d<   t         j                  j                  ||d      }t        j                  |      s||z
  nt        j                  | |<   t        | |   |      } | S )a  Lazy update the hypervolume contributions.

    S=selected_indices - {indices[max_index]}, T=selected_indices, and S' is a subset of S.
    As we would like to know argmax H(T v {i}) in the next iteration, we can skip HV
    calculations for j if H(T v {i}) - H(T) > H(S' v {j}) - H(S') >= H(T v {j}) - H(T).
    We used the submodularity for the inequality above. As the upper bound of contribs[i] is
    H(S' v {j}) - H(S'), we start to update from i with a higher upper bound so that we can
    skip more HV calculations.
    Nr   T)assume_paretog        )	optuna_hypervolumecompute_hypervolumer   argsortr   isinfinfmax)	r$   pareto_loss_valuesselected_vecsr   hv_selectedmax_contrib%index_from_larger_upper_bound_contribr#   hv_pluss	            r(   _lazy_contribs_updater:   +   s     %%99crO4 : K K,.JJy,A)2 4A;$ .q1668b%%99?$ : 
 4688G3Dg+"&&(1+{34 Or*   c           	        t        j                  |      j                         s|d | S |j                  |k(  r|S | j                  d   dk(  rt        | |||      S ||j                  k  sJ || z
  }| j                  \  }}t        j                  |d      }t        j                  |t              }t        j                  ||f      }	t        j                  |      }
t        |      D ]  }t        t        j                  |            }|
|   ||<   | |   j                         |	|<   t        j                  |j                  t              }d||<   ||   }|
|   }
| |   } ||dz
  k(  r ||   S t!        || |	d |dz    |      } ||   S )Nr   r   r   r	   Fr   )r   isfiniteallsizer   r)   r   r   r   emptyr   r   r   r   r   r   r:   )r   r   r   r   diff_of_loss_vals_and_ref_pointn_solutionsn_objectivesr$   r"   r5   indiceskr%   r'   s                 r(   _solve_hssp_on_unique_loss_valsrE   P   s    ;;'++-l{++k)b!Q&._]],,,,,&58H&H#"2"8"8[,ww6R@Hxx37HHk<89Mii$G; 
		(+,	%i0+I6;;=awwx}}D1YD>$-+D1a *++	 )&gA(>

" *++r*   c                \   ||j                   k(  r|S t        j                  | dd      \  }}|j                   }||k  r]t        j                  |j                   t              }d||<   t        j
                  |j                         |    }d||d||z
   <   ||   S t        ||||      }	||	   S )ah  Solve a hypervolume subset selection problem (HSSP) via a greedy algorithm.

    This method is a 1-1/e approximation algorithm to solve HSSP.

    For further information about algorithms to solve HSSP, please refer to the following
    paper:

    - `Greedy Hypervolume Subset Selection in Low Dimensions
       <https://doi.org/10.1162/EVCO_a_00188>`__
    Tr   )return_indexr   r	   N)r>   r   uniquer   r   r   rE   )
r   r   r   r   rank_i_unique_loss_valsindices_of_unique_loss_valsn_uniquechosenduplicated_indices$selected_indices_of_unique_loss_valss
             r(   _solve_hssprO   y   s      n)));=99t!<88 +//H+.--T:.2*+YY~':':;VGD?C!":K($:;<f%%+J!<k?,( >??r*   )
r   
np.ndarrayr   rP   r   r   r   rP   returnrP   )
r$   rP   r4   rP   r5   rP   r   rP   rQ   rP   )	
__future__r   numpyr   r-   r)   r:   rE   rO    r*   r(   <module>rU      s    "          	 
  F"""" "  	"
 "J&, &,&, &,  	&,
 &,R!@ !@!@ !@  	!@
 !@r*   