Improved pythonDEVS Simulator Improved pythonDEVS Simulator - - PowerPoint PPT Presentation

improved pythondevs simulator improved pythondevs
SMART_READER_LITE
LIVE PREVIEW

Improved pythonDEVS Simulator Improved pythonDEVS Simulator - - PowerPoint PPT Presentation

Improved pythonDEVS Simulator Improved pythonDEVS Simulator Improved pythonDEVS Simulator Improved pythonDEVS Simulator Fei Men Fei Men Fei Men Fei Men McGill University Modelling, Simulation McGill University Modelling, Simulation McGill


slide-1
SLIDE 1

Improved pythonDEVS Simulator Improved pythonDEVS Simulator Improved pythonDEVS Simulator Improved pythonDEVS Simulator

Fei Men Fei Men Fei Men Fei Men McGill University Modelling, Simulation McGill University Modelling, Simulation McGill University Modelling, Simulation McGill University Modelling, Simulation and Design Lab (MSDL) and Design Lab (MSDL) and Design Lab (MSDL) and Design Lab (MSDL) 12/15/08 12/15/08 12/15/08 12/15/08

slide-2
SLIDE 2

Outline Outline Outline Outline

  • Motivation
  • Requriments
  • Experiment
  • Implemetation
slide-3
SLIDE 3

Motivation Motivation Motivation Motivation

The existing version of pythonDEVS

simulator didn't fully match DEVS formalism

No output-input transfer functions No input events No initiation and terminate control No reset control

slide-4
SLIDE 4

Requirements Requirements Requirements Requirements

New Function:

Initialize the model by default function or customize

function(decided by customers)

Set final time(customers decide when stop simulation) Set term_conditions using term-function(provided by

customers)

Simulate DEVS model with all conditions satisfied Terminate experiments when term_conditions satisfied Reset time or initialization to simulate again INPUT segment(given by customers) used as external

events

Z-function added as output-input transfer functions

slide-5
SLIDE 5

Experiment - Experiment - Experiment - Experiment -trafficlightExperiment

trafficlightExperiment trafficlightExperiment trafficlightExperiment.

. . .py

py py py

trafficSystem = TrafficSystem(name="trafficSystem") sim=Simulator() sim.set_model(trafficSystem) sim.initalize_model(1,"trafficLight",TrafficLightMode("green"),0.5) sim.set_verbose(True) sim.set_final_time(500) sim.set_term_condition(termCond_never,()) sim.set_InputSegment([({trafficSystem.policeman.OUT:"toManual"}, 60),({trafficSystem.policeman.OUT:"toManual"}, 250),({trafficSystem.policeman.OUT:"toAutonomous"},150)]) sim.run() sim.reset(reset_time=6,d=1,submodel="policeman",state=PolicemanMode(" working")) sim.set_verbose(True) sim.set_final_time(150) sim.set_term_condition(termCond1, ("green") sim.run() result.txtres ult.txt

slide-6
SLIDE 6

Implement Implement Implement Implementation ation ation ation

Work Flow: Work Flow: Work Flow: Work Flow:

  • Initialize the model (default or customize function)
  • Set up termination conditions (end_time or end_state)
  • Simulate the model until termination conditions satisfied
  • Terminate the experiment
  • Reset and run again(time or reset time and initialization)
slide-7
SLIDE 7

The Structure of Simulator The Structure of Simulator The Structure of Simulator The Structure of Simulator.py .py .py .py

  • Class AtomicSolver

// handle msg received by atomic model

  • Class CoupledSolver

//msg received by coupled DEVS model

  • Class Simulator

//new function added here

slide-8
SLIDE 8

The structure of simulator class The structure of simulator class The structure of simulator class The structure of simulator class

  • set_model // set which model will be simulated
  • reset_time // reset the clock without changing

initialization(warm up)

  • initialize_model // provide default_init and custom_init
  • customize-init // used by initialize-model for custom

initialization

  • reset(time,init) //combination of reset time and initialization
  • set_final_time // end_time
  • set_term_condition // end_function(check it when transition

happens )

  • set_InputSegment // the eventlist,data structure: (ev, t ,inport)
  • terminate // wrap up after the experiment stopped
  • Z-function // output-input transfer functions
  • set_verbose //output for debug
  • Run //simulate
slide-9
SLIDE 9

Some interesting function- Some interesting function- Some interesting function- Some interesting function-

set_term_condition set_term_condition set_term_condition set_term_condition

  • In simulator.py:

def set_term_condition(self, term_cond_fct, *remaining_args): self.term_cond_fct = term_cond_fct self.term_cond_remaining_args = remaining_args def run(self): while clock<= self.set_final_time(self.endtime)and not(self.term_cond_fct(clock,self.model,self.term_cond_remaining_args)): if (self.term_cond_fct(clock,self.model,self.term_cond_remaining_args)): break

  • In experiment.py:

def termCond1(clock=0, model=None, remaining_args=('manual',)): if len(remaining_args) !=1: return end_state = remaining_args[0] return (str(trafficSystem.trafficLight.state.get()) == end_state) sim.set_term_condition(termCond1, ("green"))

slide-10
SLIDE 10

Some interesting function- Some interesting function- Some interesting function- Some interesting function-

set_InputSegment set_InputSegment set_InputSegment set_InputSegment In simulator.py: def set_InputSegment(self,InputEventList=None): self.input_event=sorted(InputEventList,key=lambda x:(x[1],x[0])) def run(self): elif clock >=(self.input_event[0][1]): print "\n", "__ Input_event Arrival:",self.input_event[0][1] self.send(self.model,self.input_event[0]) del self.input_event[0] In experiment.py: sim.set_InputSegment([({trafficSystem.policeman.OUT:"toManu al"}, 60),({trafficSystem.policeman.OUT:"toManual"}, 250),({trafficSystem.policeman.OUT:"toAutonomous"},150)])

slide-11
SLIDE 11

Some interesting function- Some interesting function- Some interesting function- Some interesting function-

Z-function Z-function Z-function Z-function

In DEVS.py: def connectPorts(self, p1, p2,func=None): """Connects two ports together. The coupling is to begin at {\tt p1} and to end at {\tt p2}. In

CoupledDEVS class

ZfuncKey=p1.getPortName()+p2.getPortName() self.Zfunc[ZfuncKey] = func In simulator.py: Class CoupledSolver: def receive(self, cDEVS, msg)://when connectPorts matches, use func to modify data In TrafficSystemModel.py: def __init__(self, name=None): self.connectPorts(self.policeman.OUT,self.trafficLight.INTERRUPT,self.func) ### def func(self,p1): if p1=="toManual": p2="toAutonomous" if p1=="toAutonomous": p2="toManual" return p2

slide-12
SLIDE 12

Thank you for attending! Thank you for attending! Thank you for attending! Thank you for attending!