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

Fix: the worst evil demon was wrong for no strictly decreasing potential function

parent 75dfd3a9
No related branches found
No related tags found
No related merge requests found
(* Time-stamp: <modified the 24/08/2020 (at 15:39) by Erwan Jahier> *)
(* Time-stamp: <modified the 27/08/2020 (at 18:06) by Erwan Jahier> *)
......@@ -20,8 +20,9 @@ let rec (comp : 'a cont -> 'a cont -> 'a cont) =
let (enumerate : 'a list list -> 'a list cont) = fun all ->
let rec f acc all =
let res = match all with
| [] -> Elt(acc, fun () -> NoMore)
| []::tl -> f acc tl
| [] ->
if acc = [] then NoMore else Elt(acc, fun () -> NoMore)
| []::tl -> f acc tl
| al::tl ->
List.fold_left
(fun cont_acc a ->
......@@ -33,13 +34,14 @@ let (enumerate : 'a list list -> 'a list cont) = fun all ->
in
res
in
assert(List.exists (fun l -> l<>[]) all);
f [] all
module StringMap = Map.Make(String)
module StringSet = Set.Make(String)
(* split [all] into connected components *)
let (connected_components : 'v pna list list -> 'v pna list list list) =
let (_connected_components : 'v pna list list -> 'v pna list list list) =
fun all ->
let pid2pnal =
List.fold_left
......@@ -107,25 +109,26 @@ let (worst: 'v Env.t -> ('v Process.t * 'v Register.neighbor list) list ->
match Register.get_potential () with
| None -> failwith "No potential function has been provided"
| Some user_pf ->
let pf pnal = (* pnal contains a list of activated processes *)
let pidl = List.map (fun (p,_) -> p.Process.pid) p_nl_l in
let p_a_l = List.map (fun (p,_,a) -> p.Process.pid, a) pnal in
let ne = Step.f pnal e in
let get_info pid =
{
Register.neighbors = snd (List.find (fun (p,_) -> p.Process.pid = pid) p_nl_l);
Register.curr = Env.get e pid ;
Register.next = Env.get ne pid ;
Register.action = List.assoc_opt pid p_a_l
}
in
user_pf pidl get_info
in
let alll = time "connected component" connected_components all in
let cpt = ref 0 in
let res_l =
List.map
(fun all ->
let pf pnal = (* pnal contains a list of activated processes *)
let pidl = List.map (fun (p,_) -> p.Process.pid) p_nl_l in
let p_a_l = List.map (fun (p,_,a) -> p.Process.pid, a) pnal in
let ne = Step.f pnal e in
let get_info pid =
{
Register.neighbors = snd (List.find (fun (p,_) -> p.Process.pid = pid) p_nl_l);
Register.curr = Env.get e pid ;
Register.next = Env.get ne pid ;
Register.action = List.assoc_opt pid p_a_l
}
in
user_pf pidl get_info
in
(*let alll = time "connected component" connected_components all in*)
let alll = [all] in
let cpt = ref 0 in
let res_l =
List.map
(fun all ->
let pnal1, p1, shedules =
match time "enumerate" enumerate all with
| NoMore -> assert false
......@@ -135,18 +138,18 @@ let (worst: 'v Env.t -> ('v Process.t * 'v Register.neighbor list) list ->
match shedules with
| NoMore -> (pnal_acc, v_acc)
| Elt(pnal, c) ->
incr cpt;
let v = pf pnal in
if v < v_acc
then search_max (pnal_acc, v_acc) (c())
else search_max (pnal, v) (c())
incr cpt;
let v = pf pnal in
if v < v_acc
then search_max (pnal_acc, v_acc) (c())
else search_max (pnal, v) (c())
in
fst (time2 "search" search_max (pnal1, p1) (shedules()))
)
alll
in
Printf.printf "Number of connected components: %i (%i)\n%!" (List.length alll) !cpt;
List.flatten res_l
)
alll
in
Printf.printf "Number of connected components: %i (%i)\n%!" (List.length alll) !cpt;
List.flatten res_l
(* exported *)
let (bad: int -> 'v Env.t -> 'v pna list list -> 'v pna list) =
......
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