Skip to content

Commit 949132b

Browse files
author
Ioana
committed
working day
1 parent fceefa7 commit 949132b

19 files changed

+442
-356
lines changed

ast.ml

Lines changed: 51 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,16 @@ type agent = (string * port list)
1616

1717
type mixture = agent list
1818

19-
type lnk_or_int = INT of string
20-
| LNK of link
21-
22-
type q = int*string*lnk_or_int
23-
24-
type quarks = Tested of q list
25-
| TestedMod of (q*q) list
26-
| Modified of q list
27-
2819
type rule = {
2920
lhs: mixture ;
3021
bidirectional: bool ;
3122
rhs: mixture ;
32-
prefix_map : quarks list;
3323
}
24+
3425
type t = INIT of mixture
3526
| OBS of string*mixture
3627
| RULE of string*rule
3728

38-
3929
let add_free_to_port_lnk plinks = match plinks with
4030
| [] -> [FREE]
4131
| ls -> ls
@@ -53,25 +43,35 @@ let add_free_to_mix mix =
5343
let split_ports_quarks count port =
5444
let quark_int = match port.port_int with
5545
| [] -> []
56-
| s::_ -> [(count,port.port_nme,(INT s))] in
46+
| s::_ -> [(count,port.port_nme,(Rule.INT s))] in
5747
match port.port_lnk with
5848
| [] -> []
59-
| l::_ -> (count,port.port_nme,(LNK l))::quark_int
49+
| l::_ -> match l with
50+
| LNK_VALUE i ->
51+
let rule_lnk = Rule.LNK (Idgraph.LNK_VALUE i) in
52+
(count,port.port_nme,rule_lnk)::quark_int
53+
| FREE ->
54+
let rule_lnk = Rule.LNK (Idgraph.FREE) in
55+
(count,port.port_nme,rule_lnk)::quark_int
56+
| LNK_ANY -> quark_int
57+
| LNK_SOME | LNK_TYPE _ ->
58+
(raise (ExceptionDefn.Not_Supported
59+
("rules with side effects not supported")))
6060

