-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cluster.java
68 lines (57 loc) · 1.36 KB
/
Cluster.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
import java.util.ArrayList;
import java.util.List;
import com.panayotis.gnuplot.JavaPlot;
import com.panayotis.gnuplot.plot.DataSetPlot;
import com.panayotis.gnuplot.dataset.PointDataSet;
//import java.io.File;
//import java.io.FileOutputStream;
import java.io.IOException;
//import java.io.OutputStreamWriter;
import java.io.FileWriter;
public class Cluster{
public Point centroid;
public List<Point> points;
public int id; // cluster id
public Cluster(int id){
this.centroid = null;
this.points = new ArrayList();
this.id = id;
}
public void addPoint(Point p){
points.add(p);
}
public void setPoints(List ps){
this.points = ps;
}
public List<Point> getPoints(){
return points;
}
public void setCentroid(Point c){
this.centroid = c;
}
public Point getCentroid(){
return centroid;
}
public int getId(){
return id;
}
public void clearPoints(){ //used in the beginning of the next round
points.clear();
}
public void outCluster(String file){
try{ // cluser
FileWriter fw = new FileWriter(file,true);
fw.write("cluser: " + id + "\n");
fw.write("centroid: " + centroid +"\n");
fw.write("points: \n");
for (Point p: points){
fw.write(p + "\n");
}
fw.write("\n");
fw.close();
}
catch (IOException e) {
System.out.println("error to write file");
}
}
}