mobicen / util / milanoMob.py @ b6158841
History  View  Annotate  Download (1.87 KB)
1 
# https://treyhunner.com/2018/06/howtomakeaniteratorinpython/


2  
3 
from pymobility.models.mobility import gauss_markov, reference_point_group, \ 
4 
tvc, truncated_levy_walk, random_direction, random_waypoint, random_walk 
5 
import numpy as np 
6 
import numpy 
7 
import code 
8  
9  
10 
def milano_mob(): 
11 
return iter(Milano()) 
12  
13  
14 
class Milano(object): 
15  
16 
def __init__(self): 
17 
# simulation area (units)

18 
MAX_X, MAX_Y = 100, 100 
19  
20 
# max and min velocity

21 
MIN_V, MAX_V = 0.1, 1. 
22  
23 
# max waiting time

24 
MAX_WT = 0.

25  
26 
# Random Waypoint model

27 
rwp = random_waypoint(nr_nodes=100, dimensions=(

28 
MAX_X, MAX_Y), velocity=(MIN_V, MAX_V), wt_max=MAX_WT) 
29  
30 
# Reference Point Group model

31 
# In tutto 150 nodi = 10x(5+4+3) + 15x(2)

32 
# 10 gruppi X 5

33 
groups = [5 for _ in range(10)] 
34 
nr_nodes = sum(groups)

35 
rpg5 = reference_point_group( 
36 
groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)

37  
38 
# 10 gruppi X 4

39 
groups = [4 for _ in range(10)] 
40 
nr_nodes = sum(groups)

41 
rpg4 = reference_point_group( 
42 
groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)

43  
44 
# 10 gruppi X 3

45 
groups = [3 for _ in range(10)] 
46 
nr_nodes = sum(groups)

47 
rpg3 = reference_point_group( 
48 
groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)

49  
50 
# 15 gruppi X 2

51 
groups = [2 for _ in range(15)] 
52 
nr_nodes = sum(groups)

53 
rpg2 = reference_point_group( 
54 
groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)

55  
56 
self.movers = [rwp, rpg2, rpg3, rpg4, rpg5]

57  
58 
def __iter__(self): 
59  
60 
while True: 
61 
pos = [] 
62 
for mob in self.movers: 
63 
pos.extend(next(mob))

64 
yield np.array(pos)

65  
66  
67 
if __name__ == '__main__': 
68 
m = milano_mob() 
69 
next(m)

70 
code.interact(local=dict(globals(), **locals())) 