Skip to content

Problem with CCM metric addition v2 #523

@User123363

Description

@User123363

To fix the CCM metric, the FindConnectedComponents class was implemented to find the connected components in a graph:

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);

    }
}

This class needs to be implemented in jpeek , it needs to input the graph found in the file "org/jpeek/metrics/CCM.xsl". As a result of the FindConnectedComponents class we get the number of connectivity components of the graph, this data must be placed in the ncc variable in line 65 in the file "org/jpeek/metrics/CCM.xsl".

After that the problem with CCM metrics will be solved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions