X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Feval.ml;h=0ef0d5d9b0765bbddc8ee7ad8477347bbc404b86;hp=8f8652e9759ec41f358b5c64a13e466ec9fb8b29;hb=41dd1fed04cabad212f10fce3484545f6e9d9444;hpb=3c87bbf00b98bcf40dab913cd334846b26cdb71d diff --git a/src/eval.ml b/src/eval.ml index 8f8652e..0ef0d5d 100644 --- a/src/eval.ml +++ b/src/eval.ml @@ -13,10 +13,6 @@ (* *) (***********************************************************************) -(* - Time-stamp: -*) - INCLUDE "utils.ml" open Format @@ -34,95 +30,103 @@ DEFINE TRACE(e) = (e) DEFINE TRACE(e) = () END + let html tree node i config msg = + let config = config.Ata.Config.node in + Html.trace (T.preorder tree node) i + "node: %i
%s
sat: %a
unsat: %a
todo: %around: %i
" + (T.preorder tree node) + msg + StateSet.print config.Ata.sat + StateSet.print config.Ata.unsat + (Ata.TransList.print ~sep:"
") config.Ata.todo i + - type cache = StateSet.t Cache.N1.t - let get c t n = Cache.N1.find c (T.preorder t n) + type run = { config : Ata.Config.t array; + unstable : Bitvector.t; + mutable redo : bool; + mutable pass : int; + } - let set c t n v = Cache.N1.add c (T.preorder t n) v - let top_down_run auto tree node cache _i = - let redo = ref false in + let top_down_run auto tree node run = + let module Array = + struct + include Array + let get a i = + if i < 0 then Ata.dummy_config else get a i + let unsafe_get a i = + if i < 0 then Ata.dummy_config else unsafe_get a i + end + in + let cache = run.config in + let unstable = run.unstable in + let _i = run.pass in let rec loop node = - if node != T.nil then begin + let node_id = T.preorder tree node in + if node == T.nil || not (Bitvector.get unstable node_id) then false else begin let parent = T.parent tree node in let fc = T.first_child tree node in + let fc_id = T.preorder tree fc in let ns = T.next_sibling tree node in + let ns_id = T.preorder tree ns in let tag = T.tag tree node in let config0 = - let c = get cache tree node in - if c == Cache.N1.dummy cache then - { c with Ata.todo = Ata.get_trans auto tag auto.Ata.states } + let c = cache.(node_id) in + if c == Ata.dummy_config then + Ata.Config.make + { c.Ata.Config.node with + Ata.todo = Ata.get_trans auto tag auto.Ata.states; + summary = Ata.node_summary + (node == T.first_child tree parent) (* is_left *) + (node == T.next_sibling tree parent) (* is_right *) + (fc != T.nil) (* has_left *) + (ns != T.nil) (* has_right *) + (T.kind tree node) (* kind *) + } else c in - let () = - TRACE(Html.trace (T.preorder tree node) _i "Config0
sat: %a
unsat: %a
todo: %a
" - StateSet.print config0.Ata.sat - StateSet.print config0.Ata.unsat - (Ata.TransList.print ~sep:"
") config0.Ata.todo) - in + TRACE(html tree node _i config0 "Entering node"); - let ps = get cache tree parent in - let fcs = get cache tree fc in - let nss = get cache tree ns in - let is_left = node == T.first_child tree parent - and is_right = node == T.next_sibling tree parent - and has_left = fc != T.nil - and has_right = ns != T.nil - and kind = T.kind tree node - in - let config1 = - Ata.eval_trans2 auto fcs nss ps config0 - is_left is_right has_left has_right kind - in - let () = - TRACE(Html.trace (T.preorder tree node) _i "Config1
sat: %a
unsat: %a
todo: %a
" - StateSet.print config1.Ata.sat - StateSet.print config1.Ata.unsat - (Ata.TransList.print ~sep:"
") config1.Ata.todo) - in - if not (Ata.eq_config config0 config1) then set cache tree node config1; - let () = loop fc in - let fcs1 = get cache tree fc in - let config2 = - Ata.eval_trans2 auto - fcs1 nss ps config1 - is_left is_right has_left has_right kind - in - let () = - TRACE(Html.trace (T.preorder tree node) _i "Config2
sat: %a
unsat: %a
todo: %a
" - StateSet.print config2.Ata.sat - StateSet.print config2.Ata.unsat - (Ata.TransList.print ~sep:"
") config2.Ata.todo) - in + let ps = cache.(T.preorder tree parent) in + let fcs = cache.(fc_id) in + let nss = cache.(ns_id) in + let config1 = Ata.eval_trans auto fcs nss ps config0 in - if not (Ata.eq_config config1 config2) then set cache tree node config2; - let () = loop ns in - let config3 = - Ata.eval_trans2 auto - fcs1 (get cache tree ns) ps config2 - is_left is_right has_left has_right kind - in - let () = - TRACE(Html.trace (T.preorder tree node) _i "Config3
sat: %a
unsat: %a
todo: %a
" - StateSet.print config3.Ata.sat - StateSet.print config3.Ata.unsat - (Ata.TransList.print ~sep:"
") config3.Ata.todo) + TRACE(html tree node _i config1 "Updating transitions"); + + if config0 != config1 then cache.(node_id) <- config1; + let unstable_left = loop fc in + let fcs1 = cache.(fc_id) in + let config2 = Ata.eval_trans auto fcs1 nss ps config1 in + + TRACE(html tree node _i config2 "Updating transitions (after first-child)"); + + if config1 != config2 then cache.(node_id) <- config2; + let unstable_right = loop ns in + let nss1 = cache.(ns_id) in + let config3 = Ata.eval_trans auto fcs1 nss1 ps config2 in + + TRACE(html tree node _i config3 "Updating transitions (after next-sibling)"); + + if config2 != config3 then cache.(node_id) <- config3; + let unstable_self = + unstable_left + || unstable_right + || Ata.(TransList.nil != config3.Config.node.todo) in - if not (Ata.eq_config config2 config3) then set cache tree node config3; - (* We do set the redo flat if : *) - if not ( - !redo (* already set *) - || (Ata.TransList.nil == config3.Ata.todo) (* no more transition to check *) - || (Ata.eq_config config0 config3) (* did not gain any new information *) - ) - then redo := true + Bitvector.unsafe_set unstable node_id unstable_self; + TRACE((if not unstable_self then + Html.finalize_node + node_id + _i + Ata.(StateSet.intersect config3.Config.node.sat auto.selection_states))); + unstable_self end in - loop node; - !redo + loop node let get_results auto tree node cache = let rec loop node acc = @@ -131,29 +135,49 @@ END let acc0 = loop (T.next_sibling tree node) acc in let acc1 = loop (T.first_child tree node) acc0 in - if StateSet.intersect (get cache tree node).Ata.sat auto.Ata.selection_states then - node::acc1 - else - acc1 + if Ata.( + StateSet.intersect + cache.(T.preorder tree node).Config.node.sat + auto.selection_states) then node::acc1 + else acc1 in loop node [] + + let stats run = + let count = ref 0 in + let len = Bitvector.length run.unstable in + for i = 0 to len - 1 do + if not (Bitvector.unsafe_get run.unstable i) then + incr count + done; + Logger.msg `STATS + "%i nodes over %i were skipped in iteration %i (%.2f %%), redo is: %b" + !count len run.pass (100. *. (float !count /. float len)) + run.redo + + let eval auto tree node = - let cache = Cache.N1.create { Ata.sat = StateSet.empty; - Ata.unsat = StateSet.empty; - Ata.todo = Ata.TransList.nil } + let len = T.size tree in + let run = { config = Array.create len Ata.dummy_config; + unstable = Bitvector.create ~init:true len; + redo = true; + pass = 0 + } in - let redo = ref true in - let iter = ref 0 in - Ata.reset auto; - while !redo do - redo := false; - redo := top_down_run auto tree node cache !iter; - incr iter; + while run.redo do + run.redo <- false; + Ata.reset auto; (* prevents the .cache2 and .cache4 memoization tables from growing too much *) + run.redo <- top_down_run auto tree node run; + stats run; + run.pass <- run.pass + 1; done; - at_exit (fun () -> eprintf "INFO: %i iterations\n" !iter); - let r = get_results auto tree node cache in + at_exit (fun () -> Logger.msg `STATS "%i iterations" run.pass); + at_exit (fun () -> stats run); + let r = get_results auto tree node run.config in + TRACE(Html.gen_trace (module T : Tree.S with type t = T.t) (tree)); + r end