-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBDDgui.ml
More file actions
69 lines (63 loc) · 2.37 KB
/
BDDgui.ml
File metadata and controls
69 lines (63 loc) · 2.37 KB
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
58
59
60
61
62
63
64
65
66
67
68
open BDD
open Print
(*
* Jakub Dolecki, Michael Cioff, Sean Murphy
*
* BDDgui.ml
*
* This is the GUI for our BDD application. It prints an ASCII tree
* in addition to some parameters about each tree.
*)
(* Prints an expression *)
let rec print_exp (e : BDD.expression) =
match e with
| BDD.True -> "TRUE"
| BDD.False -> "FALSE"
| BDD.Var x -> "Var " ^ string_of_int x
| BDD.And(e1, e2) -> "And(" ^ print_exp e1 ^ ", " ^ print_exp e2 ^ ")"
| BDD.Or(e1, e2) -> "Or(" ^ print_exp e1 ^ ", " ^ print_exp e2 ^ ")"
| BDD.BImp(e1, e2) -> "BImp(" ^ print_exp e1 ^ ", " ^ print_exp e2 ^ ")"
| BDD.Imp(e1, e2) -> "Imp(" ^ print_exp e1 ^ ", " ^ print_exp e2 ^ ")"
| BDD.Neg(e1) -> "Neg(" ^ print_exp e1 ^ ")"
(* Print all satisfying truth assignments *)
let rec print_sat lstlst n =
match lstlst with
| [] -> ()
| hd :: tail ->
let _ = Printf.printf "%s" ("----\nSolution " ^ string_of_int n ^
":\n" )in
let _ =
(let rec print_one lst =
match lst with
| [] -> let _ = Printf.printf "%s" "\n" in ()
| (i, b)::t ->
let _ = Printf.printf "%s"
(string_of_int i ^ " -> " ^ print_exp b ^ "\n")
in print_one t
in print_one hd)
in print_sat tail (n + 1);;
(* processes command line input *)
let _ =
try
let _ = Printf.printf "Starting BDD!\n" in
let lexbuf = Lexing.from_channel stdin in
while true do
let result = Parser.main Lexer.token lexbuf in
let b = BDD.build result in
let count = BDD.sat_count b in
let all = BDD.all_sat b in
(Printf.printf ("%s") ("----\nExpression: " ^ (print_exp result)))
; print_newline();
Printf.printf ("%s") ("----\n") ; print_newline();
Print.prettyPrint b ; print_newline();
Printf.printf ("%s") ("----\nNumber of satisfying solutions: " ^
(string_of_float count)) ; print_newline();
print_sat all 1; print_newline();
flush stdout
done
with
Lexer.Eof ->
let _ = Printf.printf "We reached end of file" in exit 0
| Failure _ | Parsing.Parse_error ->
let _ = Printf.printf "You have entered an invalid expression.
Example usage: (1 or 2 <-> 3 and (!4) -> 3) \n" in exit 0