improved pythondevs simulator improved pythondevs
play

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


  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

  2. Outline Outline Outline Outline • Motivation • Requriments • Experiment • Implemetation

  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

  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

  5. Experiment - . Experiment - Experiment - Experiment - trafficlightExperiment trafficlightExperiment . . . py trafficlightExperiment py trafficlightExperiment 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

  6. Implement ation Implement Implement Implementation 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)

  7. The Structure of Simulator .py The Structure of Simulator The Structure of Simulator The Structure of Simulator.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

  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

  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"))

  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)])

  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

  12. Thank you for attending! Thank you for attending! Thank you for attending! Thank you for attending!

Recommend


More recommend