@@ -10,9 +10,9 @@ namespace Clusterization_algorithms
10
10
class EnergyCalculator // DEEC algorithm
11
11
{
12
12
Dictionary < Point , int > allNodes ; // int - num of cluster
13
- Dictionary < Point , double > nodesLevelCharge = new Dictionary < Point , double > { } ;
13
+ private Dictionary < Point , int > nodesLevelCharge = new Dictionary < Point , int > { } ;
14
14
List < int > clustersEnergy = new List < int > { } ;
15
- double stationUsedE = 0 ; //energy used by station
15
+ int stationUsedE = 0 ; //energy used by station
16
16
17
17
//--------- Energy consumption parameters ------------
18
18
double E_fs = 0.01 ; //nJ(10^-9) amplifier energy, free space model (short distance) | d<d0
@@ -21,6 +21,20 @@ class EnergyCalculator // DEEC algorithm
21
21
int node_E = 500000000 ; //nJ; = 0,5J // initial node energy
22
22
double d0 = 87.7 ; // (m) distance threshold for swapping amplification models
23
23
int package = 4000 ; // bytes, package size
24
+
25
+ public Dictionary < Point , int > GetNodesChargeDictionary ( ) {
26
+
27
+ Dictionary < Point , int > chargeList = new Dictionary < Point , int > { } ;
28
+ int onePercent = node_E / 100 ; // (nJ)
29
+
30
+ foreach ( var node in nodesLevelCharge )
31
+ {
32
+ int charge = node . Value / onePercent ; // (%)
33
+ chargeList . Add ( node . Key , charge ) ;
34
+ }
35
+ return chargeList ;
36
+ }
37
+
24
38
//int package = Calculator.genRandInt(20, 65535);
25
39
//----------------------------------------------------
26
40
@@ -51,7 +65,7 @@ public void Start_DT_Protocol(List<Point> cluster, int stationHeight) { // direc
51
65
PPConnection ( point , center , stationHeight ) ;
52
66
}
53
67
54
- public int PPConnection ( Point node , Point station , int stationHeight ) {
68
+ public int PPConnection ( Point node , Point station , int stationHeight ) { // transmission from node -> station
55
69
56
70
double distH0 = Calculator . calcDistance ( node , station ) ;
57
71
double dist = Math . Sqrt ( distH0 * distH0 + stationHeight * stationHeight ) ;
@@ -64,10 +78,22 @@ public int PPConnection(Point node, Point station, int stationHeight) {
64
78
if ( dist < d0 )
65
79
E_transmission = package * E_elec + package * E_fs * Math . Pow ( dist , 2 ) ; // nJ
66
80
else
67
- E_transmission = package * E_elec + package * E_mp * Math . Pow ( dist , 4 ) ; // J
81
+ //E_transmission = package * E_elec + package * E_mp * Math.Pow(dist, 4); // J
82
+ E_transmission = 0 ;
68
83
69
84
double E_receive = package * E_elec ;
70
85
86
+ //minus used energy from nodes charge
87
+ if ( nodesLevelCharge . TryGetValue ( node , out int oldCharge ) )
88
+ {
89
+ int newCharge = oldCharge - ( int ) E_transmission ;
90
+ nodesLevelCharge . Remove ( node ) ;
91
+ nodesLevelCharge . Add ( node , newCharge ) ;
92
+ }
93
+
94
+ stationUsedE += Convert . ToInt32 ( E_receive ) ;
95
+
96
+
71
97
if ( dist < d0 )
72
98
Console . WriteLine ( "E: " + E_transmission + " nJ -> " + E_receive + " nJ" ) ;
73
99
else
0 commit comments