1
Fork 0
mirror of https://git.cs.ou.nl/joshua.moerman/mealy-decompose.git synced 2025-04-30 02:07:44 +02:00

More output from Main

This commit is contained in:
Joshua Moerman 2024-03-11 13:21:41 +01:00
parent d19cd9f48f
commit 74f547ed38

View file

@ -22,6 +22,9 @@ import Text.Megaparsec
converseRelation :: (Ord a, Ord b) => Map.Map a b -> Map.Map b [a] converseRelation :: (Ord a, Ord b) => Map.Map a b -> Map.Map b [a]
converseRelation m = Map.fromListWith (++) . fmap (second pure . swap) . Map.assocs $ m converseRelation m = Map.fromListWith (++) . fmap (second pure . swap) . Map.assocs $ m
myWriteFile :: FilePath -> String -> IO ()
myWriteFile filename content = writeFile ("results/" ++ filename) content
{- {-
Hacked together, you can view the result with: Hacked together, you can view the result with:
@ -115,8 +118,6 @@ main = do
forM_ projmapN (\((os, p), i) -> do forM_ projmapN (\((os, p), i) -> do
let name = intercalate "x" os let name = intercalate "x" os
filename = "component" <> show i <> ".dot"
osWithRel = concat $ os:[Map.findWithDefault [] o downSets | o <- os] osWithRel = concat $ os:[Map.findWithDefault [] o downSets | o <- os]
osWithRelAndEquiv = concat $ osWithRel:[Map.findWithDefault [] o equivInv | o <- osWithRel] osWithRelAndEquiv = concat $ osWithRel:[Map.findWithDefault [] o equivInv | o <- osWithRel]
componentOutputs = Set.fromList osWithRelAndEquiv componentOutputs = Set.fromList osWithRelAndEquiv
@ -128,8 +129,18 @@ main = do
putStrLn $ "Component " <> show os putStrLn $ "Component " <> show os
putStrLn $ "Correct? " <> show (comparePartitions p partition) putStrLn $ "Correct? " <> show (comparePartitions p partition)
putStrLn $ "Size = " <> show (numBlocks p) putStrLn $ "Size = " <> show (numBlocks p)
putStrLn $ "Output in file " <> filename
(do
let filename = "partition_" <> show i <> ".dot"
idx2State = Map.map head . converseRelation $ state2idx
stateBlocks = fmap (fmap (idx2State Map.!)) . Partition.toBlocks $ partition
content = unlines . fmap (intercalate " ") $ stateBlocks
putStrLn $ "Output (partition) in file " <> filename
myWriteFile filename content
)
(do
let MealyMachine{..} = proj let MealyMachine{..} = proj
-- We enumerate all transitions in the full automaton -- We enumerate all transitions in the full automaton
transitions = [(s, i, o, t) | s <- states, i <- inputs, let (o, t) = behaviour s i] transitions = [(s, i, o, t) | s <- states, i <- inputs, let (o, t) = behaviour s i]
@ -142,6 +153,10 @@ main = do
-- Sorting on "/= initialBlock" puts the initialBlock in front -- Sorting on "/= initialBlock" puts the initialBlock in front
initialFirst = sortOn (\(s,_,_,_) -> s /= initialBlock) transitionsBlocks initialFirst = sortOn (\(s,_,_,_) -> s /= initialBlock) transitionsBlocks
-- Convert to a file
filename1 = "component_" <> show i <> ".dot"
content1 = toString . mealyToDot name $ initialFirst
-- So far so good, `initialFirst` could serve as our output -- So far so good, `initialFirst` could serve as our output
-- But we do one more optimisation on the machine -- But we do one more optimisation on the machine
-- We remove inputs, on which the machine does nothing -- We remove inputs, on which the machine does nothing
@ -150,11 +165,17 @@ main = do
result = filter (\(_,i,_,_) -> i `Set.notMember` deadInputs) initialFirst result = filter (\(_,i,_,_) -> i `Set.notMember` deadInputs) initialFirst
-- Convert to a file -- Convert to a file
content = toString . mealyToDot name $ result filename2 = "component_reduced_" <> show i <> ".dot"
content2 = toString . mealyToDot name $ result
putStrLn $ "Output (reduced machine) in file " <> filename1
myWriteFile filename1 content1
putStrLn $ "Dead inputs = " <> show (Set.size deadInputs) putStrLn $ "Dead inputs = " <> show (Set.size deadInputs)
writeFile filename content putStrLn $ "Output (reduced machine) in file " <> filename2
myWriteFile filename2 content2
)
) )
return () return ()