-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mobility_Generation.m
194 lines (179 loc) · 11.6 KB
/
Mobility_Generation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
function s_mobility = Generate_Mobility(s_input)
%The Random Waypoint mobility model.
global s_mobility_tmp;
global nodeIndex_tmp;
trans_range=25;
s_mobility.NB_NODES = s_input.NB_NODES;
s_mobility.SIMULATION_TIME = s_input.SIMULATION_TIME;
for nodeIndex_tmp = 1:s_mobility.NB_NODES
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).cond=1; % States the current condition of the node. when the node is operational its value is =1 and when dead =0
s_mobility_tmp.VS_NODE(nodeIndex_tmp).rop=0; % number of rounds node was operational
s_mobility_tmp.VS_NODE(nodeIndex_tmp).neigh(1).arr=[]; %array of neighbour
s_mobility_tmp.VS_NODE(nodeIndex_tmp).cnt = 1;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect=struct('Prev_Hash',{},'Timestamp',{},'Data',{},'Hash',{});
s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect(1).Prev_Hash = 0;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect(1).Timestamp = datestr(now,'mm dd, yyyy HH:MM:SS.FFF ');
s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect(1).Data = nodeIndex_tmp;
strr = strcat(mat2str(s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect(1).Prev_Hash),mat2str(s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect(1).Timestamp),mat2str(s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect(1).Data));
hasher = System.Security.Cryptography.SHA256Managed;
hash0 = uint8(hasher.ComputeHash(uint8(strr)));
s_mobility_tmp.VS_NODE(nodeIndex_tmp).vect(1).Hash = dec2hex(hash0);
previousX = unifrnd(s_input.V_POSITION_X_INTERVAL(1),s_input.V_POSITION_X_INTERVAL(2));
previousY = unifrnd(s_input.V_POSITION_Y_INTERVAL(1),s_input.V_POSITION_Y_INTERVAL(2));
previousDuration = 0;
previousTime = 0;
Out_setRestrictedWalk_random_waypoint(previousX,previousY,previousDuration,previousTime,s_input);
while (s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end) < s_input.SIMULATION_TIME)
if (s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING(end) == false)%Maintenant c'est le temps d'être mobile
previousX = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X(end);
previousY = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y(end);
previousDuration = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end);
previousTime = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end);
Out_setRestrictedWalk_random_waypoint(previousX,previousY,previousDuration,previousTime,s_input);
else
%%%%%%%%Node is taking a pause:
previousDirection = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(end);
previousSpeed = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(end);
previousX = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X(end);
previousY = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y(end);
previousTime = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end);
previousDuration = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end);
distance = previousDuration*previousSpeed;
%%%
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end+1,1) = previousTime + previousDuration;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X(end+1,1) = (previousX + distance*cosd(previousDirection));
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y(end+1,1) = (previousY + distance*sind(previousDirection));
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(end+1,1) = 0;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(end+1,1) = 0;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING(end+1,1) = false;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end+1,1) = Out_adjustDuration_random_waypoint(s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end),unifrnd(s_input.V_PAUSE_INTERVAL(1),s_input.V_PAUSE_INTERVAL(2)),s_input);
end
end
nb_speed = length(s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE);
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X = zeros(nb_speed,1);
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y = zeros(nb_speed,1);
for s = 1:nb_speed
speed = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(s);
direction = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(s);
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X(s) = speed*cosd(direction);
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y(s) = speed*sind(direction);
end
v_index = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(1:end-1) == 0;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X(v_index) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y(v_index) = [];
if ((s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end) - s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end-1)) < 1e-14)
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X(end) = [];
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y(end) = [];
end
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end) = s_input.SIMULATION_TIME;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end) = 0;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(end) = 0;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X(end) = 0;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y(end) = 0;
s_mobility.VS_NODE(nodeIndex_tmp) = struct('V_TIME',s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME,...
'V_POSITION_X',s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X,...
'V_POSITION_Y',s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y,...
'V_SPEED_X',s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X,...
'V_SPEED_Y',s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y);
end
clear s_mobility_tmp;
clear nodeIndex_tmp;
end
function Out_setRestrictedWalk_random_waypoint(previousX,previousY,previousDuration,previousTime,s_input)
global s_mobility_tmp;
global nodeIndex_tmp;
x_tmp = previousX;
y_tmp = previousY;
time_tmp = previousTime + previousDuration;
duration_tmp = Out_adjustDuration_random_waypoint(time_tmp,unifrnd(s_input.V_WALK_INTERVAL(1),s_input.V_WALK_INTERVAL(2)),s_input);
direction_tmp = unifrnd(s_input.V_DIRECTION_INTERVAL(1),s_input.V_DIRECTION_INTERVAL(2));
speed = unifrnd(s_input.V_SPEED_INTERVAL(1),s_input.V_SPEED_INTERVAL(2));
distance_tmp = speed*duration_tmp;
if (distance_tmp == 0)
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end+1,1) = time_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X(end+1,1) = x_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y(end+1,1) = y_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(end+1,1) = direction_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(end+1,1) = speed;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING(end+1,1) = true;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end+1,1) = duration_tmp;
else
%The loop begins:
flag_mobility_finished = false;
while (~flag_mobility_finished)
x_dest = x_tmp + distance_tmp*cosd(direction_tmp);
y_dest = y_tmp + distance_tmp*sind(direction_tmp);
flag_mobility_was_outside = false;
if (x_dest > s_input.V_POSITION_X_INTERVAL(2))
flag_mobility_was_outside = true;
new_direction = 180 - direction_tmp;
x_dest = s_input.V_POSITION_X_INTERVAL(2);
y_dest = y_tmp + diff([x_tmp x_dest])*tand(direction_tmp);
end
if (x_dest < s_input.V_POSITION_X_INTERVAL(1))
flag_mobility_was_outside = true;
new_direction = 180 - direction_tmp;
x_dest = s_input.V_POSITION_X_INTERVAL(1);
y_dest = y_tmp + diff([x_tmp x_dest])*tand(direction_tmp);
end
if (y_dest > s_input.V_POSITION_Y_INTERVAL(2))
flag_mobility_was_outside = true;
new_direction = -direction_tmp;
y_dest = s_input.V_POSITION_Y_INTERVAL(2);
x_dest = x_tmp + diff([y_tmp y_dest])/tand(direction_tmp);
end
if (y_dest < s_input.V_POSITION_Y_INTERVAL(1))
flag_mobility_was_outside = true;
new_direction = -direction_tmp;
y_dest = s_input.V_POSITION_Y_INTERVAL(1);
x_dest = x_tmp + diff([y_tmp y_dest])/tand(direction_tmp);
end
current_distance = abs(diff([x_tmp x_dest]) + 1i*diff([y_tmp y_dest]));
current_duration = Out_adjustDuration_random_waypoint(time_tmp,current_distance/speed,s_input);
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_TIME(end+1,1) = time_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_X(end+1,1) = x_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_POSITION_Y(end+1,1) = y_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(end+1,1) = direction_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(end+1,1) = speed;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING(end+1,1) = true;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end+1,1) = current_duration;
if(flag_mobility_was_outside)
time_tmp = time_tmp + current_duration;
duration_tmp = duration_tmp - current_duration;
distance_tmp = distance_tmp - current_distance;
x_tmp = x_dest;
y_tmp = y_dest;
direction_tmp = new_direction;
else
flag_mobility_finished = true;
end
end
%the loop ended
end
end
function duration = Out_adjustDuration_random_waypoint(time,duration,s_input)
if ((time+duration) >= s_input.SIMULATION_TIME)
duration = s_input.SIMULATION_TIME - time;
end
end