Skip to content
Snippets Groups Projects
Commit d9d1abfd authored by erwan's avatar erwan
Browse files

Refactor: coloring/p.ml

parent 294cb67c
No related branches found
No related tags found
No related merge requests found
(* Time-stamp: <modified the 20/03/2019 (at 13:18) by Erwan Jahier> *)
(* Time-stamp: <modified the 10/05/2019 (at 10:04) by Erwan Jahier> *)
(* This is algo 3.1 in the book *)
......@@ -12,25 +12,26 @@ let (init_vars: neighbor list -> local_env) =
function _ -> I (Random.int k)
let (used : neighbor list -> Algo.value list) = fun nl ->
let (clash : neighbor list -> Algo.value list) = fun nl ->
let res = List.map (fun n -> n.lenv "c") nl in
res
let (free : neighbor list -> Algo.value list) = fun nl ->
let used_list = List.sort_uniq compare (used nl) in
let rec aux free used i =
let clash_list = List.sort_uniq compare (clash nl) in
let rec aux free clash i =
if i > k then free else
(match used with
| x::tail -> if x = I i then aux free tail (i+1) else aux ((I i)::free) used (i+1)
| [] -> aux ((I i)::free) used (i+1)
(match clash with
| x::tail ->
if x = I i then aux free tail (i+1) else aux ((I i)::free) clash (i+1)
| [] -> aux ((I i)::free) clash (i+1)
)
in
let res = aux [] used_list 0 in
let res = aux [] clash_list 0 in
List.rev res
let (enable_f:neighbor list -> local_env -> action list) =
fun nl e ->
if List.mem (e "c") (used nl) then ["conflict"] else []
if List.mem (e "c") (clash nl) then ["conflict"] else []
let (step_f : neighbor list -> local_env -> action -> local_env) =
fun nl e ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment