How to optimize these ocaml functions for dynamic interval planning?

I have a program that solves the weighted task of scheduling intervals using dynamic programming (and believe it or not, this is not for homework). I have profiled it, and I seem to spend most of my time filling M with p (...). Here are the functions:

let rec get_highest_nonconflicting prev count start =
  match prev with
      head :: tail -> 
    if head < start then 
      count
    else
      get_highest_nonconflicting tail (count - 1) start
    | [] -> 0;;

let m_array = Array.make (num_genes + 1) 0;;    

let rec fill_m_array ?(count=1) ?(prev=[]) gene_spans  = 
  match gene_spans with
      head :: tail -> m_array.(count) <- 
    get_highest_nonconflicting prev (count - 1) (get_start head);
    fill_m_array tail ~prev:(get_stop (head) :: prev) ~count:(count+1);
    | [] -> ();;

I cannot think of any ways to optimize this, and based on my knowledge of this algorithm, this seems to be the place that is likely to take the longest. But this is also my second OCaml program. So is it possible to optimize this?

+3
1

. , , , ?

, get_highest_nonconflicting. , , ( -, ), .

, , , -consing ( ).

+2

Source: https://habr.com/ru/post/1721876/


All Articles