Skip to content

Commit ae8d11a

Browse files
committed
Version 1.0 Correct energy model parameters, graphic, PP protocol
1 parent 139b570 commit ae8d11a

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

Calculator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,11 @@ public static List<Point> SortPointListByX(List<Point> points) {
413413

414414
public static Point FindCloserPoint(Point point, List<Point> list) {
415415

416-
List<Point> newList = new List<Point> { };
417-
newList.AddRange(list);
416+
//List<Point> newList = new List<Point> { };
417+
//newList.AddRange(list);
418418

419-
if (newList.Contains(point))
420-
newList.Remove(point);
419+
//if (newList.Contains(point))
420+
// newList.Remove(point);
421421

422422
Point minPoint = list[0];
423423
double minDist = Calculator.calcDistance(point, minPoint);

EnergyCalculator.cs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class EnergyCalculator // DEEC algorithm
1717

1818
//--------- Energy consumption parameters ------------
1919
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
2222
int node_E = 500000000; //nJ; = 0,5J // initial node energy
2323
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
2525
//int package = Calculator.genRandInt(20, 65535);
2626
//----------------------------------------------------
2727

@@ -82,13 +82,18 @@ public void Start_PP_ToRoute(List<Point> cluster, int stationHeight, List<Point>
8282

8383
public void Start_PP_Protocol(List<Point> cluster, int stationHeight) {
8484

85+
List<int> packetCountList = new List<int> { };
8586
Point center = Calculator.findCentroid(cluster);
8687

88+
for (int i = 0; i < allNodes.Count; i++)
89+
packetCountList.Add(1);
90+
8791
for (int i = 0; i < cluster.Count; i++) {
8892

8993
Point closer = center;
9094
double dist_i_to_center = Calculator.calcDistance(cluster[i], center);
9195
double dist_to_closer = dist_i_to_center;
96+
int index = -1;
9297

9398
for (int j = 0; j < cluster.Count; j++) {
9499
if (i != j) {
@@ -97,11 +102,18 @@ public void Start_PP_Protocol(List<Point> cluster, int stationHeight) {
97102
if (dist_to_node < dist_to_closer && dist_j_to_center < dist_i_to_center) {
98103
closer = cluster[j];
99104
dist_to_closer = dist_to_node;
105+
index = j;
100106
}
101107
}
102108
}
103109

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+
}
105117
}
106118
}
107119

@@ -143,31 +155,39 @@ public void Start_DT_Protocol(List<Point> cluster, int stationHeight) { // direc
143155
PPConnection(point, center, stationHeight);
144156
}
145157

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
147159

148160
double distH0 = Calculator.calcDistance(node, station);
149161
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);
153163
double E_transmission = 0;
154-
Console.WriteLine(node + " " + station);
164+
//Console.WriteLine(node + " " + station);
155165
//d0 = Math.Sqrt(E_fs / E_mp);
156166

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);
160176
}
161-
else
162-
//E_transmission = package * E_elec + package * E_mp * Math.Pow(dist, 4); // nJ
163-
E_transmission = 0; // no transmittion
164177

165-
double E_receive = package * E_elec;
178+
179+
double E_receive = (package*packetCount) * E_elec;
166180

167181
//minus used energy from nodes charge
168182
if (nodesLevelCharge.TryGetValue(node, out int oldCharge))
169183
{
170184
int newCharge = oldCharge - (int)E_transmission;
185+
186+
if (newCharge < 0) {
187+
newCharge = 0;
188+
graphic.DrawPoint(node, Brushes.Red);
189+
}
190+
171191
nodesLevelCharge.Remove(node);
172192
nodesLevelCharge.Add(node, newCharge);
173193
}

Forel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ private Point findNewCenter(Point center)
102102

103103
//Point newCenter = findBarycenter(cluster);
104104
Point newCenter = Calculator.findCentroid(cluster);
105-
graphic.DrawPoint(newCenter, Brushes.Pink);
105+
graphic.DrawPoint(newCenter, Brushes.Pink, 6);
106106
graphic.DrawCircle(newCenter, radius, Color.LightGray);
107107

108108
if (center == newCenter){
109109
graphic.DrawCircle(center, radius, Color.Black);
110-
graphic.DrawPoint(newCenter, Brushes.Red);
110+
graphic.DrawPoint(newCenter, Brushes.Red, 6);
111111
listOfClastersCenter.Add(center);
112112
}
113113

Form1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private void DrawAllSavedObjects() {
215215

216216
if (clusterCenters.Count != 0) {
217217
for (int i = 0; i < clusterCenters.Count; i++) {
218-
graphic.DrawPoint(clusterCenters[i], Brushes.Red);
218+
graphic.DrawPoint(clusterCenters[i], Brushes.Red, 6);
219219
graphic.DrawCircle(clusterCenters[i], radius, Color.Black, 0);
220220
}
221221
}

Graphic.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public void DrawCircle(Point p, int radius, Color color, int pause = 30)
3636
PAUSE(pause);
3737
}
3838

39-
public void DrawPoint(Point p, Brush brush)
39+
public void DrawPoint(Point p, Brush brush, int size = 4)
4040
{
41-
graphics.FillRectangle(brush, p.X - 2, p.Y - 2, 4, 4);
41+
int s = (int)(size/2);
42+
//graphics.FillRectangle(brush, p.X - 2, p.Y - 2, 4, 4);
43+
graphics.FillRectangle(brush, p.X - s, p.Y - s, size, size);
4244
}
4345

4446
public void DrawPointArray(Point[] points)

K_means.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Dictionary<Point, int> getPoints()
4040

4141
public void DrawSeeds() {
4242
foreach (Point seed in seeds)
43-
graphic.DrawPoint(seed, Brushes.Red);
43+
graphic.DrawPoint(seed, Brushes.Red, 6);
4444
}
4545

4646
//write select point to cluster

0 commit comments

Comments
 (0)