mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-07 19:55:41 -05:00
remove dimacs stuff
This commit is contained in:
parent
2e7ab9ba9b
commit
19d65b4069
10 changed files with 15 additions and 161 deletions
|
|
@ -1,22 +0,0 @@
|
||||||
(* Copyright 2005 INRIA *)
|
|
||||||
{
|
|
||||||
open Sidekick_util
|
|
||||||
open Parser
|
|
||||||
}
|
|
||||||
|
|
||||||
let number = ['1' - '9'] ['0' - '9']*
|
|
||||||
|
|
||||||
rule token = parse
|
|
||||||
| eof { EOF }
|
|
||||||
| "c" { comment lexbuf }
|
|
||||||
| [' ' '\t' '\r'] { token lexbuf }
|
|
||||||
| 'p' { P }
|
|
||||||
| "cnf" { CNF }
|
|
||||||
| '\n' { Lexing.new_line lexbuf; token lexbuf }
|
|
||||||
| '0' { ZERO }
|
|
||||||
| '-'? number { LIT (int_of_string (Lexing.lexeme lexbuf)) }
|
|
||||||
| _ { Error.errorf "dimacs.lexer: unexpected char `%s`" (Lexing.lexeme lexbuf) }
|
|
||||||
|
|
||||||
and comment = parse
|
|
||||||
| '\n' { Lexing.new_line lexbuf; token lexbuf }
|
|
||||||
| [^'\n'] { comment lexbuf }
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
/* Copyright 2005 INRIA */
|
|
||||||
|
|
||||||
%{
|
|
||||||
open Sidekick_util
|
|
||||||
|
|
||||||
let lnum pos = pos.Lexing.pos_lnum
|
|
||||||
let cnum pos = pos.Lexing.pos_cnum - pos.Lexing.pos_bol
|
|
||||||
let pp_pos out (start,stop) =
|
|
||||||
Format.fprintf out "(at %d:%d - %d:%d)"
|
|
||||||
(lnum start) (cnum start) (lnum stop) (cnum stop)
|
|
||||||
%}
|
|
||||||
|
|
||||||
%token <int> LIT
|
|
||||||
%token ZERO
|
|
||||||
%token P CNF EOF
|
|
||||||
|
|
||||||
%start file
|
|
||||||
%type <int list list> file
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
/* DIMACS syntax */
|
|
||||||
|
|
||||||
prelude:
|
|
||||||
| P CNF LIT LIT { () }
|
|
||||||
| error
|
|
||||||
{
|
|
||||||
Error.errorf "expected prelude %a" pp_pos ($startpos,$endpos)
|
|
||||||
}
|
|
||||||
|
|
||||||
clauses:
|
|
||||||
| l=clause* { l }
|
|
||||||
| error
|
|
||||||
{
|
|
||||||
Error.errorf "expected list of clauses %a"
|
|
||||||
pp_pos ($startpos,$endpos)
|
|
||||||
}
|
|
||||||
|
|
||||||
file:
|
|
||||||
| prelude l=clauses EOF { l }
|
|
||||||
|
|
||||||
clause:
|
|
||||||
| l=LIT+ ZERO { l }
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
|
|
||||||
(** {1 Main for dimacs} *)
|
|
||||||
|
|
||||||
type 'a or_error = ('a, string) CCResult.t
|
|
||||||
|
|
||||||
let parse file : int list list or_error =
|
|
||||||
try
|
|
||||||
CCIO.with_in file
|
|
||||||
(fun ic ->
|
|
||||||
let lexbuf = Lexing.from_channel ic in
|
|
||||||
Parser.file Lexer.token lexbuf)
|
|
||||||
|> CCResult.return
|
|
||||||
with e ->
|
|
||||||
CCResult.of_exn_trace e
|
|
||||||
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
|
|
||||||
(** {1 Main for dimacs} *)
|
|
||||||
|
|
||||||
(** This library provides a parser for DIMACS files, to represent
|
|
||||||
SAT problems.
|
|
||||||
|
|
||||||
http://www.satcompetition.org/2009/format-benchmarks2009.html
|
|
||||||
*)
|
|
||||||
|
|
||||||
type 'a or_error = ('a, string) CCResult.t
|
|
||||||
|
|
||||||
val parse : string -> int list list or_error
|
|
||||||
(** Parse a file into a list of clauses. *)
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
|
|
||||||
; main binary
|
|
||||||
(library
|
|
||||||
(name sidekick_dimacs)
|
|
||||||
(public_name sidekick.dimacs)
|
|
||||||
(optional) ; only if deps present
|
|
||||||
(libraries containers sidekick.util)
|
|
||||||
(flags :standard -w +a-4-42-44-48-50-58-32-60@8)
|
|
||||||
(ocamlopt_flags :standard -O3 -color always -bin-annot
|
|
||||||
-unbox-closures -unbox-closures-factor 20)
|
|
||||||
)
|
|
||||||
|
|
||||||
(menhir (modules Parser))
|
|
||||||
(ocamllex (modules Lexer))
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
|
|
||||||
; main binary
|
; main binary
|
||||||
(executable
|
|
||||||
(name main)
|
|
||||||
(public_name sidekick)
|
|
||||||
(package sidekick)
|
|
||||||
(libraries containers iter result msat sidekick.core
|
|
||||||
sidekick.base-term sidekick.msat-solver sidekick.smtlib sidekick.dimacs)
|
|
||||||
(flags :standard -w +a-4-42-44-48-50-58-32-60@8
|
|
||||||
-safe-string -color always -open Sidekick_util)
|
|
||||||
(ocamlopt_flags :standard -O3 -color always
|
|
||||||
-unbox-closures -unbox-closures-factor 20)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
(executable
|
||||||
|
(name main)
|
||||||
|
(public_name sidekick)
|
||||||
|
(package sidekick)
|
||||||
|
(libraries containers iter result msat sidekick.core sidekick.base-term
|
||||||
|
sidekick.msat-solver sidekick.smtlib)
|
||||||
|
(flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always
|
||||||
|
-open Sidekick_util)
|
||||||
|
(ocamlopt_flags :standard -O3 -color always -unbox-closures
|
||||||
|
-unbox-closures-factor 20))
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,6 @@ let argspec = Arg.align [
|
||||||
"-v", Arg.Int Msat.Log.set_debug, "<lvl> sets the debug verbose level";
|
"-v", Arg.Int Msat.Log.set_debug, "<lvl> sets the debug verbose level";
|
||||||
]
|
]
|
||||||
|
|
||||||
type syntax =
|
|
||||||
| Dimacs
|
|
||||||
| Smtlib
|
|
||||||
|
|
||||||
let syntax_of_file file =
|
|
||||||
if CCString.suffix ~suf:".cnf" file then Dimacs
|
|
||||||
else Smtlib
|
|
||||||
|
|
||||||
(* Limits alarm *)
|
(* Limits alarm *)
|
||||||
let check_limits () =
|
let check_limits () =
|
||||||
let t = Sys.time () in
|
let t = Sys.time () in
|
||||||
|
|
@ -109,31 +101,17 @@ let main () =
|
||||||
exit 2
|
exit 2
|
||||||
);
|
);
|
||||||
let al = Gc.create_alarm check_limits in
|
let al = Gc.create_alarm check_limits in
|
||||||
let syn = syntax_of_file !file in
|
|
||||||
Util.setup_gc();
|
Util.setup_gc();
|
||||||
let tst = Term.create ~size:4_096 () in
|
let tst = Term.create ~size:4_096 () in
|
||||||
let solver =
|
let solver =
|
||||||
let theories = match syn with
|
let theories = [
|
||||||
| Dimacs ->
|
Process.th_bool ;
|
||||||
[Process.th_bool ]
|
] (* TODO: more theories *)
|
||||||
| Smtlib ->
|
|
||||||
[Process.th_bool ;
|
|
||||||
] (* TODO: more theories *)
|
|
||||||
in
|
in
|
||||||
Process.Solver.create ~store_proof:!check ~theories tst ()
|
Process.Solver.create ~store_proof:!check ~theories tst ()
|
||||||
in
|
in
|
||||||
let dot_proof = if !p_dot_proof = "" then None else Some !p_dot_proof in
|
let dot_proof = if !p_dot_proof = "" then None else Some !p_dot_proof in
|
||||||
begin match syn with
|
Sidekick_smtlib.parse !file >>= fun input ->
|
||||||
| Smtlib ->
|
|
||||||
(* parse pb *)
|
|
||||||
Sidekick_smtlib.parse !file
|
|
||||||
| Dimacs ->
|
|
||||||
Sidekick_dimacs.parse !file >|= fun cs ->
|
|
||||||
List.rev_append
|
|
||||||
(List.rev_map (fun c -> Ast.Assert_bool c) cs)
|
|
||||||
[Ast.CheckSat]
|
|
||||||
end
|
|
||||||
>>= fun input ->
|
|
||||||
(* process statements *)
|
(* process statements *)
|
||||||
let res =
|
let res =
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,6 @@ type statement =
|
||||||
| Decl of ID.t * Ty.t
|
| Decl of ID.t * Ty.t
|
||||||
| Define of definition list
|
| Define of definition list
|
||||||
| Assert of term
|
| Assert of term
|
||||||
| Assert_bool of int list
|
|
||||||
| Goal of var list * term
|
| Goal of var list * term
|
||||||
| CheckSat
|
| CheckSat
|
||||||
| Exit
|
| Exit
|
||||||
|
|
@ -437,7 +436,6 @@ let pp_statement out = function
|
||||||
Fmt.fprintf out "(@[<1>declare-fun@ %a (@[%a@])@ %a@])"
|
Fmt.fprintf out "(@[<1>declare-fun@ %a (@[%a@])@ %a@])"
|
||||||
ID.pp id (Util.pp_list Ty.pp) args Ty.pp ret
|
ID.pp id (Util.pp_list Ty.pp) args Ty.pp ret
|
||||||
| Assert t -> Fmt.fprintf out "(@[assert@ %a@])" pp_term t
|
| Assert t -> Fmt.fprintf out "(@[assert@ %a@])" pp_term t
|
||||||
| Assert_bool l -> Fmt.fprintf out "(@[assert-bool@ %a@])" (Util.pp_list Fmt.int) l
|
|
||||||
| Goal (vars,g) ->
|
| Goal (vars,g) ->
|
||||||
Fmt.fprintf out "(@[assert-not@ %a@])" pp_term (forall_l vars (not_ g))
|
Fmt.fprintf out "(@[assert-not@ %a@])" pp_term (forall_l vars (not_ g))
|
||||||
| Exit -> Fmt.string out "(exit)"
|
| Exit -> Fmt.string out "(exit)"
|
||||||
|
|
@ -481,7 +479,7 @@ let env_add_statement env st =
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun map (id,ty,def) -> add_def id (E_defined (ty,def)) map)
|
(fun map (id,ty,def) -> add_def id (E_defined (ty,def)) map)
|
||||||
env l
|
env l
|
||||||
| Goal _ | Assert _ | Assert_bool _ | CheckSat | Exit
|
| Goal _ | Assert _ | CheckSat | Exit
|
||||||
| SetLogic _ | SetOption _ | SetInfo _
|
| SetLogic _ | SetOption _ | SetInfo _
|
||||||
-> env
|
-> env
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,6 @@ type statement =
|
||||||
| Decl of ID.t * Ty.t
|
| Decl of ID.t * Ty.t
|
||||||
| Define of definition list
|
| Define of definition list
|
||||||
| Assert of term
|
| Assert of term
|
||||||
| Assert_bool of int list
|
|
||||||
| Goal of var list * term
|
| Goal of var list * term
|
||||||
| CheckSat
|
| CheckSat
|
||||||
| Exit
|
| Exit
|
||||||
|
|
|
||||||
|
|
@ -510,13 +510,6 @@ let solve
|
||||||
|
|
||||||
(* NOTE: hack for testing with dimacs. Proper treatment should go into
|
(* NOTE: hack for testing with dimacs. Proper treatment should go into
|
||||||
scoping in Ast, or having theory-specific state in `Term.state` *)
|
scoping in Ast, or having theory-specific state in `Term.state` *)
|
||||||
let mk_iatom =
|
|
||||||
let tbl = Util.Int_tbl.create 6 in (* for atoms *)
|
|
||||||
fun tst i ->
|
|
||||||
let c = Util.Int_tbl.get_or_add tbl ~k:(abs i)
|
|
||||||
~f:(fun i -> Fun.mk_undef_const (ID.makef "a_%d" i) Ty.bool) in
|
|
||||||
Lit.atom tst ~sign:(i>0) @@ Term.const tst c
|
|
||||||
|
|
||||||
(* process a single statement *)
|
(* process a single statement *)
|
||||||
let process_stmt
|
let process_stmt
|
||||||
?hyps
|
?hyps
|
||||||
|
|
@ -573,11 +566,6 @@ let process_stmt
|
||||||
CCOpt.iter (fun h -> Vec.push h [atom]) hyps;
|
CCOpt.iter (fun h -> Vec.push h [atom]) hyps;
|
||||||
Solver.add_clause_lits solver (IArray.singleton atom);
|
Solver.add_clause_lits solver (IArray.singleton atom);
|
||||||
E.return()
|
E.return()
|
||||||
| A.Assert_bool l ->
|
|
||||||
let c = List.rev_map (mk_iatom tst) l in
|
|
||||||
CCOpt.iter (fun h -> Vec.push h c) hyps;
|
|
||||||
Solver.add_clause_lits_l solver c;
|
|
||||||
E.return ()
|
|
||||||
| A.Goal (_, _) ->
|
| A.Goal (_, _) ->
|
||||||
Error.errorf "cannot deal with goals yet"
|
Error.errorf "cannot deal with goals yet"
|
||||||
| A.Data _ ->
|
| A.Data _ ->
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue