33,013
社区成员
发帖
与我相关
我的任务
分享
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.HashMap.createEntry(HashMap.java:901)
at java.util.HashMap.addEntry(HashMap.java:888)
at java.util.HashMap.put(HashMap.java:509)
at java.util.HashSet.add(HashSet.java:217)
at java.util.AbstractCollection.addAll(AbstractCollection.java:342)
at cn.ac.ict.cluster.LinkCluster.clusterSim(LinkCluster.java:134)
at cn.ac.ict.cluster.LinkCluster.startAnalysis(LinkCluster.java:84)
at cn.ac.ict.cluster.LinkCluster.main(LinkCluster.java:144)
private int clusterSim(Cluster A, Cluster B) {
HashSet<Integer> merge = A.getLink();
merge.addAll(B.getLink());
return A.getLink().size() + B.getLink().size() - merge.size();
}
public ArrayList<Cluster> startAnalysis(double threshold, String toFile) {
long t1, t2;
t1 = System.currentTimeMillis();
System.out.println("开始聚类!");
ArrayList<Cluster> finalClusters = new ArrayList<Cluster>();
ArrayList<Cluster> originalClusters = initClusters();
finalClusters = originalClusters;
int clusternum = -1;
double mostsim = threshold;
while (mostsim >= threshold) {
if (clusternum == finalClusters.size())
break;
clusternum = finalClusters.size();
mostsim = 0;
int mergeIndexA = 0;
int mergeIndexB = 0;
// 遍历任意两个簇,找到最像似的两簇合并
for (int i = 0; i < clusternum; i++) {
for (int j = i+1 ; j < clusternum; j++) {
Cluster clusterA = finalClusters.get(i);
Cluster clusterB = finalClusters.get(j);
int tempDis = this.clusterSim(clusterA, clusterB);
System.out.println(i+"/"+j+"tempDis: "+tempDis);
if (tempDis > mostsim) {
mostsim = tempDis;
mergeIndexA = i;
mergeIndexB = j;
}
}
}
// 合并簇
if (mostsim >= threshold){
finalClusters = mergeCluster(finalClusters, mergeIndexA,
mergeIndexB);
System.out.println(clusters.size());
}
}
this.clusters = finalClusters;
for (Cluster cluster : originalClusters) {
System.out.println(cluster.toString());
fileUtil.saveToFile(cluster.toString()+"\n", toFile, true);
}
System.out.println("==========================================");
fileUtil.saveToFile("================================="+"\n\n", toFile, true);
t2 = System.currentTimeMillis();
System.out.println("聚类完成,耗时:" + (t2 - t1) / 1000 + "s");
return finalClusters;
}