Commit 80d78438 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

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
...@@ -112,6 +112,11 @@ genTransitions' numTransitions = do ...@@ -112,6 +112,11 @@ genTransitions' numTransitions = do
let n = numStates wtaSpec let n = numStates wtaSpec
m = IndexedTransition.maxIndex 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 transitions <- lift $ map (IndexedTransition.fromIndex wtaSpec) <$> uniqueTransitions numTransitions m
weightedTransitions <- (traverse.traverse.traverse) (const genMonoidValue) transitions weightedTransitions <- (traverse.traverse.traverse) (const genMonoidValue) transitions
......
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module IndexedTransition (IndexedTransition(..), maxIndex, fromIndex) where module IndexedTransition (IndexedTransition(..), maxIndex, fromIndex) where
...@@ -10,6 +12,7 @@ import Data.Tuple ...@@ -10,6 +12,7 @@ import Data.Tuple
import Types import Types
newtype IndexedTransition = Index Integer newtype IndexedTransition = Index Integer
deriving newtype (Num, Eq, Ord)
deriving (Show) deriving (Show)
maxIndex :: WTASpec m -> IndexedTransition maxIndex :: WTASpec m -> IndexedTransition
......
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