a
    J5d                  
   @   s   d dl mZ G dd dZG dd deZG dd deZG dd	 d	eZG d
d deZG dd deZG dd deZG dd deZ	G dd deZ
G dd deZG dd deZeeeeeee	ee
d	ZdS )   )utilsc                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )Matrixa*  A square matrix created from a list of numbers.

    Elements are accessible using matrix notation. Negative indexing is not
    allowed.

    :param list numbers: the elements of the matrix
    :param int size: the width (also height) of the matrix
    :param int min_index: the minimum index
        c                 C   s   t || _|| _|| _d S N)listnumberssize	min_index)selfr   r   r	    r   K/var/www/html/django/DPS/env/lib/python3.9/site-packages/tsplib95/matrix.py__init__   s    
zMatrix.__init__c                 C   s
   | j | S r   )value_at)r
   keyr   r   r   __getitem__   s    zMatrix.__getitem__c                 C   sL   || j 8 }|| j 8 }| ||s6td| d| d| ||}| j| S )zGet the element at row *i* and column *j*.

        :param int i: row
        :param int j: column
        :return: value of element at (i,j)
        (z, z) is out of bonuds)r	   is_valid_row_column
IndexError	get_indexr   )r
   ijindexr   r   r   r      s    

zMatrix.value_atc                 C   s4   d|  ko| j k n  o2d|  ko.| j k S   S )zReturn True if (i,j) is a row and column within the matrix.

        :param int i: row
        :param int j: column
        :return: whether (i,j) is within the bounds of the matrix
        :rtype: bool
        r   r   r
   r   r   r   r   r   r   &   s    zMatrix.is_valid_row_columnc                 C   s
   t  dS )zReturn the linear index for the element at (i,j).

        :param int i: row
        :param int j: column
        :return: linear index for element (i,j)
        :rtype: int
        N)NotImplementedErrorr   r   r   r   r   0   s    zMatrix.get_indexN)r   )	__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r      s   


r   c                   @   s   e Zd ZdZdd ZdS )
FullMatrixzA complete square matrix.

    :param list numbers: the elements of the matrix
    :param int size: the width (also height) of the matrix
    :param int min_index: the minimum index
    c                 C   s   || j  | S r   r   r   r   r   r   r   C   s    zFullMatrix.get_indexN)r   r   r   r   r   r   r   r   r   r   ;   s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )
HalfMatrixzA triangular half-matrix.

    :param list numbers: the elements of the matrix
    :param int size: the width (also height) of the matrix
    :param int min_index: the minimum index
    Tc                    s0   ||kr| j sdS | ||\}}t ||S )Nr   )has_diagonal_fix_indicessuperr   r   	__class__r   r   r   R   s    zHalfMatrix.value_at)r   r   r   r   r!   r   __classcell__r   r   r$   r   r    G   s   r    c                   @   s$   e Zd ZdZdZdd Zdd ZdS )UpperDiagRowzUpper-triangular matrix that includes the diagonal.

    :param list numbers: the elements of the matrix
    :param int size: the width (also height) of the matrix
    :param int min_index: the minimum index
    Tc                 C   s2   ||kr||fn||f\}}| j s*|d8 }||fS Nr   r!   r   r   r   r   r"   c   s    zUpperDiagRow._fix_indicesc                 C   s*   | j t| j  }t||| ||  S r   )r   intr!   r   integer_sum)r
   r   r   nr   r   r   r   i   s    zUpperDiagRow.get_indexNr   r   r   r   r!   r"   r   r   r   r   r   r'   Y   s   r'   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )LowerDiagRowzLower-triangular matrix that includes the diagonal.

    :param list numbers: the elements of the matrix
    :param int size: the width (also height) of the matrix
    :param int min_index: the minimum index
    Tc                 C   s2   ||k r||fn||f\}}| j s*|d8 }||fS r(   r)   r   r   r   r   r"   x   s    zLowerDiagRow._fix_indicesc                 C   s   t || S r   )r   r+   r   r   r   r   r   ~   s    zLowerDiagRow.get_indexNr-   r   r   r   r   r.   n   s   r.   c                   @   s   e Zd ZdZdZdS )UpperRowzUpper-triangular matrix that does not include the diagonal.

    :param list numbers: the elements of the matrix
    :param int size: the width (also height) of the matrix
    :param int min_index: the minimum index
    FNr   r   r   r   r!   r   r   r   r   r/      s   r/   c                   @   s   e Zd ZdZdZdS )LowerRowzLower-triangular matrix that does not include the diagonal.

    :param list numbers: the elements of the matrix
    :param int size: the width (also height) of the matrix
    :param int min_index: the minimum index
    FNr0   r   r   r   r   r1      s   r1   c                   @   s   e Zd ZdS )UpperColNr   r   r   r   r   r   r   r2      s   r2   c                   @   s   e Zd ZdS )LowerColNr3   r   r   r   r   r4      s   r4   c                   @   s   e Zd ZdS )UpperDiagColNr3   r   r   r   r   r5      s   r5   c                   @   s   e Zd ZdS )LowerDiagColNr3   r   r   r   r   r6      s   r6   )	ZFULL_MATRIXZUPPER_DIAG_ROWZ	UPPER_ROWZLOWER_DIAG_ROWZ	LOWER_ROWZUPPER_DIAG_COLZ	UPPER_COLZLOWER_DIAG_COLZ	LOWER_COLN) r   r   r   r    r'   r.   r/   r1   r2   r4   r5   r6   TYPESr   r   r   r   <module>   s*   6