• Aucun résultat trouvé

Bigraphical Reactive Systems

2.3 Non-quantitative connector algebras

2.3.5 Bigraphical Reactive Systems

be investigated. In fact, at least in principle, these techniques might be applied to the sub-set of similarly typed connectors for which compositionality holds.

Figure 2.21: Bare bigraph together with the forest and hypergraph

Bigraphs & interfaces

We can extend a bare bigraphG0 to a full bigraph Gby the assignment of both an outer and an inner interface. These define signatures that allow us to combine bigraphs together, as we will see in a moment.

Formally, an interface for a bigraphGis a pair(m, X)defined as follows:

DefineX to be a global countably infinite labelling set. If(m, X)is an outer interface, thenm∈Nis interpreted as a set{0,1, . . . , m−1}, each element of which (except for possibly one) indexes the roots of the forest ofG0. The distinguished element, if it exists, is used to represent the general space outside of the root nodes. X ⊆ X represents the set of edges in G0 labelled by members of X that are visible through the outer interface.

Similarly, if(m, X)is an inner interface, thenX ⊆ X represents the set of edges inG0labelled by mem-bers ofX that are visible through the inner interface. Again,m∈Nis interpreted as a set{0,1, . . . , m−1}, but in this case each element (except for possibly one) indexes the sites ofG0, i.e. a node within which we can choose to add more nodes. Yet again, the distinguished element, if it exists, refers to the space outside all nodes.

A bigraphG, written asG: (m, X)→(n, Y), consists of the forest and hypergraph ofG0together with the inner and outer interfaces(m, X)and(n, Y)respectively. The arrow notation is correctly suggestive of categories, as the bigraph may be seen as a morphism in a precategory (objects correspond to interfaces).

Composition of bigraphs

Given two bigraphsG: (l, X)→(m, Y)andH : (m, Y)→(n, Z), their composition is a bigraphH ◦G: (l, X)→(n, Z), in which for eachi∈mrootiofGis positioned in spaceiofH, and for eachx∈X, the edge labelled byxinGis linked to the edgexinH.

Thus the bigraphH◦Ghas a forest obtained by taking the forest ofH and grafting each root ofGonto the corresponding space inH. The hypergraph is obtained by taking the union of the links inGandH, and connecting those links that are labelled from the vocabulary ofY.

In the case that the bigraphH◦Gis defined, we say thatH is a contextual or enclosing bigraph ofG.

This is equivalent to saying thatGis a sub-bigraph ofH. Restrictions on bigraphs

In bigraphical modelling, it is common to want to ascribe information and meaning to certain nodes.

Perhaps a node represents a term in theλ-calculus, in which case we would want to have nodes corre-sponding to variables,λ-abstractions and applications etc. Each of these node types should only allow a set number of links to be connected to them. Thus we define the notion of a signature.

Asignature for a bigraph Gin a pair (K, ar), where Kis a finite set of node-types and ar : K → N defines the arity (or number of ports) on each node-type. Each node inGhas a typekdrawn fromK, and possesses exactlyar(k)ports.

Bigraphical Reactive Systems

We now present a very informal definition of a Simple BRS. A Simple BRS consists of a bigraph G, together with a set of reaction rulesR. Each ruleR∈ Ris a pairR= (R1, R2), whereRi: (m, X)→(n, Y)

are bigraphs. We say thatR1 is theredex and R2 is thereactum. In a very waffly sense, if a redexR matches a portion of the bigraphG, we can pullRout and reconnectR0in its place, providing(R, R0)∈ R.

This new bigraph replaces the bigraph G in the BRS. The bigraph in a BRS evolves over time by the repeated application of reaction rules.

2.3.5.2 Scenario modelling

We now provide a model of theMary Scenario in terms of a BRS. We begin by defining a signature for the components in the environment. This will simply be:

({phone, exchanger, contact},{phone7→1, exchanger7→2, contact7→0}). (2.1) The initial configuration of the environment is denoted by the following bigraph, which will be the initial bigraph in the BRS. The phones are initially disconnected from the exchanger, and phone1 contains 3 contacts, whilstphone2contains a single contact.

Figure 2.22: Initial bigraph for the Mary Scenario

We now need to define the reaction rules for transferring contacts from one phone to the other. These are shown in Figure 2.23. The rules adopt a number of conventions, as we explain:

