modelling devs applications

38
Modelling DEVS applications The CD++ tool http://cell-devs.sce.carleton.ca/ http://www.sce.carleton.ca/faculty/wainer/CD+ +BuilderSetup.exe http://www.sce.carleton.ca/faculty/wainer/setupCDpp.exe

Upload: renee-barlow

Post on 02-Jan-2016

46 views

Category:

Documents


2 download

DESCRIPTION

Modelling DEVS applications. The CD++ tool http://cell-devs.sce.carleton.ca/ http://www.sce.carleton.ca/faculty/wainer/CD++BuilderSetup.exe http://www.sce.carleton.ca/faculty/wainer/setupCDpp.exe. Review of the DEVS formalism. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Modelling DEVS applications

Modelling DEVS applications

The CD++ tool

http://cell-devs.sce.carleton.ca/

http://www.sce.carleton.ca/faculty/wainer/CD++BuilderSetup.exe

http://www.sce.carleton.ca/faculty/wainer/setupCDpp.exe

Page 2: Modelling DEVS applications

Atomic: lowest level model, contains structural dynamics -- model level modularity

Coupled: composed of one or more atomic and/or coupled models -- hierarchical construction

Elements of an atomic model:

input ports

output ports

state variables

state transition functions

output function

time advance function

Elements of coupled model:

Components

Couplings

– Internal Couplings– External Input Couplings– External Output Couplings

Review of the DEVS formalism

Page 3: Modelling DEVS applications

Algorithmic languages State-based languages DEVS graph

– Node : sequential state– Arc : (XY{S}) ta(S)

Internal transition

External transition

out ! y=(s0) Internal Transition (i) ta(s0) (ii) out = (s0) , int(s0)=s1

External Transition ext(s0, t, (x,in))=s2

DEVS graphs

out ! (s0)

in ? x,t

Page 4: Modelling DEVS applications

DEVS graphs definition

state : stateId …stateId : lifetime

[modelname] atomic or coupled model name

I/O ports:in : inport1 inport2 ...out : outport1 outport2 ...

Internal transitions:int:source destination [outport!value]* ( { (action;)* } )(Action: complex function to generate an output).

External transitions :ext : source destination EXPRESSION ( { (action;)* } )? value

Page 5: Modelling DEVS applications

DEVS graphs definition

States (bubbles) Internal transitions (dotted lines)

Output_port!output_value External transitions (full lines)

Input_port?input_value I/O ports

TL=inf

TL=inf

TL=100 s

Page 6: Modelling DEVS applications

DEVS graphs analytical specification

[myAtomic]

in: Port1 PortY

out: PortX

state: Start Process Finish

int: Process Finish PortX!1

ext: Start Process Value(Port1)?0

ext: Finish Start Value(PortY)?1

Start: 0:0:10:0

Process: 0:0:10:0

Finish: 0:0:10:0

Page 7: Modelling DEVS applications

CD++ (1997/98)

• Basic tool following DEVS formalism.• Extension to include Cell-DEVS models.• High level specification language.

-operator==()-operator=()-receiveInitMessage()-receiveInternalMessage()-receiveOutputMessage()-receiveExternalMessage()-receiveDoneMessage()-receiveCollectMessage()+nextChange()+lastChange()+absoluteNext()

+Model+externalMsgs-next-last-processorId

Processor

+initialize()+finalize()+simulate()+receiveOutputMessage()+receiveDoneMessage()+stop()+addExternalEvent()+stopTime()+addDeadline()

-externalEvents : EventList-deadlines : DeadlineList

Root

Simulator

+imminentChildren()

-syncSet : ModelId

Coordinator

+addExternalMessage()+eraseAll()

-msgs : MessageList-msgCout : int-msgTime : Time

MessageBag

+currentTime() : Time

-hour -min -sec -msec

Time

+imminentChildren()+nextChange()+lastChange()+absoluteNext()

-syncSet : ModelId

FlatDEVSCoordinator

+generateRoot()+generateProcessor()+add2DB()

-procDB : ProcessorDB-procIdCount : ProcId

ProcessorAdmin

