Statistics
| Branch: | Revision:

mobicen / util / ConfPars.py @ 38d1e922

History | View | Annotate | Download (6.62 KB)

1
import configparser  # https://docs.python.org/2.7/library/configparser.html
2
from pymobility.models.mobility import gauss_markov, reference_point_group, \
3
    tvc, truncated_levy_walk, random_direction, random_waypoint, random_walk
4
import sys
5

    
6
class ConfSettings(object):
7

    
8
    def __init__(self, settingsFile, sectionExp):
9
        self.SF = settingsFile
10
        self.SEC = sectionExp
11
        # return self.getSimulationParameters(settingsFile, sectionExp)
12

    
13
    def getSimulationParameters(self):
14
        settingsFile, sectionExp = self.SF, self.SEC
15
        retParameters = {}
16
        settings = configparser.ConfigParser()
17
        settings._interpolation = configparser.ExtendedInterpolation()
18
        settings.read(settingsFile)
19
        mand = set([
20
            'mob_model', 'max_x', 'max_y', 'max_velocity', 'radius'
21
            'mobility_timer', 'min_velocity', 'duration'])
22
        opts = dict(settings.items(sectionExp))
23
        if (not mand.issubset(opts.keys())):
24
            sys.exit('You are missing a mandatory parameter!\n'
25
                     'These are required:\n' + ', '.join(mand))
26

    
27
        for option in settings.options(sectionExp):
28
            arg = settings.get(sectionExp, option)
29
            #code.interact(local=dict(globals(), **locals()))
30
            if option == 'duration':
31
                retParameters['duration'] = int(arg.strip('s'))
32
            elif option == 'mob_model':
33
                mobset = set(['RandoWalk', 'RandomWayPoint', 'RandomDirection',
34
                              'TruncatedLevyWalk', 'GaussMarkov', 'ReferencePointGroup', 'TimeVariantCommunity'])
35
                if arg not in mobset:
36
                    sys.exit(arg+' is not a mobility model supported!\n'
37
                             'These are supported:\n' + ', '.join(mobset))
38
                retParameters['mob_model'] = arg
39
            elif option == 'max_x':
40
                retParameters['max_x'] = int(arg)
41
            elif option == 'max_y':
42
                retParameters['max_y'] = int(arg)
43
            elif option == 'nodes_number':
44
                retParameters['nodes_number'] = int(arg)
45
            elif option == 'max_velocity':
46
                retParameters['max_velocity'] = float(arg)
47
            elif option == 'min_velocity':
48
                retParameters['min_velocity'] = float(arg)
49
            elif option == 'max_wait_time':
50
                retParameters['max_wait_time'] = float(arg)
51
            elif option == 'radius':
52
                retParameters['radius'] = float(arg)
53
            elif option == 'mobility_timer':
54
                retParameters['mobility_timer'] = float(arg.strip('s'))
55
            elif option == 'nodes_x_group':
56
                retParameters['nodes_x_group'] = int(arg)
57
            elif option == 'groups_number':
58
                retParameters['groups_number'] = int(arg)
59
            else:
60
                print 'Unparsed ', option, '=', settings.get(sectionExp, option)
61
        return retParameters
62

    
63
    def configMobility(self, params):
64
        userMobi = params['mob_model']
65
        supportedModels = ["RandomWayPoint", "TimeVariantCommunity"]
66
        if userMobi not in supportedModels:
67
            print userMobi + " is not supported now!\n" \
68
                "This moility models are currently supported:"
69
            print ", ".join(supportedModels)
70
            sys.exit(1)
71
        else:
72
            if userMobi == "RandomWayPoint":
73
                if not set(['max_x', 'max_y', 'nodes_number', 'max_velocity']).issubset(params.keys()):
74
                    print "You miss some params to configure RandomWayPoint"
75
                    sys.exit(1)
76
                else:
77
                    N = params['nodes_number']
78
                    max_x, max_y = params['max_x'], params['max_y']
79
                    min_v, max_v = params['min_velocity'], params['max_velocity']
80
                    max_wt = params['max_wait_time']
81
                    rw = random_waypoint(N, dimensions=(
82
                        max_x, max_y), velocity=(min_v, max_v), wt_max=max_wt)
83
                    return rw
84
            elif userMobi == "TimeVariantCommunity":
85
                '''
86
    Time-variant Community Mobility Model, discussed in the paper
87

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

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

101
    Required arguments:
102

103
      *nr_nodes*:
104
        list of integers, the number of nodes in each group.
105

106
      *dimensions*:
107
        Tuple of Integers, the x and y dimensions of the simulation area.
108

109
    keyword arguments:
110

111
      *velocity*:
112
        Tuple of Doubles, the minimum and maximum values for community velocities.
113

114
      *aggregation*:
115
        List of Doubles, parameters (between 0 and 1) used to aggregate the nodes around the community center.
116
        Usually between 0 and 1, the more this value approximates to 1,
117
        the nodes will be more aggregated and closer to the group center.
118
        With aggregation 0, the nodes are randomly distributed in the simulation area.
119
        With aggregation near 1, the nodes are closer to the group center.
120

121
      *epoch*:
122
        List of Integers, the number of steps each epoch stage lasts.
123
    '''
124
                if not set(['max_x', 'max_y', 'nodes_x_group', 'min_velocity',
125
                            'max_velocity', 'groups_number']).issubset(params.keys()):
126
                    print "You miss some params to configure TimeVariantCommunity"
127
                    sys.exit(1)
128
                else:
129
                    NxG = params['nodes_x_group']
130
                    NG = params['groups_number']
131
                    max_x, max_y = params['max_x'], params['max_y']
132
                    min_v, max_v = params['min_velocity'], params['max_velocity']
133
                    groups = [NxG for _ in range(NG)]
134
                    nr_nodes = sum(groups)
135

    
136
                    tvcm = tvc(groups, dimensions=(100, 100), velocity=(min_v, max_v),
137
                               aggregation=[0.5, 0.], epoch=[100, 100])
138
                    return tvcm