6161
let create_quarks mixture count =
6262
List.fold_left
63-
(fun (qs,agent_names,count) (name,plist) ->
63+
(fun (qs,agent_names,count) ((name:string),plist) ->
6464
let qs' =
6565
List.fold_left
6666
(fun acc port -> (split_ports_quarks count port)@acc) [] plist in
67-
(qs'@qs,(name,count)::agent_names,count+1))
67+
(qs'@qs,(count,name)::agent_names,count+1))
6868
([],[],count) mixture
6969

7070
let create_rhs_quarks agent_names mixture =
7171
let rec aux qs mixt count ag_nm =
7272
match mixt with
7373
| (name,plist)::mixt' ->
74-
if (List.mem (name,count) ag_nm) then
74+
if (List.mem (count,name) ag_nm) then
7575
let qs' =
7676
List.fold_left
7777
(fun acc port -> (split_ports_quarks count port)@acc) [] plist in
@@ -83,7 +83,7 @@ let create_rhs_quarks agent_names mixture =
8383
aux [] mixture 0 agent_names
8484

8585
let match_il il il' = match (il,il') with
86-
| (INT _,INT _) | (LNK _,LNK _) -> true
86+
| (Rule.INT _,Rule.INT _) | (Rule.LNK _,Rule.LNK _) -> true
8787
| _ -> false
8888

8989
let remove_quark (n,p,il) ls =
@@ -95,52 +95,55 @@ let partition_quarks lhs_quarks rhs_quarks =
9595
let find (n,p,il) rhs =
9696
List.find (fun (n',p',il') ->
9797
(n=n')&&(String.equal p p')&&(match_il il il')) rhs in
98-
let (tested,tested_mod,rhs)=
98+
let (qlist,rhs)=
9999
List.fold_left
100-
(fun (tested,tested_mod,rhs) (n,p,il) ->
101-
if (List.mem (n,p,il) rhs_quarks) then
102-
(((n,p,il)::tested),tested_mod,(remove_quark (n,p,il) rhs))
100+
(fun (qlist',rhs') (n,p,il) ->
101+
if (List.mem (n,p,il) rhs') then
102+
let new_quark = Rule.Tested (n,p,il) in
103+
(new_quark::qlist',(remove_quark (n,p,il) rhs'))
103104
else
104105
let (n',p',il') =
105-
(try (find (n,p,il) rhs)
106+
(try (find (n,p,il) rhs')
106107
with _ ->
107108
(raise
108109
(ExceptionDefn.Syntax_Error
109110
("agent does not have the same ports in lhs and rhs")))) in
110-
(tested,((n,p,il),(n',p',il'))::tested_mod,
111-
(remove_quark (n,p,il) rhs)))
112-
([],[],rhs_quarks) lhs_quarks in
113-
let () =
114-
List.iter (fun (ag,_,_) ->
115-
List.iter
116-
(fun (ag',_,_) ->
117-
if (ag=ag') then
118-
(raise
119-
(ExceptionDefn.Syntax_Error
120-
("agent does not have the same ports
121-
in lhs and rhs")))) rhs)
122-
tested in
123-
(tested,tested_mod,rhs)
111+
let new_quark = Rule.TestedMod ((n,p,il),(n',p',il')) in
112+
(new_quark::qlist',(remove_quark (n,p,il) rhs')))
113+
([],rhs_quarks) lhs_quarks in
114+
let modified =
115+
List.map
116+
(fun ((ag,_,_) as q) ->
117+
let () =
118+
List.iter (fun q -> if (ag=(Rule.get_agent q)) then
119+
(raise
120+
(ExceptionDefn.Syntax_Error
121+
("agent does not have the same ports
122+
in lhs and rhs")))) qlist in
123+
Rule.Modified q) rhs in
124+
(modified@qlist)
124125

125126
let create_prefix_map lhs rhs =
126127
let (lhs_quarks,lhs_agent_nm,_) = create_quarks lhs 0 in
127128
let (rhs_quarks,rhs_agent_nm) = create_rhs_quarks lhs_agent_nm rhs in
128-
let (t_quarks,tm_quarks,m_quarks) =
129-
partition_quarks lhs_quarks rhs_quarks in
130-
[Tested t_quarks; TestedMod tm_quarks; Modified m_quarks]
131-
132-
let clean_rules = function
133-
| INIT mix -> INIT (add_free_to_mix mix)
134-
| OBS (name,mix) -> OBS (name,add_free_to_mix mix)
129+
(partition_quarks lhs_quarks rhs_quarks,rhs_agent_nm)
130+
131+
let clean_rule = function
132+
| INIT mix ->
133+
let (quarks,agent_names) = create_prefix_map (add_free_to_mix mix) [] in
134+
let label = List.fold_left (fun acc (nme,_) -> acc^nme) "" mix in
135+
Rule.INIT (label,quarks,agent_names)
136+
| OBS (name,mix) ->
137+
let (quarks,agent_names) = create_prefix_map [] (add_free_to_mix mix) in
138+
Rule.OBS (name,quarks,agent_names)
135139
| RULE (name,r) ->
136140
let () = if (r.bidirectional) then
137141
(raise (ExceptionDefn.Not_Supported
138142
("bidirectional rules not supported"))) in
139143
let lhs = add_free_to_mix r.lhs in
140144
let rhs = add_free_to_mix r.rhs in
141-
let r' = {lhs; bidirectional=r.bidirectional;rhs;
142-
prefix_map = (create_prefix_map lhs rhs)} in
143-
RULE (name,r')
145+
let (quarks,agent_names) = create_prefix_map lhs rhs in
146+
Rule.RULE (name,quarks,agent_names)
144147

145148
let print_link = function
146149
| LNK_VALUE i -> Format.printf "!%d" i
@@ -149,27 +152,6 @@ let print_link = function
149152
| LNK_SOME -> Format.printf "!_"
150153
| LNK_TYPE (i,a) -> Format.printf "!%s.%s" i a
151154

152-
let print_quarks qs =
153-
let print_q (n,p,il) =
154-
Format.printf "(%d,%s," n p;
155-
(match il with
156-
INT i -> Format.printf "int=%s " i
157-
| LNK lnk ->
158-
Format.printf "lnk= "; print_link lnk);
159-
Format.printf ")" in
160-
let print_qlist qlist =
161-
List.iter (fun q -> print_q q) qlist in
162-
match qs with
163-
| Tested qlist ->
164-
Format.printf "\nTested: "; print_qlist qlist
165-
| Modified qlist ->
166-
Format.printf "\nModified: "; print_qlist qlist
167-
|TestedMod qqlist ->
168-
Format.printf "\nTestedMod ";
169-
List.iter (fun (q1,q2) ->
170-
Format.printf"[before = ";print_q q1;Format.printf "] ";
171-
Format.printf"[after = ";print_q q2;Format.printf "] ") qqlist
172-
173155
let print_port p =
174156
Format.printf "%s~[" p.port_nme;
175157
List.iter (fun intern -> Format.printf "%s " intern;) p.port_int;
@@ -185,42 +167,13 @@ let print_rule r =
185167
List.iter (fun a -> print_agent a) r.lhs;
186168
if (r.bidirectional) then Format.printf " <-> "
187169
else Format.printf " -> ";
188-
List.iter (fun a -> print_agent a) r.rhs;
189-
List.iter (fun quarks -> print_quarks quarks) r.prefix_map
170+
List.iter (fun a -> print_agent a) r.rhs
190171

191172
let print = function
192173
| INIT mix -> Format.printf "\n init "; List.iter (fun a -> print_agent a) mix
193174
| OBS (name,mix) -> Format.printf "\n obs '%s' " name;
194175
List.iter (fun a -> print_agent a) mix
195176
| RULE (name,r) -> Format.printf "\n rule '%s' " name; print_rule r
196177

197-
let empty_rule = {lhs =[];rhs=[];bidirectional=false;prefix_map=[]}
198-
178+
let empty_rule = {lhs =[];rhs=[];bidirectional=false;}
199179
let empty = RULE ("empty",empty_rule)
200-
201-
let get_label = function
202-
| INIT mix -> List.fold_left (fun acc (nme,_) -> acc^nme) "" mix
203-
| OBS (name,_) -> name
204-
| RULE (name,_) -> name
205-
206-
let get_rule_by_label nme rules =
207-
List.find
208-
(fun r -> String.equal (get_label r) nme) rules
209-
210-
let get_lhs = function
211-
| INIT mix -> []
212-
| OBS (name,mix) -> mix
213-
| RULE (name,r) -> r.lhs
214-
215-
let get_rhs = function
216-
| INIT mix -> mix
217-
| OBS (name,mix) -> mix
218-
| RULE (name,r) -> r.rhs
219-
220-
let is_init = function
221-
| INIT _ -> true
222-
| OBS _ | RULE _ -> false
223-
224-
let is_obs = function
225-
| OBS _ -> true
226-
| INIT _ | RULE _ -> false

ast.mli

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,10 @@ type agent = (string * port list)
1616

1717
type mixture = agent list
1818

19-
type lnk_or_int = INT of string
20-
| LNK of link
21-
22-
type q = int*string*lnk_or_int
23-
24-
type quarks = Tested of q list
25-
| TestedMod of (q*q) list
26-
| Modified of q list
2719
type rule = {
2820
lhs: mixture ;
2921
bidirectional:bool ;
3022
rhs: mixture ;
31-
prefix_map : quarks list ;
3223
}
3324

3425
type t = INIT of mixture
@@ -42,12 +33,4 @@ val print : t -> unit
4233

4334
(* the parser returns the empty list for a free link
4435
we replace the empty list in link with [FREE] *)
45-
val clean_rules : t -> t
46-
47-
val get_label : t -> String.t
48-
val get_rule_by_label : String.t -> t list -> t
49-
50-
val get_lhs : t -> mixture
51-
val get_rhs : t -> mixture
52-
val is_init : t -> bool
53-
val is_obs : t -> bool
36+
val clean_rule : t -> Rule.t

concret.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
let linears s =
32
LinearPoset.linearisations(s)
43

5-
let concretise (s:LinearPoset.t) (rs:Ast.t list) =
4+
let concretise (s:LinearPoset.t) (rs:Rule.t list) =
65
let () = if (!Parameter.debug_mode) then
76
(Format.printf "concretise linear poset :";
87
List.iter (fun i -> Format.printf "%d " i) s.LinearPoset.seq) in
@@ -11,31 +10,32 @@ let concretise (s:LinearPoset.t) (rs:Ast.t list) =
1110
(fun (trace,rf) eid ->
1211
let event = Poset.get_event_by_id eid s.LinearPoset.pos in
1312
let rname = Event.get_label event in
14-
let rule = Ast.get_rule_by_label rname rs in
13+
let rule = Rule.get_rule_by_label rname rs in
1514
let m = Transition.get_rhs (Trace.get_first_transition trace) in
16-
let trans = Transition.make m rule (Event.get_quarks event) in
17-
((Trace.add_transition trace trans), ((eid,trans)::rf)))
18-
(* else (raise (ExceptionDefn.NotKappa_Poset *)
19-
(* ("quarks of event "^rname^" not valid")))) *)
15+
let (trans,new_nodes,new_ports) =
16+
Transition.make m rule (Event.get_quarks event)
17+
trace.Trace.node_names trace.Trace.port_names in
18+
((Trace.add_transition trace trans new_nodes new_ports),
19+
((eid,trans)::rf)))
2020
(Trace.empty,[]) s.LinearPoset.seq in
2121
trace
2222

23-
let test_concret (s:LinearPoset.t) (rs:Ast.t list) =
23+
let test_concret (s:LinearPoset.t) (rs:Rule.t list) =
2424
let () = if (!Parameter.debug_mode) then
2525
(Format.printf "concretise linear poset :";
2626
List.iter (fun i -> Format.printf "%d " i) s.LinearPoset.seq) in
2727
let event = Poset.get_event_by_id 4 s.LinearPoset.pos in
2828
let rname = Event.get_label event in
29-
let rule = Ast.get_rule_by_label rname rs in
29+
let rule = Rule.get_rule_by_label rname rs in
3030

3131
let () = if (!Parameter.debug_mode) then
3232
(Format.printf "info on first event ";
3333
Event.print_event event;
34-
Ast.print rule) in
34+
Rule.print rule) in
3535

36-
let trans = Transition.make [] rule (Event.get_quarks event) in
36+
let (trans,_,_) = Transition.make [] rule (Event.get_quarks event) [] [] in
3737
let () = if (!Parameter.debug_mode) then
3838
Transition.print trans in
3939
Trace.empty
4040

41-
let concret (s:Poset.t) (rs:Ast.t list) = concretise (linears s) rs
41+
let concret (s:Poset.t) (rs:Rule.t list) = concretise (linears s) rs

concret.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
val concret : Poset.t -> Ast.t list -> Trace.t
2+
val concret : Poset.t -> Rule.t list -> Trace.t

formulas.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ val holds : (string -> Domain.domain list -> Domain.domain) *
2121
(Domain.domain list) ->
2222
(string -> Domain.domain) -> Domain.domain fol formula -> bool
2323

24-
val interpretation : Domain.t -> Ast.t list ->
24+
val interpretation : Domain.t -> Rule.t list ->
2525
(string -> Domain.domain list -> Domain.domain) *
2626
(string -> Domain.domain list -> bool) *
2727
Domain.domain list

grammar/parserRule.mly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ start_rule:
2424
rule_expression:
2525
| rule_label lhs_rhs arrow lhs_rhs
2626
{ Ast.RULE ($1,({Ast.lhs=$2; Ast.bidirectional=$3;
27-
Ast.rhs=$4;Ast.prefix_map=[]}))}
27+
Ast.rhs=$4}))}
2828
;
2929

3030
arrow:

main.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ let parse_rules () =
6161
let lexbuf = Lexing.from_channel chan in
6262
while true do
6363
let result = ParserRule.newline LexerRule.token lexbuf in
64-
let free_res = Ast.clean_rules result in
65-
read_rule := free_res::(!read_rule);
64+
let rule = Ast.clean_rule result in
65+
read_rule := rule::(!read_rule);
6666
if (!Parameter.debug_mode) then
67-
(Format.printf "parsing \n"; Ast.print result;Format.printf"\n")
67+
(Format.printf "parsing \n"; Ast.print result;
68+
Format.printf " becomes \n"; Rule.print rule;Format.printf "\n")
6869
done
6970
with LexerRule.Eof -> ()
7071

notes/bio.bib

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,13 @@ @proceedings{DBLP:conf/fsttcs/1992
9292
timestamp = {Wed, 03 Jul 2002 10:23:36 +0200},
9393
biburl = {http://dblp.uni-trier.de/rec/bib/conf/fsttcs/1992},
9494
bibsource = {dblp computer science bibliography, http://dblp.org}
95+
}
96+
97+
@misc{RussInfluence,
98+
author = {Russ Harmer},
99+
title = {Lecture notes in Rule-based modeling},
100+
month = {October},
101+
year = {2016},
102+
publisher={ENS Lyon},
103+
url = {http://perso.ens-lyon.fr/russell.harmer/rbm.html}
95104
}

notes/grammar.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ \section{Logic on posets}
3232

3333
\subsection{Grammar}
3434

35-
Let $R$ a set of labels, $\mathcal{S}$ a set of posets and let $\varepsilon = \cup_{s_i\in S} E_i$ be the set of events in $\mathcal{S}$, where $E_i$ is the set of events in $s_i$.
36-
We denote $A,B$ elements of $R$ and $s$ elements of $\mathcal{S}$.
35+
Let $\mathcal{R}$ be a set of labels, $\mathcal{S}$ be a set of posets and let $\varepsilon = \cup_{s_i\in S} E_i$ be the set of events in $\mathcal{S}$, where $E_i$ is the set of events in $s_i$.
36+
We denote $A,B$ elements of $\mathcal{R}$ and $s$ elements of $\mathcal{S}$.
3737

3838
\begin{align*}
3939
x ::= & x^e ~|~ x^s & \tag{variables on events and posets} \\

0 commit comments

Comments
 (0)