Skip to content
Snippets Groups Projects
Commit 27675cf8 authored by LukasEttel's avatar LukasEttel
Browse files

Fixed the calculation of the clustering-costs and display it

parent 6d071ed6
No related branches found
No related tags found
No related merge requests found
......@@ -60,11 +60,14 @@ public class YoshikoSolution {
private Logger logger = YoshikoLogger.getInstance().getLogger();
private final double clusteringCost;
public YoshikoSolution(YoshikoResult yoshikoResult, long id) {
public YoshikoSolution(YoshikoResult yoshikoResult, long id, double clusteringCost) {
clusters = new HashMap<Long,YoshikoCluster>();
this.result = yoshikoResult;
this.id = id;
this.clusteringCost = clusteringCost;
}
public void delete() {
......@@ -121,5 +124,9 @@ public class YoshikoSolution {
clusters.put(cluster.getID(), cluster);
}
public double getClusteringCost(){
return clusteringCost;
}
}
......@@ -62,6 +62,7 @@ import de.hhu.ba.yoshikoWrapper.tasks.CreateMetaGraphTask;
public class SolutionTab extends JPanel {
//SWING COMPONENTS
private final JLabel clusteringCosts;
private final JLabel clusterCount;
private final JCheckBox hideSingles;
private final JScrollPane scrollPane;
......@@ -127,6 +128,8 @@ public class SolutionTab extends JPanel {
scrollPane = new JScrollPane(clusterViewList);
clusteringCosts = new JLabel("Clustering-Cost: "+s.getClusteringCost());
clusterCount = new JLabel(LocalizationManager.get("clusterFound")+" "+s.getClusters().size());
createClusterView = new JButton(LocalizationManager.get("createClusterView"));
......@@ -176,7 +179,7 @@ public class SolutionTab extends JPanel {
//Add configured Swing Components to self
SwingUtil.addAll(this,clusterCount,scrollPane,createClusterView,createMetaGraph);
SwingUtil.addAll(this, clusteringCosts, clusterCount,scrollPane,createClusterView,createMetaGraph);
//Layout
......@@ -206,6 +209,8 @@ public class SolutionTab extends JPanel {
.addComponent(createClusterView,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE)
.addComponent(createMetaGraph,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE)
.addGap(8)
.addComponent(clusteringCosts,DEFAULT_SIZE,DEFAULT_SIZE,Short.MAX_VALUE)
.addGap(8)
.addComponent(clusterCount,DEFAULT_SIZE,DEFAULT_SIZE,Short.MAX_VALUE)
.addComponent(hideSingles,DEFAULT_SIZE,DEFAULT_SIZE,Short.MAX_VALUE)
.addGap(8)
......@@ -216,6 +221,8 @@ public class SolutionTab extends JPanel {
.addComponent(createClusterView,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
.addComponent(createMetaGraph,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
.addGap(8)
.addComponent(clusteringCosts,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
.addGap(8)
.addComponent(clusterCount,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
.addComponent(hideSingles,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
.addGap(4)
......
......@@ -25,7 +25,6 @@ public class ClusteringAlgorithm {
numberOfNodes = edgeArray.length;
clusters = new ArrayList<>();
this.taskMonitor = taskMonitor;
clusteringCost = 0;
}
public List<List<Integer>> runClusteringAlgorithm() throws NetworkParsingException{
......@@ -47,11 +46,10 @@ public class ClusteringAlgorithm {
workHeap();
}
}
addSingleNodesToClusters();
System.out.println("Clustering costs:" +clusteringCost);
this.calculateClusteringCost();
return clusters;
}
......@@ -168,10 +166,6 @@ public class ClusteringAlgorithm {
}
private void makeEdgePermanent(YoshikoEdge e){
if(e.weight < 0){
clusteringCost -= e.weight;
}
substactInfluenceOfVerticesOnIcfIcp(e);
mergeVertexes(e);
......@@ -323,9 +317,6 @@ public class ClusteringAlgorithm {
private void makeEdgeForbidden(YoshikoEdge e) {
if(e.weight > 0){
clusteringCost +=e.weight;
}
editInfluenzeOfForbiddenEdge(e);
e.weight=Double.NEGATIVE_INFINITY;
......@@ -435,4 +426,37 @@ public class ClusteringAlgorithm {
newCluster.add(i);
clusters.add(newCluster);
}
private void calculateClusteringCost(){
clusteringCost = 0;
for (List<Integer> cluster : clusters){
for (int i : cluster){
for (int j : cluster){
if (i > j){
if (edgeArray[i][j].startingWeight < 0){
clusteringCost -= edgeArray[i][j].startingWeight;
System.out.println("Insert edge:("+i+","+ j+") with cost "+edgeArray[i][j].startingWeight);
}
edgeArray[i][j].startingWeight = 0;
}
}
}
}
for (int i = 1; i < edgeArray.length; i++){
for (int j = 0; j < i; j++){
if (edgeArray[i][j].startingWeight > 0){
clusteringCost += edgeArray[i][j].startingWeight;
System.out.println("Delete edge:("+i+","+ j+") with cost "+(-edgeArray[i][j].startingWeight));
}
}
}
}
public double getClusteringCost() {
return clusteringCost;
}
}
\ No newline at end of file
......@@ -53,11 +53,12 @@ public final class GraphTranslator {
this.edgeArray = new YoshikoEdge[size][size];
Map<CyNode, Integer> reverseNodeMap = new HashMap();
int i = 0;
int i = nodeList.size()-1;
for (CyNode n : nodeList){
System.out.println(i+":"+network.getRow(n).get(CyNetwork.NAME, String.class));
nodeMap.put(i, n);
reverseNodeMap.put(n,i);
i++;
i--;
}
for (CyEdge e : edgeList){
......
......@@ -39,7 +39,7 @@ public class YoshikoAlgoritmController {
taskMonitor.setStatusMessage("Clustering the Graph");
clusters = clusteringAlgorithm.runClusteringAlgorithm();
YoshikoSolution solution = new YoshikoSolution(result, 0);
YoshikoSolution solution = new YoshikoSolution(result, 0, clusteringAlgorithm.getClusteringCost());
result.addSolution(solution);
taskMonitor.setStatusMessage("Processing Clusters");
......
......@@ -7,6 +7,7 @@ public class YoshikoEdge {
int source;
int target;
double startingWeight;
double weight;
double icf;
double icp;
......@@ -23,6 +24,7 @@ public class YoshikoEdge {
public YoshikoEdge(long suid, double weight, int u, int v){
this.suid = suid;
this.weight = weight;
this.startingWeight = weight;
this.edgeId = this.makeEdgeId(u, v);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment