@@ -1869,24 +1869,37 @@ PyObject *igraphmodule_Graph_knn(igraphmodule_GraphObject *self,
1869
1869
PyObject *igraphmodule_Graph_radius(igraphmodule_GraphObject * self,
1870
1870
PyObject * args, PyObject * kwds)
1871
1871
{
1872
- PyObject *mode_o = Py_None;
1872
+ PyObject *mode_o = Py_None, *weights_o = Py_None ;
1873
1873
igraph_neimode_t mode = IGRAPH_OUT;
1874
1874
igraph_real_t radius;
1875
+ igraph_vector_t *weights;
1875
1876
1876
- static char *kwlist[] = { "mode", NULL };
1877
+ static char *kwlist[] = { "mode", "weights", NULL };
1877
1878
1878
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist,
1879
- &mode_o))
1879
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &mode_o, &weights_o)) {
1880
1880
return NULL;
1881
+ }
1881
1882
1882
- if (igraphmodule_PyObject_to_neimode_t(mode_o, &mode))
1883
+ if (igraphmodule_PyObject_to_neimode_t(mode_o, &mode)) {
1883
1884
return NULL;
1885
+ }
1884
1886
1885
- if (igraph_radius(&self->g, &radius, mode)) {
1887
+ if (igraphmodule_attrib_to_vector_t(weights_o, self, &weights, ATTRIBUTE_TYPE_EDGE)) {
1888
+ return NULL;
1889
+ }
1890
+
1891
+ if (igraph_radius_dijkstra(&self->g, weights, &radius, mode)) {
1892
+ if (weights) {
1893
+ igraph_vector_destroy(weights); free(weights);
1894
+ }
1886
1895
igraphmodule_handle_igraph_error();
1887
1896
return NULL;
1888
1897
}
1889
1898
1899
+ if (weights) {
1900
+ igraph_vector_destroy(weights); free(weights);
1901
+ }
1902
+
1890
1903
return igraphmodule_real_t_to_PyObject(radius, IGRAPHMODULE_TYPE_FLOAT_IF_FRACTIONAL_ELSE_INT);
1891
1904
}
1892
1905
@@ -4862,18 +4875,21 @@ PyObject *igraphmodule_Graph_decompose(igraphmodule_GraphObject * self,
4862
4875
*/
4863
4876
PyObject *igraphmodule_Graph_eccentricity(igraphmodule_GraphObject* self,
4864
4877
PyObject* args, PyObject* kwds) {
4865
- static char *kwlist[] = { "vertices", "mode", NULL };
4866
- PyObject *vobj = Py_None, *list = NULL, *mode_o = Py_None;
4878
+ static char *kwlist[] = { "vertices", "mode", "weights", NULL };
4879
+ PyObject *vobj = Py_None, *list = NULL, *mode_o = Py_None, *weights_o = Py_None ;
4867
4880
igraph_vector_t res;
4868
4881
igraph_neimode_t mode = IGRAPH_OUT;
4869
4882
igraph_bool_t return_single = false;
4870
4883
igraph_vs_t vs;
4884
+ igraph_vector_t* weights;
4871
4885
4872
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO ", kwlist, &vobj, &mode_o))
4886
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO ", kwlist, &vobj, &mode_o, &weights_o)) {
4873
4887
return NULL;
4888
+ }
4874
4889
4875
- if (igraphmodule_PyObject_to_neimode_t(mode_o, &mode))
4890
+ if (igraphmodule_PyObject_to_neimode_t(mode_o, &mode)) {
4876
4891
return NULL;
4892
+ }
4877
4893
4878
4894
if (igraphmodule_PyObject_to_vs_t(vobj, &vs, &self->g, &return_single, 0)) {
4879
4895
igraphmodule_handle_igraph_error();
@@ -4885,17 +4901,31 @@ PyObject *igraphmodule_Graph_eccentricity(igraphmodule_GraphObject* self,
4885
4901
return igraphmodule_handle_igraph_error();
4886
4902
}
4887
4903
4888
- if (igraph_eccentricity(&self->g, &res, vs, mode)) {
4904
+ if (igraphmodule_attrib_to_vector_t(weights_o, self, &weights, ATTRIBUTE_TYPE_EDGE)) {
4905
+ igraph_vs_destroy(&vs);
4906
+ igraph_vector_destroy(&res);
4907
+ return NULL;
4908
+ }
4909
+
4910
+ if (igraph_eccentricity_dijkstra(&self->g, weights, &res, vs, mode)) {
4911
+ if (weights) {
4912
+ igraph_vector_destroy(weights); free(weights);
4913
+ }
4889
4914
igraph_vs_destroy(&vs);
4890
4915
igraph_vector_destroy(&res);
4891
4916
igraphmodule_handle_igraph_error();
4892
4917
return NULL;
4893
4918
}
4894
4919
4895
- if (!return_single)
4920
+ if (weights) {
4921
+ igraph_vector_destroy(weights); free(weights);
4922
+ }
4923
+
4924
+ if (!return_single) {
4896
4925
list = igraphmodule_vector_t_to_PyList(&res, IGRAPHMODULE_TYPE_FLOAT);
4897
- else
4926
+ } else {
4898
4927
list = PyFloat_FromDouble(VECTOR(res)[0]);
4928
+ }
4899
4929
4900
4930
igraph_vector_destroy(&res);
4901
4931
igraph_vs_destroy(&vs);
@@ -14786,7 +14816,7 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
14786
14816
/* interface to igraph_eccentricity */
14787
14817
{"eccentricity", (PyCFunction) igraphmodule_Graph_eccentricity,
14788
14818
METH_VARARGS | METH_KEYWORDS,
14789
- "eccentricity(vertices=None, mode=\"all\")\n--\n\n"
14819
+ "eccentricity(vertices=None, mode=\"all\", weights=None )\n--\n\n"
14790
14820
"Calculates the eccentricities of given vertices in a graph.\n\n"
14791
14821
"The eccentricity of a vertex is calculated by measuring the\n"
14792
14822
"shortest distance from (or to) the vertex, to (or from) all other\n"
@@ -14797,6 +14827,9 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
14797
14827
" that edge directions are followed; C{\"out\"} means that edge directions\n"
14798
14828
" are followed the opposite direction; C{\"all\"} means that directions are\n"
14799
14829
" ignored. The argument has no effect for undirected graphs.\n"
14830
+ "@param weights: a list containing the edge weights. It can also be\n"
14831
+ " an attribute name (edge weights are retrieved from the given\n"
14832
+ " attribute) or C{None} (all edges have equal weight).\n"
14800
14833
"@return: the calculated eccentricities in a list, or a single number if\n"
14801
14834
" a single vertex was supplied.\n"},
14802
14835
@@ -15358,7 +15391,7 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
15358
15391
/* interfaces to igraph_radius */
15359
15392
{"radius", (PyCFunction) igraphmodule_Graph_radius,
15360
15393
METH_VARARGS | METH_KEYWORDS,
15361
- "radius(mode=\"out\")\n--\n\n"
15394
+ "radius(mode=\"out\", weights=None )\n--\n\n"
15362
15395
"Calculates the radius of the graph.\n\n"
15363
15396
"The radius of a graph is defined as the minimum eccentricity of\n"
15364
15397
"its vertices (see L{eccentricity()}).\n"
@@ -15367,6 +15400,9 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
15367
15400
" edge directions, C{IN} considers paths that follow the opposite\n"
15368
15401
" edge directions, C{ALL} ignores edge directions. The argument is\n"
15369
15402
" ignored for undirected graphs.\n"
15403
+ "@param weights: a list containing the edge weights. It can also be\n"
15404
+ " an attribute name (edge weights are retrieved from the given\n"
15405
+ " attribute) or C{None} (all edges have equal weight).\n"
15370
15406
"@return: the radius\n"
15371
15407
"@see: L{eccentricity()}"
15372
15408
},
0 commit comments