1
2
3 """Routing example for new go method: routed movement
4 - routed movement (currently still shortest-path)
5 - 50% chance to use random movement after destination was reached
6 - 25% chance to get back to routed movement after node was reached
7 - showing routing destinations as markers
8 - output to socket player
9 """
10
11 import sys
12 sys.path.append("..")
13
14 import struct
15
16 from mosp.core import Simulation, Person
17 from mosp.geo import osm
18 from mosp.impl import movement
19 from mosp.monitors import SocketPlayerMonitor
20
21 __author__ = "P. Tute"
22 __maintainer__ = "B. Henne"
23 __contact__ = "henne@dcsec.uni-hannover.de"
24 __copyright__ = "(c) 2010-2012, DCSec, Leibniz Universitaet Hannover, Germany"
25 __license__ = "GPLv3"
26
27 COLOR = {0: [1.0, 0.0, 0.0, 1.0],
28 1: [0.0, 1.0, 0.0, 1.0]}
29
30
32 """Person for routing demonstration.
33
34 If person arrives at its destination, next destination
35 is randomly selected and user routed to it.
36 With a 50% chance the person will then switch to random movement.
37 It switches back with 25% probability.
38 @author: P. Tute"""
39
47
49 """Find next destination, change movement and/or check if next_node was reached."""
50 if self.next_node == self.dest_node and self.routed:
51 self.start_node = self.dest_node
52 self.dest_node = self._random.choice([n for n in self.sim.geo.way_nodes if "border" not in n.tags])
53 color = self.p_color_rgba[:-1] + [0.5]
54 self.sim.monitors[0].draw_point(self.p_id + 100, self.dest_node.lat, self.dest_node.lon, 5, self.p_color_rgba, ttl=0)
55 if self._random.random() < 0.5:
56 self.routed = False
57 self.p_color_rgba[2] += 1
58 self.next_target = self.next_target_random
59 self.sim.monitors[0].remove_object('point', self.p_id + 100)
60 elif not self.routed:
61 if self._random.random() < 0.25:
62 self.p_color_rgba[2] -= 1
63 self.routed = True
64 self.next_target = self.next_target_routed
65 self.sim.monitors[0].draw_point(self.p_id + 100, self.dest_node.lat, self.dest_node.lon, 5, self.p_color_rgba, ttl=0)
66 self.need_next_target = True
67
74
76 """Find a new next_node to move to.
77 Person gets routed to it."""
78 self.last_node = self.next_node
79 next = self.last_node.get_route(self.dest_node)
80 if not next:
81 self.dest_node = self.next_node
82 else:
83 self.next_node = next
84
85
87 """Defines the simulation, map, monitors, persons."""
88 s = Simulation(geo=osm.OSMModel('../data/hannover1.osm'), rel_speed=40)
89 m = s.add_monitor(SocketPlayerMonitor, 2)
90 s.add_persons(RoutingShowcaseWiggler, 2, monitor=m)
91 s.run(until=10000, real_time=True)
92
93 if __name__ == '__main__':
94 main()
95