3.3. Petri NetsThe Petri network (or Petri net ), a notion devised in 1962 by the mathematician Carl Adam Petri, is a formal graphical process modeling language that can design systems as diverse as train track switches and business processes. With respect to the latter, Petri nets help describeand indeed, can be used to implementthe semantics of process control flow, including basic branch and join rules, as well as more complicated synchronization scenarios; notably, dead path elimination , a core topic in the languages WSFL and BPEL. Petri net theory saturates the literature on process patterns, a topic introduced in Chapter 4. The keen analysis of this work, undertaken by a group of pro-Petri authors referred to in this book as the P4, injects much-needed rigor into an historically ambiguous and haphazard subject. Though among BPM champions it lacks the renown of the pi-calculus, the Petri net is a valuable abstraction and merits the attention it has been paid. 3.3.1. Petri Nets in a NutshellThe Petri net's characteristic appearance is that of an unusual assembly of circles, rectangles, arrows, and black dots. The beginner might at first mistake it for a state-transition diagram, reasoning that the circles and rectangles are states, the arrows transitions, and the dots some other curious artifact specific to the model. But although the Petri net shares with the state machine a preoccupation with the notion of state, to compare the two is like comparing apples and oranges. In Petri's original conception, referred to as the classical net, the symbols are the following:
The Java applet design editor and simulator (at http://is.tm.tue.nl/staff/wvdaalst/pn_applet/pn_applet.html) shown in Figure 3-4 is a typical Petri net modeling tool, which promotes a design-and-simulate approach to building a Petri net. Figure 3-4. Petri net simulator Java appletDesigning a system involves dragging places and transitions onto a canvas, drawing arcs between them, and dropping an initial placement of tokens into a subset of the places. Simulating a design initiates a step-by-step run of the Petri net in which each step involves firing a transition and watching the tokens advance to new places. Here are some elementary rules of Petri net design:
Here are the rules of execution:
The next section illustrates these concepts in action. 3.3.1.1 ExampleConsider the process by which magazine editors might vote on whether to accept an article for publication. When the article arrives, it is distributed for review and voting to a number of editors. The voting completes either when two editors accept it or when one rejects it; in the former case, the author is sent an acceptance notice, in the latter a rejection. Figure 3-5 shows the Petri net for this process. The Petri net starts at the New place. When the Send For Vote transition fires, the net branches into three paths: two for acceptance, one for rejection. In the acceptance paths, the place Accepting links to the transition Accept, whose output place is Accepted; in effect, when Accept fires, a token is passed from Accepting to Accepted. The rejection path is similar: the transition Reject moves a token from the place Rejecting to the place Rejected. The two acceptance paths converge in the transition Send accept notice. Similarly, in the rejection path, the place Rejected links to the transition Send reject notice. Each of the send notice transitions links to the output place Done, the final step in the process. The curiously named place Mutex, an input to the send notice transitions, is discussed later in this section. The behavior of the voting process is best understood by following the path of tokens through the net. Step (a) shows the initial placement: one token in New and one in Mutex. The shading of the transition Send for vote indicates that it is enabled; it is enabled because its one input place, New, has a token. When Send for vote fires, the token is removed from New, and tokens are populated in the Rejecting and Accepting places, thus enabling the transitions Accept and Reject, as shown in (b). Step (c) depicts the state of Figure 3-5. Petri net process for votethe net after one acceptance and one rejection. The token from the uppermost Accepting has now moved to Accepted; likewise, Rejecting has now transitioned to Rejected. Of the two send notice transitions, only Send reject notice is enabled because both of its input placesRejected and Mutexhave a token. When Send reject notice fires in Step (d), the tokens from Rejected and Mutex disappear, and a token is moved into Done. Exemplifying the powerful synchronization capabilities of Petri nets is the Mutex (mutual exclusion) place, which ensures that only one noticean acceptance or a rejectionis sent to the author. Mutex is an input place to both the Send accept notice and Send reject notice transitions, and hence neither of these transitions can fire unless Mutex has a token. However, in the initial token placement, Mutex has exactly one token. If two acceptances and one rejection occur at roughly the same time, both Send accept notice and Send reject notice will contend for that token. But when one transition fires, it will consume the token, immediately disabling the other transition, thereby preventing it from firing. 3.3.1.2 Petri Net ExtensionsThe high-level Petri net extends the classical conception considered previously and facilitates the construction of larger and more complex processes. It supports the following constructs:
3.3.2. Petri Nets and BPM PatternsThe Petri net is a suitable model for control flow in business processes. Van der Aalst and his group, the P4 (mentioned previously), have published a mountain of papers on control flow and patterns, much of it applying ideas of Petri nets to demonstrate semantics. This section explores the P4 findings on basic AND, XOR, and dead path elimination patterns.[*]
3.3.2.1 AND and XOR split and joinEvery BPM modeling language permits a process to branch into parallel paths and then later join these paths back into one. In the process fragment shown in Figure 3-6, when activity A completes, activities B and C begin running in parallel; activity D begins only upon completion of both B and C. Figure 3-6. Typical AND split and join in pseudocodeFigure 3-7 shows an exclusive-OR conditional split from A to either B or C; when the split is joined back, activity D is executed. Figure 3-7. Typical XOR split and join in pseudocodeThe P4 approach to modeling flow charts as Petri nets is to represent flow chart activities as transitions, where the name of the transition is the name of the activity. Some transitionsknown as lambda (also known as anonymous) transitionsare left unlabeled (i.e., unnamed), as are all places. Places and lambda transitions, as we will see, combine to drive the control flow (that is, the parallel, conditional, sequential, and synchronization logic) of a process.engine. A Petri net model for the AND split and join is shown in Figure 3-8. Figure 3-8. Petri net AND split and joinThe Petri net model for an XOR split and an OR join is shown in Figure 3-9. Figure 3-9. Petri net XOR split and OR joinThe best way to understand the behavior of the model, in particular the unusual lambda transitions, is to trace the flow of tokens through these processes. Figure 3-10 shows the AND case. Figure 3-10. Token flow in Petri AND split-joinIn Step 1, transition A is enabled because its input place has a token. When A completes, a lambda transition is enabled (Step 2) that accomplishes the split to B and C by duplicating the token from its input place to the input places of B and C. At this point, B and C are enabled (Step 3), and in unpredictable order (Steps 4 and 5), B and C complete. The lambda transition that follows B and C, by virtue of Petri net token synchronization semantics, waits for tokens from both of the branches before commencing (Step 6). Once it fires, transition D is enabled, and its completion ends the process (Step 7). The key to the split is the token duplication from a single input place to two output places; the key to the join is the synchronization of input places. The XOR case, shown in Figure 3-11, starts the same way as the AND case. Figure 3-11. Token flow in Petri XOR split-OR JoinIn Step 1, transition A, having a token in its input place, is enabled and executes. The succeeding lambda transition in Step 2 evaluates a condition based on information in the token and accordingly passes that token to exactly one of its output places. In the example, that output place is the input to B (Step 3), and when B completes (Step 4), its succeeding lambda transition passes through the token to enable D (Step 5), whose completion in Step 6 concludes the process. The key to the split is the conditional flow made possible by the color extension; the join is trivial. 3.3.2.2 Dead path eliminationDead path elimination is a technique used in languages such as BPEL and WSFL to bypass, or "pass through," activities whose preconditions are not met. For example, in Part (a) of Figure 3-12, the activity Buy new home waits for the parallel activities Sell home and Get mortgage to complete, and it executes only if both have a true result. If at least one is false, the execution of Buy new home is skipped (i.e., can't buy a new home without financing and the sale of your old home), as is the execution of the successor activity Hire movers (i.e., don't call movers if you aren't moving). Figure 3-12. Dead path elimination for home movePart (b) shows the Petri net representation. Both the Sell home and Get mortgage transitions, representing the respective activities, branch upon completion in one of two paths: a true result leads into the place T, a false result to place F. A set of four lambda transitions waits for and aggregates the results of the two activities: TT is enabled when both activities return true, FF when both are false, TF when Sell home is true and Get mortgage false, and FT the converse of TF. The TT transition passes a token to the place T, thereby enabling the Buy home transition, and, further downstream, Hire movers. TF, FT, and FF each link to the place F, which leads into lambda transitions representing the no-op version of Buy home and Hire movers. The Petri net functions as a synchronizing truth table, allowing the purchase of the home and subsequent activities only when it receives "trues" for all inputs. 3.3.3. Petri Nets and the StandardsOf the major BPM standards, threeBPEL (Chapter 5), WSFL (Chapter 9), and BPMN (Chapter 6)have roots in Petri nets. Each standard uses the notion of token passing to describe the semantics of control flow. The BPMN specification uses the token concept throughout. In WSFL and BPEL, the most striking Petri-net-inspired discussion is dead path elimination. |