11

11

+addInputPort()+addOutputPort()+nextChange()+lastChange()+sendOutput()

-ident : ModelId-parent_id : ModelId-execId : ModelId-inputList : PortList-outputList : PortList

Model

+operator ==()+registerAtomic()+newAtomic()+newCoupled()

-kinds : AtomicKinds-types : AtomicTypes

ModelAdmin

+addModel()+children()+addInfluence()

-childs : ModelList

Coupled

+operator=()+operator==()+initFunction()+externalFunction()+internalFunction()+outputFunction()+confluentFunction ()+holdIn()+passivate()+state()

Atomic

+influences()+model()+addInfluence()+delInfluence()+findInfluence()+pDriver()

-influenceList : PortList-pid : PortId-portName-mid : ModelId

Port

1

*

+run()+registerNewAtomics()+isFlatDEVS()+loadModels()+loadExternalEvents()+loadPorts()+loadLinks()+loadFlattenLinks()+updateOutLinks()+updateAtomicOutLinks()+addFlattenedLinksToFlatTop()+elapsedTime() : Time+registerTopPorts()

MainSimulator

+sendTo()+time()+procId()+operator==()+operator=()+clone()+type()

-time : Time-proc : ProcId

Message

+operator==()+operator=()+run()+stop()+send()

-unprocessedQueue : UnprocessedMsgQueue

MessageAdmin

1*

InitMessage

1

*

DoneMessage

+port() : Port+value() : double

-port : Port-value : double

OutputMessageInternalMessage

+port() : Port+value() : double

-port : Port-value : double

ExternalMessage

CollectMessage

Messaging Subsystem

Simulation Subsystem

Modeling Subsystem

Main Simulator Subsystem

Page 8: Modelling DEVS applications

Example: Robot Vehicle Model

Page 9: Modelling DEVS applications

Example: Robot Vehicle Model

Page 10: Modelling DEVS applications

Autonomous Reconnaissance Vehicle

Radar Controller Atomic model

Page 11: Modelling DEVS applications

Autonomous Reconnaissance Vehicle

Movement Controller

Page 12: Modelling DEVS applications

holdIn(state, time)

passivate()

timelast()

timenext()

sendOutput(time, port, value)

state()

distribution().get()

CD++ programming services

Page 13: Modelling DEVS applications

Adding new atomic models

Atomic model definitions initFunction

externalFunction

outputFunction

internalFunction

Linking with the abstract simulator registerNewAtomic

Page 14: Modelling DEVS applications

Generator

out

Represents a generator of impulses represented

by consecutive natural numbers.

Period between impulses

defined by a random function using different distributions (Chi2, Gamma, Normal, etc.).

Generator model: description

0, 1, 2,...

f(t) = ...

Implementing atomic models

Page 15: Modelling DEVS applications

External transition function:

none (model does not include input ports)

Internal transition function:

generates numbers according to

a specified probability distribution. Output function: sends following

consecutive natural number through the out port.

Transition functions

Atomic modelGenerator

Output Port : out

0, 1, 2,...

ext

int

Generator: conceptual definition

Page 16: Modelling DEVS applications

Generator

distributionnext

internalFunction()outputFunction()initFunction()

Atomic

initFunction()internalFunction()outputFunction()externalFunction()

(from Models)

class Generator:public Atomic {public: . . .protected: Model &initFunction() ; Model &externalFunction(const ExternalMessage &); Model &internalFunction(const InternalMessage &); Model &outputFunction(const InternalMessage&);

private: int next; int initial; Port &out ; Distribution *distribution ;};

Generator model: header files

Page 17: Modelling DEVS applications

CD++ - initFunction

Model &initFunction(){ this->next = this->initial; this->holdIn(Atomic::active, Time::Zero) ; return *this ;}

Programmed to have an Instantaneous internal trans.

Generator: coding example

Page 18: Modelling DEVS applications

CD++ - internalFunction

Model &internalFunction(const InternalMessage &) { this->next++ ; Time t(fabs(this->distribution().get()) ) ; this->holdIn(active, t) ; return *this ;}

Reprogrammed for the following internaltransition.

Obtains the timevalue bycomputinga probabilisticfunction

Generator (cont.)

Page 19: Modelling DEVS applications

CD++ - outputFunction

Model &outputFunction(const InternalMessage &msg) { this->sendOutput(msg.time(), this->out, this->next); return *this ;} The output value

increments sequentially

Generator (cont.)

Page 20: Modelling DEVS applications

out

gen

CD++ - Coupling scheme

[top]components : gen@Generatorout : MyoutLink : out@gen Myout

[gen]distribution : normalmean : 2deviation : 1

top

Myout

Generator: stand-alone testing

Page 21: Modelling DEVS applications

Description

It is in charge of computing the number of jobs finished in a given time unit.

It computes the usage ratio for the server (a CPU in this case).

It transfers the outputs with a given frequency.

Transducer

time

jobs

Jobs

Transducer model

Page 22: Modelling DEVS applications

The external transition function is in charge of record the jobs received and those finished.

The internal transition function should be activated in the following job burst.

The output function will send the metrics through output ports.

DEVS

Atomic ModelTransducer

cpuusage

ext

int

arrived

throughput

solved

Outputs

Inputs

Transducer model : conceptual definition

Page 23: Modelling DEVS applications

CD++

class Transducer: public Atomic {public: . . .protected: Model &initFunction(); Model &externalFunction(const ExternalMessage&); Model &internalFunction(const InternalMessage&); Model &outputFunction(const InternalMessage&);private: const Port &arrived, &solved ; Port &throughput, &cpuUsage ; Time frec, tUnit ; long procCount, cpuLoad ; JobsList unsolved ; };

Atomic

initFunction()externalFunction()internalFunction()outputFunction()

(from Models)

TransducercpuLoad : longprocCount : longfrec : TimetUnit : Time

initFunction()externalFunction()internalFunction()outputFunction()

Transducer: header files

Page 24: Modelling DEVS applications

Transducer: coding example

CD++ - initFunction

Model &initFunction() { cpuLoad = procCount = 0 ; unsolved.erase() ; this->holdIn( active, this->frequence() ) ; return *this ;} The results are sent

with a predefinedfrequency.

State variables initialization

Page 25: Modelling DEVS applications

CD++ - externalFunction

Model &externalFunction( const ExternalMessage &msg ) { Time dif = ( msg.time() - this->lastChange() ) ; cpuLoad += dif.asMsecs() * unsolved.size() if( msg.port() == arrived ) unsolved[ msg.value() ] = msg.time() ;

if( msg.port() == solved ) { procCount ++ ; unsolved.erase( msg.value() ) ; } return *this ;}

Record a non-finished job

Update the numberof tasks

CPU load

Transducer (cont.)

Page 26: Modelling DEVS applications

CD++ - internalFunction

Model &internalFunction( const InternalMessage & ) { this->holdIn( active, this->frequence() ) ; return *this ;}

Programmed to informthe results with a certainfrequency

Transducer (cont.)

Page 27: Modelling DEVS applications

CD++ - outputFunction

Model &outputFunction( const InternalMessage &msg ) { long ms = msg.time().asMsecs() ; float t( ms / this->timeUnit().asMsecs() ) ; Time dif = ( msg.time() - this->lastChange() ) ; cpuLoad += dif.asMsecs() * unsolved.size() ) ; this->sendOutput( msg.time(),throughput,procCount/t ); this->sendOutput( msg.time(),cpuUsage, cpuLoad / ms ); return *this ;}

Transducer (cont.)

Page 28: Modelling DEVS applications

CPU model

CPU

out

A processor running individual tasks in a non preemptive fashion.

Execution time for each

tasks defined by a probability distribution

chosen by the user.

Description

0, 1, 2,...

f(t) = ...

in

0, 1, 2,...

Page 29: Modelling DEVS applications

CPU: conceptual definition

External transition function starts theprocessing a task. Internal transition scheduled for the end of the job, defined at random. If model already processing a task, new one is discarded.

Internal transition function finishesprocessing the job, leaving the model in a passive state waiting

