config.ml 1.55 KiB
open Algo
open State
open P
let debug = false
let rec (pot : pid -> (pid -> ('a * ('a neighbor*pid) list)) -> int -> int -> int) =
fun pid get level acc ->
(* From a pid and its level, adds to acc the potential of the tree
rooted in pid *)
let s, nl = get pid in
let nl2 = List.map fst nl in
let acc = if P.enable_f s nl2 <> [] then (
if debug then Printf.printf "%s -> acc=%d+%d\n%!" pid acc level ;
acc+level
)
else acc in
List.fold_left (fun acc (_, pid) -> pot pid get (level+1) acc) acc nl
(* The potential is defined as the sum of enabled nodes levels (the
level is 1 for root, 2 for its children, and so on *)
let (pf: pid list -> (pid -> ('a * ('a neighbor * pid) list)) -> float) =
fun pidl get ->
let root_pot = pot "root" get 1 0 in
if debug then (
let enab pid =
let v,nl = get pid in
if P.enable_f v (List.map fst nl) = [] then
""
else
pid
in
let enab_list = List.map enab pidl in
Printf.printf "=================> potential(%s) = %d\n%!" (String.concat "," enab_list) root_pot
);
(* (String.concat "," (List.map (fun pid -> Printf.sprintf "%s=%b" get pid) pidl) root_pot ; *)
float_of_int root_pot
let potential = Some pf
let legitimate = None (* None => only silent configuration are legitimate *)
let fault = None
open State
let maxi = 2*k+1
let s2n s = [I (0, s.alpha, maxi)]
let n2s nl s =
match nl with
| [I(_, i, _)] -> { s with alpha = i }
| _ -> assert false
let init_search_utils = Some (s2n, n2s)