Skip to content

Commit acaa054

Browse files
author
Ioana
committed
up to matchings
1 parent 9d1ac81 commit acaa054

File tree

9 files changed

+130
-44
lines changed

9 files changed

+130
-44
lines changed

concret.ml

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,71 @@ let concretise s sigs =
1111
(fun trace eid ->
1212
let event = Poset.get_event_by_id eid s.LinearPoset.pos in
1313
let step = Event.get_step event in
14+
15+
let () = if (!Param.debug_mode) then
16+
(Format.printf "concret of event\n";
17+
Event.print_event event) in
18+
1419
let lhs_state =
1520
try Transition.get_rhs_state
1621
(TraceConcret.get_first_transition trace)
17-
with Failure s -> init_state in
18-
let (rhs_state,_) = Replay.do_step sigs lhs_state step in
19-
let trans = Transition.make lhs_state rhs_state in
22+
with Failure s -> init_state ~with_connected_components:false in
23+
24+
let () = if (!Param.debug_mode) then
25+
(Format.printf "lhs_state\n";
26+
Edges.debug_print (Format.std_formatter)
27+
(lhs_state.Replay.graph)) in
28+
let lhs_copy = Transition.copy_state lhs_state in
29+
let (rhs_state,_) = Replay.do_step sigs lhs_copy step in
30+
31+
let () = if (!Param.debug_mode) then
32+
(Format.printf "rhs_state\n";
33+
Edges.debug_print (Format.std_formatter)
34+
(rhs_state.Replay.graph)) in
35+
36+
let trans = Transition.make lhs_state rhs_state eid in
2037

2138
TraceConcret.add_transition trace trans)
2239
TraceConcret.empty s.LinearPoset.seq in
2340
trace
2441

25-
let concret s sigs = concretise (linears s) sigs
42+
let concret s sigs =
43+
let trace = concretise (linears s) sigs in
44+
List.rev trace
45+
46+
let context_of_application s1 s2 sigs env =
47+
let contact_map = Model.contact_map env in
48+
49+
let t1 = concret s1 sigs in
50+
let pt1 = TraceConcret.pattern_trace sigs contact_map t1 in
51+
let graph1 = TraceConcret.get_last_context pt1 in
52+
53+
let t2 = concret s2 sigs in
54+
let pt2 = TraceConcret.pattern_trace sigs contact_map t2 in
55+
let graph2 = TraceConcret.get_last_context pt2 in
56+
57+
let () = if (!Param.debug_mode) then
58+
(TraceConcret.print pt1 sigs;TraceConcret.print pt2 sigs) in
59+
let () = Format.printf "@.trace1 = ";TraceConcret.print pt1 sigs;
60+
Format.printf "@.trace2 = ";TraceConcret.print pt2 sigs;
61+
Format.printf "@.graph1 = "; Transition.print_side graph1 sigs ;
62+
Format.printf "@.graph2 = "; Transition.print_side graph2 sigs in
63+
let g1 = List.hd graph1 in
64+
let g2 = List.hd graph2 in
65+
let cc_list = Pattern.infs g1 g2 in
66+
let () = Format.printf "@.the infs =";
67+
List.iter (fun cc -> Pattern.print_cc ~new_syntax:true ~sigs:sigs
68+
~with_id:true
69+
(Format.std_formatter) cc;
70+
Format.printf ";; ")
71+
cc_list in
72+
let () =
73+
List.iter
74+
(fun cc ->
75+
List.iter (fun m ->
76+
Format.printf "@.matching %a@." Renaming.print_full m;
77+
(*let pushout = Pattern.pushout m g1 g2 in
78+
Format.printf "pushout =";
79+
Transition.print_side [pushout] sigs*))
80+
(Pattern.matchings cc g1)) cc_list in
81+
()

concret.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11

22
val concret : Poset.t -> Signature.s -> TraceConcret.s
3+
val context_of_application :
4+
Poset.t -> Poset.t -> Signature.s -> Model.t -> unit

event.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ let test_event event_id event_label =
1515
{ event_id; event_label; step = Trace.Dummy "none"; }
1616

1717
let print_event e =
18-
Format.printf " (%i, %s) " (e.event_id) (e.event_label)
18+
Format.printf "\n(%i, %s) " (e.event_id) (e.event_label)
19+
20+
let print_complete_event e =
21+
print_event e;Trace.print_step (Format.std_formatter) e.step;Format.printf"\n"
1922

