Search in sources :

Example 6 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class AutomaticCluster method init.

/**
 * Initializes the clustering algorithm.
 */
private void init() {
    mapBetweenArcs = new HashMap<Integer, Map<Integer, Integer>>();
    indices = new HashSet<Integer>();
    mapIndexCluster = new HashMap<Integer, Set<NodeDescriptor>>();
    mapClusterIndex = new HashMap<NodeDescriptor, Integer>();
    size = new HashMap<Integer, Integer>();
    index = 0;
    clusternum = 0;
    // remove unneeded clusters, create indices for the clusters
    final Set<Set<NodeDescriptor>> clustersToRemove = new HashSet<Set<NodeDescriptor>>();
    for (final Set<NodeDescriptor> cluster : clustersToCheck) {
        if (cluster == null || cluster.isEmpty()) {
            clustersToRemove.add(cluster);
        } else {
            indices.add(index);
            mapIndexCluster.put(index, cluster);
            size.put(index, cluster.size());
            for (final NodeDescriptor v : cluster) {
                mapClusterIndex.put(v, index);
            }
            index++;
            clusternum++;
        }
    }
    for (final Set<NodeDescriptor> cluster : clustersToRemove) {
        clustersToCheck.remove(cluster);
    }
    // create matrix of components
    for (final int i : indices) {
        final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (final int j : indices) {
            map.put(j, 0);
        }
        mapBetweenArcs.put(i, map);
    }
    for (final EdgeDescriptor e : moduleGraph.getEdges()) {
        final NodeDescriptor v = moduleGraph.getSource(e);
        final NodeDescriptor w = moduleGraph.getDest(e);
        final int i = mapClusterIndex.get(v);
        final int j = mapClusterIndex.get(w);
        changeCell(i, j, 1);
    }
    mq = MQ();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 7 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class AutomaticCluster method improve.

/**
 * Tries to improve the current clustering by iterating over all nodes.
 *
 * @return false if there was a change
 */
private boolean improve() {
    final Queue<NodeDescriptor> queue = calculatePriorities();
    boolean optimal = true;
    while (!queue.isEmpty()) {
        final NodeDescriptor v = queue.poll();
        final boolean check = checkNode(v);
        optimal = optimal && check;
    }
    return optimal;
}
Also used : NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor)

Example 8 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor 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 9 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class FolderNameCluster method checkProject.

@Override
protected void checkProject(final IProgressMonitor progress) throws CoreException {
    progress.subTask("Checking " + project.getName());
    final IResource[] contents = project.members();
    final Set<NodeDescriptor> cluster = new HashSet<NodeDescriptor>();
    for (final IResource content : contents) {
        check(content, cluster, progress);
    }
    if (!cluster.isEmpty()) {
        clusters.add(cluster);
        mapNameCluster.put("/", cluster);
    }
}
Also used : NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 10 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class FolderNameCluster method checkFolder.

/**
 * Checks the folder for modules.
 *
 * @param folder
 *            The folder to check
 * @param monitor
 *            A progress monitor
 * @throws CoreException
 */
protected void checkFolder(final IFolder folder, final IProgressMonitor monitor) throws CoreException {
    monitor.subTask("Checking " + folder.getName());
    final IResource[] contents = folder.members();
    final Set<NodeDescriptor> cluster = new HashSet<NodeDescriptor>();
    for (final IResource nextContent : contents) {
        check(nextContent, cluster, monitor);
    }
    addNewCluster(cluster, folder);
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    monitor.worked(1);
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Aggregations

NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)30 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)10 HashSet (java.util.HashSet)7 HashMap (java.util.HashMap)5 Set (java.util.Set)5 Dimension (java.awt.Dimension)4 CustomVisualizationViewer (org.eclipse.titanium.graph.gui.common.CustomVisualizationViewer)3 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Point2D (java.awt.geom.Point2D)2 Matcher (java.util.regex.Matcher)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 IResource (org.eclipse.core.resources.IResource)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 ClusterNode (org.eclipse.titanium.graph.clustering.visualization.ClusterNode)2 LayoutEntry (org.eclipse.titanium.graph.gui.utils.LayoutEntry)2 MetricsLayoutEntry (org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry)2 Function (com.google.common.base.Function)1