Search in sources :

Example 1 with ClusterEdge

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;
}
Also used : ClusterNode(org.eclipse.titanium.graph.clustering.visualization.ClusterNode) Set(java.util.Set) HashMap(java.util.HashMap) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) ClusterEdge(org.eclipse.titanium.graph.clustering.visualization.ClusterEdge) DirectedSparseGraph(edu.uci.ics.jung.graph.DirectedSparseGraph)

Example 2 with ClusterEdge

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);
}
Also used : ClusterNode(org.eclipse.titanium.graph.clustering.visualization.ClusterNode) ClusterEdge(org.eclipse.titanium.graph.clustering.visualization.ClusterEdge)

Aggregations

ClusterEdge (org.eclipse.titanium.graph.clustering.visualization.ClusterEdge)2 ClusterNode (org.eclipse.titanium.graph.clustering.visualization.ClusterNode)2 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)1 NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)1