DEVS Introduction

advertisement
DEVS-based Modeling and Simulation
References:
1. B. P. Zeigler, Hessam S. Sarjoughian, Introduction to DEVS Modeling and
Simulation with JAVA: Developing Component-Based Simulation Models,
http://www.acims.arizona.edu/SOFTWARE/devsjava_licensed/CBMSManuscript.zi
p
2. B. P. Zeigler, H. Preahofer, T. G. Kim, Theory of Modeling and Simulation, New
York, NY, Academic Press, 2000.
3. http://www.acims.arizona.edu
DEVS Background
• DEVS = Discrete Event System Specification
• Provides formal M&S framework: specification,simulation
• Derived from Mathematical dynamical system theory
• Supports hierarchical, modular composition
• Object oriented implementation
• Supports discrete and continuous paradigms
• Exploits efficient parallel and distributed simulation
techniques
SYSTEM
output
input
state
SYSTEM
Input
trajectory
Output
trajectory
output
input
state
We view systems as having input and output interfaces (input ports and output
ports) through which they can interact with other systems
The term “port” signifies a specific means of interacting with the system. Ports
are the only channel through which one can interact with the system.
The time-indexed inputs to systems are called input trajectories
The time-indexed outputs are called output trajectories
State and initial state
A Forest System
lightning
rain
wind
FOREST
smoke
Discrete Time Systems
Input
trajectory
Output
trajectory
output
input
state
Continuous systems – differential equation system specification
Discrete time systems – difference equation – discrete time system specification
Discrete Event Systems
output
input
output
input
state
The system is driven by events
Discrete time systems is a special case of discrete event systems
Discrete event system specification (DEVS)
FSM, petri net, etc.
Experimental Frame
Basic Entities and Relations
in Modeling and Simulation
Device for
executing model
Simulator
Real World
Data: Input/output
relation pairs
modeling
relation
Experimental frame specifies
conditions under which the system
is experimented with and observed
Each entity is represented
as a dynamic system
Each relation is represented
by a homomorphism or other
equivalence
simulation
relation
Model
Structure for generating behavior
claimed to represent real world
DEVS Models
There are two kinds of Models in DEVS
• Atomic Model
• Coupled Model
DEVS Atomic Model
Elements of an atomic model:
• input events
• output events
• state variables
• state transition functions
– External transition
– Internal transition
– Confluent transition
• output function
• time advance function
DEVS Atomic Model Formalism
A Discrete Event System Specification (DEVS) is a structure
M = <X,S,Y,int,ext,con,, ta>
where
X is the set of input values.
S is a set of states.
Y is the set of output values.
int: S  S is the internal transition function.
ext: Q  Xb  S is the external transition function, where
Q  {(s,e) | s  S
? , 0  e  ta(s)} is the total state set,
e is the time elapsed since last transition,
Xb denotes the collection of bags over X.
con: S  Xb  S is the confluent transition function.
: S  Yb is the output function.
+
ta: S  R 0, is the time advance function
Discrete Event Time Segments
X
x0
t0
x1
t1
X
S
e
y0
Y
t2
(S,e)
Y
Atomic Model Operation
•
Ports are represented explicitly – there can be any number of input and output ports
on which values can be received and sent
•
The time advance function determines the maximum lifetime in a state
•
A bag can contain many elements with possibly multiple occurrences of its
elements.
•
Atomic DEVS models can handle bags of inputs and outputs.
•
The external transition function handles inputs of bags by causing an immediate state
change, which also may modify the time advance.
•
The output function can generate a bag of outputs when the time advance has
expired.
•
The internal transition function is activated immediately after the output function
causing an immediate state change, which also may modify the time advance.
•
The confluent transition function decides the next state in cases of collision between
external and internal events.
Dynamic of Atomic Model
Make a
transition
(external)
input
external
Handle
input
State
Make a
transition
(internal)
internal
time advance
output
output
Hold for
some time
Send an
output
Atomic Model Examples
pulse
start Pulse
Generator
out
time
Pulse Generator
Output
interPulseTime >0
start
active
passive
ta = ∞
Output
Fire-once Neuron
receptive
Input
Firing delay >0 ta = ∞
ta = ∞
external event
refract
fire
Internal event
output event
Internal Transition /Output Generation
output
Generate output
using the
output
function
Time advance
s’
s
Make a transition
Discussion: time advance =0, = Infinity
using the
internal
transition
function
Response to External Input
input
Make a transition
elapsed
time
Time advance
using the
external
transition
function
Response to Simultaneous External Input and Internal Event
output
input
Make a transition
elapsed
time
Time advance
Generate output
using the
confluent
transition
function
Discussion
1. There is no way to generate an output directly from an external input
event. An output can only occur just before an internal transition.
2. To have an external event cause an output without delay, we have it
“schedule” an internal state with a hold time of zero
3. The output function does not change a model’s state
4. In general, the only way to interact with a model is through input/output
ports.
5. An implementation issue -- An atomic model works with any objectoriented classes
6. A coupled model does not have its own states or state transition
functions.
DEVS Coupled Model
Elements of coupled model:
• Components
• Interconnections
– Internal Couplings
– External Input Couplings
– External Output Couplings
Coupling in Action
Coupling
(internal)
AB
B
A
external
State
Output
port
Input
port
external
State
internal
time advance
output
internal
time advance
output
DEVS Hierarchical Modular Composition
Atomic: lowest level model,
contains structural
dynamics -- model level
modularity
Atomic
Coupled: composed of
one or more atomic
and/or coupled
models
hierarchical
construction
Ato mic
Atomic
Atomic
A to mic
Atomic
Atomic
Coupled Model Example – Neuron net
can compute the shortest path in a directed graph by mapping distances of edges to equivalent
time values.
pulseIn
Pulse
Generator
FireOnce
Neuron 1
pulseOut
pulseIn
Small network of fire-once neurons
FireOnce
Neuron 2
pulseOut
pulseOut
pulseIn
pulseIn
FireOnce
Neuron 3
FireOnce
Neuron 4
pulseOut
pulseOut
•a pulse emitted from the generator explores
two paths concurrently to reach the final
neuron (number 4).
•depending on the summed firing delays
along each path, a pulse emerging from one
or the other will arrive first to the final
neuron, the other will be shut out and
prevented from continuing
• in general, the clock time when a pulse first
arrives to a neuron represents the shortest
time to reach it
• if nodes and link distances are mapped to
neurons and firing times, then the path taken
by a pulse represents the shortest path of an
associated digraph.
• the path can be reconstructed by extending
the neuron model to allow retracing the path
of earliest firings.
This method turns out to be isomorphic to
the well known Dikstrai shortest path
algorithm.
If instead of shortest paths, we request longest paths, a net of neurons that fire after their
assigned fireDelays every time they receive a pulse will do the job. Finding critical paths in PERT
charts require such longest path computation.
Back to the forest fire monitor system
Basic Atomic Methods
public double ta() : the time advance function;
returns the value of sigma for atomic models
public message out() : the output function; releases
the message just before an internal transition
public void deltint(): the internal transition function
public double ta(){return sigma; }
public message out(){return new message()} //override
public void deltint() {} //override
public void deltext(double e,message x) {} //override
public void deltext(double e,message x): the
external transition funciton
public void deltcon(double e,message x): the
confluent transition function
public void Continue(double e) : subtract e from
sigma; use to retain the same time of next event
after an external event
public void holdIn(String phase, double sigma) :
set the phase and sigma values as given in the
arguments
public void passivateIn(String phase) : set the
phase as given in the argument and sigma to
INFINITY
public void passivate() : set the phase to passive
and sigma to INFINITY
public boolean phaseIs(String phase) : return true
if the current phase equals the argument
public void deltcon(double e,message x){}//default
deltint();
deltext(0,x);
}
public void Continue(double e){
if (sigma < INFINITY)
sigma = sigma - e;
}
public void holdIn(String phase, double sigma) {
this.phase = phase;
this.sigma = sigma;;
}
public void passivateIn(String phase) {holdIn(phase, INFINITY);}
public void passivate() {passivateIn("passive");}
public boolean phaseIs(String phase){
return this.phase.equals(phase);
}
Basic Generator Concepts
0
first
First
Duration second
third
Duration
second
Duration
third
passive
active
public void initialize(){
super.initialize();
holdIn("active",0);
}
public void deltext(double
Continue(e);
e,message x){
if (somethingOnPort(x,"start"))
holdIn("first",firstDuration);
else if (somethingOnPort(x,"stop"))
passivate();
}
public void deltint(){
if (phaseIs("active")) holdIn("first",firstDuration);
else if (phaseIs("first")) holdIn("second",secondDuration);
else if (phaseIs("second")) holdIn("third",thirdDuration);
else passivate();
}
public message out(){
if (phaseIs("active"))
return outputRealOnPort(firstOutput,"out");
else if (phaseIs("first"))
return outputRealOnPort(secondOutput,"out");
else if (phaseIs("second"))
return outputRealOnPort(thirdOutput,"out");
else //if (phaseIs("third"))
return outputRealOnPort(0,"out");
}
Coupled Model Example:
using a basic generator to dynamically set the period of a pulse generator
boxCar
public class boxCar extends ViewableDigraph{
public boxCar(){
super("boxCar");
ViewableAtomic basic =
new basicGenr("basic",15,20,14, 2,1,1000);
\\ d1,d2,d3 ,p1,p2,p3
add(basic);
ViewableAtomic pg = new pulseGenr("pg");
add(pg);
addCoupling(basic,"out",pg,"setInterPulseTime");
}
Homework
• Read Chapter 1 chapter 2, Chapter 3
• Install DEVS JAVA
• Next class – More details on DEVS JAVA
• Next class – take any questions, Modeling in DEVSJAVA
Download