Statistics
| Branch: | Revision:

mobicen / util / milanoMob.py @ c16015e2

History | View | Annotate | Download (1.86 KB)

1 2dbcade9 LoreBz
# https://treyhunner.com/2018/06/how-to-make-an-iterator-in-python/
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
8
9
def milano_mob():
10
    return iter(Milano())
11
12
13
class Milano(object):
14
15
    def __init__(self):
16
        # simulation area (units)
17
        MAX_X, MAX_Y = 100, 100
18
19
        # max and min velocity
20
        MIN_V, MAX_V = 0.1, 1.
21
22
        # max waiting time
23
        MAX_WT = 0.
24
25
        # Random Waypoint model
26 c16015e2 LoreBz
        rwp = random_waypoint(nr_nodes=200, dimensions=(
27 2dbcade9 LoreBz
            MAX_X, MAX_Y), velocity=(MIN_V, MAX_V), wt_max=MAX_WT)
28
29
        # Reference Point Group model
30
        # In tutto 150 nodi = 10x(5+4+3) + 15x(2)
31
        # 10 gruppi X 5
32 c16015e2 LoreBz
        groups = [5 for _ in range(3)]
33 2dbcade9 LoreBz
        nr_nodes = sum(groups)
34
        rpg5 = reference_point_group(
35
            groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)
36
37
        # 10 gruppi X 4
38 c16015e2 LoreBz
        groups = [4 for _ in range(3)]
39 2dbcade9 LoreBz
        nr_nodes = sum(groups)
40
        rpg4 = reference_point_group(
41
            groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)
42
43
        # 10 gruppi X 3
44 c16015e2 LoreBz
        groups = [3 for _ in range(3)]
45 2dbcade9 LoreBz
        nr_nodes = sum(groups)
46
        rpg3 = reference_point_group(
47
            groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)
48
49
        # 15 gruppi X 2
50 c16015e2 LoreBz
        groups = [2 for _ in range(10)]
51 2dbcade9 LoreBz
        nr_nodes = sum(groups)
52
        rpg2 = reference_point_group(
53
            groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)
54
55
        self.movers = [rwp, rpg2, rpg3, rpg4, rpg5]
56
57
    def __iter__(self):
58
59
        while True:
60
            pos = []
61
            for mob in self.movers:
62
                pos.extend(next(mob))
63
            yield np.array(pos)
64
65
66
if __name__ == '__main__':
67
    m = milano_mob()
68
    next(m)
69
    code.interact(local=dict(globals(), **locals()))