mirror of
https://git.cs.ou.nl/joshua.moerman/mealy-decompose.git
synced 2025-04-30 02:07:44 +02:00
30 lines
1 KiB
Haskell
30 lines
1 KiB
Haskell
module Main where
|
|
|
|
import DotParser ( convertToMealy, parseTransFull )
|
|
import Mealy ( MealyMachine(..) )
|
|
import SplittingTree ( PRState(..), refine, initialPRState )
|
|
|
|
import Control.Monad.Trans.State ( execStateT )
|
|
import Data.Map.Strict qualified as Map
|
|
import Data.Maybe ( mapMaybe )
|
|
import System.Environment ( getArgs )
|
|
import Text.Megaparsec ( parseMaybe )
|
|
|
|
main :: IO ()
|
|
main = do
|
|
[dotFile] <- getArgs
|
|
print dotFile
|
|
transitions <- mapMaybe (parseMaybe parseTransFull) . lines <$> readFile dotFile
|
|
|
|
-- convert to mealy
|
|
let
|
|
MealyMachine{..} = convertToMealy transitions
|
|
outputFuns = [(i, fun) | i <- inputs, let fun s = fst (behaviour s i)]
|
|
reverseTransitionMaps i = Map.fromListWith (++) [ (t, [s]) | s <- states, let t = snd (behaviour s i)]
|
|
reverseFuns = [(i, fun) | i <- inputs, let m = reverseTransitionMaps i, let fun s = Map.findWithDefault [] s m]
|
|
|
|
tree <- execStateT (refine print outputFuns reverseFuns) (initialPRState states)
|
|
|
|
print (partition tree)
|
|
print (splittingTree tree)
|
|
|