Commit 80d78438 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢
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
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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

+3 −0
Original line number Diff line number Diff line
{-# 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