Skip to content

Commit e55118a

Browse files
committed
2023-24: Fix z3 performance issue
Apparently mk_simple_solver does not use any of Z3's usual heuristics. Weird...
1 parent d08afbf commit e55118a

File tree

2 files changed

+4
-65
lines changed

2 files changed

+4
-65
lines changed

2023/24/sol.z3

Lines changed: 0 additions & 60 deletions
This file was deleted.

2023/24/sol2.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
open! Core
44

5+
let debug = false
56
let pat = Re.(compile (seq [ opt (char '-'); rep1 digit ]))
67

78
let input =
@@ -26,7 +27,7 @@ let make_rules i (px, py, pz, vx, vy, vz) ~context ~x0 ~y0 ~z0 ~vx0 ~vy0 ~vz0 =
2627

2728
let main () =
2829
let context = Z3.mk_context [] in
29-
let solver = Z3.Solver.mk_simple_solver context in
30+
let solver = Z3.Solver.mk_solver context None in
3031
let x0, y0, z0, vx0, vy0, vz0 =
3132
( Z3.Arithmetic.Integer.mk_const_s context "x0"
3233
, Z3.Arithmetic.Integer.mk_const_s context "y0"
@@ -41,12 +42,12 @@ let main () =
4142
~f:(make_rules ~context ~x0 ~y0 ~z0 ~vx0 ~vy0 ~vz0)
4243
in
4344
Z3.Solver.add solver rules;
44-
print_endline (Z3.Solver.to_string solver);
45+
if debug then print_endline (Z3.Solver.to_string solver);
4546
match Z3.Solver.check solver [] with
4647
| UNSATISFIABLE | UNKNOWN -> raise_s [%message "no solution"]
4748
| SATISFIABLE ->
4849
let model = Z3.Solver.get_model solver |> Option.value_exn in
49-
print_endline (Z3.Model.to_string model);
50+
if debug then print_endline (Z3.Model.to_string model);
5051
let ans =
5152
let get var =
5253
Z3.Model.get_const_interp_e model var
@@ -59,6 +60,4 @@ let main () =
5960
print_s [%sexp (ans : int)]
6061
;;
6162

62-
(* TODO: Why is this so much slower than printing the SMT and then plugging it
63-
into z3 at the command line? *)
6463
let () = main ()

0 commit comments

Comments
 (0)