1 module Reuse 2 3 ( reuse 4 5 ) 6 7 where 8 9 import Trace 10 11 import Set 12 import FiniteMap 13 14 import Stuff 15 import Options 16 17 import TA 18 import FAtypes 19 import Ids 20 21 22 import FAmap 23 import FAkeepst 24 25 reuse :: Opts -> TNFA Int -> [Int] -> TNFA Int 26 27 28 -- replace some of the states used in |news| 29 -- by eps moves to states already used in |moves| 30 31 reuse1 opts a @ (TNFA cons all starts moves) addons = 32 33 let 34 rmoves = invert moves 35 36 -- find possible covers for addon state b 37 38 -- relies on strange behaviour of 39 -- intersectManySets [] = emptySet 40 cands b = intersectManySets 41 [ lookupset rmoves t `minusSet` unitSet b 42 | t <- setToList (lookupset moves b) 43 ] 44 45 bas = listToFM 46 [ (b, head as) 47 | b <- addons 48 , let as = setToList (cands b) 49 , not (null as) 50 ] 51 52 f x = lookupWithDefaultFM bas x x 53 54 nobs = all `minusSet` mkSet (keysFM bas) 55 56 a1 = keepstTNFA opts a nobs 57 a2 = mapTNFA opts f a1 58 59 in 60 61 trace ("Reuse.reuse1.moves = " ++ show moves) $ 62 trace ("Reuse.reuse1.bas = " ++ show bas) $ 63 trace ("Reuse.reuse1.nobs = " ++ show nobs) $ 64 65 a2 66 67 68 69 reuse opts a addons = fixpoint (\ b -> reuse1 opts b addons) a 70