Skip to content

Commit 10bcbcc

Browse files
author
Ioana
committed
coding
1 parent 61dbfac commit 10bcbcc

File tree

12 files changed

+234
-165
lines changed

12 files changed

+234
-165
lines changed

ast.ml

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,47 +74,51 @@ let add_free_to_mix mix =
7474
{port_nme=p.port_nme;port_int=p.port_int; port_lnk=p_lnks}) pl in
7575
(n,pl')) mix
7676

77-
let split_ports_quarks count port =
77+
let split_port_quarks id_node id_port port =
7878
let quark_int = match port.port_int with
7979
| [] -> []
80-
| s::_ -> [(count,port.port_nme,(Rule.INT s))] in
80+
| s::_ -> [(id_node,id_port,(Rule.INT s))] in
8181
match port.port_lnk with
8282
| [] -> []
8383
| l::_ -> match l with
8484
| LNK_VALUE i ->
8585
let rule_lnk = Rule.LNK (Idgraph.LNK_VALUE i) in
86-
(count,port.port_nme,rule_lnk)::quark_int
86+
(id_node,id_port,rule_lnk)::quark_int
8787
| FREE ->
8888
let rule_lnk = Rule.LNK (Idgraph.FREE) in
89-
(count,port.port_nme,rule_lnk)::quark_int
89+
(id_node,id_port,rule_lnk)::quark_int
9090
| LNK_ANY -> quark_int
9191
| LNK_SOME | LNK_TYPE _ ->
9292
(raise (ExceptionDefn.Not_Supported
9393
("rules with side effects not supported")))
9494

95+
let split_ports_in_quarks count plist =
96+
let (_,qs) =
97+
List.fold_left (fun (i,acc) port ->
98+
(i+1,(split_port_quarks count i port)@acc))
99+
(0,[]) plist in
100+
qs
101+
95102
let create_quarks mixture count =
96103
List.fold_left
97-
(fun (qs,agent_names,count) ((name:string),plist) ->
98-
let qs' =
99-
List.fold_left
100-
(fun acc port -> (split_ports_quarks count port)@acc) [] plist in
101-
(qs'@qs,(count,name)::agent_names,count+1))
102-
([],[],count) mixture
103-
104-
let create_rhs_quarks agent_names mixture =
105-
let rec aux qs mixt count ag_nm =
104+
(fun (qs,agent_names,port_names,count) ((name:string),plist) ->
105+
let qs' = split_ports_in_quarks count plist in
106+
let ports = List.mapi (fun i p -> (i,p.port_nme)) plist in
107+
(qs'@qs,(count,name)::agent_names,(count,ports)::port_names,count+1))
108+
([],[],[],count) mixture
109+
110+
let create_rhs_quarks agent_names port_names mixture =
111+
let rec aux qs mixt count ag_nm po_nm =
106112
match mixt with
107113
| (name,plist)::mixt' ->
108114
if (((List.length ag_nm) >0)&&(List.mem (count,name) ag_nm)) then
109-
let qs' =
110-
List.fold_left
111-
(fun acc port -> (split_ports_quarks count port)@acc) [] plist in
112-
aux (qs'@qs) mixt' (count+1) ag_nm
115+
let qs' = split_ports_in_quarks count plist in
116+
aux (qs'@qs) mixt' (count+1) ag_nm po_nm
113117
else
114-
let (qs',ag_nm',_) = create_quarks mixt (List.length ag_nm) in
115-
(qs'@qs, ag_nm'@ag_nm)
116-
| [] -> (qs, ag_nm) in
117-
aux [] mixture 0 agent_names
118+
let (qs',ag_nm',po_nm',_) = create_quarks mixt (List.length ag_nm) in
119+
(qs'@qs, ag_nm'@ag_nm, po_nm')
120+
| [] -> (qs, ag_nm, po_nm) in
121+
aux [] mixture 0 agent_names port_names
118122

119123
let match_il il il' = match (il,il') with
120124
| (Rule.INT _,Rule.INT _) | (Rule.LNK _,Rule.LNK _) -> true
@@ -123,12 +127,12 @@ let match_il il il' = match (il,il') with
123127
let remove_quark (n,p,il) ls =
124128
List.filter
125129
(fun (n',p',il') ->
126-
(not((n=n')&&(String.equal p p')&&(match_il il il')))) ls
130+
(not((n=n')&&(p=p')&&(match_il il il')))) ls
127131

128132
let partition_quarks lhs_quarks rhs_quarks =
129133
let find (n,p,il) rhs =
130134
List.find (fun (n',p',il') ->
131-
(n=n')&&(String.equal p p')&&(match_il il il')) rhs in
135+
(n=n')&&(p=p')&&(match_il il il')) rhs in
132136
let (qlist,rhs)=
133137
List.fold_left
134138
(fun (qlist',rhs') (n,p,il) ->
@@ -158,26 +162,27 @@ let partition_quarks lhs_quarks rhs_quarks =
158162
(modified@qlist)
159163

160164
let create_prefix_map lhs rhs =
161-
let (lhs_quarks,lhs_agent_nm,_) = create_quarks lhs 0 in
162-
let (rhs_quarks,rhs_agent_nm) = create_rhs_quarks lhs_agent_nm rhs in
165+
let (lhs_quarks,lhs_an,lhs_pn,_) = create_quarks lhs 0 in
166+
let (rhs_quarks,rhs_an,rhs_pn) = create_rhs_quarks lhs_an lhs_pn rhs in
163167
let () = Format.printf "rhs_agent = ";
164-
List.iter (fun (c,n) -> Format.printf "(%d,%s) " c n) rhs_agent_nm in
165-
(partition_quarks lhs_quarks rhs_quarks,rhs_agent_nm)
168+
Maps.printn rhs_an; Maps.printp rhs_pn in
169+
(partition_quarks lhs_quarks rhs_quarks,rhs_an,rhs_pn)
166170

167171
let clean_rule = function
168172
| INIT mix ->
169-
let (quarks,agent_names) = create_prefix_map [] (add_free_to_mix mix) in
173+
let (quarks,agent_names,port_names) =
174+
create_prefix_map [] (add_free_to_mix mix) in
170175
let label = List.fold_left (fun acc (nme,_) -> acc^nme) "" mix in
171-
Rule.INIT (label,quarks,agent_names)
176+
Rule.INIT (label,quarks,agent_names,port_names)
172177
| OBS (name,mix) ->
173178
let mix' = add_free_to_mix mix in
174-
let (quarks,agent_names) = create_prefix_map mix' mix' in
175-
Rule.OBS (name,quarks,agent_names)
179+
let (quarks,agent_names,port_names) = create_prefix_map mix' mix' in
180+
Rule.OBS (name,quarks,agent_names,port_names)
176181
| RULE (name,r) ->
177182
let () = if (r.bidirectional) then
178183
(raise (ExceptionDefn.Not_Supported
179184
("bidirectional rules not supported"))) in
180185
let lhs = add_free_to_mix r.lhs in
181186
let rhs = add_free_to_mix r.rhs in
182-
let (quarks,agent_names) = create_prefix_map lhs rhs in
183-
Rule.RULE (name,quarks,agent_names)
187+
let (quarks,agent_names,port_names) = create_prefix_map lhs rhs in
188+
Rule.RULE (name,quarks,agent_names,port_names)

concret.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let concretise (s:LinearPoset.t) (rs:Rule.t list) =
2020
(Trace.empty,[]) s.LinearPoset.seq in
2121
trace
2222

23-
let test_concret (s:LinearPoset.t) (rs:Rule.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
@@ -37,5 +37,6 @@ let test_concret (s:LinearPoset.t) (rs:Rule.t list) =
3737
let () = if (!Parameter.debug_mode) then
3838
Transition.print trans in
3939
Trace.empty
40+
*)
4041

4142
let concret (s:Poset.t) (rs:Rule.t list) = concretise (linears s) rs

event.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let nodes_of_json (node:Yojson.Basic.json) =
3838
let () = if ((Quark.exists_mod clean_quarks [0;1])
3939
&&(Quark.exists_testmod clean_quarks [0;1])) then
4040
(raise (ExceptionDefn.NotKappa_Poset
41-
("quarks of init event not valid"))) in
41+
("quarks of obs event not valid"))) in
4242
{ event_id = id; event_label = label; quarks = clean_quarks; }
4343
| `List [`Int id; `String "INIT"; `List l;
4444
(`Assoc ["quarks", `List ql])] ->

lib.ml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(* interleave 1 [2;3] = [ [1;2;3]; [2;1;3]; [2;3;1] ] *)
2+
(*permutations [1; 2; 3] =
3+
[[1; 2; 3]; [2; 1; 3]; [2; 3; 1]; [1; 3; 2]; [3; 1; 2]; [3; 2; 1]] *)
14

25
let fst (a,b) = a
36
let snd (a,b) = b
@@ -16,16 +19,24 @@ let remove_duplicates l compare =
1619
| x :: xs -> go (remove_elt x xs compare) (x::acc)
1720
in go l []
1821

19-
(* interleave 1 [2;3] = [ [1;2;3]; [2;1;3]; [2;3;1] ] *)
2022
let rec interleave x lst =
21-
match lst with
22-
| [] -> [[x]]
23-
| hd::tl -> (x::lst) :: (List.map (fun y -> hd::y) (interleave x tl))
23+
match lst with
24+
| [] -> [[x]]
25+
| hd::tl -> (x::lst) :: (List.map (fun y -> hd::y) (interleave x tl))
2426

25-
(*permutations [1; 2; 3] =
26-
[[1; 2; 3]; [2; 1; 3]; [2; 3; 1]; [1; 3; 2]; [3; 1; 2]; [3; 2; 1]] *)
2727
let rec permutations lst =
28-
match lst with
29-
| hd::tl -> List.concat (List.map (interleave hd) (permutations tl))
30-
| _ -> [lst]
31-
;;
28+
match lst with
29+
| hd::tl -> List.concat (List.map (interleave hd) (permutations tl))
30+
| _ -> [lst]
31+
32+
let mapping list1 list combine =
33+
let list_of_list = permutations list in
34+
List.fold_left
35+
(fun acc list2 ->
36+
try
37+
let working_map =
38+
List.map2 (fun p1 p2 ->
39+
if (combine p1 p2) then (p1,p2)
40+
else (raise (ExceptionDefn.Mappings()))) list1 list2 in
41+
working_map::acc
42+
with ExceptionDefn.Mappings() -> acc) [] list_of_list

lib.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ val thd : 'a* 'b* 'c -> 'c
44

55
val remove_duplicates : 'a list -> ('a -> 'a -> bool) -> 'a list
66
val permutations : 'a list -> 'a list list
7+
val mapping : 'a list -> 'b list -> ('a -> 'b -> bool) -> ('a*'b) list list

notes/ts_graphs.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ \subsection{Transition systems}
152152
Let $t_1:M_1\overset{m_1,p_1}{\Rightarrow} N_1$ and $t_2:M_2\overset{m_2,p_2}{\Rightarrow} N_2$ be two transitions in a trace $\theta:t_1;t_1':t_2';\cdots t_n';t_2$ and let $p_1:L_1{\remb} D_1 {\lemb} R_1$ and $p_2:L_2{\remb} D_2 {\lemb} R_2$ be two corresponding rules. The morphism $M_1\pmorph M_2$ is the composition of $\spo(t_1)\circ\spo(t_1')\circ\dots\spo(t_n')$.
153153
\begin{description}
154154
\item[high res inhibition]
155-
Let the span $\spa:L_1\remb O\lemb L_2$ be the pullback of the cospan $L_1{\lemb}M{\remb}L_2$ in the multisum of $L_1$ and $L_2$ such that $p_1\redl{-}_{\spa} p_2$. If the diagram commutes
155+
Let the span $\spa:L_1\remb O\lemb L_2$ be the pullback of the cospan $L_1{\lemb}M{\remb}L_2$ in the multisum of $L_1$ and $L_2$ such that $p_2\redl{-}_{\spa} p_1$. If the diagram commutes
156156
\[
157157
\begin{tikzpicture} %[scale=0.8]
158158
\node (o) at (1,0) {\(O\)};
@@ -179,7 +179,7 @@ \subsection{Transition systems}
179179
\]
180180
then $t_2$ is high res inhibiting $t_1$, denoted $t_2 \Dashv t_1$.
181181
\item[low res inhibition]
182-
If there exists $\spa:L_1\remb O\lemb L_2$ such that $p_1\redl{-}_{\spa} p_2$ and such that the diagram commutes
182+
If there exists $\spa:L_1\remb O\lemb L_2$ such that $p_2\redl{-}_{\spa} p_1$ and such that the diagram commutes
183183
\[
184184
\begin{tikzpicture} %[scale=0.8]
185185
\node (o) at (1,0) {\(O\)};
@@ -326,7 +326,7 @@ \subsection{Transition systems}
326326

327327
\begin{definition}[Equivalence on transitions]
328328
\label{def:equiv_trans}
329-
Let $\sim$ be a binary relation on transitions such that $t_1\sim t_1'$ iff there exists $t_2$, $t_1\Diamond_{\text{par}} t_2$ and $t_1' = t_1/t_2$.
329+
Let $\sim$ be a binary relation on transitions such that $t_1\sim t_1'$ iff there exists $t_2$, $t_1\Diamond_{\text{par}} t_2$ and $t_1' = t_1/t_2$. We denote $\simeq$ the transitive and reflexive closure of $\sim$.
330330
%% \begin{itemize}
331331
%% \item there exists $t_2$, $t_2;t_1$, $\neg(t_2<t_2)$, $\neg(t_2\Diamond_{\text{seq}}t_1)$ and $t_1=t_1|t_2$.
332332
%% \end{itemize}

rule.ml

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,63 @@
11
type lnk_or_int = INT of string
22
| LNK of Idgraph.link
33

4-
type quark = Tested of (int*string*lnk_or_int)
5-
| TestedMod of ((int*string*lnk_or_int)*(int*string*lnk_or_int))
6-
| Modified of (int*string*lnk_or_int)
4+
type quark = Tested of (int*int*lnk_or_int)
5+
| TestedMod of ((int*int*lnk_or_int)*(int*int*lnk_or_int))
6+
| Modified of (int*int*lnk_or_int)
77

8-
type rule = string*(quark list)*((int*string) list)
8+
type rule = string*(quark list)*Maps.node_map*Maps.port_map
99

1010
type t = INIT of rule
1111
| OBS of rule
1212
| RULE of rule
1313

14-
let empty = RULE ("empty",[],[])
14+
let make_port pid il pname =
15+
let (internal,lnk) =
16+
(match il with
17+
| INT s -> ([s],[])
18+
| LNK lnk -> ([],[lnk])) in
19+
{ Idgraph.port_nme = pname;
20+
Idgraph.port_id = pid;
21+
Idgraph.port_int = internal;
22+
Idgraph.port_lnk = lnk;}
23+
24+
let make_agent aname pname = function
25+
| Modified (ag,p,il) ->
26+
let port = make_port p il pname in
27+
(aname,ag,[port])
28+
| _ -> (raise (ExceptionDefn.Internal_Error("make_agent")))
29+
30+
let empty = RULE ("empty",[],[],[])
1531

1632
let get_quarks = function
17-
| INIT (_,qs,_) | OBS (_,qs,_) | RULE (_,qs,_) -> qs
33+
| INIT (_,qs,_,_) | OBS (_,qs,_,_) | RULE (_,qs,_,_) -> qs
1834

1935
let get_node_map = function
20-
| INIT (_,_,nm) | OBS (_,_,nm) | RULE (_,_,nm) -> nm
36+
| INIT (_,_,nm,_) | OBS (_,_,nm,_) | RULE (_,_,nm,_) -> nm
37+
38+
let get_port_map = function
39+
| INIT (_,_,_,nm) | OBS (_,_,_,nm) | RULE (_,_,_,nm) -> nm
2140

2241
let get_agent = function
2342
Tested (ag,_,_) | TestedMod ((ag,_,_),_) | Modified (ag,_,_) -> ag
2443

2544
let get_port = function
2645
Tested (_,p,_) | TestedMod ((_,p,_),_) | Modified (_,p,_) -> p
2746

28-
let print_quarks qlist nmap =
47+
let get_il = function
48+
Tested (_,_,il) | TestedMod ((_,_,il),_) | Modified (_,_,il) -> il
49+
50+
let print_quarks qlist nmap pmap =
2951
let print_triple (n,p,il) =
3052
(try
31-
let (_,agent_name) = List.find (fun (id,na) -> id=n) nmap in
32-
Format.printf "(%s%d,%s," agent_name n p;
33-
with _ -> Format.printf "(%d,%s," n p);
53+
let (_,agent_name) = List.find (fun (id,na) -> id=n) nmap in
54+
Format.printf "(%s%d," agent_name n;
55+
(try
56+
let (_,plist) = List.find (fun (id,plist) -> id=n) pmap in
57+
let (_,port_name) = List.find (fun (idp,na) -> idp=p) plist in
58+
Format.printf "%s%d," port_name p;
59+
with _ -> Format.printf "%d" p);
60+
with _ -> Format.printf "(%d,%d" n p);
3461
(match il with
3562
INT i -> Format.printf "int=%s " i
3663
| LNK lnk ->
@@ -49,37 +76,22 @@ let print_quarks qlist nmap =
4976
List.iter (fun q -> print_q q) qlist
5077

5178
let print t =
52-
let print_rule (label,qs,nmap) =
53-
Format.printf "rule %s = " label; print_quarks qs nmap in
79+
let print_rule (label,qs,nmap,pmap) =
80+
Format.printf "rule %s = " label; print_quarks qs nmap pmap in
5481
match t with
5582
| INIT r -> Format.printf "\ninit ";print_rule r
5683
| OBS r -> Format.printf "\nobs ";print_rule r
5784
| RULE r -> Format.printf "\nrule ";print_rule r
5885

5986

6087
let get_label = function
61-
| INIT (name,_,_) | OBS (name,_,_) | RULE (name,_,_) -> name
88+
| INIT (name,_,_,_) | OBS (name,_,_,_) | RULE (name,_,_,_) -> name
6289

6390
let get_rule_by_label nme rules =
6491
List.find (fun r -> String.equal (get_label r) nme) rules
6592

66-
(*
67-
let get_rhs = function
68-
| INIT mix -> mix
69-
| OBS (name,mix) -> mix
70-
| RULE (name,r) -> r.rhs
71-
72-
let is_init = function
73-
| INIT _ -> true
74-
| OBS _ | RULE _ -> false
75-
76-
let is_obs = function
77-
| OBS _ -> true
78-
| INIT _ | RULE _ -> false
79-
*)
80-
8193
let filter_on_port p quarks =
82-
List.filter (fun q -> (String.equal (get_port q) p)) quarks
94+
List.filter (fun q -> (get_port q)=p) quarks
8395

8496
let filter_on_node n quarks =
8597
List.filter (fun q -> ((get_agent q)=n)) quarks
@@ -109,12 +121,11 @@ let mod_il = function Modified (_,_,il) -> (match il with
109121
| _ -> None
110122

111123
let find_replace (n1,n2) (p1,p2) quarks =
112-
let () = Format.printf "find_replace (%d,%d) (%s,%d)" n1 n2 p1 p2 in
113124
List.map (function
114-
|Tested (n,p,il) as q -> if ((n=n1)&&(String.equal p1 p)) then
115-
Tested (n2,p,il) else q
125+
|Tested (n,p,il) as q -> if ((n=n1)&&(p1=p)) then
126+
Tested (n2,p2,il) else q
116127
|TestedMod ((n,p,il),(_,_,il')) as q ->
117-
if ((n=n1)&&(String.equal p1 p)) then
118-
TestedMod ((n2,p,il),(n2,p,il')) else q
119-
|Modified (n,p,il) as q -> if ((n=n1)&&(String.equal p1 p)) then
120-
Modified (n2,p,il) else q) quarks
128+
if ((n=n1)&&(p1=p)) then
129+
TestedMod ((n2,p2,il),(n2,p2,il')) else q
130+
|Modified (n,p,il) as q -> if ((n=n1)&&(p1=p)) then
131+
Modified (n2,p2,il) else q) quarks

0 commit comments

Comments
 (0)