Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
cyrilbouvier opened this issue Mar 16, 2023 · 0 comments · Fixed by #35310
Closed
2 tasks done

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

cyrilbouvier opened this issue Mar 16, 2023 · 0 comments · Fixed by #35310

Comments

@cyrilbouvier
Copy link
Contributor

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

dcoudert added a commit to dcoudert/sage that referenced this issue Mar 19, 2023
vbraun pushed a commit that referenced this issue Apr 1, 2023
…rtices

Fixes #35300.

### 📚 Description

We specify an ordering of the vertices in the call to `eccentricity`.
This way we fix both `radius` and `diameter`.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] I have made sure that the title is self-explanatory and the
description concisely explains the PR.
- [x] I have linked an issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.

### ⌛ Dependencies
<!-- List all open pull requests that this PR logically depends on -->
<!--
- #xyz: short description why this is a dependency
- #abc: ...
-->

URL: #35310
Reported by: David Coudert
Reviewer(s): Frédéric Chapoton
@mkoeppe mkoeppe added this to the sage-10.0 milestone Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants