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();
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations