Petri Nets Group Project Report 1
Petri Nets Group Project Report 1
REPORT 1
Edwin Chung
Tim Kimber
Ben Kirby
Will Master
Matthew Worthington
Supervisor: Dr W. Knottenbelt
Submission Date: 26 January 2007
1
Contents
1 Introduction 4
1.1 Petri Nets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 PIPE2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.1 Project Development . . . . . . . . . . . . . . . . . . . . 4
1.2.2 Software Integrity under Multiple Developers . . . . . . . 4
1.2.3 Outlook . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Specification 5
2.1 Bug Fixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 Immediate transitions are not given any preference over
timed transitions . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.2 Simultaneous firing of tokens via the same channel . . . . 6
2.1.3 Random null pointer exception generated while saving af-
ter running an analysis module . . . . . . . . . . . . . . . 6
2.1.4 Infinite while (!(isEmptySet(chj))) loop in the invariant
analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1.5 Null pointer exception . . . . . . . . . . . . . . . . . . . 6
2.1.6 Border of an annotation . . . . . . . . . . . . . . . . . . . 6
2.2 Code refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.2 Scope of work . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.3 Additional changes . . . . . . . . . . . . . . . . . . . . . 8
2.2.4 Anticipated outcome . . . . . . . . . . . . . . . . . . . . 9
2.2.5 Note on testing . . . . . . . . . . . . . . . . . . . . . . . 10
2.3 Testing Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.2 Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.3 Technologies . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.4 Documentation . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Reachability Graph Functionality . . . . . . . . . . . . . . . . . 15
2.4.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4.2 Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4.3 Technologies . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4.4 Documentation . . . . . . . . . . . . . . . . . . . . . . . 18
2.4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.5 Additional Zoom Functionality . . . . . . . . . . . . . . . . . . . 19
2.5.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.5.2 Anticipated outcome . . . . . . . . . . . . . . . . . . . . 19
2.5.3 Scope of work . . . . . . . . . . . . . . . . . . . . . . . . 21
2.6 Specification for improving options functionality and usability . . 22
2
3 Responsibilities 22
3.1 Will Master (tm106) - Team Leader . . . . . . . . . . . . . . . . 22
3.2 Ben Kirby (bmk06) - Team Secretary . . . . . . . . . . . . . . . . 23
3.3 Edwin Chung (xsc02) . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4 Tim Kimber (tk106) . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.5 Matthew Worthington (mjw106) . . . . . . . . . . . . . . . . . . 23
4 Schedule 23
5 Conclusion 25
3
1 Introduction
1.1 Petri Nets
Petri nets are a popular graphical way of modelling concurrent
systems such as communications protocols, multiprocessor comput-
ers and a growing variety of real world scenarios. With Petri nets it
is possible to assess the correctness of systems - for example by ver-
ifying that the system cannot deadlock or result in buffer overflows.
Stochastic Petri nets extend ordinary Petri nets by incorporating
time. This allows designers to use the same formalism to reason both
about the correctness and the performance of systems.
Although there are many Petri net tools available (please refer
to website1 ), in the majority of cases the actual functionality of the
software is limited to the imagination of the programmer. PIPE2
attempts to break these limitations through the construction of a
Petri net editor and animator capable of supporting the arbitrary
run-time extension of its analysis which would be powered by user-
designed modules.
1.2 PIPE2
1.2.1 Project Development
The Platform Independent Petri net Editor (PIPE2) is an open
source framework for Petri net research. The project is an ongoing
development sustained by the continuous collaboration of successive
years of Imperial College London Computer Science students and the
open source community at large. Due to the fact that the software
has remained open source, contributions to this project have come
from all four corners of the globe. The development is being pushed
forward through the use of the Java platform and updates are moni-
tored through the use of CVS and specifically for Imperial students,
Eclipse (an open source windows development enviroment).
4
Therefore, it was a logical step for the initial developers to manage
this project under CVS and has made version control much simplified.
Through Eclipse, this group is continuing in their footsteps making
the minor releases throughout the projects life cycle straightforward
and therefore highly beneficial.
1.2.3 Outlook
Over the last five years the project has come in leaps and bounds
through the dedicated effort of small groups of students for short
periods and a few developers that have continually pushed its lim-
its. Nevertheless, as a result of the fluctuating levels of activity sur-
rounding the project and the constantly evolving group of software
developers, the code remains imperfect.
2 Specification
2.1 Bug Fixes
2.1.1 Immediate transitions are not given any preference over timed
transitions
2.1.1.1 Description
5
thus this problem has to be rectified to allow true representation of
the modelled system.
6
of the application to some extent, the unnecessarily complex code,
which in places fails to adhere to principles of object oriented design,
means that over time it will become increasingly difficult to under-
stand and extend the application.
7
matrices repeatedly.
We will investigate ways of reducing unnecessary updates to the data
model used in the analysis modules, perhaps by developing methods which
can monitor when an impactful change has been made to a Petri net and
flag this up to the analysis module, which will only then update the model
(or parts of the model) it is using for the analysis.
• The code supports finding multiple methods in a Module if they have a
single parameter with a DataLayer object. There should always be one
called "run", since that is required to support the Module Interface. But,
if other methods are defined, they are also located and added to the tree.
Is this behavior exploited? If we can get rid of this feature, the calling of
the run method can be much simplified. (Without using reflection.)
• There is a lot of wasted effort in the initialisation code in general. Many
copies of the DataLayer object are created. The code also instantiates
each of the Module classes twice. We will log and remove all instances
of unnecessary initialisation using unit testing to ensure there is no wider
impact across the application.
• PIPE2 currently does not use the generics feature introduced in J2SE
5. Generics can provide several advantages: cleaner code, because fewer
casts are required; there is less ambiguity between containers, so code re-
views are simpler; and it offers the flexibility of dynamic binding, with
the advantage of static type-checking (and compiler-detected errors are
less expensive to repair than those detected at run time). PIPE2 invokes
numerous collections (ArrayLists of Place and Transition objects in par-
ticular), so introducing generics could significantly improve the code.
We intend to identify any areas which could benefit from this treatment
and implement generics.
• There is considerable inefficiency in how data is managed. For example,
the DataLayer keeps ArrayLists of Place and Transition objects, which
are generated by the analysis modules. There are numerous places where
arrays are generated only because the length of the array is required,
whereas a method which only returns the length of the array require much
less overhead. In some cases, an array is called to get its length, then a
few lines of code later, another copy of the array is generated. It would
be more efficient to call the array once, get it’s length locally, then use
it as required. We would aim to look into the management of data, par-
ticularly in the analysis modules and the DataLayer class, and eliminate
these inefficiencies wherever possible.
8
areas are likely to be identified where refactoring will be useful. While
we recognise the potential problems of straying too far from the initial
specification, we may extend or alter the specification if we find issues
that we feel are important to address, and estimate that we have
enough time remaining to make the changes.
9
top-level project that includes a range of tools that can be used to profile
Java applications. TPTP provides a comprehensive suite of open source
performance-testing and profiling tools, including integrated application
monitoring, testing, tracing and profiling functionalities, and static-code
analysis tools.
Profiling an application typically involves observing how the application
copes under stress. A common way of doing this is to run a set of tests (for
example, JUnit tests) on a deployed application and use profiling tools to
record the application’s behavior. Metrics are produced including mem-
ory usage (how many objects are being created, and how big they are),
execution statistics (where did the application spend most of its time?),
and test coverage (how much of the code was actually executed during the
tests).
As well as providing quantitative analysis of the PIPE2 application before
and after refactoring, TPTP should help identify areas that need atten-
tion. For example, using TPTP, it’s possible to identify the percentage
of methods called in a class, which may bring to light any redundant
functionality.
• Cyclomatic complexity:
Cyclomatic complexity is a measure of path complexity. By counting the
distinct paths through a method, this integer-based metric aptly depicts
method complexity. In fact, various studies over the years have deter-
mined that methods having a cyclomatic complexity (or CC) greater than
10 have a higher risk of defects.
A few open source tools available to Java developers can report on cy-
clomatic complexity. One such tool is JavaNCSS, which determines the
length of methods and classes by examining Java source files. What’s
more, this tool also gathers the cyclomatic complexity of every method in
a code base.
• NCSS:
NCSS stands for Non Commenting Source Statements. An NCSS score
is equivalent to counting ’;’ and ’{’ characters in Java source files. This
gives a basic but potentially valid measuremet of code complexity which
may be worth documenting on a class by class basis. Of course, with
additional functionality being added to PIPE2, it is unfair to compare
the NCSS score for the entire application before and after the team’s
work. JavaNCSS (see c above) provides NCSS measurements in addition
to cyclomatic complexity.
10
refactoring work - testing will be incorporated into each individual
change and carried out with every update that’s committed to CVS.
The second problem the tangled code gives rise to, having gained a
working appreciation of PIPE2, is making changes without breaking
the existing functionality. It seems unavoidable that new bugs would
be introduced. At best this would slow down development while
these bugs are tracked down and fixed. At worst, if a bug occurs in
a function that is logically remote from the story being developed,
it may go entirely unnoticed. This is highly undesirable, especially
given that PIPE2 is an open source project with people in the Petri
nets world who both use it and sometimes get involved in further
development.
2.3.2 Concept
The test suite should contain two types of test: high-level func-
tional tests and unit tests.
11
The functional tests should exercise the application at the user
interface level, without making any assumptions about the underlying
implementation.
12
Unit tests should exercise the code at the class level. Ideally all
non-trivial (non ’getter’ or ’setter’ methods) should have a test writ-
ten to check their correct operation. The test class should instantiate
a copy of the class under test, call the relevant methods and check
the output. Just as for the functional tests the unit tests should be
independent of the implementation within the class, only checking
the interface. Also, every test should be independent of every other
one, so all tests should ’clean up behind themselves’ and not assume
anything about the outcome of a previous test.
Second priority, but still fairly essential, will be to write unit tests
for all new classes and all revised methods within existing classes. i.e.
unit test all code that we ’touch’ as we go along. Third priority, and
quite a luxury item, would be to write unit tests for as much of the
remaining code as possible, starting at a high level of logical abstrac-
tion and then going into finer granularity. Tools exist to analyse unit
test coverage and we will investigate using one of these to provide a
measure of progress.
2.3.3 Technologies
2.3.3.1 JUnit
13
The test suite will be built using the familiar JUnit open source
library (http://JUnit.sourceforge.net). JUnit provides test and test-
suite classes that can be extended to test specific application classes.
The JUnit test runner provides detailed information about any failed
tests and what caused the failure.
2.3.3.2 Abbot
2.3.3.3 Ant
2.3.4 Documentation
The main documentation to be produced will be:
• A description of the essentials of the framework, and how and when to
run the tests
• The functional test list, and coverage
14
2.3.5 Summary
2.3.5.1 Essentials
• User functionality catalogue
• 100% Functional test coverage
• 85% Unit test coverage within new classes
15
2.4.2 Concept
The following steps broadly outline the development route of this
new aspect of the software.
16
Translate the initial representation of the code into the .dot for-
mat that can then take advantage of Graphviz’s engine. This stage
should require a parsing of the data structure produced in the pre-
vious stage into a format that can be imported and manipulated via
Graphviz. The dot format employed in Graphviz is fairly explicit and
basic representation of both the state names and corresponding tran-
sitions which naturally can incorporate general labelling. Therefore
in the development of the previous stage, data structure choices will
be made both based on efficient information storing as well as the
necessities of the subsequent conversion.
The reachability graph will extend the tangible data with which
the user may evaluate a particular net. This will include performance
figures outlining average token numbers and firing rates for individual
states. These figures will offer the user additional information with
which more insightful judgements may be made with respect to the
current Petri net.
2.4.2.6 Testing
2.4.3 Technologies
2.4.3.1 Graphviz
17
Graphviz is a powerful open source software capable of represent-
ing structural information as abstract graphs and networks. It uses
a basic text format input (.doc files) to generate various format out-
put files which can be immediately integrated and simply displayed
through the PIPE2 GUI. It should be noted though that this will not
permit manipulation of the actual graph or tree. Nevertheless, this
an area of mounting interest and shall be kept in mind throughout
the development.
2.4.3.2 Grappa
2.4.4 Documentation
Documentation will be produced outlining:
2.4.5 Summary
The development of reachability graphs as an extension for PIPE2’s
functionality is an important piece of the jigsaw puzzle. The PIPE2
user base is rapidly expanding and it is fundamental that developers
responsed to the various needs of the users. This particular arm of
the development is capable of both taking advantage of the current
analysis techniques in place while providing the user with additional
information and insight into the net in question.
2.4.5.1 Essentials
• Fully working Reachability Graph
• Additional Functions
18
• a state space representation that provides interaction options similar to
those offered for the petri net which offers interesting possibilities for mod-
ification and regeneration of a new net but is beyond the scope of this years
development.
19
These example buttons are taken from Abobe Acrobat. From the
left, they represent:
• Zoom In: clicking this zooms in by 20%
• Zoom Percentage: user can specify magnification to zoom to by typing
or selecting a value from the option selectbox. Values will be in sensible
increments (see dropdown graphic below) with an option for ’Fit Page’
• Zoom Out: clicking this zooms out by 20%
• Zoom Select: works like ’Select’. Cursor becomes ’target’ when in drawing
pane, and user can click and drag a box on the pane to select a section of
the model to Zoom into. Selection zooms to fit page or to a maximum of
400%
All zoom options apart from Fit Page and Zoom Select will zoom
on the co-ordinates at the centre of the model currently filling the
drawing pane. Zoom Select will zoom on the co-ordinates at the
centre of the selection box. Fit Page will zoom on the centre of the
entire model to the nearest 1% so that it fills the current size of the
drawing pane.
20
and scroll around it at any magnification. All other functionality
must remain the same.
At the outset it appears that much of the work for this function-
ality will involve augmenting classes within the pipe.dataLayer and
pipe.gui packages, which are used to paint the objects of the Petri net
in the drawing pane according to user input. New classes will also
need to be added to handle Zoom actions. So the next task will be
to study the current process for drawing objects in the application
and the current UML diagram, and then determine what additional
classes and methods need to be added. The team member will have
to determine how to achieve the following:
• when a zoom magnification is selected, each object in the net is redrawn
to the correct scale, and the view centred on the correct co- ordinates
• any new objects created with that magnification selected are drawn to the
scale previously selected
• the new buttons are created in the toolbar and clicking them initiates the
correct action. Relevant Alt text should also be added
• the new dropdown options are added to the dropdown menu and clicking
them initiates the correct action
21
2.6 Specification for improving options functionality and
usability
Many options that would be useful to specify are defined all over
the code and cannot be changed dynamically. We plan to implement
a single properties file with all of the options in it. These options
could include:
• arcs curved / straight by default
• colours of active transitions (red is difficult to see for some users)
It would also be much easier if this single file had a series of en-
tries starting with "module.class.whatever" that defined the analysis
classes to load. For normal use within Eclipse, we intend to have the
options file within the normal src directory structure. For people who
want more flexibility (normally running from a jar file, for example),
we could enable a parameter on the main class that contains the lo-
cation of the option file, making it possible to override the defaults
stored in a jar file. This would give us a single Properties object that
could be widely available.
3 Responsibilities
3.1 Will Master (tm106) - Team Leader
Will has spent time investigating the refactoring of the PIPE2
application. The resulting part of the specification is based on input
from Dave Patterson (a software engineer working in the US who
has a good knowledge of the PIPE2 application, and is an active
commenter and contributor to the project).
Will has also looked into a number of Eclipse plug-ins which can
measure performance and provide indications of the complexity of
Java applications. This should help us to quantify the effectiveness
of the refactoring work the group plans to undertake.
22
3.2 Ben Kirby (bmk06) - Team Secretary
Ben has so far spent time investigating the addition of zoom func-
tionality to the application, examining existing code and deciding on
what new functionality should be introduced. Ben will continue to
work on this, and will also be refactoring code along with the rest of
the team.
4 Schedule
The group has put together a fairly comprehensive and individ-
ually detailed framework in which the major milestones of PIPE2’s
yearly development have been lain down. Estimations of the time
23
24
commitments necessary have been made based on the research car-
ried out up to this point, as well as past project development experi-
ence. The schedule not only incorporates research and development,
but sets aside significant time for both testing and the compiling of
the intermediate and final reports. Naturally, one is obliged to accept
that potential complications and/or new routes may come to light in
the weeks ahead. Although these cannot be anticipated, this group
has taken the necessary steps in setting out a suitable schedule which
both allows for these obstacles and provides the flexibility for incor-
porating essential objectives that are feasible within the constraints
of the project’s own specifications.
5 Conclusion
As the development of PIPE2 enters another year, one looks to its
future with both a sense of expectation and urgency. The overhaul
and additional functionality that have been proposed by this year’s
group are both a requirement for the longevity of the program itself,
as well as a long awaited response to the requirements of worldwide
users. It is the group’s belief that this years specifications closely
parallel both logical development path of this software package while
simultaneously incorporating specific areas of key interests individual
members and developers alike.
25