m
>Ic           @   s  d    Z  d   Z d f  d     YZ d f  d     YZ d   Z d   Z d   Z d	 f  d
     YZ e g  d 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 f  d     YZ d   Z d   Z d   Z d   Z d   Z d   Z d    Z d! f  d"     YZ d#   Z d$   Z d%   Z  d&   Z! d'   Z" d(   Z# d)   Z$ d* f  d+     YZ% d,   Z& d-   Z' d.   Z( d/   Z) d0   Z* d1 S(2   c         C   s0   g  } |  D] } | | j o | | q q ~ S(   N(   t   _[1]t   listt   elt   elRemove(   R   R   R    R   (    (    t   METEORS_0_4.pyt   removedList   s    c         C   s   |  } | i |  | S(   N(   R   t   lt   appendR   (   R   R   R   (    (    R   t   appendedList   s    t   ActionBoundc           B   s   t  Z d   Z RS(   Nc         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   actiont   selft   asett   bound(   R   R
   R   R   (    (    R   t   __init__   s    		(   t   __name__t
   __module__R   (    (    (    R   R	      s   t
   EventBoundc           B   s   t  Z d   Z d   Z RS(   Nc         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   iR   t   jR   t   actionbound(   R   R   R   R   R   (    (    R   R      s    			c         C   s/   t  |  i  d t  |  i  d t  |  i  S(   Ns   , (   t   strR   R   R   R   (   R   (    (    R   t   __str__   s    (   R   R   R   R   (    (    (    R   R      s   	c         C   s   g  } x t t |    D]x } xo | D]g } |  | | i j oM t | d | i	 |   } | | j  o# | i t | | | i |   q q& q& Wq W| S(   Ni   (   t   eventUBst   ranget   lent
   eventOrderR   t	   actionUBst   ubR
   t   upperBoundIndexR   R   R   R   R   (   R   R   R   R   R   R   (    (    R   t   createUpperBounds   s       /c         C   sG   x6 t  |  t |   D] } | | | j o | Sq q Wt |  d S(   Ni   (   R   t
   startIndexR   R   R   R   (   R   R   R   R   (    (    R   R   %   s
     c         C   s   g  } x t t |    D]{ } xr | D]j } |  | | i j oP t | d | i	 |  |  } | | j  o# | i t | | | i |   q q& q& Wq W| S(   Ni   (   R   R   R   R   R   R   R   R
   t    upperBoundIndexWithIgnoredEventsR   t   ignoredEventSpecR   R   R   R   (   R   R   R!   R   R   R   R   (    (    R   t"   createUpperBoundsWithIgnoredEvents,   s       /t   IgnoredEventSetc           B   s   t  Z d   Z d   Z RS(   Nc         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   eventsR   R   R   (   R   R$   R   R   (    (    R   R   6   s    		c         C   s7   t  |  i  d d t  |  i  d t  |  i  d S(   Ns    into t   (t   ,s   );(   R   R   R$   R   R   (   R   (    (    R   R   ;   s    (   R   R   R   R   (    (    (    R   R#   5   s   	i    c         C   s   x t  |  t |   D] } xc | D][ } | d | i j oA | | i j o1 x. | i D] } | | j o | d SqW qW Wq# q# W| | | j o | Sq q Wt |  d S(   Ni   (   R   R   R   R   R   R!   t   ignoredEventSetR   R$   t   eventR   (   R   R   R   R!   R   R'   R(   (    (    R   R    @   s      $
 c         C   sm   g  } x` | D]X } | i |  j oB | i | j o2 | t | g |  |  | i | t | |   } q q W| S(   N(   t   coversR   R   R   R   t	   findCoverR   (   R   R   R   R)   R   (    (    R   t
   findCoversR   s      6c         C   s   | | j o |  g Sn g  } x | D] } | i | j ot | i t | |  j o[ | i | j oK | i | j o; | t
 t |  |  | | i | i | t | |   } q% q% W| S(   N(   t   qR   t   ubListt   ubListsR   R   R   t   maxt   kR   R*   R   R   (   R-   R0   R   R,   R   R   R.   R   (    (    R   R*   Z   s     I?c         C   s   x |  D] } | GHq Wd  S(   N(   t   eventBoundsR   (   R1   R   (    (    R   t   printBoundse   s     c         C   sN   xG t  t |    D]3 } d G| GHd GHx |  | D] } | GHq2 Wd GHq Wd  S(   Nt   Covers   ---------------(   R   R   t	   coverListR0   R   (   R4   R0   R   (    (    R   t
   printCoverj   s     	 	c      	   C   s   g  } x t t |   d  D] } x} t | d t |    D]b } xY | D]Q } |  | | i j o7 |  | | i	 j o# | i
 t | | | i |   qJ qJ Wq= Wq W| S(   Ni   (   t   eventLBsR   R   R   R   R   t	   actionLBst   lbR
   R   R   R   R   (   R   R7   R8   R   R   R6   (    (    R   t   createLowerBounds   s       (/c            s
     d   S(   Nc            s     g |  S(   N(   t   headR   (   R   (   R:   (    R   t   <lambda>   s    (    (   R:   (    (   R:   R   t	   concatFun   s    c   
      C   s]  | d } | } d } xq t t |   D]] }	 | |	 } |  | i	 j o= | i  | j o- t
 | | i   } | d j o
 |	 } q q) q) W| | j o g  Sn g  } x t | t |   D] }	 | |	 } |  | i	 j oz | i  | j oj | i	 | j  oZ t | i  | | |	  } | g  j o | i | g  qU| i t t |  |   q q W| S(   Ni   i(   R   t   defaultjt   minLBjt   firstLBindexR   R   R6   R0   R8   R   t   mint   LBst   findDistLBSetst   followingDLBsR   t   extendt   mapR<   (
   R   R   R6   RA   R?   R>   R=   RC   R8   R0   (    (    R   RB      s,    
 
   
0$c         C   s"   g  } |  D] } | | i q ~ S(   N(   R    t   boundSett   boundObjectR   (   RF   R    RG   (    (    R   t   extractBounds   s    c   	      C   s   x t  |  d  D] } x t  | d |   D] } t | | |  } t | | |  } | g  j p | g  j o d G| G| GHq+ n d G| G| GHx8 | D]0 } x' | D] } t |  Gd Gt |  GHq Wq Wq+ Wq Wd  S(   Ni   s   no constraints fors   constraints derived fromt   >(   R   t   EOLengthR   R   R+   t   UBst   CUBSetsRB   RA   t   DLBSetst   CUBSett   DLBsetRH   (	   RJ   RK   RA   R   RO   R   RN   RL   RM   (    (    R   t   printConstraints   s        c         C   s6   t  g  } | D] } | |  j o | | q q ~  S(   N(   R   R    R   t   zt   x(   RR   R   R    RQ   (    (    R   t   numberOf   s    c      	   C   s4  x-t  |  d  D]}
 xt  |
 d |   D] } t |
 | |  } t |
 | |  } | g  j p | g  j o d G|
 G| GHq+ n d G|
 G| GHx | D] } x | D]| } t |  } t |  } t }	 x= | D]5 \ } } t | |  t | |  j o
 t }	 q q W|	 o | Gd G| GHq q Wq Wq+ Wq Wd  S(   Ni   s   no constraints fors   constraints derived fromRI   (   R   RJ   R   R   R+   RK   RL   RB   RA   RM   RN   RO   RH   t   dlbt   cubt   Falset
   realizablet   boundsOrderRR   t   yRS   t   True(   RJ   RK   RA   RX   RL   RT   RU   RM   RO   RW   R   R   RN   RY   RR   (    (    R   t   printConstraintsFiltered   s.         t   IntervalBoundc           B   s   t  Z d   Z RS(   Nc         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   R   R   RU   RT   (   R   R   R   RU   RT   (    (    R   R      s    			(   R   R   R   (    (    (    R   R\      s   c         C   s   |  i Gd G|  i GHd  S(   NRI   (   t   intervalBoundRT   RU   (   R]   (    (    R   t   printIntervalBound   s    c         C   sC   x< |  D]4 } d G| i Gd G| i Gd GH| i Gd G| i GHq Wd  S(   Ns   Constraints derived from [R&   s   ]:RI   (   t   intervalBoundst   bR   R   RT   RU   (   R_   R`   (    (    R   t   printIntervalBounds   s     c         C   s(   x! |  D] } | i Gd G| i GHq Wd  S(   NRI   (   R_   R`   RT   RU   (   R_   R`   (    (    R   t"   printIntervalBoundsWithoutInterval   s     c         C   sB   x; | D]3 \ } } t | |  t | |   j o t Sq q Wt S(   N(   RX   RR   RY   RS   RT   RU   RZ   RV   (   RU   RT   RX   RY   RR   (    (    R   RW     s
     c      
   C   s=  g  } x0t |  d  D]} xt | d |   D] } t | | |  } t | | |  } | g  j p | g  j o | o d G| G| GHq1 q1 n | o d G| G| GHn x | D]z }
 xq | D]i } t |
  } t |  }	 t | |	 |  o8 | i t | | | |	   | o |	 Gd G| GHq)q q Wq Wq1 Wq W| S(   Ni   s   no constraints fors   constraints derived fromRI   (   R_   R   RJ   R   R   R+   RK   RL   RB   RA   RM   t   printOnRN   RO   RH   RU   RT   RW   RX   R   R\   (   RJ   RK   RA   RX   Rc   R   RO   R_   R   RT   RN   RU   RL   RM   (    (    R   t   createIntervalBounds
  s0           %c         C   s]  t  |  |  }
 t |  |  } t t |   |
 | | t
  } t t |   } x t t |  d  D] } | | j o qe n x t | d t |   D] } | | j p | | j o q n | | } | | } t | | |  \ } }	 | o | i |  q n |	 o | i |  q q q Wqe Wg  } | D] } | | | q5~ } t |  d  S(   Ni   (   R   R   R   R   R9   R7   R6   Rd   R   RX   RV   R_   R   t   weekConstraintIndexR   R   t   iboundt   jboundt   implicationCheckt   i_implies_jt   j_implies_it   removeR    R0   t   weekConstraintsRa   (   R   R   R7   RX   Rg   Rl   R6   Ri   R_   Rj   R   Rf   R   R0   R   R    Re   (    (    R   t   deriveConstraints"  s.        


%c   	      C   s   t  } t  } x | D] \ } } t | |  i  t | | i  } t | |  i  t | | i  } | | j o
 t } n | | j  o
 t } n | | j o | d j  o
 t } n | | j o | d j o
 t } q q W| | g S(   Ni    (   RZ   t   c1_implies_c2t   c2_implies_c1RX   RR   RY   RS   t   constraint1RT   t   constraint2t   xdiffRU   t   ydiffRV   (	   Rp   Rq   RX   Rr   Rs   RR   RY   Ro   Rn   (    (    R   Rh   D  s     "" 
 
 
 t   Constraintsc           B   s   t  Z d   Z RS(   Nc         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R   R!   t   constraints(   R   R   R!   Ru   (    (    R   R   U  s    		(   R   R   R   (    (    (    R   Rt   T  s   c         C   s   t  |   d j S(   Ni   (   R   R   (   R   (    (    R   t	   singletonZ  s    c      	   C   s6   g  } |  D]$ } | t d d | d | d  q ~ S(   Ni    i   (   R    t   assumedUnrealizableConstraintst
   constraintR\   (   Rw   R    Rx   (    (    R   t    constructUnrealizableConstraintsi  s    c         C   sA   |  Gt |  d j o! d Gd Gx | D]
 } | Gq& Wn d GHd  S(   Ni    t   :t   insertt    (   R   R   R!   R'   (   R   R!   R'   (    (    R   t   printEventOrderm  s     c         C   s   |  d j  o d GHg  Sn t g t g g } xb t d |   D]Q } g  } x< | D]4 } | i | t g g  | i | t g g  qO W| } q< W| S(   Ni   sF   Error: CreateAllBooleanCombo requires a positive number for its input.(	   t   nRZ   RV   t   combosR   R   t
   new_combost   b_seqRD   (   R~   R   R   R   R   (    (    R   t   createAllBooleanCombosu  s      
c         C   sa  g  } t | i | i  } x>| D]6}	 |  } g  } x t
 | i | i  D]q } |	 | | i oY | t |	 | | i  } | i | d | i d  | i t | i | | d   qL qL Wxj | D]b } | i t |	 | i | i  } | i t |	 | i | i  }
 | i t | i | |
   q W| o t | |  n | i | | f  q# W| S(   Ni   i    (   t   decomposedEventOrderListR   t   repetitionsR   R   t   booleanCombost   comboR   t   newEventOrdert   newIgnoredEventSpecR   t   insertPointt   insertDifferencet   newInsertPointR{   R$   R   R#   R!   R'   t   new_it   new_jRc   R}   (   R   R   R!   Rc   R   R   R   R'   R   R   R   R   R   R   (    (    R   t   decomposeEventOrder  s*      (     c         C   sU   d } xH t t |    D]4 } | | j o | Sn |  | o | d } q q W| S(   Ni    i   (   t   diffR   R   t   booleanComboR   t   position(   R   R   R   R   (    (    R   R     s       c   	      C   s   x |  D] } g  } xi | i D]^ } t } xC | D]; } t	 | | |  d } | o t } | i |  Pq0 q0 W| p Pq q W| o) d GHt | i  d GHt |  d  Sq q Wd GHd  S(   Ni    s   The disjunctive constraintss$   subsumes the disjunctive constraintss"   Error in printSubsumedConstraints.(   t   derivedConstraintListt   existingConstraintst   subsumedConstraintListRu   t   existingConstraintRV   t   foundt   newConstraintst   newConstraintRh   RX   t   exising_implies_newRZ   R   Rb   (	   R   R   RX   R   R   R   R   R   R   (    (    R   t   printSubsumedConstraints  s,     
  		
t	   EOAsystemc           B   st   t  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(   Nc         C   sR   | |  _  | |  _ | |  _ g  |  _ | |  _ t |  |  _ t |  _	 t |  _
 d  S(   N(   R   R   R7   RX   R   Rw   Ry   t   unrealizableConstraintsRV   Rc   t   debugOn(   R   R   R7   RX   Rw   (    (    R   R     s    						c         C   s   |  i o d Gt | |  n t | | |  i |  i |  i |  i |  i	  } t | |  i |  i  t | |  i |  i  o |  i o	 d GHq nN |  i i t | | |   t |  o$ |  i i t | d |  i   n d  S(   Nt   Addings;   The derived constraints for this event order are redundant.i    (   R   Rc   R}   R   R!   t"   deriveConstraintsWithIgnoredEventsR   R7   RX   R   R   t   pruneConstraintsR   t   redundantConstraintsR   R   Rt   Rv   t	   contraPos(   R   R   R!   R   (    (    R   t   addEventOrder  s    
	$
 c         C   s   |  i o" d GHt | | g |  d GHn t | | | |  i  } |  i o	 d GHn x& | D] } |  i	 | d | d  q^ Wd  S(   Nt   Decomposings   And obtained:s5   Adding decomposed event orders to the METEORS system.i    i   (
   R   Rc   R}   R   t   repetitionsToBeDecomposedR!   R   t   decomposedEventOrderst   decomposedEventOrderR   (   R   R   R   R!   R   R   (    (    R   t   addEventOrderWithDecomposition  s    
	
	 c         C   sx   xq |  i D]f } d GHd G| i Gt | i  d j o( d Gd Gx | i D] } | Gd GqH Wn d GHt | i  q
 Wd  S(   Ns"   ----------------------------------t   Fromi    Rz   R{   R&   R|   (	   R   R   t   taggedConstraintsR   R   R!   R'   Ra   Ru   (   R   R   R'   (    (    R   t   printConstraintList  s    
 
 c         C   s
  t  } x | p t } x |  i D] } | i } t | |  i |  i	  } | oQ t  } t |  o$ |  i i t | d |  i	   q | g  j o	 d GHq q  q  Wx[ |  i D]P } |  i } | i |  t | i | |  i	  o |  i i |  t  } q q Wq	 Wd  S(   Ni    s,   The derived constraints are unsatisfiable!!!(   RV   t   simplification_completedRZ   R   R   R   Ru   R   R   RX   t   prunedRv   R   R   t   copiedConstraintListRk   R   (   R   R   R   R   R   Ru   (    (    R   t   simplify  s*     
 	$
 
c         C   s   t  } x{ |  i D]p } t } x> | i D]3 } t	 | | |  i  \ } } | o t  } Pq& q& W| p t } d GHt | i  q q W| o	 d GHn d  S(   Ns$   The given constraint does not imply:s4   The given constraint implies the derived constraint.(   RZ   t   allConstraintsImpliedByC1R   R   R   RV   t   existsC2ImpliedByC1Ru   Rq   Rh   Rp   RX   t   C1impliesC2t   dummyRa   (   R   Rp   R   R   R   R   Rq   R   (    (    R   t   constraintSatisfiedBy  s     
 
 	c   
      C   s  t  | | |  i |  i |  i |  i |  i  } t
 | |  i |  i  x |  i D] } g  }	 xl | i D]a } t } xF | D]> } t | | |  i  d } | o t } |	 i |  Pqv qv W| p Pqc qc W| o; t | |  d GHt |	  d GHt | i  d GHd  SqM qM Wd GHd  S(   Ni    s   can be excluded bys   which is subsumed byR|   s&   Error in subsumedByDerivedConstraints.(   R   R   R!   R   R   R7   RX   Rc   R   R   R   R   R   R   R   Ru   R   RV   R   R   Rh   R   RZ   R   R}   Rb   (
   R   R   R!   R   R   R   R   R   R   R   (    (    R   t   subsumedByDerivedConstraints  s6    	$
 
  		
c         C   s  t  |  i |  i |  i |  i  } |  i | _ | i | | |  | i   | i } t |  d j oC t | |  d GH| d i } t |  i | |  i  d GHd GHnj t | | g |  d Gt |  Gd GHx' | D] } t |  i | i |  i  q Wd Gt |  Gd	 GHd GHd  S(
   Ni   s   is excluded becausei    sA   which is a sufficient condition to exclude the given event order.R|   s   requires the conjunction of s   constraints.s   With the above s3   constraints, the given event order can be excluded.(   R   R   R   R7   RX   Rw   t   decompositionSystemR   R   R   R   R!   R   R   t   conjunctionOfConstraintsR   R}   Ru   R   R   t   taggedConstraint(   R   R   R   R!   R   R   R   R   (    (    R   t,   subsumedByDerivedConstraintsForDecomposition=  s&    !
		 c         C   s   t  t | |  i |   d  S(   N(   R2   R"   R   R   R   R!   (   R   R   R!   (    (    R   t   printUpperBoundsT  s    c         C   s/   t  | |  i |  } t t | | |   d  S(   N(
   R"   R   R   R   R!   RK   R5   R+   R   R   (   R   R   R!   R   R   RK   (    (    R   t   printCUBW  s    c         C   s   t  t | |  i   d  S(   N(   R2   R9   R   R   R7   (   R   R   (    (    R   t   printLowerBounds[  s    c         C   s,   t  | |  i  } t t | | |   d  S(   N(	   R9   R   R   R7   RA   R5   RB   R   R   (   R   R   R   R   RA   (    (    R   t   printDLB_  s    (   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    R   R     s   	
						 				c         C   sm   g  } |  i D] } | t | |  q ~ } g  } |  i D] } | t | |  q; ~ } t
 d d | |  S(   Ni    (   R    Rx   RT   R8   t   oppositeRX   R-   RU   R   t   lbListR\   (   Rx   RX   R-   R8   R   R    R   (    (    R   R   e  s    --c         C   sT   xH | D]@ } | d |  j o | d Sn | d |  j o | d Sq q Wd GHd  S(   Ni    i   s!   Warning: no opposite bound found.(   RX   t
   assumptionR   (   R   RX   R   (    (    R   R   j  s       c         C   s   x| | D]t } x\ | i D]Q } t } x6 |  D]. } t | | |  d } | o t } Pq* q* W| p Pq q W| o t Sq q Wt S(   Ni    (   R   R   Ru   R   RV   R   R   R   Rh   RX   R   RZ   (   R   R   RX   R   R   R   R   R   (    (    R   R   p  s      
  		 c         C   s`   t  } xS | D]K } xB |  D]: } t | | |  d } | o |  i	 |  t
 } q q Wq W| S(   Ni    (   RV   R   R   t   unrealizableConstraintRu   Rx   Rh   RX   t/   this_constraint_implies_unrealizable_constraintRk   RZ   (   Ru   R   RX   R   Rx   R   R   (    (    R   R     s      c         C   s  t  |  | |  } t |  |  }	 t t	 |   | |	 | |  } t t	 |   } x_t t	 |  d  D]G} | | j o qh n x*t | d t	 |   D]} | | j p | | j o q n | | } | | } t | | |  \ }
 } |
 oW | i |  | o< d GHt | |  d GHt | |  d Gt | |  q q n | oW | i |  | o< d GHt | |  d GHt | |  d Gt | |  q q q q Wqh Wg  } | D] } | | | q~ } | o d G| GHn | o t |  n | S(   Ni   t   removingt   becauset   impliess   weekConstraintIndex is(   R"   R   R   R!   R   R9   R7   R6   Rd   R   RX   Rc   R_   R   Re   R   R   Rf   Rg   Rh   Ri   Rj   Rk   R   R^   R    R0   Rl   Ra   (   R   R!   R   R7   RX   Rc   R   Rg   Rl   R6   Ri   R_   Rj   R   Rf   Re   R0   R   R    R   (    (    R   R     sR        

%  N(+   R   R   R	   R   R   R   R"   R#   t   dummyIESR    R+   R*   R2   R5   R9   R<   RB   RH   RP   RS   R[   R\   R^   Ra   Rb   RW   Rd   Rm   Rh   Rt   Rv   Ry   R}   R   R   R   R   R   R   R   R   R   R   (+   R[   R   R+   Rv   RB   R   R   R   Rh   R   R   R   Rd   R    RP   R	   R^   R   R   R#   R*   R   R   Rb   Rt   R5   R   R2   Ra   R   Rm   R   R   RW   RS   Ry   R"   R   R\   RH   R}   R<   R9   (    (    R   t   ?   sT   													*													"													