Statistics
| Branch: | Revision:

mobicen / util / ConfPars.py @ c16015e2

History | View | Annotate | Download (6.82 KB)

1 1eca333b LoreBz
from inherit_config_parser import InheritConfigParser
2 e1cf8bea LoreBz
import configparser  # https://docs.python.org/2.7/library/configparser.html
3
from pymobility.models.mobility import gauss_markov, reference_point_group, \
4
    tvc, truncated_levy_walk, random_direction, random_waypoint, random_walk
5 38d1e922 LoreBz
import sys
6 2dbcade9 LoreBz
from milanoMob import milano_mob
7 1eca333b LoreBz
import code  # code.interact(local=dict(globals(), **locals()))
8 e1cf8bea LoreBz
9
class ConfSettings(object):
10
11
    def __init__(self, settingsFile, sectionExp):
12
        self.SF = settingsFile
13
        self.SEC = sectionExp
14
        # return self.getSimulationParameters(settingsFile, sectionExp)
15
16
    def getSimulationParameters(self):
17
        settingsFile, sectionExp = self.SF, self.SEC
18
        retParameters = {}
19 1eca333b LoreBz
        #settings = configparser.ConfigParser()
20
        #settings._interpolation = configparser.ExtendedInterpolation()
21
        settings = InheritConfigParser()
22
        settings.optionxform = str
23 e1cf8bea LoreBz
        settings.read(settingsFile)
24
        mand = set([
25 2dbcade9 LoreBz
            'mob_model', 'max_x', 'max_y', 'radius',
26
            'mobility_timer', 'duration'])
27 e1cf8bea LoreBz
        opts = dict(settings.items(sectionExp))
28
        if (not mand.issubset(opts.keys())):
29
            sys.exit('You are missing a mandatory parameter!\n'
30
                     'These are required:\n' + ', '.join(mand))
31
32 1eca333b LoreBz
        for option in opts:
33 e1cf8bea LoreBz
            arg = settings.get(sectionExp, option)
34
            if option == 'duration':
35
                retParameters['duration'] = int(arg.strip('s'))
36
            elif option == 'mob_model':
37 2dbcade9 LoreBz
                mobset = set(['RandoWalk', 'RandomWayPoint', 'RandomDirection', 'Milan',
38 e1cf8bea LoreBz
                              'TruncatedLevyWalk', 'GaussMarkov', 'ReferencePointGroup', 'TimeVariantCommunity'])
39
                if arg not in mobset:
40
                    sys.exit(arg+' is not a mobility model supported!\n'
41
                             'These are supported:\n' + ', '.join(mobset))
42
                retParameters['mob_model'] = arg
43
            elif option == 'max_x':
44
                retParameters['max_x'] = int(arg)
45
            elif option == 'max_y':
46
                retParameters['max_y'] = int(arg)
47
            elif option == 'nodes_number':
48
                retParameters['nodes_number'] = int(arg)
49
            elif option == 'max_velocity':
50
                retParameters['max_velocity'] = float(arg)
51
            elif option == 'min_velocity':
52
                retParameters['min_velocity'] = float(arg)
53
            elif option == 'max_wait_time':
54
                retParameters['max_wait_time'] = float(arg)
55
            elif option == 'radius':
56
                retParameters['radius'] = float(arg)
57
            elif option == 'mobility_timer':
58
                retParameters['mobility_timer'] = float(arg.strip('s'))
59 38d1e922 LoreBz
            elif option == 'nodes_x_group':
60
                retParameters['nodes_x_group'] = int(arg)
61
            elif option == 'groups_number':
62
                retParameters['groups_number'] = int(arg)
63 e1cf8bea LoreBz
            else:
64
                print 'Unparsed ', option, '=', settings.get(sectionExp, option)
65
        return retParameters
66
67
    def configMobility(self, params):
68 38d1e922 LoreBz
        userMobi = params['mob_model']
69 2dbcade9 LoreBz
        supportedModels = ["RandomWayPoint", "TimeVariantCommunity", "Milan"]
70 38d1e922 LoreBz
        if userMobi not in supportedModels:
71
            print userMobi + " is not supported now!\n" \
72
                "This moility models are currently supported:"
73
            print ", ".join(supportedModels)
74 e1cf8bea LoreBz
            sys.exit(1)
75
        else:
76 38d1e922 LoreBz
            if userMobi == "RandomWayPoint":
77
                if not set(['max_x', 'max_y', 'nodes_number', 'max_velocity']).issubset(params.keys()):
78
                    print "You miss some params to configure RandomWayPoint"
79
                    sys.exit(1)
80
                else:
81
                    N = params['nodes_number']
82
                    max_x, max_y = params['max_x'], params['max_y']
83
                    min_v, max_v = params['min_velocity'], params['max_velocity']
84
                    max_wt = params['max_wait_time']
85
                    rw = random_waypoint(N, dimensions=(
86
                        max_x, max_y), velocity=(min_v, max_v), wt_max=max_wt)
87
                    return rw
88 2dbcade9 LoreBz
            elif userMobi == "Milan":
89
                return milano_mob()
90
91
92 38d1e922 LoreBz
            elif userMobi == "TimeVariantCommunity":
93
                '''
94
    Time-variant Community Mobility Model, discussed in the paper
95

96
        Wei-jen Hsu, Thrasyvoulos Spyropoulos, Konstantinos Psounis, and Ahmed Helmy, 
97
        "Modeling Time-variant User Mobility in Wireless Mobile Networks," INFOCOM 2007, May 2007.
98

99
    This is a variant of the original definition, in the following way:
100
    - Communities don't have a specific area, but a reference point where the 
101
       community members aggregate around.
102
    - The community reference points are not static, but follow a random direction model.
103
    - You can define a list of epoch stages, each value is the duration of the stage.
104
       For each stage a different aggregation value is used (from the aggregation parameter).
105
    - Aggregation values should be doubles between 0 and 1.
106
       For aggregation 0, there's no attraction point and the nodes move in a random walk model.
107
       For aggregation near 1, the nodes move closer to the community reference point.
108

109
    Required arguments:
110

111
      *nr_nodes*:
112
        list of integers, the number of nodes in each group.
113

114
      *dimensions*:
115
        Tuple of Integers, the x and y dimensions of the simulation area.
116

117
    keyword arguments:
118

119
      *velocity*:
120
        Tuple of Doubles, the minimum and maximum values for community velocities.
121

122
      *aggregation*:
123
        List of Doubles, parameters (between 0 and 1) used to aggregate the nodes around the community center.
124
        Usually between 0 and 1, the more this value approximates to 1,
125
        the nodes will be more aggregated and closer to the group center.
126
        With aggregation 0, the nodes are randomly distributed in the simulation area.
127
        With aggregation near 1, the nodes are closer to the group center.
128

129
      *epoch*:
130
        List of Integers, the number of steps each epoch stage lasts.
131
    '''
132
                if not set(['max_x', 'max_y', 'nodes_x_group', 'min_velocity',
133
                            'max_velocity', 'groups_number']).issubset(params.keys()):
134
                    print "You miss some params to configure TimeVariantCommunity"
135
                    sys.exit(1)
136
                else:
137
                    NxG = params['nodes_x_group']
138
                    NG = params['groups_number']
139
                    max_x, max_y = params['max_x'], params['max_y']
140
                    min_v, max_v = params['min_velocity'], params['max_velocity']
141
                    groups = [NxG for _ in range(NG)]
142
                    nr_nodes = sum(groups)
143
144
                    tvcm = tvc(groups, dimensions=(100, 100), velocity=(min_v, max_v),
145
                               aggregation=[0.5, 0.], epoch=[100, 100])
146
                    return tvcm