Skip to content

Commit

Permalink
add hall of fame command
Browse files Browse the repository at this point in the history
  • Loading branch information
FardaleM committed Jul 23, 2024
1 parent 10b0464 commit 3204b8e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
82 changes: 82 additions & 0 deletions bin/dowsindex/CmdHOF.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
open CommonOpts

let cmp (time1, _) (time2, _) = CCFloat.compare time1 time2

let aux size iter_idx =
let timer = Timer.make () in
let types = Iter.to_list iter_idx |> List.sort_uniq Type.compare in
let n_types = List.length types in
let rec all_pairs i acc l =
match l with
| [] -> acc
| t1 :: t ->
Format.printf "@[<h>%i/%i: %a@]@." i n_types Type.pp t1;
let acc =
List.fold_left
(fun acc t2 ->
let env = Type.Env.make () in
Timer.start timer;
(try ignore @@ Acic.unify env t1 t2
with e ->
Format.printf "\"%a\" \"%a\"@." Type.pp t1 Type.pp t2;
raise e);
Timer.stop timer;
let time = Timer.get timer in
if time > 5. then Format.printf "@[<h>Big time: %a@]@." Type.pp t2;
CCList.tl (CCList.sorted_insert ~cmp (time, (t1, t2)) acc))
acc l
in
Gc.major ();
all_pairs (i+1) acc t
in
let hof = all_pairs 1 (List.init size (fun _ -> (0., (Type.dummy, Type.dummy)))) types in
Format.printf "@[<v>%a@]@."
(CCList.pp ~pp_sep:(CCFormat.return "@ ")
(CCPair.pp CCFloat.pp (CCPair.pp Type.pp Type.pp)))
hof

let print_stat () =
let stats =
[|
Tracing.get_nb_ac (); Tracing.get_nb_arrow (); Tracing.get_nb_timeout ();
|]
in
Fmt.pr "@.Stats@.";
Format.printf "AC sol\tArrow sol\tTimeout@.";
Format.printf "@[%a@]@."
(CCArray.pp ~pp_sep:(CCFormat.return "\t") CCInt.pp)
stats;
Fmt.pr "@."

let main size idx_file =
let iter_idx =
let db =
try Db.load idx_file
with Sys_error _ ->
error @@ Fmt.str "cannot open index file `%a'" Fpath.pp idx_file
in
Db.iter db |> Iter.map snd
in
aux size iter_idx

let main size idx_file =
try Ok (main size idx_file) with Error msg -> Error (`Msg msg)

open Cmdliner
open Cmd

let size =
let docv = "size" in
let doc = "Number of function in the hall of fame." in
Arg.(value & opt int 10 & info [ "size" ] ~docv ~doc)

let idx_file =
let docv = "file" in
let doc = "Set index file." in
Arg.(value & opt Convs.file Paths.idx_file & info [ "index" ] ~docv ~doc)

let cmd =
let doc = "compute hall of fame" in
Cmd.v
(info "hof" ~sdocs:Manpage.s_common_options ~doc)
Term.(term_result (const main $ size $ idx_file))
1 change: 1 addition & 0 deletions bin/dowsindex/dowsindex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let cmds = [
CmdStats.cmd ;
CmdSearch.cmd ;
CmdUnifiable.cmd ;
CmdHOF.cmd ;
]

let main_cmd, main_info =
Expand Down

0 comments on commit 3204b8e

Please sign in to comment.