-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweight.java
107 lines (84 loc) · 2.66 KB
/
weight.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.ArrayList;
import static java.lang.Math.round;
//purpose
//calculate weight and store the data to the row
public class weight
{
private ArrayList<hotspot> myHotSpot = new ArrayList<>();
private ArrayList<edge> myEdge = new ArrayList<>();
public weight() { } //nothing to create atm
public void setMyHotSpot(ArrayList<hotspot> new_Hot)
{
this.myHotSpot = new_Hot;
}
public void setMyEdge(ArrayList<edge> new_Edge){this.myEdge = new_Edge; }
public void matrix(int size)
{
ArrayList<edge> display = new ArrayList<>(); // for displaying data
double A, B, C;
for (int i = 0; i < myHotSpot.size(); i++)
{
for (int j = 0; j < myHotSpot.size(); j++)
{
A = A(myHotSpot.get(i).getY(), myHotSpot.get(j).getY());
B = B(myHotSpot.get(i).getX(), myHotSpot.get(j).getX());
C = Math.sqrt(B + A);
C = round(C * 100.0) / 100.0;
if(j >= i+1)
{
myEdge.add(new edge( i, j, C)); //this is using for kruskal algo
}
/* this is I want because it can prevent duplications like 1-2, 2-1 with myEdge
0 1 2 3 4
* 0 W W W W W
* 1 w w w W
* 2 w w W
* 3 w W
* 4 w W
*
* */
//this parts are for displaying
if (i == j)
{
display.add(new edge(i, j, 0)); //does not matter this is false or true
}
else
{
display.add(new edge(i, j, C));
}
}
}
printEdge(display, size); //displaying temporary results
}
public double A(double base, double height)
{
double A = -999;
if (base > height)
{
double temp = base;
base = height;
height = temp;
}
A = Math.pow(height - base, 2);
return A;
}
public double B(double base, double width)
{
double B = -999;
if (base > width)
{
double temp = base;
base = width;
width = temp;
}
B = Math.pow(width - base, 2);
return B;
}
public void printEdge(ArrayList<edge> tempEdge, int size)
{
for(int i=0; i < tempEdge.size(); i++)
{
tempEdge.get(i).print(size);
}
}
}