a
    J5d                     @   s   d dl Z d dlZddlmZ g dZejfddZejfddZejfd	d
ZejdfddZ	ejfddZ
dddejfddZeeeeeee jeejde	e
ee jedddddZdS )    N   )utils)TYPES	euclidean	manhattanmaximumgeographicalpseudo_euclideanxrayc                 C   sD   t | t |krtdtdd t| |D }t|}||S )a  Return the Euclidean distance between start and end.

    This is capable of performing distance calculations for EUC_2D and
    EUC_3D problems. If ``round=math.ceil`` is passed, this is suitable for
    CEIL_2D problems as well.

    :param tuple start: *n*-dimensional coordinate
    :param tuple end: *n*-dimensional coordinate
    :param callable round: function to use to round the result
    :return: rounded distance
    (dimension mismatch between start and endc                 s   s   | ]}|| V  qd S N .0dr   r   N/var/www/html/django/DPS/env/lib/python3.9/site-packages/tsplib95/distances.py	<genexpr>"       zeuclidean.<locals>.<genexpr>len
ValueErrorsumr   deltasmathsqrt)startendroundZsquare_distancedistancer   r   r   r      s
    
r   c                 C   s:   t | t |krtdtdd t| |D }||S )aX  Return the Manhattan distance between start and end.

    This is capable of performing distance calculations for MAN_2D and
    MAN_3D problems.

    :param tuple start: *n*-dimensional coordinate
    :param tuple end: *n*-dimensional coordinate
    :param callable round: function to use to round the result
    :return: rounded distance
    r   c                 s   s   | ]}t |V  qd S r   absr   r   r   r   r   6   r   zmanhattan.<locals>.<genexpr>)r   r   r   r   r   r   r   r   r   r   r   r   r   (   s    r   c                 C   s:   t | t |krtdtdd t| |D }||S )aV  Return the Maximum distance between start and end.

    This is capable of performing distance calculations for MAX_2D and
    MAX_3D problems.

    :param tuple start: *n*-dimensional coordinate
    :param tuple end: *n*-dimensional coordinate
    :param callable round: function to use to round the result
    :return: rounded distance
    r   c                 s   s   | ]}t |V  qd S r   r   r   r   r   r   r   I   r   zmaximum.<locals>.<genexpr>)r   r   maxr   r   r!   r   r   r   r   ;   s    r   gSc@c                 C   s   t | t |krtdt| } t|}t| j|j }t| j|j }t| j|j }|tdd| | d| |    d }t	|S )az  Return the geographical distance between start and end.

    This is capable of performing distance calculations for GEO problems.

    :param tuple start: *n*-dimensional coordinate
    :param tuple end: *n*-dimensional coordinate
    :param callable round: function to use to round the result
    :param float radius: the radius of the Earth
    :return: rounded distance
    r   g      ?r   )
r   r   r   Z	RadianGeor   cosZlngZlatacosint)r   r   r   Zradiusq1q2Zq3r   r   r   r   r   N   s    

*r   c                 C   s\   t | t |krtdtdd t| |D }t|d }||}||k rX|d7 }|S )aM  Return the pseudo-Euclidean distance between start and end.

    This is capable of performing distance calculations for ATT problems.

    :param tuple start: *n*-dimensional coordinate
    :param tuple end: *n*-dimensional coordinate
    :param callable round: function to use to round the result
    :return: rounded distance
    r   c                 s   s   | ]}|| V  qd S r   r   r   r   r   r   r   t   r   z#pseudo_euclidean.<locals>.<genexpr>
   r   r   )r   r   r   Z
square_sumvaluer   r   r   r   r	   g   s    
r	   g      ?c           
      C   s   t | t |kst | dkr$tdt| d |d  }t|t|d }t| d |d  }t| d |d  }t|| || || }	|d|	 S )a  Return x-ray crystallography distance.

    This is capable of performing distance calculations for xray
    crystallography problems. As is, it is suitable for XRAY1 problems.
    However, using ``sx=1.25``, ``sy=1.5``, and ``sz=1.15`` makes it suitable
    for XRAY2 problems.

    :param tuple start: 3-dimensional coordinate
    :param tuple end: 3-dimensional coordinate
    :param float sx: x motor speed
    :param float sy: y motor speed
    :param float sz: z motor speed
    :return: distance
       z#start and end must be 3-dimensionalr   ih  r      g      Y@)r   r   r    minr"   )
r   r   sxsyszr   ZdxZdyZdzr   r   r   r   r
   ~   s    r
   )r   g      ?g      ?gffffff?)r-   r.   r/   )ZEUC_2DZEUC_3DZMAX_2DZMAX_3DZMAN_2DZMAN_3DZCEIL_2DZGEOZATTZXRAY1ZXRAY2)	functoolsr    r   __all__Znintr   r   r   r   r	   r
   partialceilr   r   r   r   r   <module>   s*   