Skip to content

DiGraph.radius fails for directed graphs with non-comparable vertices #35300

@cyrilbouvier

Description

@cyrilbouvier

Is there an existing issue for this?

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.

Did you read the documentation and troubleshoot guide?

  • I have read the documentation and troubleshoot guide

Environment

- **OS**: Debian 11
- **Sage Version**: 3.11

Steps To Reproduce

Calling the radius method on a DiGraph with non comparable vertices

Expected Behavior

sage: G = Graph([[42, 'John'], [(42, 'John')]])
sage: G.radius()
1
sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
sage: H.radius()
1

Actual Behavior

H.radius() raises the following exception

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [10], line 1
----> 1 H.radius()

File ~/src/sage-9.8/src/sage/graphs/digraph.py:2350, in DiGraph.radius(self, by_weight, algorithm, weight_function, check_weight)
   2347 if not self.order():
   2348     raise ValueError("radius is not defined for the empty DiGraph")
-> 2350 return min(self.eccentricity(v=None, by_weight=by_weight,
   2351                              weight_function=weight_function,
   2352                              check_weight=check_weight,
   2353                              algorithm=algorithm))

File ~/src/sage-9.8/src/sage/graphs/digraph.py:2252, in DiGraph.eccentricity(self, v, by_weight, algorithm, weight_function, check_weight, dist_dict, with_labels)
   2250         return dict(zip(v, eccentricity(self, algorithm=algo, vertex_list=v)))
   2251     else:
-> 2252         return eccentricity(self, algorithm=algo)
   2254 if algorithm in ['Floyd-Warshall-Python', 'Floyd-Warshall-Cython', 'Johnson_Boost']:
   2255     dist_dict = self.shortest_path_all_pairs(by_weight=by_weight, algorithm=algorithm,
   2256                                              weight_function=weight_function,
   2257                                              check_weight=False)[0]

File ~/src/sage-9.8/src/sage/graphs/distances_all_pairs.pyx:1051, in sage.graphs.distances_all_pairs.eccentricity()
   1049 cdef list int_to_vertex
   1050 if vertex_list is None:
-> 1051     int_to_vertex = G.vertices(sort=True)
   1052 elif len(vertex_list) == n and set(vertex_list) == set(G):
   1053     int_to_vertex = vertex_list

File ~/src/sage-9.8/src/sage/graphs/generic_graph.py:11268, in GenericGraph.vertices(self, sort, key, degree, vertex_property)
  11265     raise ValueError('sort keyword is False, yet a key function is given')
  11267 if sort:
> 11268     return sorted(self.vertex_iterator(degree=degree, vertex_property=vertex_property), key=key)
  11269 return list(self.vertex_iterator(degree=degree, vertex_property=vertex_property))

File ~/src/sage-9.8/src/sage/rings/integer.pyx:916, in sage.rings.integer.Integer.__richcmp__()
    914     c = mpz_cmp_d((<Integer>left).value, d)
    915 else:
--> 916     return coercion_model.richcmp(left, right, op)
    917 
    918 return rich_to_bool_sgn(op, c)

File ~/src/sage-9.8/src/sage/structure/coerce.pyx:2008, in sage.structure.coerce.CoercionModel.richcmp()
   2006     raise bin_op_exception('<=', x, y)
   2007 elif op == Py_GT:
-> 2008     raise bin_op_exception('>', x, y)
   2009 else:
   2010     raise bin_op_exception('>=', x, y)

TypeError: unsupported operand parent(s) for >: 'Integer Ring' and '<class 'str'>'

Additional Information

Similar to #35168

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions