Skip to content

Commit 139b570

Browse files
committed
Done PP to center connection graphical model
1 parent bcd99f1 commit 139b570

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
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: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,40 @@ public void CalculteAllNodesEnergy(ConnectionType connectionType, Dictionary<Poi
6868
break;
6969

7070
case ConnectionType.PP_to_Route:
71+
Start_PP_ToRoute(cluster, stationHeight, routeList);
7172
break;
7273
}
7374
}
7475
}
7576

77+
public void Start_PP_ToRoute(List<Point> cluster, int stationHeight, List<Point> routeList) {
78+
Point center = Calculator.findCentroid(cluster);
79+
List<Point> routeFragment = Calculator.getRouteFragment(center, routeList);
80+
81+
}
82+
7683
public void Start_PP_Protocol(List<Point> cluster, int stationHeight) {
7784

78-
Console.WriteLine("Start PP");
7985
Point center = Calculator.findCentroid(cluster);
8086

81-
//if (cluster.Count == 1)
82-
// PPConnection(cluster[0], center, stationHeight);
83-
//else
84-
foreach (Point point in cluster)
85-
{
86-
Point currentPoint = point;
87-
88-
while (!currentPoint.Equals(center))
89-
{
90-
Point closer = Calculator.FindCloserPoint(currentPoint, cluster);
91-
Console.WriteLine("cur - closer " + currentPoint + "-" + closer);
92-
double distPCE = Calculator.calcDistance(currentPoint, center); //point - center
93-
double distPCL = Calculator.calcDistance(currentPoint, closer); //point - closer
94-
95-
if (distPCE <= distPCL)
96-
{
97-
currentPoint = center;
98-
PPConnection(point, center, stationHeight);
99-
}
100-
else
101-
{
102-
PPConnection(point, closer, 0);
103-
currentPoint = closer;
87+
for (int i = 0; i < cluster.Count; i++) {
88+
89+
Point closer = center;
90+
double dist_i_to_center = Calculator.calcDistance(cluster[i], center);
91+
double dist_to_closer = dist_i_to_center;
92+
93+
for (int j = 0; j < cluster.Count; j++) {
94+
if (i != j) {
95+
double dist_to_node = Calculator.calcDistance(cluster[i], cluster[j]);
96+
double dist_j_to_center = Calculator.calcDistance(cluster[j], center);
97+
if (dist_to_node < dist_to_closer && dist_j_to_center < dist_i_to_center) {
98+
closer = cluster[j];
99+
dist_to_closer = dist_to_node;
100+
}
104101
}
105102
}
103+
104+
PPConnection(cluster[i], closer, 0);// high!!!
106105
}
107106
}
108107

@@ -157,7 +156,7 @@ public int PPConnection(Point node, Point station, int stationHeight) { // trans
157156

158157
if (dist < d0) {
159158
E_transmission = package * E_elec + package * E_fs * Math.Pow(dist, 2); // nJ
160-
graphic.DrawLine(node, station, Color.LightGreen);
159+
graphic.DrawLine(node, station, Color.Olive);
161160
}
162161
else
163162
//E_transmission = package * E_elec + package * E_mp * Math.Pow(dist, 4); // nJ

0 commit comments

Comments
 (0)