Petri Nets in SEPIA

All Petri net types have common properties and methods, which are outlined in this section.

To create new places, transitions, or flow relations, no new objects need to be instan- tiated “by hand”. Instead net components are added to Petri nets by providing unique identifiers (name of places and transitions). The appropriate methods (net.addPlace(), net.addTransition(), …) are called in the Petri net with the element’s name as parameter. The instance of the net creates the respective element object. Flow relations are added by providing the identifiers of corresponding places and transitions. There are different methods for adding flow relations, depending on the direction (place to transition of vice versa). If a component’s name doesn’t exist or doesn’t belong to the expected component type, an exception is thrown.

// add elements
net.addPlace("p1");
net.addPlace("p2");
net.addTransition("t1");
net.addFlowRelationPT("p1", "t1");
net.addFlowRelationTP("t1", "p2");

In case additional properties of places or transitions have to be set, internally generated place/transition-objects can be requested from the Petri net itself (again with their identifier).

// set properties
net.getPlace("p1").setCapacity(5);
net.getTransition("t1").setLabel("Transition 1");

The initial state of a Petri net is set using a marking. Marking elements have different data types depending on the Petri net type. Markings of P/T-Nets have integer values representing the number of tokens per place, where markings of CPNs and IF-Nets have multisets of strings with the token colors. The markings are created, filled, and assigned to the Petri net object. The following code shows the marking of a P/T-Net, which assigns a number of tokens to specified places:

PTMarking marking = new PTMarking();
marking.set("p1", 2);
marking.set("p2", 1);
net.setInitialMarking(marking);

Flow relations have constraints, which specify the number of required tokens for a transition to fire for flow relations from places to transitions or the number of tokens to produce for flow relations from transitions to places. If all places in front of a transition contain enough tokens s.th. all constraints of the flow relations are satisfied, the transition is enabled. Enabled transitions can fire, where the specified number of tokens in the input places are consumed and tokens are produced in the output places. If the fire()-method of a disabled transition gets called an exception is thrown. The following code fires transition t1 if it is enabled:

if (net.getTransition("t1").isEnabled())
    net.getTransition("t1").fire();

Each Petri net type defines validity and soundness properties, whereas validity refers to a correct net structure (i.e. a net specification which makes sense somehow) and soundness typically refers to workflow-specific properties of Petri nets. The soundness property implies a valid Petri net.