Package mosp :: Module controller :: Class SimulationControlled
[hide private]
[frames] | no frames]

Class SimulationControlled

source code


The MoSP Simulation, extended for use with an external controller.


Authors:
P. Tute, B. Henne
Instance Methods [hide private]
 
__init__(self, geo, name, host, port, start_timestamp=None, rel_speed=None, seed=1, allow_dup=False)
Initialize the MOSP Simulation.
source code
 
send_string(self, string)
Send a string to the controller.
source code
 
shutdownServer(self)
Stops the simulation and closes connection to controller.
source code
 
get_data_from_sim(self)
Send all available data to the controller.
source code
 
put_data_to_sim(self)
Receive data from the controller.
source code
 
enable_step(self)
Receives the number of steps to and sets self.do_step accordingly.
source code
 
identify(self)
Send type, name and associated osm-node-id to controller.
source code
 
register(self)
Receive description data of other simulations and make them adressable.
source code
 
process_data(self, message)
Extract usable data from received message.
source code
 
run(self, until, real_time, monitor=True)
Run Simulation after setup in external-controlled modus.
source code
 
send_person(self, person, node_id)
Prepare a person to be send to another simulation.
source code

Inherited from core.Simulation: __getstate__, add_monitor, add_persons, del_person, get_person, readd_person

Inherited from SimPy.SimulationRT.SimulationRT: rtnow, rtset, simulate

Inherited from SimPy.Simulation.Simulation: activate, allEventNotices, allEventTimes, has_events, initialize, now, peek, reactivate, startCollection, step, stopSimulation

Inherited from SimPy.Simulation.Simulation (private): _post, _terminate, _unpost, _waitUntilFunc

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from SimPy.Simulation.Simulation (private): _commandcodes, _commandwords, _dispatch

Instance Variables [hide private]

Inherited from core.Simulation: geo, messages, monitors, next_person_id, person_alarm_clock, persons, random, removed_persons

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, geo, name, host, port, start_timestamp=None, rel_speed=None, seed=1, allow_dup=False)
(Constructor)

source code 

Initialize the MOSP Simulation.

Parameters:
  • geo - geo model for simulation, a mosp.geo.osm.OSMModel extending the mops.collide.World
  • name - name to identify this simulation by
  • host - host to bind connection to
  • port - port to bind connection to
  • start_timestamp - time.time timestamp when simulation starts - used to calc DateTime of simlation out of simulation ticks.
  • rel_speed - (SimPy) ratio simulation time over wallclock time; example: rel_speed=200 executes 200 units of simulation time in about one second
  • seed - seed for simulation random generator
  • allow_dup - allow duplicates? only one or multiple Simulations can be startet at once
Overrides: object.__init__

shutdownServer(self)

source code 

Stops the simulation and closes connection to controller.

This handles the QUIT-signal from the controller.

Decorators:
  • @handle(QUIT)

get_data_from_sim(self)

source code 

Send all available data to the controller.

The GET_MODE-signal is handled by this method. Calling this when the controller does not expect data will cause it to crash. Use wisely.

Decorators:
  • @handle(GET_MODE)

put_data_to_sim(self)

source code 

Receive data from the controller.

This handles the PUT_MODE-signal and should only be called when receiving PUT_MODE. You will most likely never do this by hand!

Decorators:
  • @handle(PUT_MODE)

enable_step(self)

source code 

Receives the number of steps to and sets self.do_step accordingly.

This handles the STEP-signal from the controller.

Decorators:
  • @handle(STEP)

identify(self)

source code 

Send type, name and associated osm-node-id to controller.

This handles the IDENT-signal from the controller.

Decorators:
  • @handle(IDENT)

register(self)

source code 

Receive description data of other simulations and make them adressable.

This handles the REGISTER-signal from the controller.

Decorators:
  • @handle(REGISTER)

process_data(self, message)

source code 

Extract usable data from received message.

The expected message format is typeFIELD_SEPcontents. If type is 'P', contents should be a json string representing a person to re-add. If type is 'L', contents should be a string containing a log message. This mehtod can be extended to support more message types, if necessary.

Parameters:
  • message - message containing a json-string

run(self, until, real_time, monitor=True)

source code 

Run Simulation after setup in external-controlled modus.

Parameters:
  • until - simulation runs until this tick
  • real_time - run in real-time? or as fast as possible
  • monitor - start defined monitors?
Overrides: core.Simulation.run

send_person(self, person, node_id)

source code 

Prepare a person to be send to another simulation.

Necessary data is extracted from the person and prepared for transfer using json. This does NOT remove the person from the simulation. That must be done elsewhere.

Parameters:
  • person - The person to be send,
  • node_id - ID of the node that is used as exit.