Ñò
Rá¬Pc           @   sÌ   d  Z  d d k l Z d d k Z e i d ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ	 d e f d „  ƒ  YZ
 d d d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sa  
BASIC MATRIX CLASSES
***********************************
*** 
*** BASIC MATRIX CLASSES
*** 
*** written by Markus Doering
***    BGBM, Berlin, 2003
*** 
***********************************
$RCSfile: matrix.py,v $
$Revision: 1231 $
$Author: j.holetschek $
$Date: 2012-11-21 15:12:34 +0100 (Mi, 21. Nov 2012) $

Module with a general basic matrix class.
iÿÿÿÿ(   t   joinNs   pywrapper.graph.matrixt   RowNotExistingErrorc           B   s   e  Z d  Z d „  Z RS(   sK   Exception raised when trying to reference a non existing row of the matrix.c         C   s   t  i |  ƒ d  S(   N(   t	   Exceptiont   __init__(   t   self(    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR      s    (   t   __name__t
   __module__t   __doc__R   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR      s   t   ColNotExistingErrorc           B   s   e  Z d  Z d „  Z RS(   sN   Exception raised when trying to reference a non existing column of the matrix.c         C   s   t  i |  ƒ d  S(   N(   R   R   (   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   "   s    (   R   R   R   R   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR       s   t   RowAlreadyExistingErrorc           B   s   e  Z d  Z d „  Z RS(   sJ   Exception raised when trying to add an already existing row to the matrix.c         C   s   t  i |  ƒ d  S(   N(   R   R   (   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   &   s    (   R   R   R   R   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR	   $   s   t   ColAlreadyExistingErrorc           B   s   e  Z d  Z d „  Z RS(   sM   Exception raised when trying to add an already existing column to the matrix.c         C   s   t  i |  ƒ d  S(   N(   R   R   (   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   *   s    (   R   R   R   R   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR
   (   s   t   matrixc           B   sƒ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   s   a general basic matrixc         C   s[   h  |  _  h  |  _ x | D] } d |  i | <q Wx$ | D] } |  i i ƒ  |  i  | <q7 Wd S(   sp   pass a list for rows and columns to create the matrix. Empty lists are allowed. All entries will be set to None.N(   R   t   _colst   Nonet   copy(   R   t   rowst   colst   x(    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   4   s    		  c         C   se   | \ } } |  i  i | ƒ o9 |  i  | i | ƒ o | |  i  | | <qa t ƒ  ‚ n
 t ƒ  ‚ d S(   s-   sets one entry x in the matrix at tuple (n,m)N(   R   t   has_keyR   R   (   R   t   .1R   t   nt   m(    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   set=   s    	c         C   s+   | \ } } |  i  i | d ƒ i | d ƒ S(   s.   returns the entry of the matrix at tuple (n,m)N(   R   t   getR   (   R   R   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   G   s    	c         C   sS   y< h  } x+ |  i  i ƒ  D] \ } } | | | | <q W| SWn t ƒ  ‚ n Xd S(   s*   returns the list of rows for column "col".N(   R   t   itemsR   (   R   t   colR   t   rowt   rowDict(    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   getRowK   s     c         C   s&   y |  i  | SWn t ƒ  ‚ n Xd S(   s:   returns the list of columns for row "row" as a dictionary.N(   R   R   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   getColU   s    c         C   s   t  |  i ƒ t  |  i ƒ f S(   s/   returns the size of the matrix as a tuple (n,m)(   t   lenR   R   (   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   size\   s    c         C   s   |  i  i ƒ  S(   s   returns the list of rows.(   R   t   keys(   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   listRows`   s    c         C   s   |  i  i ƒ  S(   s   returns the list of columns.(   R   R    (   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   listColsd   s    c         C   s:   |  i  i | ƒ o t ƒ  ‚ n |  i i ƒ  |  i  | <d S(   s$   adds a new, empty row to the matrix.N(   R   R   R	   R   R   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   addRowh   s    c         C   s\   |  i  i | ƒ o t ƒ  ‚ n9 d |  i  | <x( |  i i ƒ  D] } d |  i | | <q= Wd S(   s'   adds a new, empty column to the matrix.N(   R   R   R
   R   R   R    (   R   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   addColo   s     c         C   s.   |  i  i | ƒ o |  i  | =n
 t ƒ  ‚ d S(   s   removes a row of the matrix.N(   R   R   R   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   delRowx   s    c         C   sO   |  i  i | ƒ o/ |  i  | =x+ |  i i ƒ  D] } | | =q- Wn
 t ƒ  ‚ d S(   s   removes a column of the matrix.N(   R   R   R   t   valuesR   (   R   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   delCol   s    
 c         C   sÅ  t  g  } |  i ƒ  D] } | t | ƒ q ~ ƒ } xe |  i ƒ  D]W } t  t  g  } |  i ƒ  D]( } | t t |  i | | f ƒ ƒ ƒ q] ~ ƒ | ƒ } q@ Wg  } x |  i ƒ  D] } d t | ƒ d t | ƒ g } | g  }	 |  i ƒ  D]4 } |	 d t | ƒ d t |  i | | f ƒ ƒ qé ~	 7} | i t | d ƒ ƒ q® Wd t |  i ƒ  ƒ }
 |
 t g  } d g |  i ƒ  D] } | d t | ƒ d | qu~ d ƒ 7}
 |
 d 7}
 |
 t | d ƒ 7}
 |
 S(   s   build matrix string.t   %t   st   |s	   SIZE: %s
s   ---s   
(	   t   maxR"   R   R!   t   strR   t   appendR    R   (   R   t   _[1]t   valt	   maxLengthR   t   _[2]R   t   resultR   t   _[3]t   rstringt   _[4](    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   __repr__ˆ   s    3 U !RM
(   R   R   R   R   R   R   R   R   R   R!   R"   R#   R$   R%   R'   R6   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   2   s   			
		
										t   squareMatrixc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   matrix with n=mc         C   s   t  i |  | | ƒ d  S(   N(   R   R   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   ¡   s    c         C   s$   t  i |  | ƒ t  i |  | ƒ d  S(   N(   R   R#   R$   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR#   ¤   s    c         C   s$   t  i |  t ƒ t  i |  t ƒ d  S(   N(   R   R#   R   R$   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR$   ¨   s    c         C   s$   t  i |  | ƒ t  i |  | ƒ d  S(   N(   R   R%   R'   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR%   ¬   s    c         C   s$   t  i |  t ƒ t  i |  t ƒ d  S(   N(   R   R%   R   R'   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR'   °   s    (   R   R   R   R   R#   R$   R%   R'   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR7   Ÿ   s   				t   symmetricMatrixc           B   s    e  Z d  Z d „  Z d „  Z RS(   sH   Half of a square matrix. values for (x,y) and (y,x) are alqays the same.c         C   s   t  i |  | ƒ d  S(   N(   R7   R   (   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   ·   s    c         C   sB   | \ } } t  i |  | | f | ƒ t  i |  | | f | ƒ d  S(   N(   R7   R   (   R   R   R   R   R   (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR   º   s    	(   R   R   R   R   R   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyR8   µ   s   	(    (   R   t   stringR    t   loggingt	   getLoggert   logR   R   R   R	   R
   R   R7   R8   (    (    (    sD   /srv/www/vhosts/sammlung/BioCase/lib/biocase/wrapper/graph/matrix.pyt   <module>   s   
m