Reachability Graph generation using AToM3


Jaime López Jiménez <jaime.lopez@iic.uam.es>
Last Modified : 2003-02-09


1. Introduction

This tutorial describes the steps necessary to create a tool for reachability / covering graph generation with B-W PetriNets. It can be used as a simple tutorial for general modelling with AToM3. It also shows some aspects of low-level AToM3 programming using Python.

The tool takes any PN model and creates (by clicking a button) the corresponding reachability graph in a separate window.
The following picture describes the whole process:

Sample of generation

Figure 1
: Simple example of RG creation with AToM3




2. Creating the ReachGraph meta-model

Reachability graph is a kind of FSA (Finite State Automata), with special meaning for the nodes and transitions:
AToM3 has a meta-model for FSA's, but for the purpose of this application we can create our own model.

Preparing the environment

The first thing to do is to create a separate environment for this meta-model. Inside the AToM3 root directory, we create another empty called ReachGraph. This will hold the files for the project.
After that , we must run AToM3 and change the following options:

E-R Meta-Model

In the new AToM3 window, we create the following E-R (Entity Relationship) diagram:
E-R diagram for ReachGraph metamodel

Figure 2
: Meta-model for ReachGraph


We need only two entities to describe the whole model. In the Edit Entity dialog we provide these properties for each of the entities.

Graphical form

Each item of the model has a corresponding graphical form. It must be defined by clicking in the appearancebutton of the Edit Entity dialog.
For this tool we chose two basic primitives: an oval for each state of the graph, and an arrow for the transitions.

Graphical form of an RGnode item

Figure 3
: Graphical form of an RGnode item

 

Finishing up

The last step is to define global attributes for the model. It can be done by clicking on Model|Edit model attributes. For this tool we only need two string attributes Creator, Description.
On the Model Name field we must type ReachGraph.
After that we save the model under the name ReachGraph_mdl_ER.py and click on Model|Generate code

Now we can open in a different window the file ReachGraph.py as a meta-model. By using the buttons "New RGnode" and "New RGtrans" we can test our model.
 

3. Reachability Graph generation

To get a valid ReachGraph model from a PetriNet we are going to create a Python class called PNlink. It acts as a link between PetriNets and ReachGraph
The class only has one public recursive method, convert, that has the following pseudo-code:

    convert(pnmodel, rgmodel = none, parent = none) :
        if rgmodel = none :
            rgmodel = createRG()
        currentState = getCurrentState(pnmodel)
        candidates[] = getCandidates(pnmodel, currentState)
        node = createNode(rgmodel, currentState, parent)
        for each newState in candidates :
            v = visited(rgmodel, newState)
            if not v :
                v = convert(pnmodel, rgmodel, currentState)
            else
                connect(rgmodel, node, v)
        return v

In this code, the only thing to consider is:



4.Covering graph

The previous algorithm can be slightly modified to get a Covering Graph. The only thing to consider is that the comparition function must be modified to recognize as equal two states when one of them covers the other. That is, when a every place in the net has more or equal number of tokens. The other thing to consider is that, when one state covers another, it must be renamed to reflect what component of the state is going to cover the other - in b/w graphs, it means that the number of tokens of that place will be growing forever. By using the special value "w" we can manage that special situation and stop the infinite recursion.


3. Low level model management

The PNlink has to interact between two models in AToM3. The code must deal with both semantic objects (the objects containing the internal representation of the model) and graphical objects (the objects containing the visual representation of the model).

The following table shows the most relevant and useful classes, properties and methods used in that process:

Class/property Description
ATOM3 The main class of each model. It contains all the semantic / graphical objects of an instance of the model. We must instantiate this class to get a valid separate window for the resulting Reachability Graph.
ATOM3.ASGroot
It contains the model itself.The PNlink class uses one as a container for the input model (PetriNets) and another for the output model (ReachGraph)
asgroot.listNodes.get('TypeObject')
It can be used to get a list of items of type TypeObject from the model. PNlink uses this call to get a list of places from the Petri Net (to get the current state), or to navigate the transitions.
o.in_connections_
It is used to traverse / add  input connections for a given node. PNlink uses it to get the list of enabled transitions in the PetriNet
o.out_connections_
It is used to managet the output connections for a given node. PNlink uses it to pass tokens from the input to the output of a given place
o.property.getValue() / o.property.setValue()
It is used to get / set a property of a given object. The object can be each of the items of the corresponding meta-models. PNlink uses it to get / set the values of the semantic objects, for instance, when reading the number of tokens of a place or when creating new nodes for the reachability graph.
o.graphObject_
This contains the graphical form of a given semantic object. It must be used to alter the visual form of an object. PNlink uses it to add nodes to the reachability graph.
atom3.drawConnections((parent,child))
This method can be used to create a connection of the appropiate type from one node to other of the graph. PNlink uses it to connect new generated nodes in the reachability graph.



4. Linking all parts together

It is the easiest part. Open the Petri Net meta-model as a model (PNmodels/PetriNets.py). Edit the properties of the CovTree button and click on the Action button. Then type the following Python code:

from PNlink import PNlink
l=PNlink()
l.convert ( self )


5.Testing

In the ReachGraph directory there are two samples (simplepn.py andcomplexpn.py). Each demonstrates the possibilites of the tool for creating Reachability Graphs and Covering Graphs.
By opening each model and clicking on the CovTree button we can test that everything is working.

Complex covering graph