Skip to content

Commit 6b278b8

Browse files
committed
adding LouvainQualityFunctionConcept
1 parent 422d376 commit 6b278b8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

include/boost/graph/louvain_clustering.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <boost/assert.hpp>
2222
#include <boost/static_assert.hpp>
2323
#include <boost/type_traits/is_same.hpp>
24+
#include <boost/concept/assert.hpp>
2425

2526
#include <map>
2627
#include <set>
@@ -215,6 +216,9 @@ local_optimization(
215216
typename property_traits<WeightMap>::value_type min_improvement_inner = typename property_traits<WeightMap>::value_type(0.0)
216217
)
217218
{
219+
// Concept checking
220+
BOOST_CONCEPT_ASSERT((LouvainQualityFunctionConcept<QualityFunction, Graph, CommunityMap, WeightMap>));
221+
218222
using community_type = typename property_traits<CommunityMap>::value_type;
219223
using weight_type = typename property_traits<WeightMap>::value_type;
220224
using vertex_descriptor = typename graph_traits<Graph>::vertex_descriptor;
@@ -372,6 +376,9 @@ louvain_clustering(
372376
typename property_traits<WeightMap>::value_type min_improvement_inner = typename property_traits<WeightMap>::value_type(0.0),
373377
typename property_traits<WeightMap>::value_type min_improvement_outer = typename property_traits<WeightMap>::value_type(0.0)
374378
){
379+
// Concept checking
380+
BOOST_CONCEPT_ASSERT((LouvainQualityFunctionConcept<QualityFunction, Graph, ComponentMap, WeightMap>));
381+
375382
using vertex_descriptor = typename graph_traits<Graph>::vertex_descriptor;
376383
using weight_type = typename property_traits<WeightMap>::value_type;
377384
using vertex_iterator = typename graph_traits<Graph>::vertex_iterator;

include/boost/graph/louvain_quality_functions.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <boost/property_map/vector_property_map.hpp>
1717
#include <boost/static_assert.hpp>
1818
#include <boost/type_traits/is_same.hpp>
19+
#include <boost/concept/assert.hpp>
1920
#include <map>
2021
#include <unordered_map>
2122

@@ -65,6 +66,35 @@ namespace centrality_detail {
6566
};
6667
}
6768

69+
template <typename QualityFunction, typename Graph, typename CommunityMap, typename WeightMap>
70+
struct LouvainQualityFunctionConcept
71+
{
72+
using weight_type = typename property_traits<WeightMap>::value_type;
73+
using community_type = typename property_traits<CommunityMap>::value_type;
74+
using vertex_descriptor = typename graph_traits<Graph>::vertex_descriptor;
75+
76+
void constraints()
77+
{
78+
weight_type q1 = QualityFunction::quality(g, cmap, wmap);
79+
weight_type q2 = QualityFunction::quality(g, cmap, wmap, k, in, tot, m);
80+
weight_type q3 = QualityFunction::quality_from_incremental(in, tot, m, num_communities);
81+
QualityFunction::remove(in, tot, comm, weight_val, weight_val, weight_val);
82+
QualityFunction::insert(in, tot, comm, weight_val, weight_val, weight_val);
83+
weight_type gain = QualityFunction::gain(tot, m, comm, weight_val, weight_val);
84+
}
85+
86+
Graph g;
87+
CommunityMap cmap;
88+
WeightMap wmap;
89+
vector_property_map<weight_type> k;
90+
associative_property_map<std::map<community_type, weight_type>> in;
91+
associative_property_map<std::map<community_type, weight_type>> tot;
92+
weight_type m;
93+
weight_type weight_val;
94+
community_type comm;
95+
std::size_t num_communities;
96+
};
97+
6898
// Modularity: Q = sum_c [ (L_c/m) - (k_c/2m)^2 ]
6999
// L_c = internal edge weight for community c
70100
// k_c = sum of degrees in community c

0 commit comments

Comments
 (0)