for new jobs.

Output function sends the job id trhough the output port out.

Atomic ModelCPU

ext

int

out

0, 1, 2,...

in

0, 1, 2,...

Page 30: Modelling DEVS applications

CPU: header files

CD++class CPU : public Atomic {public: . . .protected: Model &initFunction() ; Model &externalFunction(const ExternalMessage&); Model &internalFunction(const InternalMessage &); Model &outputFunction(const InternalMessage&);

private: int pid; Port &in, &out ; Distribution *distribution ;};

Atomic

initFunction()internalFunction()outputFunction()externalFunction()

(from Models)

CPU

distributionpid

initFunction()outputFunction()internalFunction()ExternalFunction()

Page 31: Modelling DEVS applications

CPU: coding example

CD++ - initFunction

Model &initFunction() { this->passivate() ; return *this ;}

Passive state kept while cpu waits for new external events in input ports.

Page 32: Modelling DEVS applications

CD++ - externalFunctionModel &externalFunction(const ExternalMessage &msg){ if( this->state() == passive ) { this->pid = static_cast<int>(msg.value()) ; Time t( fabs(this->distribution().get()) ) ; this->holdIn(active, t) ; } return *this ;}

Process Id stored. Schedule internal transition at random using the chosen distribution.

CPU (Cont.)

Page 33: Modelling DEVS applications

CD++ - internalFunction

Model &internalFunction( const InternalMessage & ){ this->passivate() ; return *this ;}

Task processing finished. Passivate waiting for the

following request.

CPU (Cont.)

Page 34: Modelling DEVS applications

CD++ - outputFunction

Model &outputFunction( const InternalMessage &msg ){ this->sendOutput(msg.time(), this->out, this->pid); return *this ;} Send Process Id and time

associated with end of processing for the

present task.

CPU (Cont.)

Page 35: Modelling DEVS applications

CD++ - Coupling specification

[top]components : proc@CPUin : inout : outLink : in in@procLink : out@proc out

[proc]distribution : normalmean : 2deviation : 1

out

proc

top

out

in

in

CPU model testing

Page 36: Modelling DEVS applications

out

proc

CD++ - External event file (.EV)

00:00:10:00 in 000:00:30:00 in 100:01:00:00 in 200:02:20:00 in 3

top

out

in

in

Hh:mm:ss:ms

Input port used

Job Id

Input events to test

Page 37: Modelling DEVS applications

Mensaje I / 00:00:00:000 / Root(00) para top(01)Mensaje I / 00:00:00:000 / top(01) para proc(02)Mensaje D / 00:00:00:000 / proc(02) / ... para top(01)Mensaje D / 00:00:00:000 / top(01) / ... para Root(00)Mensaje X / 00:00:10:000 / Root(00) / in / 0.000 para top(01)Mensaje X / 00:00:10:000 / top(01) / in / 0.000 para proc(02)Mensaje D / 00:00:10:000 / proc(02) / 00:00:01:348 para top(01)Mensaje D / 00:00:10:000 / top(01) / 00:00:01:348 para Root(00)Mensaje * / 00:00:11:348 / Root(00) para top(01)Mensaje * / 00:00:11:348 / top(01) para proc(02)Mensaje Y / 00:00:11:348 / proc(02) / out / 0.000 para top(01)Mensaje D / 00:00:11:348 / proc(02) / ... para top(01)Mensaje Y / 00:00:11:348 / top(01) / out / 0.000 para Root(00)Mensaje D / 00:00:11:348 / top(01) / ... para Root(00)Mensaje X / 00:00:30:000 / Root(00) / in / 1.000 para top(01)Mensaje X / 00:00:30:000 / top(01) / in / 1.000 para proc(02)Mensaje D / 00:00:30:000 / proc(02) / 00:00:03:485 para top(01)

CD++ - Simulation

Log file

Page 38: Modelling DEVS applications

CD++ - Output file

00:00:11:348 out 000:00:33:485 out 100:01:00:328 out 200:02:21:094 out 3

Hh:mm:ss:ms Output Port

Job Id

Output file