Problem with CCM metric addition v3
User123363 opened this issue · comments
User123363 commented
To fix the CCM metric it was decided to integrate the FindConnectedComponents Java class into the jpeek project and then call it before constructing the CCM.xsl file [1] and add the result of the call to the ncc variable in the file. Thus, the problem of xslt algorithm implementation, related to the lack of possibility to redefine variable values and as a consequence the marking of visited nodes, disappears.
[1] The FindConnectedComponents class can be called in the App class of org.jpeek:
Class FindConnectedComponents:
package com.company;
import java.util.ArrayList;
class FindConnectedComponents
{
int V;
ArrayList<ArrayList<Integer>> graph;
FindConnectedComponents(int V)
{
this.V = V;
graph = new ArrayList<>();
for (int i = 0; i < V; i++) {
graph.add(i, new ArrayList<>());
}
}
void DFS(int v, boolean[] visited)
{
visited[v] = true;
System.out.print(v + " ");
for (int x : graph.get(v)) {
if (!visited[x])
DFS(x, visited);
}
}
int connectedComponents()
{
int countConnectedComponents = 0;
boolean[] visited = new boolean[V];
for (int v = 0; v < V; ++v) {
if (!visited[v]) {
DFS(v, visited);
System.out.println();
countConnectedComponents++;
}
}
return countConnectedComponents;
}
void addEdge(int src, int dest)
{
graph.get(src).add(dest);
graph.get(dest).add(src);
}
public static void main(String[] args)
{
FindConnectedComponents f = new FindConnectedComponents(7);
f.addEdge(1, 0);
f.addEdge(2, 3);
f.addEdge(3, 4);
f.addEdge(4, 5);
f.addEdge(5, 6);
System.out.println("Following are connected components");
int countConnectedComponents = f.connectedComponents();
System.out.print("Count Connected Components: ");
System.out.print(countConnectedComponents);
}
}