DBtk: a Toolkit for Directed Bigraphs Giorgio Bacci Davide Grohmann Marino Miculan Department of Mathematics and Computer Science University of Udine, Italy CALCO-tools, September, 6 2009 1 / 40
DBtk: a Toolkit for Directed Bigraphs
Giorgio Bacci Davide Grohmann Marino Miculan
Department of Mathematics and Computer ScienceUniversity of Udine, Italy
CALCO-tools, September, 6 2009
1 / 40
Outline
Part 1 - Introduction to (Directed) Bigraphical Frameworks
+ Directed Bigraphs
+ Directed Bigraphical Reactive Systems (DBRS)
+ How to derive LTSs from (DB)RSs
Part 2 - DBtk: a toolkit for Directed Bigraphs
+ Basic structures and operations
+ Algebra
+ Compilation and Drawing
+ Matching (Simulation via a DBRS)
+ RPO/IPO construction for LTSs upon DBRSs
2 / 40
Outline
Part 1 - Introduction to (Directed) Bigraphical Frameworks
+ Directed Bigraphs
+ Directed Bigraphical Reactive Systems (DBRS)
+ How to derive LTSs from (DB)RSs
Part 2 - DBtk: a toolkit for Directed Bigraphs
+ Basic structures and operations
+ Algebra
+ Compilation and Drawing
+ Matching (Simulation via a DBRS)
+ RPO/IPO construction for LTSs upon DBRSs
2 / 40
Bigraphical Models
+ Bigraphical models are an emerging framework forconcurrency and mobility.
+ Long term aim: “to express as much as possible of worldwidedistributed computing in one mathematical model” (Milner2001).
+ Bigraphs aim to be such a framework, i.e., unifying model forcomputations based on communications and locality.
+ Many calculi have been represented in bigraphs: CCS,π-calculus, Petri nets, . . .
+ . . . but they can be applied also for dealing with SystemsBiology! (as shown yesterday at MeCBIC 2009)
3 / 40
Example of a Directed Bigraph
A directed bigraph has nodes, edges and links.
0
v0
v1
v2
01
x y
e0
w
e1
1
v3
v4
2
e2
e3
z
u
Nodes
Each node v0, v1, . . . , has an arity (i.e. a set of ports);
4 / 40
Example of a Directed Bigraph
A directed bigraph has nodes, edges and links.
0
v0
v1
v2
01
x y
e0
w
e1
1
v3
v4
2
e2
e3
z
u
Edges
Edges e0, e1, . . . represent global resources.
4 / 40
Example of a Directed Bigraph
A directed bigraph has nodes, edges and links.
0
v0
v1
v2
01
x y
e0
w
e1
1
v3
v4
2
e2
e3
z
u
Ports
Ports “ask for connections” to resources.
4 / 40
Example of a Directed Bigraph
A directed bigraph has nodes, edges and links.
0
v0
v1
v2
01
x y
e0
w
e1
1
v3
v4
2
e2
e3
z
u
Placing
Nodes can be nested, instead edges are not subject to positions.Sites are holes which can be fitted by roots of another bigraph.
4 / 40
Example of a Directed Bigraph
A directed bigraph has nodes, edges and links.
0
v0
v1
v2
01
x y
e0
w
e1
1
v3
v4
2
e2
e3
z
u
Links
Links describes the access/request of resources by nodes.
4 / 40
Example of a Directed Bigraph
A directed bigraph has nodes, edges and links.
0
v0
v1
v2
01
x y
e0
w
e1
1
v3
v4
2
e2
e3
z
u
Names
Names x , y , z , . . . are “channels” through which controls can giveor request access to resources.
4 / 40
directed bigraph = place graph + directed link graph
directed bigraph
G : 〈3, ({w}, {u})〉 → 〈2, ({x , z}, {y})〉
0
v0
v1
v2
01
x y
e0
w
e1
1
v3
v4
2
e2
e3
z
u
place graph
GP : 3→ 2
0
v0 v2
v1 1
0
1
v3
v4 2
directed link graph
GL : ({w}, {u})→ ({x , z}, {y})
v0 v1
v2
x y
e0
w
e1
v3
v4
e2
e3
z
u
5 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
door is active
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
door is active
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
door is passive
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
door is passive
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
door is passive
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
door is passive
6 / 40
Dynamics: Reaction rules
A signature is a typing over nodes.
door key
A reaction rule is a pair of (parametric) bigraphs.
x x
key is atomic
door is not atomic
Reaction application: matching a rule with a sub-graph.
x y
door is passive
6 / 40
Why another graph-based (meta)model?
Answer
Bigraphs allow for deriving good Labelled Transition System fromsimple Reactive Systems.Where good means the bisimulation on the LTS is a congruence!
How to do that?
By the Leifer-Milner approach: define and use only the minimalinteractions between the agent and the environment.
Our chosen model: Directed Bigraphs
+ They allow for the definition of LTS using the aboveconstruction.
+ They have some encoding methodologies for representing realworld systems and calculi.
7 / 40
Relative and Idem Pushouts [Leifer, Milner 2000]
The “minimality” can be elegantly expressed as a universalcategorical property.
f1f0
h1h0
g1g0
h
f1f0
h1h0
g1g0 h
j k1
k0
k
f1f0
h1h0
g1g0 id
(1) (2) (3)
Fig. 6. A candidate RPO (1), an RPO (2) and an IPO (3).
add v2 to h0 and connect its port to the edge e1 in f0, to do so, there are twopossibility to target e1: trough the name y or trough the name z.
7 Related and future work
Related work. The closest work is Birkedal et al. [1], where a language and amatching algoritm for binding bigraphs are presented. That work has been ofinspiration for our matching inference system, although we had to change quitemany details both in the rules and in the implementation due to the fact thatwe consider directed bigraphs and not binding bigraphs. Also, as far as we know,DBtk provides the first constructions of RPOs and IPOs for bigraphs.
Future work. The present system is still a prototype, and needs some refinementsto mature to a ready-to-use tool. Among the features that can be added, wemention a graphical user interface (GUI), where the user can “draw” interactivelya bigraph, a reaction rule and ultimately a whole BRSs. Another interestingdevelopment will be to consider stochastic bigraphic reactive systems, where rulesare endowed with rates. We think that the matching procedure given in thispaper can be successfully used within a Gillespie algorithm.
Acknowledgements. We thank our students Raul Pellarini, Patrik Osgnach, Fe-derico Chiabai for their help in developing the code.
References
1. L. Birkedal, T. C. Damgaard, A. J. Glenstrup, and R. Milner. Matching of bigraphs.ENTCS, 175(4):3–19, 2007.
2. D. Grohmann and M. Miculan. Directed bigraphs. In Proc. XXIII MFPS, ENTCS,173:121–137. Elsevier, 2007.
3. D. Grohmann and M. Miculan. Reactive systems over directed bigraphs. InProc. CONCUR 2007, LNCS 4703, pages 380–394. Springer-Verlag, 2007.
4. D. Grohmann and M. Miculan. An algebra for directed bigraphs. In Proceedings ofTERMGRAPH 2007, ENTCS 203(1):49–63. Elsevier, 2008.
5. O. H. Jensen, R. Milner. Bigraphs and transitions. In Proc. POPL, 38–49, 2003.6. J. J. Leifer and R. Milner. Transition systems, link graphs and petri nets. Mathe-
matical Structures in Computer Science, 16(6):989–1047, 2006.7. R. Milner. Bigraphical reactive systems. In Proc. 12th CONCUR, LNCS 2154, pages
16–35. Springer, 2001.
Call g0, g1 a bound for f0, f1 if g0 ◦ f0 = g1 ◦ f1.
1. A relative bound (h0, h1, h) for f0, f1 to g0, g1.
2. A relative pushout (RPO) (h0, h1, h) for f0, f1 to g0, g1: for anyother relative bound (k0, k1, k), there is a unique mediator j .
3. A idem pushout (IPO) g0, g1 for f0, g1: (g0, g1, id) is an RPOfor f0, f1 to g0, g1.
8 / 40
Relative Pushouts: a simple example
Processes
P ::= a | P1|P2
Contexts
C ::= − | C |P | P|C
a|b b|c
−|c |d |e a| − |d |e
−|c a|−
−|d |e−|c |d a| − |d
−|e
−|d
9 / 40
Relative Pushouts: a simple example
Processes
P ::= a | P1|P2
Contexts
C ::= − | C |P | P|C
a|b b|c
−|c |d |e a| − |d |e
−|c a|−
−|d |e−|c |d a| − |d
−|e
−|d
9 / 40
Relative Pushouts: a simple example
Processes
P ::= a | P1|P2
Contexts
C ::= − | C |P | P|C
a|b b|c
−|c |d |e a| − |d |e
−|c a|−
−|d |e−|c |d a| − |d
−|e
−|d
9 / 40
Relative Pushouts: a simple example
Processes
P ::= a | P1|P2
Contexts
C ::= − | C |P | P|C
a|b b|c
−|c |d |e a| − |d |e
−|c a|−
−|d |e−|c |d a| − |d
−|e
−|d
9 / 40
Relative Pushouts: a simple example
Processes
P ::= a | P1|P2
Contexts
C ::= − | C |P | P|C
a|b b|c
−|c |d |e a| − |d |e
−|c a|−
−|d |e−|c |d a| − |d
−|e
−|d
9 / 40
Idem Pushouts: a simple example
Processes
P ::= a | P1|P2
Contexts
C ::= − | C |P | P|C
a|b b|c
−|c a|−
−|c a|−
−
10 / 40
Idem Pushouts: a simple example
Processes
P ::= a | P1|P2
Contexts
C ::= − | C |P | P|C
a|b b|c
−|c a|−
−|c a|−
−
10 / 40
LTSs from RSs and IPOs
Given a reactive system (by means of a set of reaction rules)
an IPO transition aL−→ a′ is defined when
there exist a reaction rule (r , r ′) and anactive context D, such that (L,D) is anIPO for (a, r) and a′ = D ◦ r ′.
ar
L
D
r ′
a′
Labels are only the contexts which form an IPO, that is, theminimal completion context for a that allows a reaction to takeplace, that is L ◦ a = D ◦ r (and then L ◦ a rewrites into D ◦ r ′).
Theorem (Leifer, Milner 2000)
The bisimilarity derived from an IPO LTS is a congruence.
11 / 40
Outline
Part 1 - Introduction to (Directed) Bigraphical Frameworks
+ Directed Bigraphs
+ Directed Bigraphical Reactive Systems (DBRS)
+ How to derive LTSs from (DB)RSs
Part 2 - DBtk: a toolkit for Directed Bigraphs
+ Basic structures and operations
+ Algebra
+ Compilation and Drawing
+ Matching (Simulation via a DBRS)
+ RPO/IPO construction for LTSs upon DBRSs
12 / 40
Architecture of DBtk
Core Module
Language(DBL)
Drawing (SVG)LTS: RPOsand IPOs
Matchingcompiler
decompiler
visualizer
verification
simulation
13 / 40
Architecture of DBtk
Core Module
Language(DBL)
Drawing (SVG)LTS: RPOsand IPOs
Matchingcompiler
decompiler
visualizer
verification
simulation
13 / 40
Core Module
The Core Module is divided in two sub-modules.
Data structures and operations
+ Data structures (i.e., objects) for representing directedbigraphs (and also place graphs and directed link graphs);.
+ Procedure for tensoring bigraphs by juxtaposing them.
+ Procedure for composing bigraphs by putting the roots of the“lower” one inside the holes of the “upper” one, and bypasting the same names.
Algebra
+ Constructor for elementary bigraphs.
+ Normalization procedure, which takes a bigraph and yields itback in discrete normal form.
+ Derived operations.
14 / 40
Core Module
The Core Module is divided in two sub-modules.
Data structures and operations
+ Data structures (i.e., objects) for representing directedbigraphs (and also place graphs and directed link graphs);.
+ Procedure for tensoring bigraphs by juxtaposing them.
+ Procedure for composing bigraphs by putting the roots of the“lower” one inside the holes of the “upper” one, and bypasting the same names.
Algebra
+ Constructor for elementary bigraphs.
+ Normalization procedure, which takes a bigraph and yields itback in discrete normal form.
+ Derived operations.
14 / 40
Tensor product
G0 : 〈0, (∅, ∅)〉 → 〈1, ({w}, {x})〉
v0
w
e0
x
v1
e1v2
G1 : 〈0, (∅, ∅)〉 → 〈1, (∅, {z , y})〉
yz
v3
G0 ⊗ G1 : 〈0, (∅, ∅)〉 → 〈2, ({w}, {x , z , y})〉
v0
w
e0
yzx
v1
e1v2
v3
API in Java:public class DirectedBigraph {
...
public DirectedBigraph
tensor(DirectedBigraph) {...}
...
}
G = G0.tensor(G1);
15 / 40
Composition
H : 〈2, ({w}, {x , z , y})〉 → 〈1, ({y}, ∅)〉
v4
v5
w
y
y
e5
x z
e4
G : 〈0, (∅, ∅)〉 → 〈2, ({w}, {x , z , y})〉
v0
w
e0
yzx
v1
e1v2
v3
H ◦ G : 〈0, (∅, ∅)〉 → 〈1, ({y}, ∅)〉
v0
v5
v5
e0
y
e5
v1
e1v2 e4
v3
API in Java:public class DirectedBigraph {
...
public DirectedBigraph
compose(DirectedBigraph) {...}
...
}
F = H.compose(G);
16 / 40
Core Module
The Core Module is divided in two sub-modules.
Data structures and operations
+ Data structures (i.e., objects) for representing directedbigraphs (and also place graphs and directed link graphs);.
+ Procedure for tensoring bigraphs by juxtaposing them.
+ Procedure for composing bigraphs by putting the roots of the“lower” one inside the holes of the “upper” one, and bypasting the same names.
Algebra
+ Constructor for elementary bigraphs.
+ Normalization procedure, which takes a bigraph and yields itback in discrete normal form.
+ Derived operations.
17 / 40
Elementary bigraphs
Barren root
1merge 0(special case of merge)
Merge
mergemerge 2(generalized to merge n)
0 1
Swap
γ@[1,0](generalized to @[3,4,1,0,2])
1 0
Closure
HNxy
x X y(generalized to [x,w] X [y,z]) y
x
Substitution
MyX
y/[x 1,...,x n](also y/x and y/)
y
x1 x2 . . . xn
. . .
Fusion
OYx
[y 1,...,y n]\x(also y\x and \x) x
y1 y2 . . . ym. . .
Ion
K~x~y (l)
K[-y 1,...,-y n,+x 1,...,+x m](the names in the list can be written in any order)
y1 y2 . . . yn
x1 x2 . . .xm. . .
. . .
18 / 40
Discrete Normal Form
A generic bigraph
x4 x0 x7 x6 x1
y1 y0
e0
e1
0v0
v1
x2 x3 x5
e2y2
v2
v3
v4
API in Javapublic class DirectedBigraphAlgebra {
...
public static NormalForm
toNormalForm(DIrectedBigraph) {...}
...
}
NF = DirectedBigraphAlgebra.toNormalForm(G);
Its Discrete Normal Form
x5 x4 x0 x7 x6 x1 x2 x3
w2 w0 w1 w5 w4 w3 w6 w8 w10 w9 w7 w11
e0 e1 e2
w2 w0 w1
z2 z0 z1
w5 w4 w3 w6 w8 w10 w9 w7 w11
z3
0v0
v1
v2
v3
v4
z2 z0 z1 z3
y2 y1 y0
19 / 40
Architecture of DBtk
Core Module
Language(DBL)
Drawing (SVG)LTS: RPOsand IPOs
Matchingcompiler
decompiler
visualizer
verification
simulation
20 / 40
The Directed Bigraphical Language (DBL)
Signature
Signature [ACTIVITY NAME:#PORTS, ...];
Bigraphs
They are described in a functional-stylelanguage, which allows to compose (o)or tensor (*) elementary bigraphs.
y1
e3
e2
e0
e1
v4v5
v0
v1
v2v3
An example
Signature [active t4:1,atomic t5:1,atomic t2:2];let a = merge 1 | X[x,z] | (y1X[a,y] * t4[-w]) o
(w\ w * merge 1 | t5[+a] * y/y) inlet b = (((wX[b,c] * merge 1) o (b/b * t4[+c]) o
t2[+b,-d] | t2[+x,-e]) o ([d,e]X)) inlet c = t2 [+z,+y] in a o (b * c)
21 / 40
Architecture of DBtk
Core Module
Language(DBL)
Drawing (SVG)LTS: RPOsand IPOs
Matchingcompiler
decompiler
visualizer
verification
simulation
22 / 40
Compiling from DBL into native data structures
What DBtk provides:
+ Expressions in DBL can be compiled in the internalrepresentation of bigraphs.
+ Internal data structures can be decompiled into DBLexpressions.
How they are implemented:
+ The compiler is constructed using Lex and Yacc tools.
+ The decompiler recovers the algrebraic DBL expression indiscrete normal form.
23 / 40
Architecture of DBtk
Core Module
Language(DBL)
Drawing (SVG)LTS: RPOsand IPOs
Matchingcompiler
decompiler
visualizer
verification
simulation
24 / 40
Graphical Visualization
DBtk allows to represent bigraphs in the XML-based SVG format,which is the W3C open standard for vector graphics.
y1
e3
e2
e0
e1
v4v5
v0
v1
v2v3
0
v0
v1 v5
v2
v3 v4
y1
e3
e0
e1
e2
The translation method takes adirected bigraph data structureand returns a string containingits SVG representation.
API in Javapublic class Drawing {
...
public static String
dbg2svg(DirectedBigraph) {...}
...
}
System.out.println(dbg2svg(G));
(Fruitful in combination with the compiler: bigraphs are defined inDBL, compiled to the data structure and then converted in SVG.)
25 / 40
Architecture of DBtk
Core Module
Language(DBL)
Drawing (SVG)LTS: RPOsand IPOs
Matchingcompiler
decompiler
visualizer
verification
simulation
26 / 40
How to apply a rule to an agent?
Agent
58 4. Matching
in quanto gli archi e le sostituzioni che non possono risiedere in d possono invece
risiedere all’interno del conteso C che compone con d attraverso i link Z+ lasciati
intatti dall’identita.
Sia a l’agente mostrato in Figura 4.1. Esso rappresenta una software-house dislo-
cata in due edifici distinti all’interno dei quali lavorano con i loro computer i dipen-
denti. I computer sono connessi tra loro attraverso una rete domestica che permette
la condivisione dei documenti (intesa come condivisione di parte del file-system, e
quindi di cartelle). In questa rappresentazione la condivisione dei documenti e resa
esplicita dal fatto che le cartelle sono connesse tra di loro attraverso dei link (archi o
nomi). I nodi folder rappresentano una copia locale della cartella condivisa e possono
contenere dei documenti (modificati in locale). Nell’esempio preso in considerazione,
quando due cartelle sono collegate ad un arco (e in figura), esse condividono in modo
esclusivo quella cartella, mentre se sono collegate attraverso un nome condiviso (x
in figura), queste ultime possono essere condivise anche da utenti esterni all’azienda.
a =
0
data
folder
computer
building
data
folder
computer
data
folder
data
folder
computer
buildinge
x
Figura 4.1: Agente bigrafico per la rappresentazione di un’azienda con rete condivisa.
Sia R ! R! la regola di reazione mostrata nella fascia centrale di Figura 4.2.
Tale regola codifica la situazione in cui uno di due computer all’interno della stessa
locazione (nel caso dell’agente a, all’interno dello stesso edificio) toglie la condivisione
della propria copia locale della cartella. Questa situazione viene codificata collegando
ad un arco (unario) la cartella, ovvero restringendo la condivisione della cartella ad
un solo utente. Per il redex R e possibile trovare un match all’interno dell’agente
a, ovvero e possiamo scomporre l’agente a in C " (R # id{z}+) " d, per qualche
contesto C e parametro discreto d. In Figura 4.2 e mostrata tale scomposizione,
inoltre viene mostrata la riscrittura dell’agente ovvero l’applicazione della regola di
reazione R ! R!. Si noti che questo e l’unico match possibile del redex in a, in
quanto c’e un solo edificio con almeno due computer.
Reaction rule
4.2. Regole di matching 59
R =
0
0 1 2 3
folder folder
computer computer
y
= R!
0
0 1 2 3
folder folder
computer computer
y
e!
0
data
folder
computer
building
data
folder
computer
building
0e
x
0 1 2 3
data data data
folder
0
data
folder
computer
building
data
folder
computer
building
0e
x
0 1 2 3
data data data
folder
C = = C
d = = d
Figura 4.2: Esempio di match di un redex R nell’agente a e riscrittura dell’agente:a = C ! (R" id{z}+) ! d e a! = C ! (R! " id{z}+) ! d.
4.2 Regole di matching
In questa sezione presentiamo una caratterizzazione induttiva per la ricerca di un
match, ovvero una caratterizzazione alternativa alla verifica dell’uguaglianza a =
C ! (R" idZ+) ! d, per induzione sulla struttura di a, R, C e d. Quella che andiamo
a presentare e una caratterizzazione precisa nel senso che e sia corretta che completa,
rispetto alla categoria dei bigrafi astratti. Questa tipologia di approccio ci permette
di analizzare con un buon livello di dettaglio il problema del matching, e ci da le
direttive per la specifica l’algoritmo che andremo a presentare tra poco (sezione 4.3).
Questa caratterizzazione si basa sulla forma normale discreta (DNF) dei bigrafi
diretti che permette di decomporre un qualunque bigrafo in sotto bigrafi piu semplici,
ed allo stesso tempo ci o!re un metodo standard per separare i concetti di localita
e di connettivita come sotto-grafi componibili. Quest’ultima considerazione risulta
molto utile nella definizione della caratterizzazione, in quanto essa riflettera questa
separazione “logica” tra localita e connettivita attraverso una notazione puramente
sintattica. Avvalersi della forma normale risulta comodo anche per la dimostrazione
della completezza e della correttezza della caratterizzazione stessa1 e sono utili anche
1Le dimostrazioni di questi due risultati esulano dalla trattazione di questo lavoro
27 / 40
Match the redex into the agent and replace it bythe reactum4.2. Regole di matching 59
R =
0
0 1 2 3
folder folder
computer computer
y
= R!
0
0 1 2 3
folder folder
computer computer
y
e!
0
data
folder
computer
building
data
folder
computer
building
0
z
e
x
0 1 2 3
data data data
folder
z
0
data
folder
computer
building
data
folder
computer
building
0
z
e
x
0 1 2 3
data data data
folder
z
C = = C
d = = d
Figura 4.2: Esempio di match di un redex R nell’agente a e riscrittura dell’agente:a = C ! (R" id{z}+) ! d e a! = C ! (R! " id{z}+) ! d.
4.2 Regole di matching
In questa sezione presentiamo una caratterizzazione induttiva per la ricerca di un
match, ovvero una caratterizzazione alternativa alla verifica dell’uguaglianza a =
C ! (R" idZ+) ! d, per induzione sulla struttura di a, R, C e d. Quella che andiamo
a presentare e una caratterizzazione precisa nel senso che e sia corretta che completa,
rispetto alla categoria dei bigrafi astratti. Questa tipologia di approccio ci permette
di analizzare con un buon livello di dettaglio il problema del matching, e ci da le
direttive per la specifica l’algoritmo che andremo a presentare tra poco (sezione 4.3).
Questa caratterizzazione si basa sulla forma normale discreta (DNF) dei bigrafi
diretti che permette di decomporre un qualunque bigrafo in sotto bigrafi piu semplici,
ed allo stesso tempo ci o!re un metodo standard per separare i concetti di localita
e di connettivita come sotto-grafi componibili. Quest’ultima considerazione risulta
molto utile nella definizione della caratterizzazione, in quanto essa riflettera questa
separazione “logica” tra localita e connettivita attraverso una notazione puramente
sintattica. Avvalersi della forma normale risulta comodo anche per la dimostrazione
della completezza e della correttezza della caratterizzazione stessa1 e sono utili anche
1Le dimostrazioni di questi due risultati esulano dalla trattazione di questo lavoro
28 / 40
A more formal definition of match
Matching sentence
ωa, ωR , ω′C , ωC ` a,R ↪→ C , d
=a
ωa ⊗ id
d
RidX +
ωR ⊗ id
ω′C ⊗ id
idY +
CidV -
ωC ⊗ id
idZ+
C ′
(context)
R ′
(redex)
a′
(agent)
29 / 40
How the algorithm works?
Idea
1. Creation of a match object for the pair (agent,redex).
2. At each invocation of the method next a new match iscomputed (if it exists).
3. Backtracking is implemented by using two stacks.
6oloclacidomtiroglA.3.4
Matcher Object
Stack trace
Stack current
Figura 4.4: Un oggetto matcher
possibili applicazioni. Sullo stack trace verranno inseriti oggetti di tipo rule dotati
di un metodo !ll current per generare tutte le possibili applicazioni della regola che
verranno salvate sullo stack current come coppie (rule op,matcher) dove rule op e
il tipo dell’oggetto che realizza l’operazione che dovra essere eseguita sulle soluzioni
fornite dal matcher con cui e accoppiata.
In !gura 4.4 gli stack trace e current vengono rappresentati con i due riquadri
rosa ed azzurro rispettivamente. Gli oggetti rule contenuti nel trace vengono rappre-
sentati con dei rombi, mentre le coppie (rule op,matcher) come un rettangolo e ed
un cerchio rosso racchiusi dentro lo stesso elemento. Si noti inoltre che un oggetto
matcher e formato da tutte le componenti racchiuse dentro la linea verde, quindi a
loro volta anche i matcher formano un albero in cui i nodi sono oggetti matcher e i
rami ne indicano i relativi sotto-matcher.
Ora vediamo uno schema generale di funzionamento dell’algoritmo adottato:
viene creato un nuovo matcher con parametri di ingresso i due bigra! agente
API in Javapublic class Matcher {
...
public Matcher(DirectedBigraph,
DirectedBigraph) {...}
...
public Match next() {...}
...
}
30 / 40
Another example with two possible matches - I
Agent
92 4. Matching
In figura 4.6 vengono mostrati gli unici due match presenti nel nostro esempio, in-
fatti alla terza chiamata del metodo next viene restituita un’eccezione No more match.
Si noti come ricomponendo le tre componenti C, R, d, per entrambe le soluzioni, si
ottiene sempre l’agente a, a dimostrazione della correttezza del match ottenuto.
e0
e1
e3
e2
y
a =
0
Figura 4.5: Agente e Redex utilizzati nell’esempio.
Redex
4.5. Esempi 93
R =
0 1
0
yx
C =
0
0
1
e1
e0
e3
e2
z0 z1 z2
y
d =
0
z0 z1 z2
(Primo match)
= R
0 1
0
yx
= C
0
0 1
e3
e0
e1
e2
y
= d
0
(Secondo match)
Figura 4.6: Le due occorrenze di match del redex R sull’agente a di Figura 4.5.
31 / 40
Another example with two possible matches - II
4.5. Esempi 93
R =
0 1
0
yx
C =
0
0
1
e1
e0
e3
e2
z0 z1 z2
y
d =
0
z0 z1 z2
(Primo match)
= R
0 1
0
yx
= C
0
0 1
e3
e0
e1
e2
y
= d
0
(Secondo match)
Figura 4.6: Le due occorrenze di match del redex R sull’agente a di Figura 4.5.
result of the first next() result of the second next()
32 / 40
Architecture of DBtk
Core Module
Language(DBL)
Drawing (SVG)LTS: RPOsand IPOs
Matchingcompiler
decompiler
visualizer
verification
simulation
33 / 40
RPO computation
1. Given a commuting square, i.e., a span and a bound, create aRPO object.
2. The method get yields back the corresponding RPO triple.yields back the RPO triple.
3. Notice that the construction is deterministic so only one RPOcan exit for a given square.
API in Javapublic class DirectedBigraphRPO {
...
public DirectedBigraphRPO(DirectedBigraph,
DirectedBigraph,
DirectedBigraph,
DirectedBigraph) {...}
...
public RPO get() {...}
...
}
34 / 40
RPO construction example
!4, ({x, y}, {z})"
!2, ({a, b, c, g}, {d, f})"
!3, ({o, p, q}, {l, m, n})" !4, ({k, s, t, u, v, w}, {h})"
!3, ({(o, t), (o, u), (p, t), (p, u), (q, k), v, w}, {[n, h], m})"
0
0
v11
z
l n
1
v22
y
m
2
3
e0
x
q po
0
0
v1
y
s h
1
1
k
x
2
23
e1
z
v w
3
v0
e0
tu
0
0
n m p
[n, h]m (p, t) (p, u)
1
1
2
e1
lq
v w(q, k)
2
v0
o
(o, t)(o, u)
0
0
1
hu
[n, h](p, u) (o, u)
1
2v2
v ws
v wm
2
3
k t
(p, t)(o, t)(q, k)
0
0e2
[n, h]m (o, t) (o, u) w
d ag
1
12
v3
e3
v (p, t) (p, u) (q, k)
bcf
0
0
e1
e2
e3
n m l
d ab c
1
1
2v0
v3
o p q
g f
0
0
1
e2
e3
uw h
ga b c
1
2
3v2v3
v s t k
d f
Fig.7.
An
example
ofan
RP
Oconstruction.
35 / 40
IPO computation
1. Given a span (i.e., two graphs with common inner interface),construct an IPO object.
2. For the fact that many different IPOs can exist for a span, thenon-determinism is managed with stacks as done for thematching.
3. Every time a call to the method next is performed a new IPOis computed (if it is exists).
API in Javapublic class DirectedBigraphIPO {
...
public DirectedBigraphIPO(DirectedBigraph,
DirectedBigraph) {...}
...
public IPO next() {...}
...
}
36 / 40
IPO construction example
f0 =
0
v1
x y z
e1
= f1
0
v1 v2
v3
w u t
e1
h0 =
0
x y z
v2v3
0
u x yt zt
= h1
0
w u t
zt ytux
0
!0, (", ")#
!1, ({y, z}, {x})# !1, ({t}, {w, u})#
!1, ({yt, zt}, {x, u})#
f0 =
0
v1
x y z
e1
= f1
0
v1 v2
v3
w u t
e1
h0 =
0
x y z
v2v3
0
u x yt zt
= h1
0
w u t
zt ytux
0
!0, (", ")#
!1, ({y, z}, {x})# !1, ({t}, {w, u})#
!1, ({yt, zt}, {x, u})#
Fig. 8. An example: two IPOs are possible for the span f0, f1, one connects v2
to y and the other v2 to z.
result ofthe first next()
result ofthe second next()
f0 =
0
v1
x y z
e1
= f1
0
v1 v2
v3
w u t
e1
h0 =
0
x y z
v2v3
0
u x yt zt
= h1
0
w u t
zt ytux
0
!0, (", ")#
!1, ({y, z}, {x})# !1, ({t}, {w, u})#
!1, ({yt, zt}, {x, u})#
f0 =
0
v1
x y z
e1
= f1
0
v1 v2
v3
w u t
e1
h0 =
0
x y z
v2v3
0
u x yt zt
= h1
0
w u t
zt ytux
0
!0, (", ")#
!1, ({y, z}, {x})# !1, ({t}, {w, u})#
!1, ({yt, zt}, {x, u})#
Fig. 8. An example: two IPOs are possible for the span f0, f1, one connects v2
to y and the other v2 to z.
37 / 40
Conclusion and Future Works
What we have done
+ APIs for managing directed bigraphical structures, i.e., algebra+ operations.
+ A compiler, a decompiler, and a visualizer in SVG.
+ APIs for computing a Matching between two bigraphs.
+ APIs for calculating RPOs and IPOs.
Future works
+ Integration of the toolkit into Eclipse (www.eclipse.org/).
+ A (stochastic) simulation environment based on matching.
+ Tools for verification and behavioral reasoning, like modelchecking and bisimulations, based on IPO derived LTS.
+ A better language not based on bigraph algebra.
+ A more powerful and intuitive visual interface.
38 / 40
Thank you
DBtk is available at
http://sole.dimi.uniud.it/~davide.grohmann/dbtk/
40 / 40