-
Notifications
You must be signed in to change notification settings - Fork 2
/
allocatemultiple.cpp
435 lines (279 loc) · 7.39 KB
/
allocatemultiple.cpp
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#include<bits/stdc++.h>
#define V 4
using namespace std;
float energyamplitude=70;
//"energy amplitude=70PJ/bit/m2"
//float Eamp=50;
float Eelec=50;
float totalenergy=2000000000;
float packetsize =1500;
float channelcapacity=34;
//cout<<"Channel capacity=34"<<endl;
float lengthofchannel=10;
int maxtsp(int graph[][V],int s)
{
int i;
int k;
vector<int> vertex;
for(i=0;i<V;i++)
{
if(i!=s)
{
vertex.push_back(i);
}
}
int maxpath=INT_MIN;
k=s;
do{
int cpath=0;
k=s;
for(i=0;i<vertex.size();i++)
{
cpath+=graph[k][vertex[i]];
k=vertex[i];
}
cpath+=graph[k][s];
maxpath=max(maxpath,cpath);
}
while(next_permutation(vertex.begin(),vertex.end()));
return maxpath;
}
int tsp(int graph[][V],int s)
{
int i;
int k;
vector<int> vertex;
for(i=0;i<V;i++)
{
if(i!=s)
{
vertex.push_back(i);
}
}
int minpath=INT_MAX;
k=s;
do{
int cpath=0;
k=s;
for(i=0;i<vertex.size();i++)
{
cpath+=graph[k][vertex[i]];
k=vertex[i];
}
cpath+=graph[k][s];
minpath=min(cpath,minpath);
}
while(next_permutation(vertex.begin(),vertex.end()));
return minpath;
}
int main(){
int r1,r2,r3,r4,r5;
cout<<"Enter radius of the the sensors"<<endl;
cin>>r1>>r2>>r3>>r4;
int s1,s2,s3,s4,s5;
cout<<"Enter information rate of the the sensors"<<endl;
cin>>s1>>s2>>s3>>s4;
float e1,e2,e3,e4;
cout<<"Energy information for 1st cluster sensors"<<endl;
cin>>e1>>e2>>e3>>e4;
float e5,e6,e7,e8,e9;
cout<<"Energy information of 2nd cluster sensors"<<endl;
cin>>e5>>e6>>e7>>e8;
int b1,b2,b3,b4;
b1=r1*s1;
b2=r2*s2;
b3=r3*s3;
b4=r4*s4;
int netb=( b1+b2+b3+b4)/4;
int r11,r21,r31,r41,r51;
cout<<"Enter radius of the the sensors of second cluster"<<endl;
cin>>r11>>r21>>r31>>r41;
int s11,s21,s31,s41,s51;
cout<<"Enter information rate of the the sensors"<<endl;
cin>>s11>>s21>>s31>>s41;
int b11,b21,b31,b41;
b11=r11*s11;
b21=r21*s21;
b31=r31*s31;
b41=r41*s41;
int netb1=( b11+b21+b31+b41)/4;
cout<<"average floating point constant first cluster"<<netb<<endl;
cout<<"average floating point constant second cluster"<<netb1<<endl;
cout<<"Initial energy of coolector"<<endl;
cout<<totalenergy<<endl;
cout<<"Time taken for collector1 to go to cluster1"<<endl;
int time1=5;
cout<<time1<<endl;
cout<<"Time taken for collector 2 to go to cluster2"<<endl;
int time2=8;
cout<<time2<<endl;
int graph[][V]={{ 0, 10, 15, 20 },
{ 10, 0, 35, 25 },
{ 15, 35, 0, 30 },
{ 20, 25, 30, 0 }};
int graph1[][V]={{ 0, 20, 25, 40 },
{ 20, 0, 35, 45 },
{ 25, 35, 0, 30 },
{ 40, 45, 30, 0 }};
int s=0;
int maxtspval2=maxtsp(graph1,s);
int tspval2=tsp(graph1,s);
cout<<maxtspval2<<" "<<tspval2<<endl;
s=0;
int maxtspval= maxtsp(graph,s);
int tspval= tsp(graph,s);
cout<<maxtspval<<" "<<tspval<<endl;
int i=0;
int maxradius=100;
int minradius=1;
int j,l;
int g[V][V];
for(i=0;i<V;i++)
{
for(j=0;j<V;j++)
{
g[i][j]= graph[i][j];
}
}
int g1[V][V];
for(i=0;i<V;i++)
{
for(j=0;j<V;j++)
{
g1[i][j]= graph1[i][j];
}
}
i=0;
int lambda=0;
while(tspval < maxtspval || maxtspval2>tspval2 || energyamplitude>=0||totalenergy>=0 || e1>=0 ||e2>=0||e3>=0||e4>=0 )
{
lambda++;
cout<<"------"<<endl;
cout<<"Analysis"<<endl;
cout<<lambda<<" iteration"<<endl;
int m= tspval;
netb+=8/8;
r1=netb/s1;
r2=netb/s2;
r3=netb/s3;
r4=netb/s4;
//r5=netb/s5;
netb1+=8/8;
r11=netb/s11;
r21=netb/s21;
r31=netb/s31;
r41=netb/s41;
cout<<"-----"<<endl;
cout<<"Radius changes"<<endl;
cout<<"Radius change first cluter"<<endl;
cout<<r1<<" "<<r2<<" "<<r3<<" "<<r4<<endl;
cout<<"Information source change first cluster"<<endl;
cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
cout<<"Radius change second cluster"<<endl;
cout<<r11<<" "<<r21<<" "<<r31<<" "<<r41<<endl;
cout<<"Information source change second cluster"<<endl;
cout<<s11<<" "<<s21<<" "<<s31<<" "<<s41<<endl;
cout<<"----"<<endl;
cout<<"Energy loss in the sensors"<<endl;
cout<<"Energy loss of the first cluster sources"<<endl;
e1-=0.35;
e2-=0.50;
e3-=0.42;
e4-=0.21;
cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<endl;
cout<<"Energy loss of the second cluster sources"<<endl;
e5-=0.35;
e6-=0.50;
e7-=0.42;
e8-=0.21;
cout<<e5<<" "<<e6<<" "<<e7<<" "<<e8<<" "<<endl;
cout<<"-----"<<endl;
g1[0][1]+=(int)(4/s1 + 4/s2);
g1[0][2]+=(int)(4/s1 + 4/s3);
g1[0][3]+=(int)(4/s1 + 4/s4);
g1[1][0]+=(int)(4/s1 + 4/s2);
g1[1][2]+=(int)(4/s2 + 4/s3);
g1[1][3]+=(int)(4/s2 + 4/s4);
g1[2][0]+=(int)(4/s3 + 4/s1);
g1[2][1]+=(int)(4/s3 + 4/s2);
g1[2][3]+=(int)(4/s3 + 4/s4);
g1[3][0]+=(int)(4/s4 + 4/s1);
g1[3][1]+=(int)(4/s4 + 4/s2);
g1[3][2]+=(int)(4/s4 + 4/s3);
int mini=INT_MAX;
int mini1=INT_MAX;
g[0][1]+=(int)(1/s1 + 1/s2);
g[0][2]+=(int)(1/s1 + 1/s3);
g[0][3]+=(int)(1/s1 + 1/s4);
g[1][0]+=(int)(1/s1 + 1/s2);
g[1][2]+=(int)(1/s2 + 1/s3);
g[1][3]+=(int)(1/s2 + 1/s4);
g[2][0]+=(int)(1/s3 + 1/s1);
g[2][1]+=(int)(1/s3 + 1/s2);
g[2][3]+=(int)(1/s3 + 1/s4);
g[3][0]+=(int)(1/s4 + 1/s1);
g[3][1]+=(int)(1/s4 + 1/s2);
g[3][2]+=(int)(1/s4 + 1/s3);
for(i=0;i<V;i++)
{
for(j=0;j<V;j++)
{
if(mini>g[i][j])
{
mini=g[i][j];
}
}
}
for(i=0;i<V;i++)
{
for(j=0;j<V;j++)
{
if(mini1>g1[i][j])
{
mini1=g1[i][j];
}
}
}
cout<<"Minimum information rate in cluster1"<<endl;
cout<<mini<<endl;
cout<<"Minimum information rate in cluster2"<<endl;
cout<<mini1<<endl;
int s=0;
cout<<"-----"<<endl;
cout<<"TSP module"<<endl;
cout<<"tsp in "<<i<<"th iteration "<<tsp(g,0)<<endl;
tspval=tsp(g,0);
tspval2=tsp(g1,0);
cout<<"tsp first cluster"<<endl;
cout<<"tsp second cluster"<<endl;
cout<<tspval<<" "<<maxtspval<<endl;
cout<<tspval2<<" "<<maxtspval2<<endl;
tspval=time1+tspval;
tspval2=time2+tspval2;
cout<<"Time for 1 iteration in cluster one"<<endl;
cout<<tspval<<endl;
cout<<"Time for1 iteration in cluster two"<<endl;
cout<<tspval2<<endl;
cout<<"------"<<endl;
cout<<"-------"<<endl;
cout<<"Energy calculation of the collector"<<endl;
totalenergy-= (Eelec + energyamplitude*r1*r1 + energyamplitude*r2*r2 + energyamplitude*r3*r3 + energyamplitude*r4*r4);
cout<<"Energy loss in ith iteration"<<endl;
cout<<abs(totalenergy)<<endl;
cout<<"Energy calculation of the collector afer second cluser"<<endl;
totalenergy-= (Eelec + energyamplitude*r11*r11 + energyamplitude*r21*r21 + energyamplitude*r31*r31 + energyamplitude*r41*r41);
cout<<"Energy loss in ith iteration"<<endl;
cout<<abs(totalenergy)<<endl;
cout<<"-------"<<endl;
cout<<"-----"<<endl;
cout<<"Time Analysis"<<endl;
int total_time=tspval+tspval2;
cout<<"Total time loss"<<endl;
cout<<total_time<<endl;
if(maxtspval<=tspval || maxtspval2<=tspval2|| e1<0 || e2<0||e3<0 ||e4<0)
{
cout<<"End of iterations"<<endl;
break;
}
}
return 0;}