Lect 7: DEVS Model Reuse and Schedule Conflict
Simulation Enge: Independent of Model 2 of 20 Model Execution Algorithm = Execution Enge = Simulation Enge Model and Simulation Enge should be dependent A simulation enge can execute a model different manner. Ex: Model execution time Virtual vs Real time Static System (No time specified) Dynamic System (Time advance specified ) Model Simulteneous Eq. Rule Base Differential Eq. DEVS Eq. Interface Simulation Enge Eq. Solver (Substitution) Inference Enge (Rule Matchg) Numerical Analyzer (Numerical Integrator ) DEVS Enge (Time schedule & Message delivery) One model may have different simulation enge Complexity of enge vs Execution time
DEVS M&S Environment with Language L: DEVSim-L 3 of 20 Discrete Event System Modelg/Simulation Tool Realization of the DEVS formalism C++ / Java DEVS Formalism and Object-oriented Paradigm Separatg Models from Simulation Enge DEVSim++ (C++); DEVSimJava (Java); DEVSimHLA (C++ and HLA compliant) DEVSim-L Hierarchical Simulation Enge Modeler s Interface DEVS Modelg Coupled DEVS request ack Root Coordator Coordators Atomic DEVS request ack Simulators Utility Class Library of Language L See the DEVSimHLA manual for class defitions hierarchy
Why C++ Implementation DEVSim++? 4 of 20 C++ Language Developed by Bjarne Stroustrup (Bell Laboratories) early 1980 s Motivation of C++ Imitation of the first object-oriented simulation language, Simula 67, usg C Introducg Class concept usg C C with Classes Use as discrete event simulation Characteristics of Object-oriented language C++ Object-oriented simulation language Move toward an object-oriented general purpose language One-to-one mappg from a real-world object to a model class Encapsulation as components beg resused Ease of modification/matenance Improved S/W Quality Support of C languae DEVSim++ M&S Tool Development of DEVS models usg C++
CAtomic and CCoupled Head files DEVSim++ 5 of 20 Part of Atomic DEVS defition CAtomic.h used DEVSim++ class CAtomic : public Cmodel public: virtual bool ExtTransFn(const CDEVSimMessage &) return false; virtual bool IntTransFn() return false; virtual bool OutputFn(CDEVSimMessage &) return false; virtual TimeType TimeAdvanceFn() return -1; ; void Contue() m_bcontue = true; void Cancel() m_bcancel = true; DEVSim++ classes Cmodel CAtomic CCoupled heritance Users defed classes Part of Coupled DEVS defition CCoupled.h used DEVS++ class CCoupled : public Cmodel public: bool AddComponent(t num, ); bool AddCouplg(CModel *src_model, const char *src_port, CModel *dst_model, const char *dst_port); bool AddCouplg(CModel *src_model, unsigned t src_port, CModel *dst_model, unsigned t dst_port); bool RemoveCouplg(CModel* src_model, const char* src_port, CModel* dst_model, const char *dst_port); bool RemoveCouplg(CModel* src_model, const char* src_port); bool RemoveCouplg(CModel* src_model, unsigned t src_port, CModel* dst_model, unsigned t dst_port); bool RemoveCouplg(CModel* src_model, unsigned t src_port); ; bool SetPriority(t num, );
DEVSim++/ DEVSimHLA Code For SgleServerQueue 6 of 20 SgleSeverQueue Generator QueueServer class SgleSeverQueue : public CCoupled public: SgleSverQueue(); ~SgleServerQueue(); ; SgleServerQueue::SgleServerQueue() CModel *Gen, *QueSer; Gen = new Generator; QueSer = new QueueServer; AddComponent(2, Gen, QueSer); SetPriority(2, Gen, QueSer); AddCouplg(Gen, ", QueSer, ");...
Defition of Atomic Class QueueServer API 7 of 20 class QueueServer : public CAtomic public: QueueServer(); ~ QueueServer(); virtual bool ExtTransFn(const Cmessage &); virtual bool IntTransFn(); virtual bool OutputFn(CMessage &message); virtual TimeType TimeAdvanceFn(); ; // Atomic Model: QueueServer // external transition function // ternal transition fucntion // put function // time advance function bool QueueServer ::ExtTransFn(const CMessage &message) bool QueueServer ::IntTransFn() bool QueueServer ::OutputFn(CMessage &message) TimeType QueueServer ::TimeAdvanceFn()
Server.status DEVSim++ Code For QueueServer 8 of 20 B F QueueServer 0 Queue Server Queue.length Server.status X = Y = S = (length,status) length I, status B, F ext ((n 0,-),) = (n+1,-) ext ((0,F),) = (1,B) t ((n 1,B)) = (n-1,b) t ((n=1,b)) = (0,F) ((n 0,-)) = ta((n 0,-)) = Service_time 1 2 3 queue.length (n) bool QueueServer::OutputFn(CMessage &message) bool class QueueServer::ExtTransFn(const if(!isstate(length, 0)) public CAtomic CMessage &message) message.setportvalue(, NULL); public: if(message.getport() return true; == ) QueueServer(); if(!isstate (length, 0)) ~QueueServer(); SetStateValue(length, GetIntStateValue(length)+1); virtual else if(isstate(length, bool ExtTransFn(const 0) && IsState(status, CMessage &); F)) TimeType QueueServer::TimeAdvanceFn() virtual SetStateValue(length, bool IntTransFn(); 1); virtual SetStateValue(Status, bool OutputFn(CMessage B); if(isstate(length, 0)) &); virtual return TimeType Service_Time; TimeAdvanceFn(); ; return true; else return Infity; QueueServer::QueueServer() bool QueueServer::IntTransFn() AddInPorts(1, ); if(!isstate(length, AddOutPorts(1, 1) ); && IsState(status, B )) AddStateVariables SetStateValue(length, (2, length, GetIntStateValue(length)-1); status ); InitStateValue SetStateBale(status, ( length, B); new Integer(0)); InitStateValue ( status, new Strg( F )); else if(isstate(length, 1) && IsState(status, B)) SetStateValue(length, 0); QueueServer::~QueueServer() SetStateBale(status, F); return true;
Two Dimensional Reuse DEVSim-L (L: OOP Lang.) 9 of 20 M123 M12 M3 Components reuse Coupled models Coupled models Subclasses of atomic or coupled models M12 Atomic models M1 M2 Library of characteristic functions and state variables OO Paradigm Italics can be reused M = < X, Y, S, ext, t, ta, > DN = < X,Y, M, EIC, EOC, IC, SELECT>
Reuse Through Inheritance: Subclass of Atomic DEVS 10 of 20 Atomic_ models sert : ext delete: t + Buffer ext : X Q S t : S S : S Y ta : S R + 0, reusable delete FIFO (First-, First-) sert ext : X Q S :New defition t : S S : S Y Reuse by heritance ta : S R + 0, sert delete LIFO (Last-, First-) ext : X Q S : New defition t : S S : S Y Reuse ta : S R + by heritance 0,
DEVSim++ Code : Buffer, FIFO, LIFO 11 of 20 class Buffer : public CAtomic ; virtual Buffer::ExtTransFn(const CMessage &message) Buffer bool Buffer::IntTransFn() bool Buffer::OutputFn(CMessage &message) TimeType Buffer::TimeAdvanceFn() Inheritance class FIFO : public Buffer ; FIFO bool FIFO::ExtTransFn(const Cmessage &message) class LIFO : public Buffer ; LIFO bool LIFO::ExtTransFn(const CMessage &message)
Reuse Through Inheritance: Subclass of Coupled DEVS 12 of 20 Example of Reuse couplg scheme Coupled DEVS EIC : parameterzied one of multicast, unicast, broadcast IC : fixed EOC : fixed Multicast-1 Unicast-3 Broadcast-1 M1 M1 M1 M2 M2 M2 M3 M3 M3
Example of Subclass of Coupled Models 13 of 20 Coupled_models Receiver Mi : reusable EIC IC EOC reusable select Multicast EIC : REC-to-many IC EOC select Mi Reuse by heritance Unicast EIC : REC-to-one IC EOC select Mi Reuse by heritance Broadcast EIC : REC-to-all IC EOC select Mi Reuse by heritance
DEVS as State/put Equation Form 14 of 20 DES Dynamic Equations q = (s, r ) = t (q) ext (q, x ) = t (s, r) ext ( (s, r), x ) y = (s, r) Interpretation q' = t (s, r) ext ( (s, r), x ) t (s, r) if only t occurs = ext ( (s, r), x ) if only ext occurs Input-free transition putted transition Not happen both t and ext occur y = (s, r) : always occurs with t (s, r)
DEVS Graph DEVS graph G = < V, E > Visual representation of DEVS atomic model a labeled graph V represents DEVS sequential (discrete) state V = S E represents ternal or external transition with labels on E E V V with a label (X Y ) R X: put; Y:put; : empty put; R: elapsed time Representation Example (,e) (x,0) s 0 s 0 (y, ta(s 0 )-e) s 2 Internal transition + put External transition 15 of 20 s 1 s 0 s 1 (x,e) (y, ta(s 0 )) s 2 s 0 s 1 (y, r) x s 2 Interpretation If S= s0 and X= x before r then S = s2 If S=s0 and no put until r then S=s1 and Y=y e at (x, e) is not represented this model Note] Each node G can have either ternal transition or external transition or both.
Schedule Conflict(Tie) 16 of 20 Event schedulg: Only for put event by ta after each state transition M Incomg time of is not controllable by M Outgog time of is scheduled by M s ta Assumptions on Atomic DEVS Modelg A-1: Transition either by put or by put-free, but not both :: q = t (q) ext (q, x ) A-2: Arrivg one put event at a time :: ext (q, x) Schedule Conflict Case: Violation of assumptions Internal() and External() Events Violation of A-1 M1 External(1) and External(2) Events Violation of A-2 1 2 M2 Internal(1) and Internal(2) Events Never happen (because one put for a state) M3 1 2
Schedule Tie-Break: Select function 17 of 20 Tie-break ==> Select : 2 Mi M i conflict resolution: priority of ternal transitions of models that cause conflict. Case A-1: For M1, Internal and external transitions are conflict M1 Tie-break:: Select (M1, M3) = M1 M3 t ( (s, r)) for M1 is applied first Then, t ( (s, r)) for M3 Case A-2: For M2, two puts are conflict M4 M5 1 2 M2 Tie-break:: Select (M4, M5) = M4 For M2 ext ( (s, r), 1 ) is applied first Then, ext ( (s, r), 2) Select decides order of q' = t (q) ext (q, x ) when both transition occur
Schedule Contuation or Override 18 of 20 s 0 x (y, r 0 ) s 2 s 1 Assume: ta(s 0 ) = r 0 current simulation time: t case 1: no put is arrived next r0 time unit at (t + r 0 ), ternal transition :: (s 0, r 0 ) -> (s 1, 0) generate put y new schedule r 1 = ta(s 1 ) case 2: an put x is arrived next e < r 0 time unit at (t + e), external transition :: ((s 0, e), x) -> (s 2, 0) case 2-1: contuation of previous schedule ta(s 2 ) = r 2 = r 0 e case 2-2: cancel previous schedule and make a new one ta(s 2 ) = r 2 = new value
Time Chart for Schedule Contuation/Override 19 of 20 s 0 s 0 s 1 y r 0 = ta(s 0 ) Initial Schedule r 0 Case 1: no put before scheduled time y y x s 2 r 0 -e s 2 x r 2 s 0 e s 0 e r 0 Case 2-1: contuation of previous schedule r 0 Case 2-2: make a new schedule
Schedule Contuation DEVSim++: Macro contue Time advance : ta(s) ta is decided based only on the current discrete state Executed after both ternal(put-free) and external(putted) state transitions Time advance after ternal transition A new schedule for a new state is required: ta(current-state) = new-value Time advance after external transition Schedule at the previous state (ta-old) may exist ta(current-state) after external transition is either contuation of old one or new one. Time advance after external transition For contuation extra state variables (ta-old, e) may be required (ta-old: existg schedule; e: time elapsed after existg schedule) Time advance at current state ta(current-state) = ta-old e for contuation of existg schedule = new-value otherwise Macro contue DEVSim++ contue :: ta(current-state) = ta-old e The macro contue DEVSimHLA can be used with external transition function with extra state vars by users 20 of 20