2023
let nodes_of_json env = function
2124
| `List [`Int id; step_json] ->

formulas.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,9 @@ let obs = function
244244
| _ -> raise (ExceptDefn.Malformed_Args("obs"))
245245

246246
let negative_influence env = function
247-
(Domain.Pos p1, Domain.Pos p2) ->
247+
(Domain.Ev e1, Domain.Pos p1, Domain.Ev e2, Domain.Pos p2) ->
248248
let sigs = Model.signatures env in
249-
let t = Concret.concret p1 sigs in
250-
let pre_env = Pattern.minimal_env sigs contact_map in
251-
let pattern_trace = TraceConcret.pattern_trace contact_map sigs pre_env t in
252-
(* let () = if (!Param.debug_mode) then TraceConcret.print t sigs in*)
249+
let () = Concret.context_of_application p1 p2 sigs env in
253250
true
254251
| _ -> raise(ExceptDefn.Malformed_Args("negative_influence"))
255252

@@ -286,7 +283,7 @@ let interpretation env t =
286283
| ("equal_posets", [p1;p2]) -> equal_posets (p1,p2)
287284
| ("equal_events", [e1;e2]) -> equal_events (e1,e2)
288285
| ("sub_posets", [p1;p2]) -> sub_poset (p1,p2)
289-
| ("negative_influence", [p1;p2]) ->
290-
negative_influence env (p1,p2)
286+
| ("negative_influence", [e1;p1;e2;p2]) ->
287+
negative_influence env (e1,p1,e2,p2)
291288
| _ -> raise (ExceptDefn.Uninterpreted_Predicate(p)) in
292289
(func,pred,domain)

main.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,21 @@ let () =
8585
let json = Yojson.Basic.from_file (!env_file) in
8686
let env = Model.of_yojson json in
8787
let posets = Domain.set_posets (!files) env in
88+
let () = if (!Param.debug_mode) then Format.printf "read posets\n" in
8889
let fm_neg =
89-
(Formulas.Atom(
90-
Formulas.R("negative_influence",
91-
[Formulas.Var "s1";
92-
Formulas.Var "s2"]))) in
90+
Formulas.Exists
91+
("e2","Event",
92+
Formulas.Exists
93+
("e1","Event",
94+
(Formulas.Atom(
95+
Formulas.R("negative_influence",
96+
[Formulas.Var "e1"; Formulas.Var "s1";
97+
Formulas.Var "e2"; Formulas.Var "s2"]))))) in
9398

9499
let m = Formulas.interpretation env posets in
95100
let () = Format.printf "\n evaluate formula\n" in
96101
(evaluate fm_neg m empty_valuation)
97102

98-
99103
(* test_z3 posets*)
100104
(*
101105
let m = Formulas.interpretation posets in

traceConcret.ml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ type t = Transition.t list
55

66
let empty = []
77

8-
(*
9-
let print t sigs = List.iter (fun trans -> Transition.print trans sigs) t
10-
*)
11-
128
let get_first_transition t = List.hd t
139
let get_last_transition t = List.nth t ((List.length t)-1)
1410
let add_transition trace trans = trans::trace
1511

16-
let pattern_trace contact_map sigs pre_env trace =
12+
let pattern_trace sigs contact_map trace =
13+
let () = if (!Param.debug_mode) then Format.printf "pattern of trace\n" in
1714
List.map (fun trans ->
18-
Transition.pattern_transition contact_map sigs pre_env trans) trace
15+
Transition.pattern_transition sigs contact_map trans) trace
16+
17+
let print t sigs =
18+
List.iter
19+
(fun trans ->
20+
Transition.print_side trans.Transition.lhs sigs; Format.printf " => ") t;
21+
let trans = get_last_transition t in
22+
Transition.print_side trans.Transition.rhs sigs
23+
24+
let get_last_context t =
25+
let trans = get_last_transition t in
26+
trans.Transition.rhs

traceConcret.mli

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ type t = Transition.t list
33

44

55
val empty: s
6-
(*val print: t -> Signature.s -> unit*)
6+
val print: t -> Signature.s -> unit
77

