never executed always true always false
1 {-# LANGUAGE QuasiQuotes #-}
2
3 module Conjure.Process.DealWithCuts ( dealWithCuts ) where
4
5 import Conjure.Prelude
6 import Conjure.UserError
7 import Conjure.Language.Definition
8 import Conjure.Language.Domain
9 import Conjure.Language.TH
10 import Conjure.Language.ModelStats ( finds )
11
12
13 dealWithCuts
14 :: (MonadFailDoc m, NameGen m, MonadUserError m)
15 => Model
16 -> m Model
17 dealWithCuts m = do
18 statements <- forM (mStatements m) $ \ statement ->
19 case statement of
20 SearchOrder orders0 -> do
21 (orders1, (newVars, newCons)) <- runWriterT $ forM orders0 $ \ order ->
22 case order of
23 Cut x -> do
24 varName <- nextName "cut"
25 let varDecl = Declaration (FindOrGiven Find varName DomainBool)
26 let varRef = Reference varName (Just (DeclNoRepr Find varName DomainBool NoRegion))
27 tell ( [ varDecl ]
28 , [ [essence| !&varRef <-> &x |] ]
29 )
30 return $ BranchingOn varName
31 _ -> return order
32 orders2 <-
33 if null [ () | BranchingOn{} <- orders0 ] -- no variables were given, all assumed non-aux
34 then return [ BranchingOn nm | (nm, _) <- finds m ]
35 else return []
36 return $ concat
37 [ newVars
38 , [SearchOrder (orders1++orders2)]
39 , [SuchThat newCons]
40 ]
41 _ -> return [statement]
42 return m { mStatements = concat statements }