From 5794d139fb0e987a670681424154afe68d0a3dd4 Mon Sep 17 00:00:00 2001 From: Luke Clifton Date: Tue, 10 Mar 2020 14:00:06 +0800 Subject: [PATCH] Trivial solution for trivial goals. The `[Test]` passed to the `solve` function is a conjuction of tests. In a similar vein to `all`, an empty list should mean that the condition was met. That is, all the conditions in the list were met, there just weren't any conditions. This comes up when you want to create a problem which is attempting to find a plan between two `[a]`s. The `[]` to `[]` case will result in a failure to solve due to no goals being set. --- FastDownward.hs | 131 +++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/FastDownward.hs b/FastDownward.hs index 56d01fa..59c5484 100644 --- a/FastDownward.hs +++ b/FastDownward.hs @@ -600,71 +600,78 @@ solve cfg ops tests = do Seq.fromList $ Data.Foldable.toList axioms } - planFilePath <- - liftIO ( emptySystemTempFile "sas_plan" ) - - ( exitCode, stdout, stderr ) <- - liftIO - ( Exec.callFastDownward - Exec.Options - { fastDownward = "downward" - , problem = plan - , planFilePath = planFilePath - , searchConfiguration = cfg - } - ) - - case exitCode of - ExitFailure 11 -> - return Unsolvable - - ExitFailure 12 -> - return UnsolvableIncomplete - - ExitFailure 22 -> - return OutOfMemory - - ExitFailure 23 -> - return OutOfTime - - ExitFailure 32 -> - return CriticalError - - ExitFailure 33 -> - return InputError + if null goal + then pure (Solved (Solution + { sas = plan + , operators = mempty + , stepIndices = mempty + })) + else do + planFilePath <- + liftIO ( emptySystemTempFile "sas_plan" ) + + ( exitCode, stdout, stderr ) <- + liftIO + ( Exec.callFastDownward + Exec.Options + { fastDownward = "downward" + , problem = plan + , planFilePath = planFilePath + , searchConfiguration = cfg + } + ) + + case exitCode of + ExitFailure 11 -> + return Unsolvable + + ExitFailure 12 -> + return UnsolvableIncomplete + + ExitFailure 22 -> + return OutOfMemory + + ExitFailure 23 -> + return OutOfTime + + ExitFailure 32 -> + return CriticalError + + ExitFailure 33 -> + return InputError + + ExitFailure 34 -> + return Unsupported + + ExitFailure other -> + return ( Crashed stdout stderr ( ExitFailure other ) ) + + ExitSuccess -> liftIO $ do + planText <- + Data.Text.Lazy.IO.readFile planFilePath + + let + stepIndices = + map -- Read "(op42)" as 42 + ( read + . Data.Text.Lazy.unpack + . Data.Text.Lazy.init -- keep everything up to ")" + . Data.Text.Lazy.drop 3 -- drop "(op" + ) + ( takeWhile + ( "(" `Data.Text.Lazy.isPrefixOf` ) + ( Data.Text.Lazy.lines planText ) + ) - ExitFailure 34 -> - return Unsupported - - ExitFailure other -> - return ( Crashed stdout stderr ( ExitFailure other ) ) - - ExitSuccess -> liftIO $ do - planText <- - Data.Text.Lazy.IO.readFile planFilePath - - let - stepIndices = - map -- Read "(op42)" as 42 - ( read - . Data.Text.Lazy.unpack - . Data.Text.Lazy.init -- keep everything up to ")" - . Data.Text.Lazy.drop 3 -- drop "(op" - ) - ( takeWhile - ( "(" `Data.Text.Lazy.isPrefixOf` ) - ( Data.Text.Lazy.lines planText ) + return + ( Solved + Solution + { sas = plan + , operators = IntMap.fromList ( zip [0..] ( map fst operators ) ) + , .. + } ) - return - ( Solved - Solution - { sas = plan - , operators = IntMap.fromList ( zip [0..] ( map fst operators ) ) - , .. - } - ) - exhaustEffects :: Traversable t