mirror of
https://git.cs.ou.nl/joshua.moerman/mealy-decompose.git
synced 2025-04-30 02:07:44 +02:00
moved the other commands as well so that everything goes via main
This commit is contained in:
parent
8da20fdbad
commit
c14d24a13c
8 changed files with 86 additions and 81 deletions
|
@ -27,7 +27,6 @@ decomposeInputOptionsParser :: Parser DecomposeInputOptions
|
||||||
decomposeInputOptionsParser =
|
decomposeInputOptionsParser =
|
||||||
DecomposeInputOptions
|
DecomposeInputOptions
|
||||||
<$> argument str (help "Filename to read (dot format)" <> metavar "FILE")
|
<$> argument str (help "Filename to read (dot format)" <> metavar "FILE")
|
||||||
<**> helper
|
|
||||||
|
|
||||||
-- Interleaving composition of restriction to subalphabets
|
-- Interleaving composition of restriction to subalphabets
|
||||||
-- precondition: alph1 and alph2 have no common elements
|
-- precondition: alph1 and alph2 have no common elements
|
||||||
|
|
|
@ -37,7 +37,6 @@ decomposeOutputOptionsParser =
|
||||||
DecomposeOutputOptions
|
DecomposeOutputOptions
|
||||||
<$> argument str (help "Filename to read (dot format)" <> metavar "FILE")
|
<$> argument str (help "Filename to read (dot format)" <> metavar "FILE")
|
||||||
<*> option auto (long "components" <> short 'c' <> help "Number of components" <> metavar "NUM" <> showDefault <> value 2)
|
<*> option auto (long "components" <> short 'c' <> help "Number of components" <> metavar "NUM" <> showDefault <> value 2)
|
||||||
<**> helper
|
|
||||||
|
|
||||||
mainDecomposeOutput :: DecomposeOutputOptions -> CommonOptions -> IO ()
|
mainDecomposeOutput :: DecomposeOutputOptions -> CommonOptions -> IO ()
|
||||||
mainDecomposeOutput DecomposeOutputOptions{..} CommonOptions{..} = do
|
mainDecomposeOutput DecomposeOutputOptions{..} CommonOptions{..} = do
|
||||||
|
|
51
hs/app/HsiMethod.hs
Normal file
51
hs/app/HsiMethod.hs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
module HsiMethod where
|
||||||
|
|
||||||
|
import Data.Trie qualified as Trie
|
||||||
|
import DotParser (readDotFile)
|
||||||
|
import Mealy (MealyMachine (..))
|
||||||
|
import SplittingTree (initialPRState, refine)
|
||||||
|
import StateIdentifiers (stateIdentifierFor)
|
||||||
|
|
||||||
|
import Control.Monad.Trans.State (evalStateT)
|
||||||
|
import Data.Map.Strict qualified as Map
|
||||||
|
import Options.Applicative
|
||||||
|
|
||||||
|
newtype HsiMethodOptions = HsiMethodOptions
|
||||||
|
{ filename :: FilePath
|
||||||
|
}
|
||||||
|
deriving Show
|
||||||
|
|
||||||
|
hsiMethodOptionsParser :: Parser HsiMethodOptions
|
||||||
|
hsiMethodOptionsParser =
|
||||||
|
HsiMethodOptions
|
||||||
|
<$> argument str (help "Filename to read (dot format)" <> metavar "FILE")
|
||||||
|
|
||||||
|
mainHsiMethod :: HsiMethodOptions -> IO ()
|
||||||
|
mainHsiMethod HsiMethodOptions{..} = do
|
||||||
|
let dotFile = filename
|
||||||
|
print dotFile
|
||||||
|
machine <- readDotFile dotFile
|
||||||
|
|
||||||
|
-- convert to mealy
|
||||||
|
let
|
||||||
|
MealyMachine{..} = machine
|
||||||
|
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]
|
||||||
|
|
||||||
|
(partition, splittingTree) <- evalStateT (refine print outputFuns reverseFuns) (initialPRState states)
|
||||||
|
|
||||||
|
putStrLn "\nPARTITION"
|
||||||
|
print partition
|
||||||
|
|
||||||
|
putStrLn "\nTREE"
|
||||||
|
print splittingTree
|
||||||
|
|
||||||
|
let
|
||||||
|
siFor s = stateIdentifierFor s partition splittingTree
|
||||||
|
|
||||||
|
putStrLn "\nHARMONISED STATE IDENTIFIERS"
|
||||||
|
sis <- mapM (\s -> let si = siFor s in print (Trie.toList si) >> return si) states
|
||||||
|
|
||||||
|
putStrLn "\nW-SET"
|
||||||
|
print (Trie.toList . foldr Trie.union Trie.empty $ sis)
|
|
@ -1,4 +1,4 @@
|
||||||
module Main where
|
module LStarMain where
|
||||||
|
|
||||||
import Bisimulation (bisimulation2)
|
import Bisimulation (bisimulation2)
|
||||||
import DotParser (readDotFile)
|
import DotParser (readDotFile)
|
||||||
|
@ -9,19 +9,25 @@ import Control.Monad (when)
|
||||||
import Control.Monad.Trans.Class
|
import Control.Monad.Trans.Class
|
||||||
import Control.Monad.Trans.State.Strict
|
import Control.Monad.Trans.State.Strict
|
||||||
import Data.Map.Strict qualified as Map
|
import Data.Map.Strict qualified as Map
|
||||||
import System.Environment
|
import Options.Applicative
|
||||||
|
|
||||||
debugOutput :: Bool
|
data LStarOptions = LStarOptions
|
||||||
debugOutput = False
|
{ filename :: FilePath
|
||||||
|
, debugOutput :: Bool
|
||||||
|
}
|
||||||
|
deriving Show
|
||||||
|
|
||||||
semanticsForState :: MealyMachine s i o -> s -> [i] -> o
|
lStarOptionsParser :: Parser LStarOptions
|
||||||
semanticsForState _ _ [] = error ""
|
lStarOptionsParser =
|
||||||
semanticsForState MealyMachine{..} q [a] = fst (behaviour q a)
|
LStarOptions
|
||||||
semanticsForState m@MealyMachine{..} q (a : w) = semanticsForState m (snd (behaviour q a)) w
|
<$> argument str (help "Filename to read (dot format)" <> metavar "FILE")
|
||||||
|
<*> switch (long "verbose" <> short 'v' <> help "Enable extra debugging output")
|
||||||
|
|
||||||
|
mainLStar :: LStarOptions -> IO ()
|
||||||
|
mainLStar LStarOptions{..} = do
|
||||||
|
let
|
||||||
|
dotFile = filename
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
[dotFile] <- getArgs
|
|
||||||
print dotFile
|
print dotFile
|
||||||
machine <- readDotFile dotFile
|
machine <- readDotFile dotFile
|
||||||
|
|
||||||
|
@ -62,3 +68,8 @@ main = do
|
||||||
|
|
||||||
putStrLn $ "Size: " <> show a
|
putStrLn $ "Size: " <> show a
|
||||||
putStrLn $ "MQs: " <> show b
|
putStrLn $ "MQs: " <> show b
|
||||||
|
|
||||||
|
semanticsForState :: MealyMachine s i o -> s -> [i] -> o
|
||||||
|
semanticsForState _ _ [] = error ""
|
||||||
|
semanticsForState MealyMachine{..} q [a] = fst (behaviour q a)
|
||||||
|
semanticsForState m@MealyMachine{..} q (a : w) = semanticsForState m (snd (behaviour q a)) w
|
||||||
|
|
|
@ -5,6 +5,8 @@ module Main where
|
||||||
import CommonOptions
|
import CommonOptions
|
||||||
import DecomposeInput
|
import DecomposeInput
|
||||||
import DecomposeOutput
|
import DecomposeOutput
|
||||||
|
import HsiMethod
|
||||||
|
import LStarMain
|
||||||
import RandomGen
|
import RandomGen
|
||||||
|
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
|
@ -23,6 +25,8 @@ main = do
|
||||||
case optCommand of
|
case optCommand of
|
||||||
DecomposeOutput options -> mainDecomposeOutput options commonOptions
|
DecomposeOutput options -> mainDecomposeOutput options commonOptions
|
||||||
DecomposeInput options -> mainDecomposeInput options commonOptions
|
DecomposeInput options -> mainDecomposeInput options commonOptions
|
||||||
|
HsiMethod options -> mainHsiMethod options
|
||||||
|
LStar options -> mainLStar options
|
||||||
RandomGen options -> mainRandomGen options
|
RandomGen options -> mainRandomGen options
|
||||||
|
|
||||||
data Options = Options
|
data Options = Options
|
||||||
|
@ -36,16 +40,21 @@ optionsParser =
|
||||||
<$> commandParser
|
<$> commandParser
|
||||||
<*> commonOptionsParser
|
<*> commonOptionsParser
|
||||||
<**> helper
|
<**> helper
|
||||||
|
<**> simpleVersioner "0.4.0.0"
|
||||||
|
|
||||||
data Command
|
data Command
|
||||||
= DecomposeOutput DecomposeOutputOptions
|
= DecomposeOutput DecomposeOutputOptions
|
||||||
| DecomposeInput DecomposeInputOptions
|
| DecomposeInput DecomposeInputOptions
|
||||||
|
| HsiMethod HsiMethodOptions
|
||||||
|
| LStar LStarOptions
|
||||||
| RandomGen RandomGenOptions
|
| RandomGen RandomGenOptions
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
commandParser =
|
commandParser =
|
||||||
subparser
|
hsubparser
|
||||||
( command "decompose-output" (info (DecomposeOutput <$> decomposeOutputOptionsParser) (progDesc "decompose based on output"))
|
( command "decompose-output" (info (DecomposeOutput <$> decomposeOutputOptionsParser) (progDesc "decompose based on output"))
|
||||||
<> command "decompose-input" (info (DecomposeInput <$> decomposeInputOptionsParser) (progDesc "decompose based on independent inputs"))
|
<> command "decompose-input" (info (DecomposeInput <$> decomposeInputOptionsParser) (progDesc "decompose based on independent inputs"))
|
||||||
|
<> command "hsi-method" (info (HsiMethod <$> hsiMethodOptionsParser) (progDesc "construct HSI test suite from specification dot file"))
|
||||||
|
<> command "lstar" (info (LStar <$> lStarOptionsParser) (progDesc "little l* playground"))
|
||||||
<> command "random-gen" (info (RandomGen <$> randomGenOptionsParser) (progDesc "generate random parallel compositions"))
|
<> command "random-gen" (info (RandomGen <$> randomGenOptionsParser) (progDesc "generate random parallel compositions"))
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
module Main where
|
|
||||||
|
|
||||||
import Data.Trie qualified as Trie
|
|
||||||
import DotParser (readDotFile)
|
|
||||||
import Mealy (MealyMachine (..))
|
|
||||||
import SplittingTree (initialPRState, refine)
|
|
||||||
import StateIdentifiers (stateIdentifierFor)
|
|
||||||
|
|
||||||
import Control.Monad.Trans.State (evalStateT)
|
|
||||||
import Data.Map.Strict qualified as Map
|
|
||||||
import System.Environment (getArgs)
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
args <- getArgs
|
|
||||||
case args of
|
|
||||||
("HSI" : ls) -> mainHSI ls
|
|
||||||
_ -> putStrLn "Please provide one of [HSI, InputDecomp]"
|
|
||||||
|
|
||||||
mainHSI :: [String] -> IO ()
|
|
||||||
mainHSI args = case args of
|
|
||||||
[dotFile] -> run dotFile
|
|
||||||
_ -> putStrLn "Please provide a dot file"
|
|
||||||
where
|
|
||||||
run dotFile = do
|
|
||||||
print dotFile
|
|
||||||
machine <- readDotFile dotFile
|
|
||||||
|
|
||||||
-- convert to mealy
|
|
||||||
let
|
|
||||||
MealyMachine{..} = machine
|
|
||||||
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]
|
|
||||||
|
|
||||||
(partition, splittingTree) <- evalStateT (refine print outputFuns reverseFuns) (initialPRState states)
|
|
||||||
|
|
||||||
putStrLn "\nPARTITION"
|
|
||||||
print partition
|
|
||||||
|
|
||||||
putStrLn "\nTREE"
|
|
||||||
print splittingTree
|
|
||||||
|
|
||||||
let
|
|
||||||
siFor s = stateIdentifierFor s partition splittingTree
|
|
||||||
|
|
||||||
putStrLn "\nHARMONISED STATE IDENTIFIERS"
|
|
||||||
sis <- mapM (\s -> let si = siFor s in print (Trie.toList si) >> return si) states
|
|
||||||
|
|
||||||
putStrLn "\nW-SET"
|
|
||||||
print (Trie.toList . foldr Trie.union Trie.empty $ sis)
|
|
|
@ -25,7 +25,6 @@ randomGenOptionsParser =
|
||||||
RandomGenOptions
|
RandomGenOptions
|
||||||
<$> option auto (long "states" <> short 'n' <> help "Number of states per component (max)" <> metavar "NUM" <> showDefault <> value 10)
|
<$> option auto (long "states" <> short 'n' <> help "Number of states per component (max)" <> metavar "NUM" <> showDefault <> value 10)
|
||||||
<*> option auto (long "components" <> short 'c' <> help "Number of components" <> metavar "COMP" <> showDefault <> value 2)
|
<*> option auto (long "components" <> short 'c' <> help "Number of components" <> metavar "COMP" <> showDefault <> value 2)
|
||||||
<**> helper
|
|
||||||
|
|
||||||
genTransitions :: _ => Int -> [Char] -> [Char] -> RandT _ _ _
|
genTransitions :: _ => Int -> [Char] -> [Char] -> RandT _ _ _
|
||||||
genTransitions size inputs outputs = do
|
genTransitions size inputs outputs = do
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cabal-version: 2.2
|
cabal-version: 2.2
|
||||||
name: mealy-decompose
|
name: mealy-decompose
|
||||||
version: 0.3.0.0
|
version: 0.4.0.0
|
||||||
license: EUPL-1.2
|
license: EUPL-1.2
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Joshua Moerman
|
author: Joshua Moerman
|
||||||
|
@ -53,24 +53,12 @@ executable mealy-decompose-main
|
||||||
CommonOptions,
|
CommonOptions,
|
||||||
DecomposeInput,
|
DecomposeInput,
|
||||||
DecomposeOutput,
|
DecomposeOutput,
|
||||||
|
HsiMethod,
|
||||||
|
LStarMain,
|
||||||
RandomGen
|
RandomGen
|
||||||
default-extensions:
|
default-extensions:
|
||||||
OverloadedStrings
|
OverloadedStrings
|
||||||
|
|
||||||
executable mealy-decompose-lstar
|
|
||||||
import: stuff
|
|
||||||
hs-source-dirs: app
|
|
||||||
main-is: LStarMain.hs
|
|
||||||
build-depends:
|
|
||||||
mealy-decompose
|
|
||||||
|
|
||||||
executable mealy-decompose-playground
|
|
||||||
import: stuff
|
|
||||||
hs-source-dirs: app
|
|
||||||
main-is: Playground.hs
|
|
||||||
build-depends:
|
|
||||||
mealy-decompose
|
|
||||||
|
|
||||||
test-suite mealy-decompose-test
|
test-suite mealy-decompose-test
|
||||||
import: stuff
|
import: stuff
|
||||||
hs-source-dirs: test
|
hs-source-dirs: test
|
||||||
|
|
Loading…
Add table
Reference in a new issue