DEVS M&S Tutorial 2 - Arizona Center of Integrative Modeling and

Download Report

Transcript DEVS M&S Tutorial 2 - Arizona Center of Integrative Modeling and

DEVS M&S Tutorial 2
Chungman Seo
[email protected]
Contents

DEVSJAVA Lib


Expression of Atomic Model


State Diagram
DEVSJAVA code Structure



DEVS Interface
Atomic model
Coupled model
Exercise : Fire once neuron
DEVS Interface



DEVS Supporting Interface
DEVS Modeling Interface
DEVS Simulation Interface
DEVS Supporting Interface

Provide a supporting
environment for
implementing DEVS
implementations

EntityInterface
Collection
Basic data structures




Entity
Content
Message
Port
0:n
interface EntityInterface{
String getName();
boolean equalName(String name);
}
interface Collection extends EntityInterface{
int size();
void add(EntityInterface entity);
void remove(EntityInterface entity);
boolean contains(EntityInterface entity);
}
Message-related-Interfaces

ContentInterface


A Pair of port-value
MessageInterface

A collection of
contents
Collection
interface ContentInterface {
PortInterface getPort();
EntityInterface getValue();
boolean onPort(PortInterface port);
}
0:n
ContentInterface
MessageInterface
PortInterface
EntityInterface
interface PortInterface
extends EntityInterface{
}
interface MessageInterface extends Collection{
boolean onPort(
PortInterface port,
ContentInterface content);
EntityInterface getValOnPort(
PortInterface port
,ContentInterface content);
}
Ensemble-Interface
Collection
ensembleBasic
ensembleCollection
interface ensembleBasic {
void tellAll(Method m, EntityInterface[ ] args);
ensembleCollection askAll(Method m);
ensembleCollection which(Method m);
EntityInterface whichOne(Method m);
}
interface ensembleCollection extends ensembleBasic, Collection{
public ensembleCollection copy(ensembleCollection ce);
}
DEVS Modeling Interfaces
interface IODevs {
void addInport(String portName);
void addOutport(String portName);
ensembleCollection getInports();
ensembleCollection getOutports();
ContentInterface makeContent(PortInterface
port,EntityInterface value);
boolean messageOnPort(MessageInterface x,
PortInterface port, ContentInterface c);
}
interface basicDevs {
void deltext(double e,MessageInterface x);
void deltcon(double e,MessageInterface x);
void deltint();
MessageInterface Out();
double ta();
void initialize();
}
IODevs
coupledDevs
interface coupledDevs {
void add(IODevs d);
void addCoupling(IODevs src, Port p1, IODevs dest,
Port p2);
IODevs getComponentWithName(String nm);
ensembleCollection getComponents();
ensembleCollection getCouplings(IODevs src, Port
p1);
}
basicDevs
IOBasicDevs
Coupled
atomicDevs
(optional)
AtomicInterface
DevsInterface
Extending the “Core” interfaces

