Exemplo n.º 1
0
        public FetchItemServiceResponse<Graph<UserDto>> DetectRolesInGraph(Graph<UserDto> graph)
        {
            FetchItemServiceResponse<Graph<UserDto>> response = new FetchItemServiceResponse<Graph<UserDto>>();

            try
            {
                if (graph.Communities.Count == 0)
                {
                    throw new Exception("You have to find communities first!");
                }

                GraphAlgorithm<UserDto> algorithms = new GraphAlgorithm<UserDto>(graph);
                HashSet<ShortestPathSet<UserDto>> shortestPaths = algorithms.GetAllShortestPathsInGraph(graph.Nodes);

                //setting closeness centrality
                algorithms.SetClosenessCentralityForEachNode(shortestPaths);

                //setting closeness centrality for community
                algorithms.SetClosenessCentralityForEachNodeInCommunity(shortestPaths);

                //community closeness centrality mean and standart deviation
                algorithms.SetMeanClosenessCentralityForEachCommunity();
                algorithms.SetStandartDeviationForClosenessCentralityForEachCommunity();

                //cPaths for nCBC measure
                HashSet<ShortestPathSet<UserDto>> cPaths = algorithms.CPaths(shortestPaths);

                //setting nCBC for each node
                algorithms.SetNCBCForEachNode(cPaths);

                //setting DSCount for each node
                algorithms.SetDSCountForEachNode(cPaths);

                GraphRoleDetection<UserDto> roleDetection = new GraphRoleDetection<UserDto>(graph, algorithms);
                roleDetection.ExtractOutsiders();
                roleDetection.ExtractLeaders();
                roleDetection.ExtractOutermosts();

                //sorting nodes by their mediacy score
                HashSet<Node<UserDto>> sortedNodes = algorithms.OrderNodesByMediacyScore();
                roleDetection.ExtractMediators(sortedNodes);

                response.Succeeded = true;
                response.Item = graph;
            }
            catch (Exception e)
            {
                response.Succeeded = false;
                throw new Exception(e.Message);
            }

            return response;
        }
Exemplo n.º 2
0
        public void RunApp_Test()
        {
            Graph <UserDto>              graph         = new Graph <UserDto>();
            GraphAlgorithm <UserDto>     algorithms    = new GraphAlgorithm <UserDto>(graph);
            GraphRoleDetection <UserDto> roleDetection = new GraphRoleDetection <UserDto>(graph, algorithms);


            HashSet <Edge <UserDto> > edges;

            using (IUnitOfWork uow = UnitOfWorkFactory.CreateUnitOfWork())
            {
                edges = uow.GraphRepo.ExtractEdgesFromConversation();
            }
            foreach (Edge <UserDto> edge in edges)
            {
                graph.CreateGraph(edge);
            }


            graph.GetEdgesCount();
            HashSet <ShortestPathSet <UserDto> > shortestPaths = algorithms.GetAllShortestPathsInGraph(graph.Nodes);

            //setting closeness centrality
            algorithms.SetClosenessCentralityForEachNode(shortestPaths);

            //setting closeness centrality for community
            algorithms.SetClosenessCentralityForEachNodeInCommunity(shortestPaths);

            //community closeness centrality mean and standart deviation
            algorithms.SetMeanClosenessCentralityForEachCommunity();
            algorithms.SetStandartDeviationForClosenessCentralityForEachCommunity();

            //cPaths for nCBC measure
            HashSet <ShortestPathSet <UserDto> > cPaths = algorithms.CPaths(shortestPaths);

            //setting nCBC for each node
            algorithms.SetNCBCForEachNode(cPaths);

            //setting DSCount for each node
            algorithms.SetDSCountForEachNode(cPaths);

            roleDetection.ExtractOutsiders();
            roleDetection.ExtractLeaders();
            roleDetection.ExtractOutermosts();

            //sorting nodes by their mediacy score
            HashSet <Node <UserDto> > sortedNodes = algorithms.OrderNodesByMediacyScore();

            roleDetection.ExtractMediators(sortedNodes);
        }