
    kh                     n    d dl Z d dlZd dlmZ d dlmZ d Zd Zd Zd Z	d Z
d	 Zdd
ZddZd ZddZy)    N)combinations)permutationsc                  T    dd l } | j                  | j                        j                  S )Nr   )resource	getrusageRUSAGE_CHILDRENru_utime)r   s    t/var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/pulp/utilities.pyresource_clockr      s"    h667@@@    c                 .    t        | t        t        f      S )z&Returns true if x is an int or a float)
isinstanceintfloatxs    r
   isNumberr      s    a#u&&r   c                 <    t        |       r| S | j                         S )zFReturns the value of the variable/expression x, or x if it is a number)r   valuer   s    r
   r   r      s    {wwyr   c                 <    t        |       r| S | j                         S )zReturns the value of the variable/expression x, or x if it is a number
    Variable without value (None) are affected a possible value (within their
    bounds).)r   valueOrDefaultr   s    r
   r   r      s     {!!r   c           	      z    t        j                  t        d|dz         D cg c]  }t        | |       c} S c c}w )a  
    returns all permutations of orgset with up to k items

    :param orgset: the list to be iterated
    :param k: the maxcardinality of the subsets

    :return: an iterator of the subsets

    example:

    >>> c = allpermutations([1,2,3,4],2)
    >>> for s in c:
    ...     print(s)
    (1,)
    (2,)
    (3,)
    (4,)
    (1, 2)
    (1, 3)
    (1, 4)
    (2, 1)
    (2, 3)
    (2, 4)
    (3, 1)
    (3, 2)
    (3, 4)
    (4, 1)
    (4, 2)
    (4, 3)
       )	itertoolschainrangepermutationorgsetkis      r
   allpermutationsr"   %   s2    > ??U1a!e_M[3MNNM   8c           	      z    t        j                  t        d|dz         D cg c]  }t        | |       c} S c c}w )a  
    returns all combinations of orgset with up to k items

    :param orgset: the list to be iterated
    :param k: the maxcardinality of the subsets

    :return: an iterator of the subsets

    example:

    >>> c = allcombinations([1,2,3,4],2)
    >>> for s in c:
    ...     print(s)
    (1,)
    (2,)
    (3,)
    (4,)
    (1, 2)
    (1, 3)
    (1, 4)
    (2, 3)
    (2, 4)
    (3, 4)
    r   )r   r   r   combinationr   s      r
   allcombinationsr&   G   s2    2 ??U1a!e_M[3MNNMr#   c                 &    t        | ||      \  }}|S )z
    makes a list into a dictionary with the headings given in headings
    headers is a list of header lists
    array is a list with the data
    )
__makeDict)headersarraydefaultresultdefdicts        r
   makeDictr.   c   s     !%9OFGMr   c                 j  	 i }d }t        |       dk(  r*|j                  t        t        | d   |                   |	n/t	        | d         D ]  \  }}t        | dd  ||   |      \  ||<   	  |B	fd}t        j                  |      }|j                  |       |}t        j                  |      }||fS )Nr   r   c                       S N )defaultvalues   r
   <lambda>z__makeDict.<locals>.<lambda>x   s    L r   )lenupdatedictzip	enumerater(   collectionsdefaultdict)
r)   r*   r+   r,   returndefaultvaluer!   hf	defresultr3   s
            @r
   r(   r(   m   s    F
7|qd3wqz5123gaj) 	QDAq&0eAh&P#F1I|	Q ++A.	 (44Q7%%%r   c                 2   t        | j                         D cg c]  }t        |       c}      }t        |      D cg c]  }t	                }}| j                         D ]   \  }}t        |      D ]  \  }}|||   |<    " t        |      S c c}w c c}w )a   
    Split a dictionary with lists as the data, into smaller dictionaries

    :param dict data: A dictionary with lists as the values

    :return: A tuple of dictionaries each containing the data separately,
            with the same dictionary keys
    )maxvaluesr5   r   r7   itemsr9   tuple)datarB   maxitems_outputkeyr!   vals           r
   	splitDictrK      s     dkkm<FCK<=H#Ho.df.F.zz| !V' 	!FAs F1IcN	!! = =.s
   BBc                     | j                         }|d   j                         }i }|dd D ]J  }|j                         }t        |dd       D ]'  \  }}	|r||   |d   f}
n
|d   ||   f}
 ||	      ||
<   ) L |S )aD  
    Reads in data from a simple table and forces it to be a particular type

    This is a helper function that allows data to be easily constained in a
    simple script
    ::return: a dictionary of with the keys being a tuple of the strings
       in the first row and colum of the table
    :param str data: the multiline string containing the table data
    :param coerce_type: the type that the table data is converted to
    :param bool transpose: reverses the data if needed

    Example:
    >>> table_data = '''
    ...         L1      L2      L3      L4      L5      L6
    ... C1      6736    42658   70414   45170   184679  111569
    ... C2      217266  227190  249640  203029  153531  117487
    ... C3      35936   28768   126316  2498    130317  74034
    ... C4      73446   52077   108368  75011   49827   62850
    ... C5      174664  177461  151589  153300  59916   135162
    ... C6      186302  189099  147026  164938  149836  286307
    ... '''
    >>> table = read_table(table_data, int)
    >>> table[("C1","L1")]
    6736
    >>> table[("C6","L5")]
    149836
    r      Nr   )
splitlinessplitr9   )rE   coerce_type	transposelinesheadingsr,   rowrC   r!   itemrI   s              r
   
read_tablerV      s    8 OOEQx~~HFQRy ,		 qr+ 	,GAt{E!H-Qx!-%d+F3K	,, Mr   r1   )F)r:   r   r   r%   r   r   r   r   r   r   r"   r&   r.   r(   rK   rV   r2   r   r
   <module>rW      sG      1 1A'
"ODO8&&&'r   