package edu.uci.ics.jung.algorithms.cluster;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections15.Transformer;
import edu.uci.ics.jung.algorithms.scoring.BetweennessCentrality;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.Pair;
public class EdgeBetweennessClusterer<V, E> implements
Transformer<Graph<V, E>, Set<Set<V>>> {
private int mNumEdgesToRemove;
private Map<E, Pair<V>> edges_removed;
public EdgeBetweennessClusterer(int numEdgesToRemove) {
mNumEdgesToRemove = numEdgesToRemove;
edges_removed = new LinkedHashMap<E, Pair<V>>();
}
public Set<Set<V>> transform(Graph<V, E> graph) {
if (mNumEdgesToRemove < 0
|| mNumEdgesToRemove > graph.getEdgeCount()) {
throw new IllegalArgumentException(
"Invalid number of edges passed in.");
}
edges_removed.clear();
for (int k = 0; k < mNumEdgesToRemove; k++) {
BetweennessCentrality<V, E> bc = new BetweennessCentrality<V, E>(
graph);
E to_remove = null;
double score = 0;
for (E e : graph.getEdges())
if (bc.getEdgeScore(e) > score) {
to_remove = e;
score = bc.getEdgeScore(e);
}
edges_removed.put(to_remove, graph.getEndpoints(to_remove));
graph.removeEdge(to_remove);
}
WeakComponentClusterer<V, E> wcSearch = new WeakComponentClusterer<V, E>();
Set<Set<V>> clusterSet = wcSearch.transform(graph);
for (Map.Entry<E, Pair<V>> entry : edges_removed.entrySet()) {
Pair<V> endpoints = entry.getValue();
graph.addEdge(entry.getKey(), endpoints.getFirst(),
endpoints.getSecond());
}
Object array[];
array=new Object[500];
array=clusterSet.toArray();
System.out.println(array.length);
for(int i=0;i<array.length;i++)
{
System.out.println("hello");
System.out.println("hkj"+array[i]);
}
return clusterSet;
}
/**
* Retrieves the list of all edges that were removed
* (assuming extract(...) was previously called).
* The edges returned
* are stored in order in which they were removed.
*
* @return the edges in the original graph
*/
public List<E> getEdgesRemoved() {
return new ArrayList<E>(edges_removed.keySet());
}
public static void main(String args[])
{
new EdgeBetweennessClusterer(10);
}
}
This algorithm is copied from here
I am making network based community so I used this algorithm
when I am running this code, the main method, and is not getting called. I am not able to understand what is happening. Correct me if I am wrong. What mistake am I making?
If you remove all the code which doesn’t do anything your program is the same as
If you want your program to call more code, you need to tell it to do so. Perhaps using a debugger will help you see what your program is doing any why.