File: mccs_test.ml

package info (click to toggle)
ocaml-mccs 1.1%2B19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,804 kB
  • sloc: cpp: 3,889; ml: 269; sh: 166; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 1,399 bytes parent folder | download | duplicates (3)
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
(* usage: mccs_test CUDF_FILE [SOLVER [CRITERIA]] *)

let (preamble, universe, request) as cudf =
  match Cudf_parser.load_from_file Sys.argv.(1) with
  | Some a, b, Some c -> a, b, c
  | None, b, Some c -> Cudf.default_preamble, b, c
  | _ -> assert false

(* let () =
 *   Printf.printf "## REQUEST ##\n";
 *   Cudf_printer.pp_cudf stdout (preamble, Cudf.load_universe (Mccs.get_problem_packages (Mccs.problem_of_cudf cudf)), request);
 *   Printf.printf "####\n\n%!" *)

let criteria =
  if Array.length Sys.argv <= 3 then "-removed,-count[version-lag,request],-count[version-lag,changed],-changed"
  else Sys.argv.(3)

let solver =
  if Array.length Sys.argv <= 2 then `GLPK
  else match Sys.argv.(2) with
    | "glpk" -> `GLPK
    | "coin" -> `COIN_CBC
    | "coin/clp" -> `COIN_CLP
    | "coin/cbc" -> `COIN_CBC
    | "coin/symphony" -> `COIN_SYMPHONY
    | s when String.length s > 3 && String.sub s 0 3 = "lp+" ->
      `LP (String.sub s 3 (String.length s - 3))
    | s -> Printf.ksprintf failwith "Unknown solver %s" s

let solve () =
  Mccs.resolve_cudf ~solver criteria cudf

let () =
  try
  match solve () with
  | None -> print_endline "FAIL"
  | Some sol ->
    Printf.printf "\n## SOLUTION ##\n";
    Cudf_printer.pp_solution stdout sol;
    Printf.printf "####\n%!"
  with Mccs.Timeout -> Printf.eprintf "Timeout!\n%!"
     | Sys.Break -> Printf.eprintf "User pressed CTRL+C!\n%!"