@@ -17,11 +17,11 @@ class EnergyCalculator // DEEC algorithm
17
17
18
18
//--------- Energy consumption parameters ------------
19
19
double E_fs = 0.01 ; //nJ(10^-9) amplifier energy, free space model (short distance) | d<d0
20
- // double E_mp = 1300000 ; //nJ // multipath fading model (large distance) | d >= d0
21
- int E_elec = 50 ; //nJ, energy for work signal transmission/recieve
20
+ double E_mp = 0.0000013 ; //nJ // multipath fading model (large distance) | d >= d0
21
+ int E_elec = 50 ; //nJ/bit , energy for work signal transmission/recieve
22
22
int node_E = 500000000 ; //nJ; = 0,5J // initial node energy
23
23
double d0 = 87.7 ; // (m) distance threshold for swapping amplification models
24
- int package = 4000 ; // bytes , package size
24
+ int package = 32000 ; // bits , package size
25
25
//int package = Calculator.genRandInt(20, 65535);
26
26
//----------------------------------------------------
27
27
@@ -82,13 +82,18 @@ public void Start_PP_ToRoute(List<Point> cluster, int stationHeight, List<Point>
82
82
83
83
public void Start_PP_Protocol ( List < Point > cluster , int stationHeight ) {
84
84
85
+ List < int > packetCountList = new List < int > { } ;
85
86
Point center = Calculator . findCentroid ( cluster ) ;
86
87
88
+ for ( int i = 0 ; i < allNodes . Count ; i ++ )
89
+ packetCountList . Add ( 1 ) ;
90
+
87
91
for ( int i = 0 ; i < cluster . Count ; i ++ ) {
88
92
89
93
Point closer = center ;
90
94
double dist_i_to_center = Calculator . calcDistance ( cluster [ i ] , center ) ;
91
95
double dist_to_closer = dist_i_to_center ;
96
+ int index = - 1 ;
92
97
93
98
for ( int j = 0 ; j < cluster . Count ; j ++ ) {
94
99
if ( i != j ) {
@@ -97,11 +102,18 @@ public void Start_PP_Protocol(List<Point> cluster, int stationHeight) {
97
102
if ( dist_to_node < dist_to_closer && dist_j_to_center < dist_i_to_center ) {
98
103
closer = cluster [ j ] ;
99
104
dist_to_closer = dist_to_node ;
105
+ index = j ;
100
106
}
101
107
}
102
108
}
103
109
104
- PPConnection ( cluster [ i ] , closer , 0 ) ; // high!!!
110
+ if ( index == - 1 )
111
+ PPConnection ( cluster [ i ] , closer , stationHeight , packetCountList [ i ] ) ;
112
+ else
113
+ {
114
+ packetCountList [ index ] = packetCountList [ i ] + 1 ; //packet last node + 1 his packet
115
+ PPConnection ( cluster [ i ] , closer , 0 , packetCountList [ i ] ) ;
116
+ }
105
117
}
106
118
}
107
119
@@ -143,31 +155,39 @@ public void Start_DT_Protocol(List<Point> cluster, int stationHeight) { // direc
143
155
PPConnection ( point , center , stationHeight ) ;
144
156
}
145
157
146
- public int PPConnection ( Point node , Point station , int stationHeight ) { // transmission from node -> station
158
+ public int PPConnection ( Point node , Point station , int stationHeight , int packetCount = 1 ) { // transmission from node -> station
147
159
148
160
double distH0 = Calculator . calcDistance ( node , station ) ;
149
161
double dist = Math . Sqrt ( distH0 * distH0 + stationHeight * stationHeight ) ;
150
-
151
- Console . WriteLine ( "Distance: " + Math . Round ( dist ) + " Height: " + stationHeight ) ;
152
-
162
+ //Console.WriteLine("Distance: " + Math.Round(dist) + " Height: " + stationHeight);
153
163
double E_transmission = 0 ;
154
- Console . WriteLine ( node + " " + station ) ;
164
+ // Console.WriteLine(node + " " + station);
155
165
//d0 = Math.Sqrt(E_fs / E_mp);
156
166
157
- if ( dist < d0 ) {
158
- E_transmission = package * E_elec + package * E_fs * Math . Pow ( dist , 2 ) ; // nJ
159
- graphic . DrawLine ( node , station , Color . Olive ) ;
167
+ if ( dist < d0 )
168
+ {
169
+ E_transmission = ( package * packetCount ) * E_elec + ( package * packetCount ) * E_fs * Math . Pow ( dist , 2 ) ; // nJ
170
+ graphic . DrawLine ( node , station , Color . LimeGreen ) ;
171
+ }
172
+ else {
173
+ E_transmission = package * E_elec + package * E_mp * Math . Pow ( dist , 4 ) ; // nJ
174
+ //E_transmission = 0; // no transmittion
175
+ graphic . DrawLine ( node , station , Color . IndianRed ) ;
160
176
}
161
- else
162
- //E_transmission = package * E_elec + package * E_mp * Math.Pow(dist, 4); // nJ
163
- E_transmission = 0 ; // no transmittion
164
177
165
- double E_receive = package * E_elec ;
178
+
179
+ double E_receive = ( package * packetCount ) * E_elec ;
166
180
167
181
//minus used energy from nodes charge
168
182
if ( nodesLevelCharge . TryGetValue ( node , out int oldCharge ) )
169
183
{
170
184
int newCharge = oldCharge - ( int ) E_transmission ;
185
+
186
+ if ( newCharge < 0 ) {
187
+ newCharge = 0 ;
188
+ graphic . DrawPoint ( node , Brushes . Red ) ;
189
+ }
190
+
171
191
nodesLevelCharge . Remove ( node ) ;
172
192
nodesLevelCharge . Add ( node , newCharge ) ;
173
193
}
0 commit comments