├── tools
├── communityAnalyzer
│ ├── CMakeLists.txt
│ └── source
│ │ └── main.cpp
├── f1score
│ ├── CMakeLists.txt
│ └── source
│ │ └── main.cpp
├── cc
│ ├── CMakeLists.txt
│ └── source
│ │ └── main.cpp
├── wcc
│ ├── CMakeLists.txt
│ └── source
│ │ └── main.cpp
└── selector
│ ├── CMakeLists.txt
│ └── source
│ └── main.cpp
├── source
├── common
│ └── time.cpp
├── main.cpp
├── wcc
│ └── wcc.cpp
├── graph
│ └── graph.cpp
└── communities
│ └── communities.cpp
├── include
├── common
│ ├── time.h
│ └── types.h
├── wcc
│ └── wcc.h
├── communities
│ └── communities.h
└── graph
│ └── graph.h
├── CMakeLists.txt
├── README.md
└── LICENSE
/tools/communityAnalyzer/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp")
3 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")
4 |
5 | INCLUDE_DIRECTORIES(../../include)
6 | AUX_SOURCE_DIRECTORY(./source SOURCE_FILES)
7 | AUX_SOURCE_DIRECTORY(../../source/communities SOURCE_FILES)
8 | AUX_SOURCE_DIRECTORY(../../source/wcc SOURCE_FILES)
9 | AUX_SOURCE_DIRECTORY(../../source/graph SOURCE_FILES)
10 | AUX_SOURCE_DIRECTORY(../../source/common SOURCE_FILES)
11 | ADD_EXECUTABLE(communityAnalyzer ${SOURCE_FILES})
12 |
--------------------------------------------------------------------------------
/tools/f1score/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #SCD is free software: you can redistribute it and/or modify
2 | #it under the terms of the GNU General Public License as published by
3 | #the Free Software Foundation, either version 3 of the License, or
4 | #(at your option) any later version.
5 | #
6 | #SCD is distributed in the hope that it will be useful,
7 | #but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | #GNU General Public License for more details.
10 | #
11 | #You should have received a copy of the GNU General Public License
12 | #along with this program. If not, see .
13 |
14 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -std=c++11 -g3 -fno-rtti")
15 | SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -std=c++11")
16 |
17 | AUX_SOURCE_DIRECTORY(./source SOURCE_FILES)
18 | ADD_EXECUTABLE(f1score ${SOURCE_FILES})
19 |
--------------------------------------------------------------------------------
/tools/cc/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #SCD is free software: you can redistribute it and/or modify
2 | #it under the terms of the GNU General Public License as published by
3 | #the Free Software Foundation, either version 3 of the License, or
4 | #(at your option) any later version.
5 | #
6 | #SCD is distributed in the hope that it will be useful,
7 | #but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | #GNU General Public License for more details.
10 | #
11 | #You should have received a copy of the GNU General Public License
12 | #along with this program. If not, see .
13 |
14 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp")
15 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")
16 |
17 | INCLUDE_DIRECTORIES(../../include)
18 | AUX_SOURCE_DIRECTORY(./source WCC_SOURCE_FILES)
19 | AUX_SOURCE_DIRECTORY(../../source/communities WCC_SOURCE_FILES)
20 | AUX_SOURCE_DIRECTORY(../../source/wcc WCC_SOURCE_FILES)
21 | AUX_SOURCE_DIRECTORY(../../source/graph WCC_SOURCE_FILES)
22 | AUX_SOURCE_DIRECTORY(../../source/common WCC_SOURCE_FILES)
23 | ADD_EXECUTABLE(cc ${WCC_SOURCE_FILES})
24 |
--------------------------------------------------------------------------------
/tools/wcc/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #SCD is free software: you can redistribute it and/or modify
2 | #it under the terms of the GNU General Public License as published by
3 | #the Free Software Foundation, either version 3 of the License, or
4 | #(at your option) any later version.
5 | #
6 | #SCD is distributed in the hope that it will be useful,
7 | #but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | #GNU General Public License for more details.
10 | #
11 | #You should have received a copy of the GNU General Public License
12 | #along with this program. If not, see .
13 |
14 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp")
15 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")
16 |
17 | INCLUDE_DIRECTORIES(../../include)
18 | AUX_SOURCE_DIRECTORY(./source WCC_SOURCE_FILES)
19 | AUX_SOURCE_DIRECTORY(../../source/communities WCC_SOURCE_FILES)
20 | AUX_SOURCE_DIRECTORY(../../source/wcc WCC_SOURCE_FILES)
21 | AUX_SOURCE_DIRECTORY(../../source/graph WCC_SOURCE_FILES)
22 | AUX_SOURCE_DIRECTORY(../../source/common WCC_SOURCE_FILES)
23 | ADD_EXECUTABLE(wcc ${WCC_SOURCE_FILES})
24 |
--------------------------------------------------------------------------------
/tools/selector/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #SCD is free software: you can redistribute it and/or modify
2 | #it under the terms of the GNU General Public License as published by
3 | #the Free Software Foundation, either version 3 of the License, or
4 | #(at your option) any later version.
5 | #
6 | #SCD is distributed in the hope that it will be useful,
7 | #but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | #GNU General Public License for more details.
10 | #
11 | #You should have received a copy of the GNU General Public License
12 | #along with this program. If not, see .
13 |
14 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp")
15 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")
16 |
17 | INCLUDE_DIRECTORIES(../../include)
18 | AUX_SOURCE_DIRECTORY(./source WCC_SOURCE_FILES)
19 | AUX_SOURCE_DIRECTORY(../../source/communities WCC_SOURCE_FILES)
20 | AUX_SOURCE_DIRECTORY(../../source/wcc WCC_SOURCE_FILES)
21 | AUX_SOURCE_DIRECTORY(../../source/graph WCC_SOURCE_FILES)
22 | AUX_SOURCE_DIRECTORY(../../source/common WCC_SOURCE_FILES)
23 | ADD_EXECUTABLE(selector ${WCC_SOURCE_FILES})
24 |
--------------------------------------------------------------------------------
/source/common/time.cpp:
--------------------------------------------------------------------------------
1 | /*SCD is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | SCD is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see .
13 | */
14 |
15 | #include
16 |
17 | namespace scd {
18 |
19 | uint64_t StartClock() {
20 | timeval time;
21 | gettimeofday(&time, NULL);
22 | uint64_t initTime = (time.tv_sec * 1000) + (time.tv_usec / 1000);
23 | return initTime;
24 | }
25 |
26 | uint64_t StopClock(uint64_t initTime) {
27 | timeval time;
28 | gettimeofday(&time, NULL);
29 | uint64_t endTime = (time.tv_sec * 1000) + (time.tv_usec / 1000);
30 | return endTime - initTime;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/include/common/time.h:
--------------------------------------------------------------------------------
1 | /*SCD is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | SCD is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see .
13 | */
14 |
15 | #ifndef SCD_TIME_H
16 | #define SCD_TIME_H
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | namespace scd {
23 |
24 | /** @brief Gets the current time in miliseconds.
25 | * @return The time in miliseconds.**/
26 | uint64_t StartClock();
27 |
28 | /** @brief Gets the time elapsed from a given moment.
29 | * @param[in] The time specifying the moment from whith to compute the time in miliseconds
30 | * @return The time elapsed since the specifyied time in miliseconds.**/
31 | uint64_t StopClock(uint64_t initTime);
32 |
33 | }
34 | #endif
35 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #SCD is free software: you can redistribute it and/or modify
2 | #it under the terms of the GNU General Public License as published by
3 | #the Free Software Foundation, either version 3 of the License, or
4 | #(at your option) any later version.
5 | #
6 | #SCD is distributed in the hope that it will be useful,
7 | #but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | #GNU General Public License for more details.
10 | #
11 | #You should have received a copy of the GNU General Public License
12 | #along with this program. If not, see .
13 |
14 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)
15 | PROJECT(SCD CXX)
16 | set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
17 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp -DPROFILE ")
18 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")
19 | #SET(CMAKE_VERBOSE_MAKEFILE ON)
20 |
21 |
22 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
23 | message(STATUS "Setting build type to 'Release' as none was specified.")
24 | set(CMAKE_BUILD_TYPE Release)
25 | endif()
26 |
27 | ADD_SUBDIRECTORY(./tools/wcc)
28 | ADD_SUBDIRECTORY(./tools/f1score)
29 | ADD_SUBDIRECTORY(./tools/selector)
30 | ADD_SUBDIRECTORY(./tools/cc)
31 | ADD_SUBDIRECTORY(./tools/communityAnalyzer)
32 |
33 | INCLUDE_DIRECTORIES(./include)
34 | FILE( GLOB_RECURSE SOURCE_FILES "source/*" )
35 | ADD_EXECUTABLE(scd ${SOURCE_FILES})
36 |
--------------------------------------------------------------------------------
/include/common/types.h:
--------------------------------------------------------------------------------
1 |
2 | /*SCD is free software: you can redistribute it and/or modify
3 | it under the terms of the GNU General Public License as published by
4 | the Free Software Foundation, either version 3 of the License, or
5 | (at your option) any later version.
6 |
7 | SCD is distributed in the hope that it will be useful,
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | GNU General Public License for more details.
11 |
12 | You should have received a copy of the GNU General Public License
13 | along with this program. If not, see .
14 | */
15 |
16 | #ifndef TYPES_H
17 | #define TYPES_H
18 |
19 | namespace scd {
20 | #ifndef SCD_THREAD_BLOCK_SIZE
21 | #define SCD_THREAD_BLOCK_SIZE 32
22 | #endif
23 |
24 | #ifndef SCD_SCHEDULING
25 | #define SCD_SCHEDULING dynamic
26 | #endif
27 |
28 | typedef bool bool_t;
29 | typedef unsigned char uchar_t;
30 | typedef char char_t;
31 | typedef short int uint16_t;
32 | typedef unsigned int uint32_t;
33 | typedef int int32_t;
34 | typedef long unsigned uint64_t;
35 | typedef float float32_t;
36 | typedef double double64_t;
37 |
38 | /** @brief This struct represents a node in the graph.*/
39 | struct Node {
40 | uint32_t m_Degree; /**< @brief The degree of the node.*/
41 | uint32_t m_AdjacencyIndex; /**< @brief The index into the adjacency vector where the adjacencies lay*/
42 | };
43 |
44 |
45 |
46 | };
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/include/wcc/wcc.h:
--------------------------------------------------------------------------------
1 | /*SCD is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | SCD is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see .
13 | */
14 |
15 |
16 | #ifndef WCC_H
17 | #define WCC_H
18 |
19 |
20 | #include
21 | #include
22 | #include
23 | namespace scd
24 | {
25 |
26 | /** @brief Computes the size of the intersection between two arrays.
27 | * @param[in] list1 The first array.
28 | * @param[in] size1 The size of the first array.
29 | * @param[in] list2 The second array.
30 | * @param[in] size2 The size of the second array.
31 | * @return The size of the intersection.*/
32 | uint32_t Intersect( /*const*/ uint32_t* list1, const uint32_t size1, /*const*/ uint32_t* list2, const uint32_t size2 );
33 |
34 | /** @brief Computes the WCC of a node against a community.
35 | * @param[in] graph The graph.
36 | * @param[in] alfa The alfa parameter controling the cohesiveness of the communities.
37 | * @param[in] communities The assignment of nodes to communities.
38 | * @param[in] labelsIndices The array of indexes of labels into the community inverse index.
39 | * @param[in] communitiesInvIndex The community inverse index.
40 | * @param[in] wccs An array where the WCCs of the nodes will be stored.
41 | * @return The WCC of the node against the community.*/
42 | double64_t ComputeWCC(const CGraph * graph, const double64_t alfa, const uint32_t * communities, const uint32_t numCommunities, const uint32_t* labelsIndices, const uint32_t * communitiesInvIndex, double64_t* wccs);
43 |
44 | /** @brief Computes the WCC of a node against a community.
45 | * @param[in] graph The graph.
46 | * @param[in] alfa The alfa parameter controling the cohesiveness of the communities.
47 | * @param[in] node The node.
48 | * @param[in] communityLabel The label of the community to test against.
49 | * @param[in] communities The assignment of nodes to communities.
50 | * @param[in] numCommunities The number of communities.
51 | * @param[in] labelsIndices The array of indexes of labels into the community inverse index.
52 | * @param[in] communitiesInvIndex The community inverse index.
53 | * @return The WCC of the node against the community.*/
54 | double64_t ComputeWCC(const CGraph * graph, const double64_t alfa, uint32_t node, uint32_t communityLabel, const uint32_t * communities, uint32_t communitySize );
55 |
56 | double64_t ComputeWCC(const CGraph * graph, const double64_t alfa, std::set& community );
57 | }
58 |
59 | #endif
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SCD
2 | ===
3 |
4 | This program is an implementation of the community detection algorithm described in the papers titled
5 |
6 | [High quality, scalable and parallel community detection for large real graphs.](http://www.dama.upc.edu/en/publications/fp546prat.pdf) Arnau Prat-Pérez, David Dominguez-Sal, Josep-Lluis Larriba-Pey - WWW 2014.
7 |
8 | [Put Three and Three Together: Triangle-Driven Community Detection.](http://dl.acm.org/citation.cfm?id=2775108) Arnau Prat-Prez, David Dominguez-Sal, Josep-M. Brunat, Josep-Lluis Larriba Pey - TKDD.
9 |
10 |
11 | Compile
12 | ===
13 |
14 | SCD uses CMake 2.8.2 or greater to compile. In order to build SCD, move to SCD directory and type:
15 |
16 | ```
17 | cd build
18 | cmake -DCMAKE_BUILD_TYPE=Release ..
19 | make
20 | ```
21 |
22 | This will create a build directory into the SCD folder tree, and configure and build SCD in Release mode.
23 | In order to compile SCD in Debug mode, please replace the last two lines of the snippet above by:
24 |
25 | ```
26 | cmake -DCMAKE_BUILD_TYPE=Debug ..
27 | make
28 | ```
29 |
30 | Execution
31 | ===
32 |
33 | To execute SCD type, move to the build folder and type:
34 |
35 | ```
36 | ./scd -f [network file name]
37 | ```
38 |
39 | where the [network file name] contains the network with an edge per line, and each edge is represented as a pair of numeric identifiers.
40 | IMPORTANT: each edge is interpreted as an undirected edge and can only appear once.
41 | For example, if "1 2" appears in the file, then "2 1" cannot appear too. The next snipped shows a valid network file:
42 |
43 | ```
44 | 1 2
45 | 4 5
46 | 3 4
47 | 1 3
48 | ```
49 |
50 | As an example, type:
51 |
52 | ```
53 | ./scd -f ./network.dat
54 | ```
55 |
56 | This will run the program, and will output the communities found at network.dat to "./communities.dat", which contains
57 | a community per line, represented as a list of identifiers. network.dat contains a network composed by two cliques of size 5 linked by a single edge. Therefore, communities.dat outputs:
58 |
59 | ```
60 | 1 2 3 4 5
61 | 6 7 8 9 10
62 | ```
63 |
64 | Now, we summarize the options of the program:
65 |
66 | * -f [netork file name] : Specifies the network file.
67 | * -o [output file name] : Specifies the output file name (DEFAULT="communities.dat").
68 | * -n [number of threads]: Specifies the number of threads to run the algorithm (DEFAULT=maximum available cores).
69 | * -l [lookahead]: Specifies the number of lookahead iterations to look before terminating the optimization process (DEFAULT=5).
70 | * -p [partition file name]: Specifies the initial partition to refine from (Optional).
71 |
72 |
73 | Tools
74 | ===
75 |
76 | Into the build folder, a folder named tools is automatically created and contains useful tools. The list of tools currently available are the following:
77 | * wcc: Computes, given a graph and a partition, the WCC of the partition.
78 | * Usage: wcc -f [graph file name] -p [partition file name]
79 | * f1score: Computes the f1score between two partitions.
80 | * Usage: f1score [partition file name 1] [partition file name 2]
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/tools/cc/source/main.cpp:
--------------------------------------------------------------------------------
1 | /*SCD is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | SCD is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see .
13 | */
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #define CHECK_ARGUMENT_STRING(index, option,variable,setVariable) \
26 | if( strcmp(argv[index],option) == 0 ){ \
27 | setVariable = true; \
28 | if( (index+1) < argc ) { \
29 | variable = argv[index+1]; \
30 | } else { \
31 | printf( "Invalid options.\n" ); \
32 | return 1;\
33 | }\
34 | }
35 |
36 | #define CHECK_ARGUMENT_FLOAT(index, option,variable,setVariable) \
37 | if( strcmp(argv[index],option) == 0 ){ \
38 | setVariable = true; \
39 | if( (index+1) < argc ) { \
40 | variable = atof(argv[index+1]); \
41 | } else { \
42 | printf( "Invalid options.\n" ); \
43 | return 1;\
44 | }\
45 | }
46 |
47 | #define CHECK_ARGUMENT_INT(index, option,variable,setVariable) \
48 | if( strcmp(argv[index],option) == 0 ){ \
49 | setVariable = true; \
50 | if( (index+1) < argc ) { \
51 | variable = atoi(argv[index+1]); \
52 | } else { \
53 | printf( "Invalid options.\n" ); \
54 | return 1;\
55 | }\
56 | }
57 |
58 | #define CHECK_FLAG(index, option,setVariable) \
59 | if( strcmp(argv[index],option) == 0 ){ \
60 | setVariable = true; \
61 | }
62 |
63 | using namespace scd;
64 |
65 | static void PrintUsage() {
66 | printf("Usage: wcc \n");
67 | printf("Availaible flags:\n");
68 | printf("\t-f [network file name] : Specifies the network file.\n");
69 | printf("\t-p [partition file name] : Specifies the partition file name.\n");
70 | }
71 |
72 |
73 | int main(int argc, char ** argv) {
74 |
75 | bool graphFileNameSet = false;
76 | bool partitionFileNameSet = false;
77 | bool numThreadsSet = false;
78 | bool alphaSet = false;
79 | char_t * graphFileName = NULL;
80 | char_t * partitionFileName = NULL;
81 | uint32_t numThreads = omp_get_num_procs();
82 | double alpha = 1.0;
83 |
84 | for (uint32_t i = 1; i < argc; i++) {
85 | CHECK_ARGUMENT_STRING(i, "-f", graphFileName, graphFileNameSet)
86 | }
87 |
88 | if (!graphFileNameSet) {
89 | printf("Graph filename not set\n");
90 | PrintUsage();
91 | return 1;
92 | }
93 |
94 | CGraph graph;
95 |
96 | //==================== LOAD THE GRAPH ==================================
97 | printf("Graph: %s\n", graphFileName);
98 | graph.Load(graphFileName, numThreads);
99 |
100 | double64_t cc = 0.0;
101 | for( int i = 0; i < graph.GetNumNodes(); ++i ) {
102 | uint32_t degree = graph.GetDegree(i);
103 | uint32_t numTriangles = 0;
104 | const uint32_t* adjacencies = graph.GetNeighbors(i);
105 | for( int j = 0; j < degree; ++j) {
106 | uint32_t neighbor = adjacencies[j];
107 | const uint32_t* adjacencies2 = graph.GetNeighbors(neighbor);
108 | uint32_t degree2 = graph.GetDegree(neighbor);
109 | uint32_t intersect = Intersect((uint32_t*)adjacencies,degree,(uint32_t*)adjacencies2,degree2);
110 | numTriangles+=intersect;
111 | }
112 | cc+= degree > 1 ? numTriangles / (double64_t)(degree*(degree-1)) : 0;
113 | }
114 | cc /= graph.GetNumNodes();
115 | printf("CC: %f\n", cc);
116 | //======================================================================
117 | return 0;
118 | }
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/include/communities/communities.h:
--------------------------------------------------------------------------------
1 | /*SCD is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | SCD is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see .
13 | */
14 |
15 |
16 | #ifndef COMMUNITIES_H
17 | #define COMMUNITIES_H
18 |
19 | #include
20 | #include
21 |
22 | namespace scd {
23 |
24 | #define SCD_SINGLETON 0xffffffff
25 |
26 | /** @brief This struct is a tuple formed by a node id and a clustering coefficient.*/
27 | struct NodeClustering {
28 | uint32_t m_NodeId;
29 | double64_t m_CC;
30 | uint32_t m_Degree;
31 | };
32 |
33 | struct CommunityPartition {
34 | uint32_t* m_NodeLabels; /**< @brief The labels of the communities each node belongs to.*/
35 | uint32_t* m_CommunityIndices; /**< @brief The array of indices for each label into the community array.*/
36 | uint32_t* m_Communities; /**< @brief The communities.*/
37 | uint32_t* m_InternalEdges; /**< @brief The number of internal edges of each community.*/
38 | uint32_t* m_ExternalEdges; /**< @brief The number of external edges of each community.*/
39 | double64_t* m_NodeWCC; /**< @brief The WCC of the nodes.*/
40 | uint32_t m_NumCommunities; /**< @brief The number of communities.*/
41 | uint32_t m_NumNodes; /**< @brief The number of nodes.*/
42 | double64_t m_WCC; /**< @brief The WCC of this partition.*/
43 | };
44 |
45 |
46 |
47 | /** @brief Initializes a partition structure with an initial partition.
48 | * @param[in] graph A pointer to the graph.
49 | * @param[out] partition The partition structure to initializes.
50 | * @param[in] partitionFileName The name of the partition file to load.
51 | * @param[in] alfa The alfa parameter controlling the cohesivness of the communities.
52 | * @return 0 if the computation was successful. 1 if there were errors.*/
53 | uint32_t LoadPartition( const CGraph* graph, CommunityPartition* partition, const char_t* partitionFileName, const double64_t alfa );
54 |
55 |
56 | /** @brief Initializes a partition structure with an initial partition.
57 | * @param[in] graph A pointer to the graph.
58 | * @param[out] partition The partition structure to initializes.
59 | * @param[in] alfa The alfa parameter controlling the cohesivness of the communities.
60 | * @return 0 if the computation was successful. 1 if there were errors.*/
61 | uint32_t InitializeSimplePartition( const CGraph* graph, CommunityPartition* partition, const double64_t alfa );
62 |
63 | /** @brief Frees the resources used by the partition.
64 | * @param[out] partition The partition to free.*/
65 | void FreeResources( CommunityPartition* partition );
66 |
67 | /** @brief Prints the communities into a file.
68 | * @param[in] graph The graph.
69 | * @param[in] partition The partition to print.
70 | * @param[in] fileName The name of the file where the communities will be print.
71 | * @return 0 if the execution was successful. 1 otherwise.*/
72 | uint32_t PrintPartition( const CGraph* graph, const CommunityPartition* partition, const char_t* fileName);
73 |
74 |
75 | /** @brief Improves the quality of the communities.
76 | * @param[in] graph The graph.
77 | * @param[out] partition The partition to improve.
78 | * @param[in] numThreads The number of threads.
79 | * @param[in] lookahead The number of lookahead iterations.
80 | * @param[in] alfa The alfa parameter controlling the cohesivness of the communities.
81 | * @return 0 if the execution was successful. 0 otherwise.*/
82 | uint32_t ImproveCommunities( const CGraph* graph, CommunityPartition* partition, uint32_t numThreads, uint32_t lookahead, const double64_t alfa );
83 |
84 | /** @brief Copies a partition into another partition.
85 | * @param[out] destPartition The destination partition.
86 | * @param[in] sourcePartition The source partition.
87 | * @resutl 0 if the copy was sucecssful. 1 otherwise.*/
88 | uint32_t CopyPartition( CommunityPartition* destPartition, const CommunityPartition* sourcePartition);
89 | }
90 |
91 |
92 | #endif
93 |
94 |
95 |
--------------------------------------------------------------------------------
/include/graph/graph.h:
--------------------------------------------------------------------------------
1 | /*SCD is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | SCD is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see .
13 | */
14 |
15 | #ifndef CGRAPH_H
16 | #define CGRAPH_H
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include