1. Unshaded dashed boxes are used to indicate that there could be other entities in the environment that have the same locality as objects inside the box. Thus these boxes can be thought of as part of the outer interface of the bigraph in the redex/reactum. The state of objects located outside the dashed box remains untouched by the reaction, modulo changes described in point 4.

2. Shaded dashed boxes are used to indicate that there may be additional objects contained within the enclosing node. The contents of these boxes remain unchanged, except for changes explained in point 4. These boxes can be thought of as part of the inner interface of the redex/reactum bigraph.

3. A link that extends outside of the unshaded dashed box ispossiblyconnected to a number of nodes outside of the redex/reactum bigraph, i.e., a node outside the unshaded dashed box, or a node inside a shaded dashed box. It is possible that the edge is not connected to anything outside, however.

4. It is possible to alter the links outside of the redex/reactum bigraph by connecting or disconnecting a link inside the bigraph that extends outside as described in point 3.

We now give an account of the reaction rules. The first reaction rule R1 allows either phone to be connected to the left-most port of the exchanger, providing the phone is not already connected to anything.

The phone may contain nodes, i.e. an arbitrary number of contacts, as may the exchanger.R2allows any disconnected phone to connect to the right-most port of the exchanger. R3andR4 allow for the transfer of contacts between a phone and the exchanger, and vice versa, one at a time. R5andR6allow for the disconnection of phones from the ports of the exchanger.

There are many strategies for transferring the contacts from phone1 to phone2. One such strategy proceeds as follows:

G−→R1 G1 R2

−→G2 R3

−→G3 R3

−→G4 R3

−→G5 R4

−→G6 R4

−→G7 R4

−→G8 R5

−→G9 R6

−→G0 (2.2)

Figure 2.23: Reaction rules for the Mary Scenario

Figure 2.24: The bigraphG0

UnderR1, thephonenode in the redex is mapped ontophone1inG. Thephonenode inR2is mapped ontophone2. The applications ofR3map onto any permutation ofc1,c2orc3, and similarly forR4.R5and R6are completely determined. The bigraphG0 is identical to that ofG, with the exception thatc1,c2and c3now reside onphone2, along withc9. This is shown in Figure 2.24.

2.3.5.3 Advantages and disadvantages

Before summarising the key features of BRSs, and highlighting their advantages and disadvantages, it is instructive to pose the following question to ourselves, “In what sense have we really modelled a connector for theMary Scenario?”

This in turn raises the question of defining a connector in a BRS. From the perspective of theMary Scenario, a connector corresponds loosely to a strategy in the BRS. The bigraph represents the state of the system under consideration, which we hope the Connect Enabler will be able to learn, or at least an abstraction of it. The reaction rules correspond to capabilities of the entities in the system; methods that we hope our Connect Enabler can interact with and instantiate. This then prescribes to us exactly what the Connect Enabler must do. It should traverse the execution tree of the BRS to find a bigraph that satisfies our goal conditions i.e. one where the contacts have been moved from one phone to the other.

The sequence of reactions that get us to the goal bigraph is then a connector that achieves our tasks. Of course, we will need to perform systematic learning and discovery along the way, but bigraphs give us a high-level overview of what we should do (or at least one way of doing this).

We now return to our summarisation of BRSs. We saw early on that bigraphs arecompositional, and so there is a natural way in which BRSs may be combined: combine the bigraphs and take the union of the reaction rules. As a result, we are also guaranteedincrementalityof BRSs, because we can extend them adhoc by throwing in more nodes and links, as well as by adding more reaction rules.

The BRS notation is alsoscalable. This follows from the fact that we can build BRSs of any size, and that we can also change our level of abstraction.

It is ambiguous to say whether BRSs supportcompositional reasoning, as this is dependent on the property to be inferred. It certainly seems plausible that properties that can be inferred component-wise can also be interpreted in this notation using similar techniques.

As we remarked earlier, a connector is a series of instructions, therefore connectors in this notation are reusable. We can simply re-execute the sequential coordination actions. The BRS notation also supports evolvability, as we can, in theory, generate the strategy on the fly responding to any unexpected changes to the system as we try to achieve our goals. In BRSs, components are generally modelled as nodes that have a locality. Thus migration of components can be captured effortlessly in this notation.

There is a stochastic extension of BRSs that can be used for capturing non-functional properties. This extension allows for reasoning about non-functional propertiesby using quantitative model-checking techniques.

Finally, the IT University of Copenhagen has been working on developing a Bigraphical Programming Language [5], thustoolkit supportis well on its way.