Skip to content

Commit 34cb467

Browse files
committed
Add calculating node energy changing. Add printing to panel. Off d2(>d0 distance) model
1 parent fed9e73 commit 34cb467

File tree

7 files changed

+81
-42
lines changed

7 files changed

+81
-42
lines changed

Calculator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ public static Dictionary<Point, int> generatePoints(int count, int rangeX, int r
6969
return points;
7070
}
7171

72-
public static String printPointsDictionary(Dictionary<Point, int> points)
72+
public static String printPointsDictionary(Dictionary<Point, int> nodes, Dictionary<Point, int> nodesCharge)
7373
{
74-
points = sortDictionaryByValue(points);
74+
nodes = sortDictionaryByValue(nodes);
7575

7676
String str = "";
7777

7878
//Console.WriteLine("\nPoints list:");
7979

80-
foreach (var point in points)
80+
foreach (var node in nodes)
8181
{
8282
//Console.WriteLine(point.ToString());
83-
str += point.ToString() + "\n";
83+
nodesCharge.TryGetValue(node.Key, out int charge);
84+
str += node.ToString() +" "+ charge + "%\n";
85+
//str += "(" + node.Key.X + ", " + node.Key.Y + ") [" + node.Value + "] " + "<" +""+ ">\n";
8486
}
8587
//Console.WriteLine();
8688
return str;

EnergyCalculator.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace Clusterization_algorithms
1010
class EnergyCalculator // DEEC algorithm
1111
{
1212
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> { };
1414
List<int> clustersEnergy = new List<int> { };
15-
double stationUsedE = 0; //energy used by station
15+
int stationUsedE = 0; //energy used by station
1616

1717
//--------- Energy consumption parameters ------------
1818
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
2121
int node_E = 500000000; //nJ; = 0,5J // initial node energy
2222
double d0 = 87.7; // (m) distance threshold for swapping amplification models
2323
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+
2438
//int package = Calculator.genRandInt(20, 65535);
2539
//----------------------------------------------------
2640

@@ -51,7 +65,7 @@ public void Start_DT_Protocol(List<Point> cluster, int stationHeight) { // direc
5165
PPConnection(point, center, stationHeight);
5266
}
5367

54-
public int PPConnection(Point node, Point station, int stationHeight) {
68+
public int PPConnection(Point node, Point station, int stationHeight) { // transmission from node -> station
5569

5670
double distH0 = Calculator.calcDistance(node, station);
5771
double dist = Math.Sqrt(distH0 * distH0 + stationHeight * stationHeight);
@@ -64,10 +78,22 @@ public int PPConnection(Point node, Point station, int stationHeight) {
6478
if (dist < d0)
6579
E_transmission = package * E_elec + package * E_fs * Math.Pow(dist, 2); // nJ
6680
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;
6883

6984
double E_receive = package * E_elec;
7085

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+
7197
if(dist < d0)
7298
Console.WriteLine("E: " + E_transmission + " nJ -> " + E_receive+" nJ");
7399
else

Forel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void addToCluster(Point key)
5151

5252
//Console.WriteLine("Add point " + key + " to cluster " + clusterNum);
5353

54-
Calculator.printPointsDictionary(points);
54+
//Calculator.printPointsDictionary(points);
5555
}
5656

5757
// write points in list to cluster

Form1.Designer.cs

Lines changed: 25 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)