Statistics
| Branch: | Revision:

## mobicen / util / milanoMob.py @ c16015e2

 1 ```# https://treyhunner.com/2018/06/how-to-make-an-iterator-in-python/ ``` ```from pymobility.models.mobility import gauss_markov, reference_point_group, \ ``` ``` tvc, truncated_levy_walk, random_direction, random_waypoint, random_walk ``` ```import numpy as np ``` ```import numpy ``` ```def milano_mob(): ``` ``` return iter(Milano()) ``` ```class Milano(object): ``` ``` def __init__(self): ``` ``` # simulation area (units) ``` ``` MAX_X, MAX_Y = 100, 100 ``` ``` # max and min velocity ``` ``` MIN_V, MAX_V = 0.1, 1. ``` ``` # max waiting time ``` ``` MAX_WT = 0. ``` ``` # Random Waypoint model ``` ``` rwp = random_waypoint(nr_nodes=200, dimensions=( ``` ``` MAX_X, MAX_Y), velocity=(MIN_V, MAX_V), wt_max=MAX_WT) ``` ``` # Reference Point Group model ``` ``` # In tutto 150 nodi = 10x(5+4+3) + 15x(2) ``` ``` # 10 gruppi X 5 ``` ``` groups = [5 for _ in range(3)] ``` ``` nr_nodes = sum(groups) ``` ``` rpg5 = reference_point_group( ``` ``` groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5) ``` ``` # 10 gruppi X 4 ``` ``` groups = [4 for _ in range(3)] ``` ``` nr_nodes = sum(groups) ``` ``` rpg4 = reference_point_group( ``` ``` groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5) ``` ``` # 10 gruppi X 3 ``` ``` groups = [3 for _ in range(3)] ``` ``` nr_nodes = sum(groups) ``` ``` rpg3 = reference_point_group( ``` ``` groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5) ``` ``` # 15 gruppi X 2 ``` ``` groups = [2 for _ in range(10)] ``` ``` nr_nodes = sum(groups) ``` ``` rpg2 = reference_point_group( ``` ``` groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5) ``` ``` self.movers = [rwp, rpg2, rpg3, rpg4, rpg5] ``` ``` def __iter__(self): ``` ``` while True: ``` ``` pos = [] ``` ``` for mob in self.movers: ``` ``` pos.extend(next(mob)) ``` ``` yield np.array(pos) ``` ```if __name__ == '__main__': ``` ``` m = milano_mob() ``` ``` next(m) ``` ` code.interact(local=dict(globals(), **locals()))`