-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractSolver.hs
58 lines (44 loc) · 1.32 KB
/
AbstractSolver.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module AbstractSolver where
data Var = Var
{ name :: Int
, value :: Maybe Bool}
deriving (Eq)
instance Show Var where
show (Var
{ name = n
, value = v}) =
show n ++ " " ++ further
where
further =
case v of
(Just value) -> show value
otherwise -> show "nothing"
var :: Int -> Maybe Bool -> Var
var i val = Var {name = i, value = val}
data Status = Undecided | Decided deriving (Eq, Show)
data Clause = Disj
{ posVars :: [Var]
, negVars :: [Var]}
deriving (Eq)
instance Show Clause where
show (Disj {posVars = ps, negVars = ns}) =
"Disj: " ++ " pos " ++ show ps ++ " neg " ++ show ns
disj :: [Var] -> [Var] -> Clause
disj p n = Disj {posVars = p, negVars = n}
newtype Formula = Formula [Clause] deriving (Eq)
instance Show Formula where
show (Formula clauses) = do
clause <- clauses
(show clause) ++ "\n"
data Model
= Model { falses :: [Var]
, trues :: [Var]
, undecided :: [Var]
, decisionLit :: [Var]}
deriving (Eq, Show)
example = Formula [
disj [] [var 1 Nothing, var 2 Nothing],
disj [var 2 Nothing, var 3 Nothing] [],
disj [var 4 Nothing] [var 1 Nothing, var 3 Nothing],
disj [var 2 Nothing] [var 4 Nothing, var 3 Nothing],
disj [var 1 Nothing, var 4 Nothing] []]