Commit 51bcc0ee authored by bguillaum's avatar bguillaum

replace list by set in new strategies applications

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@9148 7838e531-6607-4d57-9587-6c381814729c
parent 22883cb3
......@@ -347,32 +347,32 @@ module Grs = struct
Rule.one_step ?domain: grs.domain name inst modul.Modul.rules
end
(* Union of strategies *)
| Ast.Plus strat_list -> List_.flat_map (loop inst) strat_list
| Ast.Plus strat_list ->
List.fold_left (fun acc strat -> Instance_set.union acc (loop inst strat)) Instance_set.empty strat_list
(* Sequence of strategies *)
| Ast.Seq [] -> Log.fcritical "Empty sequence in strategy definition"
| Ast.Seq [one] -> loop inst one
| Ast.Seq (head::tail) ->
let after_first_mod = loop inst head in
List_.flat_map (fun new_inst -> loop new_inst (Ast.Seq tail)) after_first_mod
Instance_set.fold (fun new_inst acc -> Instance_set.union acc (loop new_inst (Ast.Seq tail))) after_first_mod Instance_set.empty
(* Interation of a strategy *)
| Ast.Star sub_strat ->
begin
match loop inst sub_strat with
| [] -> [inst]
| l -> List_.flat_map (fun new_inst -> loop new_inst (Ast.Star sub_strat)) l
end
let one_iter = loop inst sub_strat in
if Instance_set.is_empty one_iter
then Instance_set.singleton inst
else Instance_set.fold (fun new_inst acc -> Instance_set.union acc (loop new_inst (Ast.Star sub_strat))) one_iter Instance_set.empty
(* Diamond *)
| Ast.Diamond sub_strat ->
begin
match one_rewrite grs sub_strat inst with
| Some new_inst -> [new_inst]
| None -> []
| Some new_inst -> Instance_set.singleton new_inst
| None -> Instance_set.empty
end
(* Old style seq definition *)
| Ast.Sequence module_list -> loop inst (new_style grs module_list) in
List.map
(fun inst -> inst.Instance.graph)
(loop (Instance.from_graph graph) (Parser.strat_def strat_desc))
(Instance_set.elements (loop (Instance.from_graph graph) (Parser.strat_def strat_desc)))
......@@ -472,7 +472,7 @@ module Grs = struct
begin
printf "%s one_step (module=%s)...%!" (String.make (2 * (max 0 !indent)) ' ') modul.Modul.name;
let domain = get_domain grs in
match Rule.one_step ?domain modul.Modul.name instance modul.Modul.rules with
match Instance_set.elements (Rule.one_step ?domain modul.Modul.name instance modul.Modul.rules) with
| [] -> printf "0\n%!"; let res = Libgrew_types.Empty in decr indent; res
| instance_list -> printf "%d\n%!" (List.length instance_list);
Libgrew_types.Node
......
......@@ -1041,7 +1041,7 @@ module Rule = struct
if List.length instance.Instance.rules >= !max_depth_non_det
then
if !debug_loop
then []
then Instance_set.empty
else Error.run "[Module %s] max depth %d reached, last rules applied: …, %s"
modul_name !max_depth_non_det (List_.rev_to_string (fun x->x) ", " (List_.cut 5 instance.Instance.rules))
else
......@@ -1050,10 +1050,10 @@ module Rule = struct
let matching_list = match_in_graph ?domain ?param:rule.param rule.pattern instance.Instance.graph in
List.fold_left
(fun acc1 matching ->
try (apply_rule ?domain modul_name instance matching rule) :: acc1
try Instance_set.add (apply_rule ?domain modul_name instance matching rule) acc1
with Command_execution_fail -> acc1
) acc matching_list
) [] rules
) Instance_set.empty rules
(* ---------------------------------------------------------------------- *)
(** [conf_one_step ?domain modul_name instance rules] computes one Some (one-step reduct) with rules, None if no rule apply *)
......@@ -1113,7 +1113,7 @@ module Rule = struct
let (new_to_do_set,new_nf_set) =
Instance_set.fold
(fun v (to_do_set_acc,nf_set_acc) ->
match one_step ?domain modul_name v rules with
match Instance_set.elements (one_step ?domain modul_name v rules) with
| [] -> (to_do_set_acc,Instance_set.add (Instance.rev_steps v) nf_set_acc)
| step_of_v -> (List.fold_left (fun acc v1 -> Instance_set.add v1 acc) to_do_set_acc step_of_v, nf_set_acc)
)
......
......@@ -96,7 +96,7 @@ module Rule : sig
Instance.t ->
Instance_set.t * Instance_set.t
val one_step: ?domain: Domain.t -> string -> Instance.t -> t list -> Instance.t list
val one_step: ?domain: Domain.t -> string -> Instance.t -> t list -> Instance_set.t
val conf_one_step: ?domain: Domain.t -> string -> Instance.t -> t list -> Instance.t option
(** the type matching encodes the graph morphism from a pattern to a graph *)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment