@@ -13048,68 +13048,63 @@ PyObject *igraphmodule_Graph_community_edge_betweenness(igraphmodule_GraphObject
13048
13048
PyObject *res, *qs, *ms;
13049
13049
igraph_matrix_int_t merges;
13050
13050
igraph_vector_t q;
13051
- igraph_vector_t *weights = 0 ;
13051
+ igraph_vector_t *weights = NULL ;
13052
13052
13053
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &directed, &weights_o))
13053
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &directed, &weights_o)) {
13054
13054
return NULL;
13055
+ }
13055
13056
13056
- if (igraphmodule_attrib_to_vector_t(weights_o, self, &weights,
13057
- ATTRIBUTE_TYPE_EDGE)) return NULL;
13057
+ if (igraphmodule_attrib_to_vector_t(weights_o, self, &weights, ATTRIBUTE_TYPE_EDGE)) {
13058
+ return NULL;
13059
+ }
13058
13060
13059
13061
if (igraph_matrix_int_init(&merges, 0, 0)) {
13060
- if (weights != 0 ) {
13062
+ if (weights) {
13061
13063
igraph_vector_destroy(weights); free(weights);
13062
13064
}
13063
13065
return igraphmodule_handle_igraph_error();
13064
13066
}
13065
13067
13066
13068
if (igraph_vector_init(&q, 0)) {
13067
13069
igraph_matrix_int_destroy(&merges);
13068
- if (weights != 0 ) {
13070
+ if (weights) {
13069
13071
igraph_vector_destroy(weights); free(weights);
13070
13072
}
13071
13073
return igraphmodule_handle_igraph_error();
13072
13074
}
13073
13075
13074
13076
if (igraph_community_edge_betweenness(&self->g,
13075
- /* removed_edges = */ 0 ,
13076
- /* edge_betweenness = */ 0 ,
13077
+ /* removed_edges = */ NULL ,
13078
+ /* edge_betweenness = */ NULL ,
13077
13079
/* merges = */ &merges,
13078
- /* bridges = */ 0 ,
13079
- /* modularity = */ weights ? 0 : &q,
13080
- /* membership = */ 0 ,
13080
+ /* bridges = */ NULL ,
13081
+ /* modularity = */ &q,
13082
+ /* membership = */ NULL ,
13081
13083
PyObject_IsTrue(directed),
13082
13084
weights,
13083
- /* lengths = */ 0)) {
13084
- igraphmodule_handle_igraph_error();
13085
- if (weights != 0) {
13085
+ /* lengths = */ NULL)) {
13086
+
13087
+ igraph_vector_destroy(&q);
13088
+ igraph_matrix_int_destroy(&merges);
13089
+ if (weights) {
13086
13090
igraph_vector_destroy(weights); free(weights);
13087
13091
}
13088
- igraph_matrix_int_destroy(&merges);
13089
- igraph_vector_destroy(&q);
13090
- return NULL;
13092
+
13093
+ return igraphmodule_handle_igraph_error();;
13091
13094
}
13092
13095
13093
- if (weights != 0 ) {
13096
+ if (weights) {
13094
13097
igraph_vector_destroy(weights); free(weights);
13095
13098
}
13096
13099
13097
- if (weights == 0) {
13098
- /* Calculate modularity vector only in the unweighted case as we don't
13099
- * calculate modularities for the weighted case */
13100
- qs=igraphmodule_vector_t_to_PyList(&q, IGRAPHMODULE_TYPE_FLOAT);
13101
- igraph_vector_destroy(&q);
13102
- if (!qs) {
13103
- igraph_matrix_int_destroy(&merges);
13104
- return NULL;
13105
- }
13106
- } else {
13107
- qs = Py_None;
13108
- Py_INCREF(qs);
13109
- igraph_vector_destroy(&q);
13100
+ qs = igraphmodule_vector_t_to_PyList(&q, IGRAPHMODULE_TYPE_FLOAT);
13101
+ igraph_vector_destroy(&q);
13102
+ if (!qs) {
13103
+ igraph_matrix_int_destroy(&merges);
13104
+ return NULL;
13110
13105
}
13111
13106
13112
- ms= igraphmodule_matrix_int_t_to_PyList(&merges);
13107
+ ms = igraphmodule_matrix_int_t_to_PyList(&merges);
13113
13108
igraph_matrix_int_destroy(&merges);
13114
13109
13115
13110
if (ms == NULL) {
@@ -18531,12 +18526,18 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
18531
18526
"is typically high. So we gradually remove the edge with the highest\n"
18532
18527
"betweenness from the network and recalculate edge betweenness after every\n"
18533
18528
"removal, as long as all edges are removed.\n\n"
18529
+ "When edge weights are given, the ratio of betweenness and weight values\n"
18530
+ "is used to choose which edges to remove first, as described in\n"
18531
+ "M. E. J. Newman: Analysis of Weighted Networks (2004), Section C.\n"
18532
+ "Thus, edges with large weights are treated as strong connections,\n"
18533
+ "and will be removed later than weak connections having similar betweenness.\n"
18534
+ "Weights are also used for calculating modularity.\n\n"
18534
18535
"Attention: this function is wrapped in a more convenient syntax in the\n"
18535
18536
"derived class L{Graph}. It is advised to use that instead of this version.\n\n"
18536
18537
"@param directed: whether to take into account the directedness of the edges\n"
18537
18538
" when we calculate the betweenness values.\n"
18538
18539
"@param weights: name of an edge attribute or a list containing\n"
18539
- " edge weights.\n\n"
18540
+ " edge weights. Higher weights indicate stronger connections. \n\n"
18540
18541
"@return: a tuple with the merge matrix that describes the dendrogram\n"
18541
18542
" and the modularity scores before each merge. The modularity scores\n"
18542
18543
" use the weights if the original graph was weighted.\n"
0 commit comments