-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.sml
65 lines (57 loc) · 2.2 KB
/
driver.sml
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
structure Driver =
struct
val inputfiles = Params.paramacc []
(SOME("-f", "File containing JSON encoded input", #","))
"file"
val timep = Params.param "60"
(SOME("-t", "Time limit, in seconds to produce output"))
"timeout"
val memp = Params.param "1024"
(SOME("-m", "Memory limit, in megabytes, to produce output"))
"mem"
val cores = Params.param "1"
(SOME("-c", "Number of processor cores available"))
"cores"
val power = Params.paramacc []
(SOME("-p", "Phrase of power", #","))
"phrase"
fun solve_problem time file =
let val problem = Board.fromjson file
fun obj_of_sol sol seed_idx =
"{ \"problemId\": " ^ Int.toString (Board.id problem) ^ ",\n" ^
"\"seed\": " ^
Int.toString (Word32.toInt (Vector.sub
(Board.seeds problem,
seed_idx))) ^ ",\n" ^
"\"tag\": \"CBV\",\n" ^
"\"solution\": \"" ^ sol ^ "\"\n}"
in
Vector.foldli (fn (seed_idx, _, s) =>
let val sol =
Solutions.best_solution {seconds = time,
problem = problem,
seed_idx = seed_idx,
power = !power}
in
s ^ obj_of_sol sol seed_idx ^ ",\n"
end)
""
(Board.seeds problem)
end
fun main () =
case !inputfiles of
nil => print "No input files.\n"
| _ =>
let
fun seeds_for_prob file =
Vector.length (Board.seeds (Board.fromjson file))
val seeds = List.foldl op+ 0 (List.map seeds_for_prob (!inputfiles))
val time = Int.div (Params.asint 60 timep, seeds)
val sols = List.map (solve_problem time) (!inputfiles)
val s = "[" ^ String.concat sols
val s' = String.substring (s, 0, (String.size s) - 2) ^ "]"
in
print s'
end
end
val () = Params.main0 "Takes no arguments" Driver.main