interface dynamicStructureInterface {
void addCoupling(String srcName, String p1,
String destName, String p2);
void removeCoupling(String srcName, String p1,
String destName, String p2);
void addModel(String ModelName);
void removeModel(String ModelName);
void addInport(String ModelName, String port);
void addOutport(String ModelName, String port);
void removeInport(String ModelName, String
port);
Simulator Interfaces
coreSimulatorInterface
CoordinatorInterface
atomicSimulatorInterface
CoupledSimulatorInterface
CoupledCoordinatorInterface
State Diagram of Atomic Model :
Generator
Variable : interArrivalTime, count
? start
? stop
! out : Job
Active
Ta =
interArrivalTime
Message type : Job
! out
? stop
? start
Passive
Ta = infinity
State Diagram of Atomic Model :
Processor
Variable : processing_time
? in
? in
passive
Ta = infinity
Message type : Job
! out : Job
! out
busy
Ta =
processing_time
State Diagram of Atomic Model :
Transducer
Variable : observation_time
? ariv
? ariv
active
Ta =
observation_time
passive
Ta = infinity
? solved
? solved
Message type : Job , entity
! out
! out : entity
Mapping state diagram to Atomic
DEVS model
Variable : interArrivalTime, count
? start
! out : Job
Active
Ta =
interArrivalTime
? stop
! out
? stop
? start
Passive
Ta = infinity
Message type : Job
addInport("start");
addInport("stop");
addOutport("out");
? start
? stop
! out
! out : Job
Active
Ta =
interArrivalTime
public void
deltint( ) {
count = count +1;
if(phaseIs("active"))
holdIn("active",interArrivalTime);
else passivate();
}
public message
out( ) {
return
outputNameOnPort("job" +
name+count,"out");}
Active
Ta =
interArrivalTime
? stop
? start
Passive
Ta = infinity
public void
deltext(double e,message x) {
Continue(e);
if (phaseIs("passive")&&
somethingOnPort(x,"start"))
holdIn("active",interArrivalTime);
if (phaseIs("active")&&
somethingOnPort(x,"stop"))
phase = "passive";}
Overall Structure of Atomic DEVS
with DEVSJAVA
package gpt;
SRC Folder
import simView.*;
import genDevs.modeling.*;
DEVSJAVA LIB
import GenCol.*;
public class Genr extends ViewableAtomic{
Class Name & DEVS Interface
protected double interArrivalTime;
Definition of variables
protected int count;
public Genr() {this("genr", 20);}
Constructors
public Genr(String name,double interArrivalTime){
super(name);
addOutport("out");
Definition & Addition
addInport("stop");
in-out ports
addInport("start");
this.interArrivalTime = interArrivalTime ;
Variable setting
addTestInput("start",new entity(""));
Test Input
addTestInput("stop",new entity(""));
}
public void initialize(){
holdIn("active", interArrivalTime);
Initialize DEVS Model
count = 0;
super.initialize();
}
public void
deltext(double e,message x) {
Continue(e);
if (phaseIs("passive")&& somethingOnPort(x,"start"))
holdIn("active",interArrivalTime);
Definition of Delt
external function
if (phaseIs("active")&& somethingOnPort(x,"stop"))
phase = "passive";
}
public void
deltint( ) {
count = count +1;
if(phaseIs("active"))
Definition of Delt
holdIn("active",interArrivalTime);
internal function
else passivate();
}
public void deltcon(double e,message x)
{
deltint();
Definition of Delt
deltext(0,x);
Confluent function
}
public message
out( ) {
Definition of out
return outputNameOnPort("job" + name+count,"out");
message
}
}
Overall Structure of Coupled DEVS
with DEVSJAVA
SRC Folder
package gpt;
import java.awt.Dimension;
import java.awt.Point;
import genDevs.modeling.atomic;
DEVSJAVA LIB
import genDevs.modeling.digraph;
import genDevs.simulation.coordinator;
import simView.*;
Class Name &
public class Efp extends ViewableDigraph {
public Efp (){
super("Efp");
atomic proc = new Proc("Proc",25);
digraph
ef = new Ef("Ef",10,100);
add(ef);
add(proc);
addCoupling(ef,"out",proc,"in");
addCoupling(proc,"out",ef,"in");
}
DEVS Interface
Constructors
Definition of DEVS
Models
Addition of DEVS
Model instances
Addition of
Coupling Info
public static void main(String[] args) {
digraph efp = new Efp();
coordinator rootCoordinator = new
coordinator(efp);
rootCoordinator.initialize();
rootCoordinator.simulate(Integer.MAX_VALUE);
}
/**
* Automatically generated by the SimView program.
* Do not edit this manually, as such changes will
get overwritten.
*/
public void layoutForSimView()
{
ComputeLayout = false;
preferredSize = new Dimension(760, 402);
((ViewableComponent)withName("Proc")).setPreferredLocati
on(new Point(590, 149));
((ViewableComponent)withName("Ef")).setPreferredLocation
(new Point(64, 30));
}
}
Running DEVS
Coupled Model
without SimView
Exercise : Fire-Once Neuron
Out
Fire-once Neuron
Input
receptive
ta = ∞
fire
refract
Firing delay >0 ta = ∞
State Diagram : Fire-Once Neuron
Variable : firing_delay
receptive
Ta = infinity
? Input
fire
Ta = firing_delay
! out
?Input
! out : entity
refract
Ta = infinity
Message type : entity