Commit 273a65b1 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

random-dfa: Allow to specify probability for final states

parent bd186b68
......@@ -27,9 +27,10 @@ import ValmariOutput
randomDFA
:: Word16 -- ^ Number of states
-> Word16 -- ^ Size of the alphabet
-> IO Bool -- ^ Random finality
-> IO DFA
randomDFA s a = do
finals <- VU.replicateM (fromIntegral s) randomIO
randomDFA s a randomIsFinal = do
finals <- VU.replicateM (fromIntegral s) randomIsFinal
matrix <- V.replicateM
(fromIntegral s)
(VU.replicateM (fromIntegral a) (randomRIO (0, s - 1)))
......@@ -40,6 +41,9 @@ randomDFA s a = do
}
percentTrue :: Int -> IO Bool
percentTrue percent = (< percent) <$> randomRIO (0, 99)
data OutputFormat = Dot | Copar | Valmari
instance Show OutputFormat where
......@@ -51,6 +55,7 @@ instance Show OutputFormat where
data Options = Options
{ _optStates :: Word16
, _optLetters :: Word16
, _optFinal :: Int
, _optOutputs :: [(OutputFormat, Maybe (NE.NonEmpty Char))]
} deriving (Show)
makeLensesWith abbreviatedFields ''Options
......@@ -65,6 +70,13 @@ options =
<*> OptParse.argument
OptParse.auto
(OptParse.metavar "M" <> OptParse.help "Size of the alphabet")
<*> OptParse.option
OptParse.auto
( OptParse.long "final"
<> OptParse.metavar "PERCENT"
<> OptParse.value 50
<> OptParse.help "Percent of final states"
)
<*> some
(OptParse.argument
readOutput
......@@ -104,7 +116,9 @@ main = do
)
)
dfa <- randomDFA (opts ^. states) (opts ^. letters)
dfa <- randomDFA (opts ^. states)
(opts ^. letters)
(percentTrue (opts ^. final))
forM_ (opts ^. outputs) $ \(outputFormat, outputFile) -> do
let builder = case outputFormat of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment