Revision 38d1e922 util/ConfPars.py

View differences:

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

  
5 6
class ConfSettings(object):
6 7

  
......
16 17
        settings._interpolation = configparser.ExtendedInterpolation()
17 18
        settings.read(settingsFile)
18 19
        mand = set([
19
            'mob_model', 'max_x', 'max_y', 'nodes_number', 'max_velocity',
20
            'radius', 'mobility_timer', 'min_velocity', 'duration', 'max_wait_time'
21
        ])
20
            'mob_model', 'max_x', 'max_y', 'max_velocity', 'radius'
21
            'mobility_timer', 'min_velocity', 'duration'])
22 22
        opts = dict(settings.items(sectionExp))
23 23
        if (not mand.issubset(opts.keys())):
24 24
            sys.exit('You are missing a mandatory parameter!\n'
......
52 52
                retParameters['radius'] = float(arg)
53 53
            elif option == 'mobility_timer':
54 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)
55 59
            else:
56 60
                print 'Unparsed ', option, '=', settings.get(sectionExp, option)
57 61
        return retParameters
58 62

  
59 63
    def configMobility(self, params):
60
        '''# Time-variant Community Mobility Model
61
        groups = [4 for _ in range(10)]
62
        nr_nodes = sum(groups)
63
        tvcm = tvc(groups, dimensions=(100, 100),
64
                   aggregation=[0.5, 0.], epoch=[100, 100])
65
        #return tvcm'''
66
        if params['mob_model'] != "RandomWayPoint":
67
            print "Only RandomWayPoint supported now!"
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)
68 70
            sys.exit(1)
69 71
        else:
70
            if not set(['max_x', 'max_y', 'nodes_number', 'max_velocity']).issubset(params.keys()):
71
                print "You miss some params to configure RandomWayPoint"
72
                sys.exit(1)
73
            else:
74
                N = params['nodes_number']
75
                max_x, max_y = params['max_x'], params['max_y']
76
                min_v, max_v = params['min_velocity'], params['max_velocity']
77
                max_wt = params['max_wait_time']
78
                rw = random_waypoint(N, dimensions=(
79
                    max_x, max_y), velocity=(min_v, max_v), wt_max=max_wt)
80
                return rw
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

Also available in: Unified diff