Package mosp :: Module core :: Class Simulation
[hide private]
[frames] | no frames]

Class Simulation

source code


A MOSP Simulation.

Extends SimPy's SimulationRT (Simulation with Real Time Synchronization) to store MOSP specific data and implement specific methods.


Authors:
F. Ludwig, P. Tute, B. Henne
Instance Methods [hide private]
 
__getstate__(self)
Returns Simulation information for pickling using the pickle module.
source code
 
__init__(self, geo, start_timestamp=None, rel_speed=None, seed=1, allow_dup=False)
Initialize the MOSP Simulation.
source code
 
add_monitor(self, monitor_cls, tick=1, **kwargs)
Add a Monitor to Simulation to produce any kind of output.
source code
 
add_persons(self, pers_cls, n=1, monitor=None, args=None)
Add a Person to Simulation.
source code
 
del_person(self, person)
Remove a person from the simulation.
source code
 
get_person(self, id)
Find a person by its ID.
source code
 
readd_person(self, id, changes={})
Add a previously removed person to the simulation again.
source code
 
run(self, until, real_time, monitor=True)
Runs Simulation after setup.
source code

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]
  geo
the geo-modell of the Simulation
  messages
stores scheduled Calls of PersonGroups for execution as zombie's infect()
  monitors
contains all Monitors of the Simulation
  next_person_id
the next id that will be given to a new person
  person_alarm_clock
central Process for waking up Persons on pause
  persons
stores simulated Persons
  random
central simulation-wide random generator
  removed_persons
stores removed Persons for later use
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, geo, 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
  • 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__

add_monitor(self, monitor_cls, tick=1, **kwargs)

source code 

Add a Monitor to Simulation to produce any kind of output.

Parameters:
  • monitor_cls - the monitor class from mops.monitors
  • tick - new monitor will observe every tick tick
  • kwargs - keyword parameters for monitor class instantiation
Returns:
reference to new, added monitor instance

add_persons(self, pers_cls, n=1, monitor=None, args=None)

source code 

Add a Person to Simulation.

Parameters:
  • pers_cls - the person class (inherited from mosp.core.Person)
  • n - the number of new, added instances of pers_cls
  • monitor - (list of) monitor(s) the person(s) shall be observed by
  • args - dictionary of arguments for pers_cls instantiation

del_person(self, person)

source code 

Remove a person from the simulation.

The person will be saved in self.removed_persons for later reference.

Parameters:
  • person - the person to be removed. The person must have been added and must be active.
To Do:
  • try using Process.cancel() from SimPy (is broken atm and may stay broken...try again with new go)
  • maybe remove person from monitors

get_person(self, id)

source code 

Find a person by its ID.

Returns:
the person or None, if the ID was not found

readd_person(self, id, changes={})

source code 

Add a previously removed person to the simulation again.

Parameters:
  • id (int) - id of the removed person
  • changes (dict with pairs of 'variable_name': value (variable_name in a string)) - changes to be made when reinserting the person

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

source code 

Runs Simulation after setup.

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