Package mosp_examples :: Module exit_wiggler
[hide private]
[frames] | no frames]

Source Code for Module mosp_examples.exit_wiggler

 1  #!/bin/env python 
 2   
 3  """ Exit example: people doing things, when arriving at an exit/border node 
 4      - random movement 
 5      - if person arrives at any exit node placed at the map borders,  
 6        it sleeps for a while, changes its color and moves on 
 7          - uses person.act_at_node() and and location/exit 
 8      - output to visual player, which is executed as child process 
 9  """ 
10   
11  import sys 
12  sys.path.append("..")  
13   
14  from mosp.core import Simulation, Person 
15  from mosp.geo import osm 
16  from mosp.impl import movement 
17  from mosp.locations import Location 
18  from mosp.monitors import ChildprocessPlayerChamplainMonitor, SocketPlayerMonitor 
19   
20  __author__ = "B. Henne" 
21  __contact__ = "henne@dcsec.uni-hannover.de" 
22  __copyright__ = "(c) 2011, DCSec, Leibniz Universitaet Hannover, Germany" 
23  __license__ = "GPLv3" 
24   
25   
26  COLORS = [ 
27            (0.1,0.1,0.9,1.0), # blue 
28            (0.9,0.1,0.1,1.0), # red 
29            (0.1,0.9,0.1,1.0), # green 
30            (0.5,0.0,0.5,1.0), # purple 
31            (0.0,1.0,1.0,1.0), # aqua 
32            (0.6,0.6,0.0,1.0), # olive 
33            (0.5,0.5,0.5,1.0), # grey 
34            (0.0,0.0,0.0,1.0)  # black 
35            ]                     #: blue, red, green, purple, aqua, olive, grey, black 
36   
37 -class WigglerExit(Location):
38 """The demo exit location. 39 40 People entering this location/exit will change their color, 41 sleep, wake up and move on. 42 @author: B. Henne""" 43
44 - def __init__(self, name, sim):
45 """Inits the demo exit location.""" 46 super(WigglerExit, self).__init__(name=name, sim=sim)
47
48 - def interact(self, person, duration=600):
49 """Wiggler interacting with this location sleeps for duration seconds and changes his color.""" 50 person.p_color = (person.p_color + 1) % 5 51 person.p_color_rgba = COLORS[person.p_color] 52 self.visit(person, duration)
53 54
55 -class ExitWiggler(Person):
56 """Demo wiggler for acting at border nodes / at exits.""" 57 58 next_target = movement.person_next_target_random 59
60 - def act_at_node(self, node):
61 """Wiggler acts at WigglerExit.""" 62 worldobject = node.worldobject 63 if worldobject is not None: 64 if isinstance(worldobject, WigglerExit): 65 self.passivate = True 66 self.passivate_with_stop_actions = True 67 worldobject.interact(self, 120)
68 69
70 -def main():
71 """Defines the simulation, map, monitors, persons and exits at border nodes.""" 72 s = Simulation(geo=osm.OSMModel('../data/hannover2.osm'), rel_speed=60) 73 #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2) 74 m = s.add_monitor(SocketPlayerMonitor, 2) 75 s.add_persons(ExitWiggler, 20, monitor=m) 76 exits = [node for node in s.geo.way_nodes if "border" in node.tags] 77 exit = WigglerExit('theExit', s) 78 s.activate(exit, exit.serve(), 0) 79 for e in exits: 80 e.worldobject = exit 81 s.run(until=10000, real_time=True, monitor=True)
82 83 84 if __name__ == '__main__': 85 main() 86