88
val get_last_transition: s -> Transition.s
99
val get_first_transition: s -> Transition.s
1010
val add_transition: s -> Transition.s -> s
11-
val pattern_trace:
12-
(int list * (int * int) list) array array -> Signature.s ->
13-
Pattern.PreEnv.t -> s -> t
11+
val pattern_trace: Signature.s -> Contact_map.t -> s -> t
12+
val get_last_context: t -> Pattern.cc list

transition.ml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,49 @@ open Lib
33
type t = {
44
lhs: Pattern.cc list;
55
rhs: Pattern.cc list;
6+
eid: int;
67
}
78

89
type s = {
910
lhs_state: Replay.state;
1011
rhs_state: Replay.state;
12+
eid_state: int;
1113
}
1214

13-
let empty sigs = {lhs=[Pattern.empty_cc sigs];rhs=[Pattern.empty_cc sigs];}
15+
let empty sigs =
16+
{lhs=[Pattern.empty_cc sigs];rhs=[Pattern.empty_cc sigs];eid=(-1)}
17+
18+
let copy_state s = {
19+
Replay.graph = (Edges.copy s.Replay.graph); time=s.Replay.time;
20+
event = s.Replay.event;connected_components=s.Replay.connected_components;}
21+
22+
let copy s =
23+
{lhs_state = (copy_state s.lhs_state);
24+
rhs_state = (copy_state s.rhs_state);
25+
eid_state = s.eid_state}
26+
27+
let print_side s sigs =
28+
List.iter (fun cc -> Pattern.print_cc ~new_syntax:true ~sigs:sigs
29+
~with_id:true
30+
(Format.std_formatter) cc ) s;
31+
Format.printf "\n"
1432

1533
let print t sigs =
16-
Format.printf "\ntransition\n";
17-
List.iter (fun cc ->
18-
Pattern.print_cc ~new_syntax:true ~sigs:sigs
19-
(Format.std_formatter) cc ) t.lhs;
20-
Format.printf " => ";
21-
List.iter (fun cc ->
22-
Pattern.print_cc ~new_syntax:true ~sigs:sigs
23-
(Format.std_formatter) cc) t.rhs
24-
25-
let pattern_transition contact_map sigs pre_env s =
34+
Format.printf "\ntransition\n"; print_side t.lhs sigs;
35+
Format.printf " => "; print_side t.rhs sigs
36+
37+
let pattern_transition sigs contact_map s =
38+
let pre_env = Pattern.PreEnv.empty sigs in
2639
let lhs_state = s.lhs_state in
2740
let (_,lhs) =
2841
Snip.patterns_of_mixture contact_map sigs pre_env
2942
(lhs_state.Replay.graph) in
43+
let pre_env = Pattern.PreEnv.empty sigs in
3044
let rhs_state = s.rhs_state in
3145
let (_,rhs) =
3246
Snip.patterns_of_mixture contact_map sigs pre_env
3347
(rhs_state.Replay.graph) in
34-
{lhs;rhs}
48+
{lhs;rhs;eid=(s.eid_state)}
3549

3650
let get_rhs_state s = s.rhs_state
37-
let make lhs_state rhs_state = {lhs_state;rhs_state}
51+
let make lhs_state rhs_state eid_state = {lhs_state;rhs_state;eid_state}

transition.mli

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
type t = {
22
lhs: Pattern.cc list;
33
rhs: Pattern.cc list;
4+
eid: int;
45
}
56

67
type s = {
78
lhs_state: Replay.state;
89
rhs_state: Replay.state;
10+
eid_state: int;
911
}
1012

1113
val empty : Signature.s -> t
1214
val print : t -> Signature.s -> unit
15+
val print_side : Pattern.cc list -> Signature.s -> unit
1316

1417
val get_rhs_state : s -> Replay.state
15-
val make : Replay.state -> Replay.state -> s
18+
val make : Replay.state -> Replay.state -> int -> s
1619

17-
val pattern_transition:
18-
(int list * (int * int) list) array array -> Signature.s ->
19-
Pattern.PreEnv.t -> s -> t
20+
val pattern_transition: Signature.s -> Contact_map.t -> s -> t
21+
val copy_state: Replay.state -> Replay.state
22+
val copy: s -> s

0 commit comments

Comments
 (0)