Upload
hilary-watts
View
226
Download
0
Embed Size (px)
Citation preview
DEVS M&S Tutorial 2
Chungman [email protected]
Contents
DEVSJAVA Lib DEVS Interface
Expression of Atomic Model State Diagram
DEVSJAVA code Structure 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 Basic data structures
Entity Content Message Port
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);}
EntityInterface Collection
0:n
Message-related-Interfaces
ContentInterface A Pair of port-value
MessageInterface A collection of conten
tsContentInterface
MessageInterface
Collection
0:n
interface MessageInterface extends Collection{boolean onPort(
PortInterface port, ContentInterface content);
EntityInterface getValOnPort(PortInterface port,ContentInterface content);
}
PortInterface EntityInterface
interface ContentInterface {PortInterface getPort();EntityInterface getValue();boolean onPort(PortInterface port);}
interface PortInterfaceextends EntityInterface{
}
Ensemble-Interface
ensembleBasic
Collection
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);}
ensembleCollection
DEVS Modeling Interfaces
IODevs
atomicDevs(optional)
interface basicDevs {void deltext(double e,MessageInterface x);void deltcon(double e,MessageInterface x);void deltint();MessageInterface Out(); double ta();void initialize();}
IOBasicDevs
basicDevs
coupledDevs
AtomicInterfaceCoupledinterface 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);}
DevsInterface
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);}
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
atomicSimulatorInterface
CoupledSimulatorInterface
CoordinatorInterface
CoupledCoordinatorInterface
State Diagram of Atomic Model :Generator
ActiveTa =
interArrivalTime PassiveTa = infinity
! out : Job
? stop
? start
! out
? start
? stop
Message type : Job
Variable : interArrivalTime, count
State Diagram of Atomic Model :Processor
Variable : processing_time
passiveTa = infinity
busyTa =
processing_time
? in
! out : Job
Message type : Job
! out? in
State Diagram of Atomic Model :Transducer
activeTa =
observation_time
? ariv
? solved
passiveTa = infinity
! out : entity
Variable : observation_time
? ariv
? solved
! out
Message type : Job , entity
Mapping state diagram to Atomic DEVS model
ActiveTa =
interArrivalTime PassiveTa = infinity
! out : Job
? stop
? start
! out
? start
? stop
Message type : Job
Variable : interArrivalTime, count
? start? stop
! out
addInport("start");addInport("stop");addOutport("out");
ActiveTa =
interArrivalTime
! out : Job
public void deltint( ) { count = count +1; if(phaseIs("active")) holdIn("active",interArrivalTime); else passivate(); }
public message out( ) { return outputNameOnPort("job" + name+count,"out");}
ActiveTa =
interArrivalTime
PassiveTa = infinity
? stop
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";}
? start
Overall Structure of Atomic DEVS with DEVSJAVA
package gpt;import simView.*;import genDevs.modeling.*;import GenCol.*;public class Genr extends ViewableAtomic{ protected double interArrivalTime; protected int count; public Genr() {this("genr", 20);} public Genr(String name,double interArrivalTime){ super(name); addOutport("out"); addInport("stop"); addInport("start"); this.interArrivalTime = interArrivalTime ; addTestInput("start",new entity("")); addTestInput("stop",new entity("")); } public void initialize(){ holdIn("active", interArrivalTime); count = 0; super.initialize(); } 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"; } public void deltint( ) { count = count +1; if(phaseIs("active")) holdIn("active",interArrivalTime); else passivate(); } public void deltcon(double e,message x) { deltint(); deltext(0,x); } public message out( ) { return outputNameOnPort("job" + name+count,"out"); }}
DEVSJAVA LIB
SRC Folder
Class Name & DEVS Interface
Definition of variables
Constructors
Definition & Addition in-out ports
Variable setting
Test Input
Initialize DEVS Model
Definition of Delt external function
Definition of Delt internal function
Definition of Delt Confluent function
Definition of out message
Overall Structure of Coupled DEVS with DEVSJAVA
package gpt;import java.awt.Dimension;import java.awt.Point;import genDevs.modeling.atomic;import genDevs.modeling.digraph;import genDevs.simulation.coordinator;import simView.*;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");
}
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")).setPreferredLocation(new Point(590, 149)); ((ViewableComponent)withName("Ef")).setPreferredLocation(new Point(64, 30)); }}
SRC Folder
DEVSJAVA LIB
Class Name & DEVS Interface
Constructors
Definition of DEVS Models
Addition of DEVSModel instances
Addition of Coupling Info
Running DEVS Coupled Model
without SimView
Exercise : Fire-Once Neuron
receptive refractInput
fireFiring delay >0
Out Fire-once Neuron
ta = ∞ ta = ∞
State Diagram : Fire-Once Neuron
receptiveTa = infinity
fireTa = firing_delay
! out : entity
? Input
! out?Input
Message type : entity
Variable : firing_delay
refractTa = infinity