Skip to content
Snippets Groups Projects
root.ml 918 B
Newer Older
(* Time-stamp: <modified the 18/06/2019 (at 22:40) by Erwan Jahier> *)

(* This is algo 5.3 in the book *)

open Algo
open P
    
let (init_state: int -> 'v) =
  fun i ->
    {
      P.d = Random.int P.d;
      P.par = -1;
    }   

let (enable_f:'v neighbor list -> 'v -> action list) =
  fun nl st ->
    if st.d <> 0 then ["CD"] else []
let (step_f : 'v neighbor list -> 'v -> action -> 'v) =
  fun _nl st ->
    function  | _ -> { st with P.d = 0 }
  Algo.register {
    algo = [
      {
        algo_id = "root";
        init_state = init_state;
        actions = Some ["CD"];
        enab = enable_f;
        step = step_f;          
      };
      {
        algo_id = "p";
        init_state = P.init_state;
        actions = Some P.actions;
        enab = P.enable_f;
        step = P.step_f;          
      }
    ];
    state_to_string = P.state_to_string;
    copy_state = P.copy_state;
  }