1
2
3 """ A simple example for the usage of Person.send()
4 - random movement
5 - output to visual player, which is executed as child process
6 - you may try the other commented monitor examples - you can choose a single or multiple monitors
7 - print a message send to another person
8 """
9
10 import sys
11 sys.path.append("..")
12 import time
13 import random
14
15 from mosp.core import Simulation, Person
16 from mosp.geo import osm
17 from mosp.impl import movement
18 from mosp.monitors import *
19
20 __author__ = "P. Tute, B. Henne"
21 __maintainer__ = "B. Henne"
22 __contact__ = "henne@dcsec.uni-hannover.de"
23 __copyright__ = "(c) 2010-2011, DCSec, Leibniz Universitaet Hannover, Germany"
24 __license__ = "GPLv3"
25
26
28 """Implements a simple person doing only random movement on the map, sending and receiving some messages.
29 @author: P. Tute"""
30 next_target = movement.person_next_target_random
31
33 """On receiving a message, the message is printed to stdout."""
34
35 print 't=%s, sender=%s, receiver=%s' % (self.sim.now(), sender.p_id, self.p_id)
36 print '\t message=%s' % m
37 return True
38
40 """Person with id 23 sends hello messages to all people in his vicinity of 50 meters."""
41 super(MsgRandomWiggler, self).think()
42 if self.p_id == 23:
43
44 self.send(self.get_near(50, self_included=False), "Hello Person in my vicinity at t=%s" % self.sim.now())
45
46
47
48
49
50
52 """Defines the simulation, map, monitors, persons."""
53 t = time.time()
54 s = Simulation(geo=osm.OSMModel('../data/hannover2.osm'), rel_speed=40)
55 print time.time() - t
56
57
58
59
60
61 m = s.add_monitor(SocketPlayerMonitor, 2)
62
63 s.add_persons(MsgRandomWiggler, 100, monitor=m)
64 s.run(until=1000, real_time=True, monitor=True)
65
66
67 if __name__ == '__main__':
68 main()
69