<commit_before>open Core.Std

type pop = { x: int; y: int; capacity: int }
type call = { x: int; y: int; time: int; duration: int }
type connection = { i: int; call: int; pop: int; time: int }

type invalid_pop = {connection: int; pop: int}
type invalid_call = {connection: int; call: int}
type invalid_time = {connection: int; time: int; call_time: int}
type pop_full = {connection: int; pop: int; time: int; free_time: int}
type used_call = {connection1: int; connection2: int; call: int}

exception Invalid_pop of invalid_pop
exception Invalid_call of invalid_call
exception Invalid_time of invalid_time
exception Pop_full of pop_full
exception Already_used_call of used_call

let score pops (calls : call array) connections =
  let queues = Array.init (Array.length pops)
      ~f:(fun i -> Heap.create ~min_size:(pops.(i).capacity) ~cmp:compare ()) in
  let connected = Array.create ~len:(Array.length calls) (-1) in
  let add_connection score connection =
    let {i; call; pop; time} = connection in
    if pop < 0 || pop >= Array.length pops
    then raise (Invalid_pop {connection = i; pop})
    else if call < 0 || call >= Array.length calls
    then raise (Invalid_call {connection = i; call})
    else if connected.(call) >= 0
    then raise (Already_used_call {connection1 = i; connection2 = connected.(call); call})
    else if time < calls.(call).time
    then raise (Invalid_time {connection = i; time; call_time =  calls.(call).time})
    else if (Heap.length queues.(pop)) = pops.(pop).capacity then
      begin
        let top = Heap.pop_exn queues.(pop) in
        if top > time
        then raise (Pop_full {connection = i; pop; time; free_time = top})
      end;
    connected.(call) <- i;
    if false then
      printf "Connection %d: Adding call %d to POP %d at time %d with duration %d until %d\n"
        (i + 1) call pop time calls.(call).duration (time + (calls.(call).duration));
    Heap.add queues.(pop) (time + calls.(call).duration);
    (* Ranking by distance *)
    let call = calls.(call) in
    let pop = pops.(pop) in
    let xdiff = (Float.of_int call.x) -. (Float.of_int pop.x) in
    let ydiff = (Float.of_int call.y) -. (Float.of_int pop.y) in<commit_msg>Remove debugging output<commit_after>open Core.Std

type pop = { x: int; y: int; capacity: int }
type call = { x: int; y: int; time: int; duration: int }
type connection = { i: int; call: int; pop: int; time: int }

type invalid_pop = {connection: int; pop: int}
type invalid_call = {connection: int; call: int}
type invalid_time = {connection: int; time: int; call_time: int}
type pop_full = {connection: int; pop: int; time: int; free_time: int}
type used_call = {connection1: int; connection2: int; call: int}

exception Invalid_pop of invalid_pop
exception Invalid_call of invalid_call
exception Invalid_time of invalid_time
exception Pop_full of pop_full
exception Already_used_call of used_call

let score pops (calls : call array) connections =
  let queues = Array.init (Array.length pops)
      ~f:(fun i -> Heap.create ~min_size:(pops.(i).capacity) ~cmp:compare ()) in
  let connected = Array.create ~len:(Array.length calls) (-1) in
  let add_connection score connection =
    let {i; call; pop; time} = connection in
    if pop < 0 || pop >= Array.length pops
    then raise (Invalid_pop {connection = i; pop})
    else if call < 0 || call >= Array.length calls
    then raise (Invalid_call {connection = i; call})
    else if connected.(call) >= 0
    then raise (Already_used_call {connection1 = i; connection2 = connected.(call); call})
    else if time < calls.(call).time
    then raise (Invalid_time {connection = i; time; call_time =  calls.(call).time})
    else if (Heap.length queues.(pop)) = pops.(pop).capacity then
      begin
        let top = Heap.pop_exn queues.(pop) in
        if top > time
        then raise (Pop_full {connection = i; pop; time; free_time = top})
      end;
    connected.(call) <- i;
    Heap.add queues.(pop) (time + calls.(call).duration);
    (* Ranking by distance *)
    let call = calls.(call) in
    let pop = pops.(pop) in
    let xdiff = (Float.of_int call.x) -. (Float.of_int pop.x) in
    let ydiff = (Float.of_int call.y) -. (Float.of_int pop.y) in
{'fraction_non_alphanumeric': 0.125712927756654, 'fraction_numerical': 0.004039923954372623, 'mean_word_length': 3.4586864406779663, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5839528', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1343, 'n_words': 487}