mirror of
https://git.cs.ou.nl/joshua.moerman/mealy-decompose.git
synced 2025-04-29 17:57:44 +02:00
Added RandomGen to the main executable
This commit is contained in:
parent
e938befa20
commit
8da20fdbad
3 changed files with 29 additions and 19 deletions
|
@ -5,6 +5,7 @@ module Main where
|
|||
import CommonOptions
|
||||
import DecomposeInput
|
||||
import DecomposeOutput
|
||||
import RandomGen
|
||||
|
||||
import Options.Applicative
|
||||
import System.Directory
|
||||
|
@ -22,6 +23,7 @@ main = do
|
|||
case optCommand of
|
||||
DecomposeOutput options -> mainDecomposeOutput options commonOptions
|
||||
DecomposeInput options -> mainDecomposeInput options commonOptions
|
||||
RandomGen options -> mainRandomGen options
|
||||
|
||||
data Options = Options
|
||||
{ optCommand :: Command
|
||||
|
@ -38,10 +40,12 @@ optionsParser =
|
|||
data Command
|
||||
= DecomposeOutput DecomposeOutputOptions
|
||||
| DecomposeInput DecomposeInputOptions
|
||||
| RandomGen RandomGenOptions
|
||||
deriving Show
|
||||
|
||||
commandParser =
|
||||
subparser
|
||||
( command "decompose-output" (info (DecomposeOutput <$> decomposeOutputOptionsParser) (progDesc "decompose based on output"))
|
||||
<> command "decompose-input" (info (DecomposeInput <$> decomposeInputOptionsParser) (progDesc "decompose based on independent inputs"))
|
||||
<> command "random-gen" (info (RandomGen <$> randomGenOptionsParser) (progDesc "generate random parallel compositions"))
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{-# LANGUAGE PartialTypeSignatures #-}
|
||||
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
|
||||
|
||||
module Main where
|
||||
module RandomGen where
|
||||
|
||||
import Data.Partition (Block (..))
|
||||
import SplittingTree
|
||||
|
@ -11,9 +11,22 @@ import Control.Monad.Trans.State (execStateT)
|
|||
import Data.List (sortOn)
|
||||
import Data.Map qualified as Map
|
||||
import Data.Set qualified as Set
|
||||
import System.Environment
|
||||
import Options.Applicative
|
||||
import System.Random
|
||||
|
||||
data RandomGenOptions = RandomGenOptions
|
||||
{ numStates :: Int
|
||||
, numComponents :: Int
|
||||
}
|
||||
deriving Show
|
||||
|
||||
randomGenOptionsParser :: Parser RandomGenOptions
|
||||
randomGenOptionsParser =
|
||||
RandomGenOptions
|
||||
<$> 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)
|
||||
<**> helper
|
||||
|
||||
genTransitions :: _ => Int -> [Char] -> [Char] -> RandT _ _ _
|
||||
genTransitions size inputs outputs = do
|
||||
let
|
||||
|
@ -61,12 +74,11 @@ reachability initialState inputs transitions = go 0 Map.empty [initialState]
|
|||
newStates = [t | i <- inputs, let t = transitions s i, t `Map.notMember` newVis]
|
||||
in go (n + 1) newVis (rest ++ newStates)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
[nStr, cStr] <- getArgs
|
||||
mainRandomGen :: RandomGenOptions -> IO ()
|
||||
mainRandomGen RandomGenOptions{..} = do
|
||||
let
|
||||
n = read nStr
|
||||
c = read cStr
|
||||
n = numStates
|
||||
c = numComponents
|
||||
|
||||
-- create random composition
|
||||
(init0, inputs, trans0, outpf0) <- evalRandIO (genComposition n c ['a', 'b'])
|
||||
|
@ -89,7 +101,7 @@ main = do
|
|||
|
||||
PRState{..} <- execStateT (refine (const (pure ())) outputFuns reverseFuns) (initialPRState states)
|
||||
|
||||
-- print
|
||||
-- print to stdout
|
||||
let
|
||||
toBlock s = getBarePartition partition Map.! s
|
||||
allTransitions = [(toBlock s, i, o, toBlock t) | s <- states, i <- inputs, let o = outpf s i, let t = trans s i]
|
||||
|
|
|
@ -46,11 +46,14 @@ executable mealy-decompose-main
|
|||
directory,
|
||||
filepath,
|
||||
mealy-decompose,
|
||||
optparse-applicative
|
||||
MonadRandom,
|
||||
optparse-applicative,
|
||||
random
|
||||
other-modules:
|
||||
CommonOptions,
|
||||
DecomposeInput,
|
||||
DecomposeOutput
|
||||
DecomposeOutput,
|
||||
RandomGen
|
||||
default-extensions:
|
||||
OverloadedStrings
|
||||
|
||||
|
@ -61,15 +64,6 @@ executable mealy-decompose-lstar
|
|||
build-depends:
|
||||
mealy-decompose
|
||||
|
||||
executable mealy-decompose-random-gen
|
||||
import: stuff
|
||||
hs-source-dirs: app
|
||||
main-is: RandomGen.hs
|
||||
build-depends:
|
||||
mealy-decompose,
|
||||
MonadRandom,
|
||||
random
|
||||
|
||||
executable mealy-decompose-playground
|
||||
import: stuff
|
||||
hs-source-dirs: app
|
||||
|
|
Loading…
Add table
Reference in a new issue