pldag 5.0.2

A DAG-based combinatorial-model framework.
Documentation
�

|p�i�*�	��ddlZddlmZddlmZeGd�d����ZeGd�d����Zdeed	eeeeeffd
�Zdeded	e	fd
�Z
d"dededed	efd�Z
d#dedede	de	fd�Zdedeedefd�Zedkr>ed��D]4Zed ��e�gd!���Zeee����3dSdS)$�N)�	dataclass)�Listc�.�eZdZUeed<eed<eed<dS)�
ProductPeriod�id�_from�_toN)�__name__�
__module__�__qualname__�str�__annotations__�int���3/Users/rikardolsson/Develop/Rust/pldag-rust/test.pyrrs+��������G�G�G��J�J�J�	�H�H�H�H�Hrrc	��eZdZUeed<eed<edd���Zedede	dfd���Z
edede	dfd���Zedd	ed
ede	dfd���Zede	e
eefde	dfd
���ZdS)�Item�period�value�returnc��ttjdd����}tjdd��}tjdd��}||z}tjdd��}t	t|||���|���S)N順�?Br�
��rrr	�rr)r
�random�randint�uniformrr)�
product_id�start�duration�endrs     rrzItem.randoms��������7�7�8�8�
���q�"�%�%���>�!�Q�'�'���h�����q�"�%�%��� �������
�

�
�
�	
r�countc
��g}d}t|��D]�}ttjdd����}tj��dkrd}ntjdd��}||z}tjdd��}||z}tjdd	��}	|�t
t|||�
��|	�����|}��|S)zNGenerate a list of non-overlapping items with random gaps (some back-to-back).rrrg�?���rrrr)�ranger
rr r!�appendrr)
r&�items�current_day�_r"�gapr#r$r%rs
          r�random_non_overlappingzItem.random_non_overlapping*s��������u���	�	�A��V�^�F�F�;�;�<�<�J��}����$�$�����n�Q��*�*���#�%�E��~�a��+�+�H��(�"�C��N�1�b�)�)�E��L�L��$�!������
�
���
�
�
��K�K��rc
��g}d}t|��D]�}ttjdd����}|tjdd��z}t	d|��}tjdd��}||z}tjdd��}|�tt|||���|�	����|tjd
d��z}��|S)z3Generate a list of items with intentional overlaps.rrr�����r*rrrrr(r))	r+r
rr �maxr!r,rr)	r&r-r.r/r"r#r$r%rs	         r�random_overlappingzItem.random_overlappingPs��������u���	7�	7�A��V�^�F�F�;�;�<�<�J� �&�.��Q�"7�"7�7�E���5�M�M�E��~�a��+�+�H��(�"�C��N�1�b�)�)�E��L�L��$�!������
�
���
�
�
� �&�.��A�"6�"6�6�K�K��r�@�same_price_count�same_price_valuec
�(�g}d}t|��D]v}ttjdd����}tjdd��}|}||z}|�tt
|||���|�����|}�wttjdd����}tjdd��}|}||z}tjdd	��}	|�tt
|||���|	�����|S)
zfGenerate multiple back-to-back periods with the same price, then a latest period with different price.rrrr*rrr�@g"@)r+r
rr r,rrr!)
r7r8r-r.r/r"r$r#r%�different_prices
          r�same_price_back_to_backzItem.same_price_back_to_backrsM�������'�(�(�	�	�A��V�^�F�F�;�;�<�<�J��~�a��+�+�H��E��(�"�C��L�L��$�!������
'�
���
�
�
��K�K������7�7�8�8�
��>�!�Q�'�'�����h���!�.��c�2�2��
���T� �������
"�

�
�
�	�	�	��r�groupsc�*�g}d}|D]�\}}t|��D]v}ttjdd����}tjdd��}|}||z}	|�tt
|||	���|�����|	}�w��|S)a�Generate groups of back-to-back periods with specified counts and prices.

        Args:
            groups: List of tuples (count, price) where count is the number of
                   back-to-back periods and price is the value for that group.

        Example:
            Item.grouped_back_to_back([(3, 5.0), (2, 7.5), (1, 3.2)])
            Creates 3 periods at 5.0, then 2 periods at 7.5, then 1 period at 3.2
        rrrr*rrr)r+r
rr r,rr)
r=r-r.r&�pricer/r"r$r#r%s
          r�grouped_back_to_backzItem.grouped_back_to_back�s�������"�	"�	"�L�E�5��5�\�\�
"�
"�� �����!?�!?�@�@�
�!�>�!�Q�/�/��#���h�&�����T�(�%�#�����
 �
