use of org.eclipse.titanium.graph.clustering.visualization.ClusterEdge in project titan.EclipsePlug-ins by eclipse.
the class ClusteringTools method generateClusterGraph.
/**
* It creates the cluster graph from a module graph and the clusters with
* their names.
*
* @param moduleGraph
* The module graph
* @param mapNameCluster
* The clusters mapped to their names
* @return The cluster graph
*/
public static DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> generateClusterGraph(final DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> moduleGraph, final Map<String, Set<NodeDescriptor>> mapNameCluster) {
final Map<Set<NodeDescriptor>, ClusterNode> mapClusterNode = new HashMap<Set<NodeDescriptor>, ClusterNode>();
final DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> clusterGraph = new DirectedSparseGraph<NodeDescriptor, EdgeDescriptor>();
for (final Entry<String, Set<NodeDescriptor>> entry : mapNameCluster.entrySet()) {
final String name = entry.getKey();
final Set<NodeDescriptor> cluster = entry.getValue();
for (final NodeDescriptor v : cluster) {
v.setCluster(cluster);
}
final ClusterNode clusternode = new ClusterNode(name, cluster);
clusterGraph.addVertex(clusternode);
mapClusterNode.put(cluster, clusternode);
}
for (final EdgeDescriptor e : moduleGraph.getEdges()) {
final NodeDescriptor v = moduleGraph.getSource(e);
final NodeDescriptor w = moduleGraph.getDest(e);
final Set<NodeDescriptor> clusterv = v.getCluster();
final Set<NodeDescriptor> clusterw = w.getCluster();
if (clusterv == null || clusterw == null) {
continue;
}
if (clusterv != clusterw) {
final ClusterNode clusterNodev = mapClusterNode.get(clusterv);
final ClusterNode clusterNodew = mapClusterNode.get(clusterw);
if (clusterNodev == null || clusterNodew == null) {
continue;
}
EdgeDescriptor ce = clusterGraph.findEdge(clusterNodev, clusterNodew);
if (ce != null) {
ce.setWeight((Integer) ce.getWeight() + 1);
} else {
ce = new ClusterEdge(clusterNodev.getName() + "-" + clusterNodew.getName(), 1);
clusterGraph.addEdge(ce, clusterNodev, clusterNodew);
}
}
}
return clusterGraph;
}
use of org.eclipse.titanium.graph.clustering.visualization.ClusterEdge in project titan.EclipsePlug-ins by eclipse.
the class FullModuleNameCluster method addEdge.
/**
* Grows the tree.
*
* @param prev
* Name of the parent node
* @param next
* Name of the child node
*/
private void addEdge(final String prev, final String next) {
final ClusterNode parent = mapNameNode.get(prev);
final ClusterNode child = new ClusterNode(next, mapNameCluster.get(next));
clusterGraph.addVertex(child);
mapNameNode.put(next, child);
final ClusterEdge ce = new ClusterEdge(prev + "-" + next, 1);
clusterGraph.addEdge(ce, parent, child);
}
Aggregations