A MODELLING TOOL FOR HIERARCHICAL STOCHASTIC ACTIVITY NETWORKS Mohammad Abdollahi Azgomi Ali Movaghar Department of Computer Engineering Sharif University of Technology, Tehran 11365, Iran. E-mail:
[email protected] and
[email protected]
KEYWORDS Petri Nets, Hierarchical Stochastic Activity Networks, Modelling Tool, SANBuilder. ABSTRACT Stochastic activity networks (SANs) are a powerful and flexible extension of Petri nets. These models have been used to evaluate a wide range of systems and are supported by several powerful modelling tools. Hierarchical stochastic activity networks (HSANs) are a newly introduced extension of SANs. For modelling and evaluation with HSANs, we have developed a software tool called SANBuilder. This tool has an integrated development environment (IDE) for construction, animation, simulation and analytic solution of SANbased models. We have implemented in this tool some state-of-the-art methods for the simulation and analytic solution of SAN-based models. In this paper, after an introduction to HSANs, we present the specification, structure, solution methods and an evaluation of SANBuilder modelling tool. 1 INTRODUCTION Stochastic activity networks (SANs) (Movaghar and Meyer 1984) are a powerful and flexible extension of Petri nets (Peterson 1981). SAN models have been used to evaluate performance, dependability and performability of a wide range of systems and are supported by several powerful modelling tools such as UltraSAN (Sanders et al. 1995) and Möbius (Deavours et al. 2002). Hierarchical stochastic activity networks (HSANs) (Abdollahi and Movaghar 2003a) are a newly introduced hierarchical extension of SAN models. HSAN models encapsulate hierarchies and a key benefit of these models is the possibility of automatic employment of composition techniques, such as Replicate/Join (Sanders and Meyer 1991) or Graph Composition (Stillman 1999) formalisms by their modelling tool. HSANs have formal definitions and their semantics and behavior is described by transformation into equivalent SAN models. Modelling and analysis with Petri nets and their extensions need a software tool to help model
construction and analysis. As we mentioned, SANs are supported in the Möbius multi-paradigm modelling framework. It is ideal to integrate HSANs into this framework. Because of the existence of various kinds of solvers and simulators and implementation of SANs as an atomic model, Möbius is the best modelling framework for supporting HSANs. In the lack of such integration, we have developed a modelling tool for SAN and HSAN models called SANBuilder. This tool has an integrated development environment (IDE), which allows modelers to construct, compile, animate, simulate and solve SAN-based models. In this paper, after a brief introduction to HSANs, we present the specification, structure, solution methods and an evaluation of SANBuilder modelling tool. The rest of this paper is organized into six sections. In Sec. 2, an introduction to HSANs is presented. Sec. 3 gives a general overview of SANBuilder and its algorithms and techniques. An evaluation of the tool is presented in Sec. 4. Finally, some concluding remarks are mentioned in Sec. 5. 2 HIERARCHICAL STOCHASTIC ACTIVITY NETWORKS An HSAN model is composed of five elements of SANs, including place ( ), timed activity ( ), instantaneous activity ( ), input gate ( ) and output gate ( ), and a new element called macro activity (MA). MA is an HSAN submodel, which is composed of some SAN elements or lower-level macro activities. The syntax of the usage of MA is quite similar to the timed or instantaneous activities. Place fusion is used as a mechanism for interfacing macro activities to other parts of an HSAN model. An MA may have zero or more input and output fusion places. Fusion places are a subset of normal places. An MA has a well-defined interface that is similar to parameter passing of procedure and functions in high-level programming languages. The places surrounding an MA are formal fusion places. When an MA is used in an HSAN model, these formal places will be bound by actual places, which are normal places of SANs. In a graphical representation, a fusion place is depicted as . A graphical representation of an MA is shown in Fig. 1(a) and its usage in Fig. 1(b).
MAName
Animator IFP
IFPn Input fusion places
Analytic Solver
OFP 1
MA
1
OFPm Output fusion places
GUI
SAN Editor
Model Compiler
(a) C++Builder
Model Transformer
State Space Generator
Model Flattener D.-E. Simulator
State Space Handler
MAName OP
IP1
1
Fig. 3 Software Structure of SANBuilder
MAInstance IP n
OP
(b)
m
Fig. 1. Graphical Notation of A Macro Activity: (a) Definition, and (b) Usage
(a)
Fig. 4. A view of the user interface of SANBuilder
3.1 Software Structure of SANBuilder (b)
Fig. 2. HSAN Model of A Queueing Network: (a) MM1NQ Macro Activity, (b) HSAN Model
As an example of HSAN models, see the model depicted in Fig. 2. Fig. 2(a) displays a macro activity, called MM1NQ, for the M/M/1/N queue. The MA has the following elements: input (an input fusion place), Arrival (a timed activity that models the arrival process), ChkFull (an output gate that checks for the capacity of the queue, N), Queue (a place that models the queue line), Service (a timed activity that models the service time) and output (an output fusion place). Fig. 2(b) displays the HSAN model for a queueing network, composed of six tandem/parallel queues. Q1 through Q6, are some instantiations of the MM1NQ. Arrival and Departure timed activities models the input and output process of the network. Input, Output1 through Output4 are some places, which are bound to the input/output fusion places of Q1 through Q6. 3 SANBUILDER MODELLING TOOL In this section, we introduce the software structure and implementation of SANBuilder modelling tool. This modeling tool runs under Windows 2000/XP and provide an IDE for constructing SAN-based models (including SANs and HSANs) in a graphical editor, load and save models and macro activities. It can also compile, animate, simulate and analytically solve SAN and HSAN models.
The overall software structure of SANBuilder, including its main modules and their relations, has been depicted in Fig. 3. Elements of this structure are as follows: 1. The Graphical User Interface (GUI): The GUI of SANBuilder is an IDE for editing SANs and HSAN models, checking their syntax and semantics, compilation, animation and evaluation using state space analysis or simulation methods. This integration makes SANBuilder a user-friendly modeling tool. A view of the user interface of SANBuilder is displayed in Fig. 4. 2. SAN Editor: This graphical editor allows to easily construct HSAN models. An important feature of SAN Editor is its feature for saving and loading models and macro activities in an interchange format, called SAN markup language (SANML). SANML is based on the Petri nets markup language (PNML) (Billington et al. 2003). 3. Model Compiler: The input/output function of the input/output gates of SANs are general computable functions. Therefore, this module generates C/C++ codes corresponding to the above functions and calls Borland C++Builder to generate a dynamic link library (DLL). SANBuilder will load this DLL before animation, simulation or analytic solution of the model. 4. Model Flattener: A simple approach for the evaluation of HSAN models is transforming them into a flat SAN model and using the existing methods. Model Flattener does such transformation. 5. Model Transformer: An advanced approach for the evaluation of HSAN models is using the existing techniques for the construction of composed models with reduced state
spaces. Model Transformer converts an HSAN model using one of these techniques. 6. Model Animator: SANBuilder can animate models. This feature is also known as token-game animation. For animating, the tool shows a step-by-step execution of the network by firing enabled activities and changing the marking. Animation is done in a stochastic manner (i.e. the result of discrete-event simulation of the model is animated on the graphical user interface). Debugging is a useful feature of this animator, which enables the modeler to define queries about the model behavior and trace their results while the animation is in progress. 7. State Space Generator: It executes a SAN model for generating its state space. The reachability graph (RG) of the model is built using the following State Space Handler module. 8. State Space Handler: This module stores and manages the RG in a hash table data structure. 9. Analytic Solver: If all timed activities of the model are exponentially distributed, this module can be used for model solution. If so, the corresponding continuous-time Markov chain (CTMC) will be generated and if it is finite, its ergodicity will also be checked. If it is ergodic, its global balance equations will be solved to compute its steady-state probabilities. Finally, the predefined results of the solution and user-defined queries will be computed from the steady-state probabilities and displayed on GUI. 10. Discrete-Event Simulator: If the steady-state solver cannot be used, simulation may be utilized for performance evaluation. This module simulates SANs using a discreteevent simulation algorithm. It also collects the predefined and user-defined statistics and displays them whenever the simulation is in progress or completed.
3.2 Implementation of SANBuilder In the following subsections, we briefly describe some important algorithms and techniques used for the implementation of SANBuilder. We have used C/C++ programming language and Borland C++Builder compiler for the implementation of SANBuilder. 3.2.1 State Space Generator The state space generation algorithm of SANBuilder for SAN models is based on the work in the Möbius modelling framework (Sowder 1997). The state space generation algorithm is divided into two parts. The first part is the main state generation algorithm that determines all states of a model in a breadth-first manner. The second part specifies precisely how to determine next states when timed and/or instantaneous activities are enabled in a specific state. The state-space generation algorithm (Algorithm 1) is shown in Fig. 5. The set of generated states (S) contains all unique states that have been produced at any point in time by the state-space generator. Generated states are those tangible states that have been found using the GenerateNS algorithm. A tangible state is a state that has no instantaneous activity enabled in it. The unexplored set contains all tangible states that have not
been used by GenerateNS. The set of next tangible states found by GenerateNS is stored in the NS set. Algorithm 2 (GenerateNS) that is shown in Fig. 6 is used to determine all tangible next states of an unstable state. GenerateNS is a recursive algorithm that takes as input a state and a probability. Initially, the probability value is set to 1.0. 3.2.2 State Space Handler The most important problem with state space handling is the amount of time and memory needed for large models. Due to fast lookup and insertion time, a hash table is an appropriate data structure for storing the set of generated states (S). Such a hash table is used in the Möbius tool (Sowder 1997). We have implemented a hash table, which is based on the method proposed in (Weiss 1994). In this method, the hash function is computed by the polynomial function of Fig. 7. Algorithm 1. State-Space Generation TA = {ta1, ta2, … } // TA is the set of all timed activities IA = {ia1, ia2, … } // IA is the set of all instantaneous activities S = {∅} // S is the set of generated states U = {µ0}// U is the set of unexplored states, µ0 is the initial state NS = {∅} // NS is the set of next states While U ≠ ∅ For some µ∈U NS = {∅} NS = GenerateNS(µ, p=1.0) // Using Algorithm ∀ns ∈ NS If ns ∉ S S = S ∪ {ns} U = U ∪ {ns} End ∀ U = U – {µ} End For End While
Fig. 5. State Space Generation Algorithm Algorithm 2. GenerateNS (s, p) NS = {∅} If s is not stable ∀ia ∈ IA If ia can be fired then fire it in s µ' is the state of system after firing ia µ'.p = ia.p NS = NS ∪ {µ'} End If End ∀ µ. p µ. p = × s. p ∀µ∈NS µ. p ∑ µ∈NS End If If s is stable ∀ta ∈ TA If ta can be fired then fire it in s Fire ta µ' is the state of system after firing ta µ'.p = ta.rate × s.p NS = NS ∪ {µ'} End If End ∀ End If NS' = {∅} ∀µ∈NS If µ is stable NS' = NS' ∪ {µ} Else NS" = GenerateNS(µ, µ.p) NS' = NS' ∪ NS" End If End ∀ Return NS'
Fig. 6. Next Tangible States Generation Algorithm
Function HashFunction (State) HashKey = 0 for i = 0 to StateSize-1 HashKey = 37 * HashKey + State[i] HashKey = HashKey mod HashSize Return HashKey
Fig. 7. The Hash Function of State Space Handler
To minimize the number of collisions, the hash size is a prime number. Since, the method is not collision-free, a quadratic probing collision resolution strategy is used for rehashing. In this strategy, in the case of collision, the new index is computed by function f(j) = f(j-1) + 2j – 1, where j is the number of collisions. For insertion, new indices are computed until an empty position is found. For a lookup, all states that are reached must be compared to the next state until either a match occurs (the state is not a new state), or an empty position is reached (the state is a new state, and should be added to the table). If a hash size that is a prime number is used, the quadratic probing procedure is guaranteed to terminate if the table is at least half empty (Weiss 1994). 3.2.3 Well-Defined Checker If an HSAN model is well-defined, it can be solved by analytic or simulative methods. An HSAN model is well-defined if its dependency graph (DG) is finite and acyclic. In a DG, nodes are macro activities and the composition relation between MAs and the main HSAN model determines arcs. The root of DG is the HSAN model. If a cycle is detected in DG, the model is not well-defined and therefore cannot be analyzed. Otherwise, it is possible to employ an algorithm to transform and analyze the corresponding HSAN model. Well-defined checker construct a DG for the model and checks it to be finite and acyclic. 3.2.4 Model Flattener Each HSAN model has an equivalent flat SAN model. For the analysis of an HSAN model, it is possible to transform it to an equivalent flat SAN model. A substitution algorithm can be employed to flatten the HSAN model. In each step of the algorithm, all MAs on the leaves of the graph will be substitute by their definitions. This will be repeated until the only node on the graph is the root node. The resulting model is a flat SAN model. The Algorithm 3 of Fig. 8 does such a transformation. In this algorithm, we use the notations of the formal definitions of HSANs (Abdollahi and Movaghar 2003a). Naming in HSAN models is local. Therefore, the name of two elements in two different levels of the hierarchy of an HSAN model may be identical. To resolve the problem of duplicate names in the substitution of MA with its definition, the name of each element of an MA will be preceded by the name of its parent MA. For example, if we have an MA named ma1 in an HSAN model and there is a place named p1 in the definition of ma1, a place named ma1.p1 will be added to the flattened model.
Algorithm 3. Flattener (HSAN) While MA ≠ ∅ // MA is the set of all macro activities of HSAN For some ma ∈ MA P = P ∪ ma .P // P is the set of all places TA = TA ∪ ma .TA // TA is the set of all timed activities IA = IA ∪ ma .IA // IA is the set of all instantaneous activities MA = MA ∪ ma .MA // MA is the set of all macro activities IG = IG ∪ ma .IG // IG is the set of all input gates OG = OG ∪ ma .OG // OG is the set of all output gates IR = IR ∪ ma .IR // IR is the set of all input relations OR = OR ∪ ma .OR // OR is the set of all output relations MA = MA – {ma} End For End While Return HSAN //An HSAN with no MA that is actually a SAN model
Fig. 8. HSAN Flattening Algorithm
3.2.5 Model Transformer The main disadvantage of the above flattening method is the explosion of nodes in the resulting model that may lead to the explosion of the state space of the model. There are a few techniques for constructing SAN models in a way, which avoid state-space explosion problem. A key benefit of HSAN models is the possibility of automatic employment of such techniques by their modelling tools. SANBuilder can transform an HSAN model into the following composition formalisms: 1. Replicate/Join construct: A composition technique for SANs is the Replicate/Join construct (Sanders and Meyer 1991). A possible way of the analysis of HSAN models is to transform them into this construct. For this purpose, SANBuilder checks for a tree-like structure in the dependency graph of an HSAN model. Then, it automatically finds shared states based on the fusion places and organizes the model using Replicate and Join operations. For the solution of the resulting model, the technique proposed in (Sanders and Meyer 1991 or Stillman 1999) can be employed. 2. Graph Composition formalism: Another composition formalism, which has been proposed in the Möbius modelling framework for SANs and other models, is the Graph Composition formalism (Stillman 1999). This formalism does not limit the model hierarchy to a tree-like structure and any arbitrary structure (such as ring or mesh) is possible. SANBuilder checks for the possibility of the usage of this formalism. Then, it transforms the corresponding HSAN model and uses the method proposed in (Stillman 1999) to solve the model.
3.2.6 Analytic Solver If all timed activities of a SAN model are exponentially distributed, it can be represented by a continuous-time Markov chain (CTMC). The resulting CTMC will be ergodic if its reachability graph (RG) is finite and fully connected. An ergodic CTMC can then be solved analytically using standard Markovian solution techniques. Accordingly, the global balance equations of a CTMC may be solved to compute the steady-state probabilities of its states. Since the state-transition-rate matrices of such CTMCs are usually sparse, numerical methods such as Gauss-Seidel and Gauss-elimination (Rice 1993) are used. Most performance measures of interest, such as responsiveness (including waiting time, processing time, queue length, etc.) and usage-level
(including throughput and utilization factor) may be evaluated from such steady-state probabilities. In SANBuilder, when the state space is being generated, the state-transition-rate matrix will be constructed. We have implemented two techniques for handling sparse matrices. One of them uses main memory and the other uses a C++Builder database table for storing the matrix. The first technique is limited to the amount of free main memory, but is fast. On the other hand, the second technique is less limited, but is not fast. SANBuilder automatically computes the steady-state probabilities, the maximum and average number of tokens of places, throughput of timed or instantaneous activities and the average enabling time of timed activities. In addition, it allows the user to define his/her interested markings and queries that will be computed by the tool when the solution is completed. Currently, we are working on implementation of some fast and efficient methods for analytic solution. One of these methods is "on-the-fly" solution technique, such as (Deavours and Sanders 1998), which do not need to explicitly store the matrix. 3.2.7 Discrete-Event Simulator If an HSAN model or one of its macro activities is composed of one or more non-exponential timed activities or its state-space is infinite, it may not be solved analytically. In such cases, discrete-event simulation may be employed to solve the model. The discrete-event simulation algorithm for SAN models is shown in Fig. 10. Algorithm 4. Discrete-Event Simulator 1. Determine the set of enabled activities in the current marking of the model. 2. Reactivate those disabled activities whose reactivation predicates are true in the current marking. 3. Generate the activity execution time for newly enabled or reactivated activities. 4. Apply the corresponding enabling rates on the remaining time of the enabled timed activities. 5. If more than one instantaneous activity is enabled in an unstable marking, select one of them probabilistically. The probability of selection of each enabled instantaneous activity a in marking µ is computed by the following formula (Movaghar 2001): C (µ , a) α= ∑a'∈A' C(µ , a' )
SANBuilder automatically computes the maximum and average number of tokens for all places, number of firings, throughput, total enabling time and enabling probability for all timed activities and the number of firings and throughput for all instantaneous activities for all models. In addition, it allows the user to define his/her interested markings and queries that will be computed at the end of simulation or even while the simulation is in progress. We are working on implementation of efficient techniques for the simulation of HSAN models. These methods are based on a method proposed for fast simulation of SAN composed models (Sanders and Freire 1993) and techniques for discrete-event simulation in the Möbius framework (Williamson 1998). 4 EVALUATION OF THE TOOL Kanban model (Ciardo and Tilgner 1996) is used as a base model to evaluate several tools (such as, UltraSAN and Möbius). The model represents a simple factory production line. The model has four stages. By varying the capacity of each stage, the state space of the corresponding model will change considerably. We have constructed the Kanban model with SANs and HSANs that are shown in Fig. 11 and 12, respectively. Fig. 11 shows a flat SAN model. Kanban1 through Kanban4 places represent the capacity of each stage. Fig. 12(a) shows KanMA macro activity corresponding to each Kanban stage. Fig. 12(b) shows an HSAN model composed of four KanMA macro activities. K1 through K4 places represent the capacity of each stage.
Fig. 11. A Flat SAN Model for Kanban
Where A’ is the set of all enabled instantaneous activities and C is the case probability of a in marking µ. 6. In a stable marking (no instantaneous activity is enabled), considering the remaining time of all enabled timed activities and their respective enabling rates, select the next timed activity for completion. In the case of two equal completion times, select one of the corresponding timed activities, probabilistically. 7. Fire the selected instantaneous or timed activity: - Remove a token from all input places, - Execute the function of all input gates, - Add a token to all output places, and - Execute the function of all output gates. 8. Disable those enabled activities whose enabling predicate are not true in the current marking. 9. Set the simulation clock to the time of the most eminent event. 10.Collect the aggregated statistics and update user-defined queries. 11. If the specified confidence level (or fixed replications/time interval) has not been achieved, go to step 1.
Fig. 10. Discrete-Event Simulator of SAN Models
Fig. 12. The Kanban HSAN Model: (a) KanMA and (b) Kanban HSAN Model
Tab. 1. Results of State Space Generation of Kanban Model No. of Tokens 1 2 3 4 5
No. of States 160 4,600 58,400 454,475 2,546,532
Time (sec.) 0.01 0.10 3.00 44.00 1998.00
Tab. 2. Simulation Time for Kanban Model No. of Tokens 1 2 3 4 5
Time (sec.) 176 323 365 501 550
We have investigated the performance of the state-space generator for the two models while the hash size is 3,000,017 (a prime number) and the number of tokens in Kanban places varies from 1 to 5. These executions are on a personal computer with Pentium 4 CPU and 256MB RAM. The results are same for both models and are shown in Tab. 1. We have also investigated the performance of the steady-state simulator for the two models while the number of tokens in Kanban places varies from 1 to 5. For this purpose, we have executed the simulation for 10 replications each for 1,000,000 units of time, while the enabling rate of all timed activities is equal to 1. The results are (nearly) same for both models and are shown in Tab. 2. 5 CONCLUSION In this paper, we have introduced SANBuilder as a modelling tool for SAN-based models. Currently, this tool supports stochastic activity networks (SANs) and hierarchical stochastic activity networks (HSANs). This tool has an integrated development environment (IDE) for the graphical edition, animation, simulation and analytic solution of SAN-based models. SANBuilder checks for the employment of composition formalisms, such as Replicate/Join construct or the Graph Composition formalism, based on the structure of the hierarchy of HSAN models. We have implemented in SANBuilder some state-of-the-art methods for simulation and analytic solution of SAN-based models. We have employed this tool in a few case studies and evaluated its performance with some well-known models. To make SANBuilder more useful for the application on large-scale systems, we are working to implement efficient methods for steady-state and transient solution and simulation of SAN and HSAN models. We are also planning to add support for two other highlevel extensions of SANs, including coloured stochastic activity networks (CSANs) (Abdollahi and Movaghar 2003b) and object stochastic activity networks (OSANs) (Abdollahi and Movaghar 2003c).
REFERENCES Abdollahi Azgomi M. and Movaghar A. 2003a, "Hierarchical Stochastic Activity Networks," In Proc. of ESM04/ ASMTA03 (Nottingham, UK), 169-174. Abdollahi Azgomi M. and Movaghar A. 2003b, "Coloured Stochastic Activity Networks: Preliminary Definitions and Properties," In Proc. of the ICALP03 Satellite Workshop on Stochastic Petri Nets and Related Formalisms (Eindhoven, The Netherlands), 154-169. Abdollahi Azgomi M. and Movaghar A. 2003c, "Towards an Object-Oriented Extension for Stochastic Activity Networks," In Proc. of 10th Workshop on Algorithms and Tools for Petri Nets (AWPN'03) (Eichstätt, Germany), 144155. Billington J. et al. 2003, "The Petri Net Markup Language: Concepts, Technology, and Tools," In Proc. of 24th Int. Conf. on App. and Theory of Petri Nets (LNCS 2679), Springer, 482-505. Ciardo G. and Tilgner M. 1996, "On the use of Kronecker operators for the solution of generalized stochastic Petri nets," NASA Langley Research Center, ICASE Report #9635 CR-198336. Deavours D.D. and Sanders W.H. 1998, "On-the-Fly Solution Techniques for Stochastic Petri Nets and Extensions," IEEE Trans. on Soft. Eng., Vol. 24, No. 10, 889-902. Deavours D.D. et al. 2002, "The Möbius Framework and Its Implementation," IEEE Trans. on Soft. Eng., Vol. 28, No. 10, 956-969. Movaghar A. and Meyer J.F. 1984, "Performability Modeling with Stochastic Activity Networks," In Proc. of the 1984 Real-Time Systems Symp. (Austin, TX, USA), 215-224. Movaghar A. 2001, "Stochastic Activity Networks: A New Definition and Some Properties," Scientia Iranica, Vol. 8, No. 4, 303-311. Peterson J.L. 1981, "Petri Nets Theory and the Modeling of Systems," Prentice-Hall. Rice J.R. 1993, "Numerical Methods, Software and Analysis," Academic Press. Sanders W.H. and Freire R.S. 1993, "Efficient Simulation of Hierarchical Stochastic Activity Network Models," Discrete Event Dynamic Systems: Theory and App., Vol. 3, No. 2/3, 271-300. Sanders W.H. and Meyer J.F. 1991, "Reduced Base Model Construction Methods for Stochastic Activity Networks," IEEE J. on Selected Areas in Comm., Vol. 9, No. 1, 25–36. Sanders W.H., Obal II W.D., Qureshi M.A., Widjanarko F.K. 1995, "The UltraSAN Modeling Environment," Performance Evaluation, Vol. 24, 1-33. Sowder J.M. 1997, State Space Generation Techniques in the Möbius Modeling Framework, M.S. Thesis, University of Illinois at Urbana-Champaign. Stillman A.J. 1999, Model Composition in the Möbius Modeling Framework, M.S. Thesis, University of Illinois at Urbana-Champaign. Weiss M.A. 1994, Data Structures and Algorithm Analysis in C++. New York, Benjamin/Cummings Publishing Company. Williamson A.L. 1998, Discrete Event Simulation in the Möbius Modeling Framework, M.S. Thesis, University of Illinois at Urbana-Champaign.