������"���!
"�$�rN)rr)r6)r
rrrr�float�staticmethodrrrr1r5r<�tupler@rrrrrs1������������L�L�L��
�
�
��\�
�0�#�c�#�d�6�l�#�#�#��\�#�J��#��$�v�,�����\��B�*�*�#�*��*�Y]�^d�Ye�*�*�*��\�*�X�!�T�%��U�
�*;�%<�!��f��!�!�!��\�!�!�!rr�
collectionrc����t|d�d���}|d�t�fd�t|dd�d���D��d��}|�tddd�	��}�||fS||dz
}td|jjd
z
|jj�	����fd�|D��}|rt
|d��
��|�fS�|�fS)Nc��|jjS�N)rr)�xs r�<lambda>zpil.<locals>.<lambda>�s
�����rT)�key�reverserc3�B�K�|]\}}|j�jk�|V��dSrG�r)�.0�i�c�currents   �r�	<genexpr>zpil.<locals>.<genexpr>�s5�����]�]�t�q�!�A�G�w�}�D\�D\��D\�D\�D\�D\�]�]rr()r#�pilrrc�>��g|]}t|j����|��Sr)�periods_overlapr)rNrP�
pil_periods  �r�
<listcomp>zpil.<locals>.<listcomp>�s;��������1�8�Z�0�0��	���rc��|jSrGrM)rPs rrIzpil.<locals>.<lambda>�s��A�G�r)rJ)�sorted�next�	enumeraterrr�min)rD�sorted_collection�latest_total_before_current_idx�empty_period�latest_total_before_current�overlapping_itemsrQrVs      @@rrSrS�s<����6�z�/G�/G�QU�V�V�V����"�G�'+�]�]�]�]�y�!2�1�2�2�!6�a�@�@�@�]�]�]��'�'�#�
'�.�$��Q�A�>�>�>���)�<�7�7�"3�4S�TU�4U�"V����)�0�6��;�'�.�4����J�����$������\��$�*;�*;�<�<�<�>O�Q[�[�[��%�z�1�1r�p1�p2c��|j|jks|j|jkrdS|j|jkr||fn||f\}}|j|jkS)zCheck if two periods overlap.F)rr	)rbrc�earliest_period�
latest_periods    rrUrUs]��
�x�2�6���R�X���/�/��u�24��B�H�1D�1D�b�"�X�X�2�r�(�"�O�]���-�"5�5�5r���from_day�to_day�max_daysc���dg|z}t|t||����D]}d||<�||krd||<||kr||krd||<d�|d|���S)zHCreate a visual representation of a period where each character = 1 day.� �-�|�N)r+r\�join)rhrirj�timelinerOs     r�visualize_periodrrs����u�x��H��8�S���2�2�
3�
3����������(��� ��������V�h�.�.�����
�7�7�8�I�X�I�&�'�'�'rroFT�item�label�	highlight�show_visualc��|rdnd}|jj|jjz
}t|�|����t|�d|jj����t|�d|jj����t|�d|jj����t|�d|�d���t|�d|jd	����|r8t
|jj|jj��}t|�d
|����t��dS)z#Print an item in a readable format.z>>> z    z
  Period ID: z
  From:      z
  To:        z
  Duration:  z daysz
  Value:     �.2fz
  Timeline:  N)rr	r�printrrrr)rsrtrurv�markerr$�visuals       r�
print_itemr|#s&�� �
,�V�V�f�F��{����!2�2�H�	�V�
�U�
�
����	�V�
2�
2�$�+�.�
2�
2�3�3�3�	�V�
5�
5�$�+�"3�
5�
5�6�6�6�	�V�
3�
3�$�+�/�
3�
3�4�4�4�	�V�
1�
1�(�
1�
1�
1�2�2�2�	�V�
2�
2�$�*�
2�
2�
2�3�3�3��0�!�$�+�"3�T�[�_�E�E��
��.�.�f�.�.�/�/�/�	�G�G�G�G�Gr�
pil_resultrVc��td�|D����}|rO|j|jkr?t|j|j|dz��}t	d|�d���t	��t|��D]V\}}t|jj|jj|dz��}|r||krdnd}t	|�d|jd�d	|�����Wd
S)z.Print all items with aligned visual timelines.c3�.K�|]}|jjV��dSrG)rr	)rNrss  rrRz*print_collection_visual.<locals>.<genexpr>6s&����9�9�d�$�+�/�9�9�9�9�9�9rr(zz  PIL PERIOD z <-- PILroz  rxrlN)r4rr	rrryr[rr)r}rDrV�max_dayr{rOrsrzs        r�print_collection_visualr�3s����9�9�j�9�9�9�9�9�G���j�&�*�.�8�8�!�*�"2�J�N�G�a�K�P�P��
�5��5�5�5�6�6�6�
�����Z�(�(�6�6���4�!�$�+�"3�T�[�_�g�PQ�k�R�R��)�H�d�j�.@�.@���b��
��4�4�4�:�4�4�4�F�4�4�5�5�5�5�6�6r�__main__�z2--------------------------------------------------))rr:)r*g@)r*g@)rg)roFT)r�dataclassesr�typingrrrrCrS�boolrUrr
rrr|r�r
r+r/ryr@�random_collectionrrr�<module>r�s��
�
�
�
�!�!�!�!�!�!�������
�
�
�
�
�
�
�
���
��t�t�t�t�t�t�t���t�l=2�D��J�=2�5��t�D�z�=�)H�#I�=2�=2�=2�=2�@6�
�6�=�6�T�6�6�6�6�(�(�s�(�C�(�3�(��(�(�(�(�*
�
�T�
�#�
�t�
�RV�
�
�
�
� 6��6�$�t�*�6�R_�6�6�6�6�"�z���
�U�2�Y�Y�9�9��
��h���� �5�5�6T�6T�6T�U�U������%6�!7�!7�8�8�8�	��9�9r