Skip to content
Snippets Groups Projects
Commit 80d78438 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel :turtle:
Browse files

wta: Guard against too many transitions

When the user requests more transitions than the maximal number for the given
automaton, the current generator runs into an endless loop trying to find new
unused transitions. We now detect this case early and throw an error.
parent dbd78cf8
Branches
No related tags found
1 merge request!12WIP: Random WTA generator
......@@ -112,6 +112,11 @@ genTransitions' numTransitions = do
let n = numStates wtaSpec
m = IndexedTransition.maxIndex wtaSpec
-- FIXME Handle this case better. A nicer error output or something along this
-- line.
when (fromIntegral numTransitions >= m) $ do
error $ "genTransitions: More transitions than possible requested"
transitions <- lift $ map (IndexedTransition.fromIndex wtaSpec) <$> uniqueTransitions numTransitions m
weightedTransitions <- (traverse.traverse.traverse) (const genMonoidValue) transitions
......
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module IndexedTransition (IndexedTransition(..), maxIndex, fromIndex) where
......@@ -10,6 +12,7 @@ import Data.Tuple
import Types
newtype IndexedTransition = Index Integer
deriving newtype (Num, Eq, Ord)
deriving (Show)
maxIndex :: WTASpec m -> IndexedTransition
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment