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
Graph constructor forgets vertex labels #14708
Comments
comment:1
I'm also totally confused about what |
comment:2
Somewhat related:
Ok, I would have expected a ValueError when calling
wat? |
comment:3
I think that these "vertex labels" are meant to associate non-hashable values to a vertex (whose name must be hashable). I never used it, I also think that it is useless (just use an external dictionary..) and that we would be better without it. Nathann |
Stopgaps: wrongAnswerMarker |
comment:9
I would like to address the issue raised in the comments section. This is the source code for the set_vertex() function for generic graphs def set_vertex(self, vertex, object):
if hasattr(self, '_assoc') is False:
self._assoc = {}
self._assoc[vertex] = object Since _assoc is a dictionary, even if the vertex isn't added beforehand (as in the example demonstrated in the comments section), the dictionary adds an entry into it. For example, >>> vert = {}
>>> vert['foo'] = 'bar'
>>> vert
{'foo': 'bar'} But we are adding a new vertex only on the call of the method _backend.add_vertex() in the graph. Hence, on calling the method get_vertices(), 'foo' was not displayed. But remember that _alloc already has the dictionary entry {foo: bar}. So once the method add_vertex('foo') is called, the entry foo is added to the list of vertices in the graph, and so on calling get_vertices, the entry {foo: bar} is displayed. |
comment:10
The issue in the comments is addressed in #27399 |
comment:11
Are you also planning to work on the other issue: copy of vertex labels when calling If so, there is a minor improvement to do in - if verts is None:
- verts = list(self)
+ if verts is None:
+ verts = self |
comment:12
This solution did not work. The problem still persist
I think the problem is in not communicating the labels of vertices in If we look at the
which, I believe, is not being transferred to Graph(g). On the other hand, in the
I am not yet sure how these two different implementations affect Graph(g), but edge labels are retained in Graph(g) but not vertex labels |
comment:13
And this is one more thing I've found: if
|
comment:14
When calling When a list of edges is given as input, we get a deprecation warning and the constructor sets parameter for multiple edges to True if necessary, but this behavior will soon be changed to False unless the user specifies |
comment:15
Oh ok Sir. Anything suggestions on comment 13? |
comment:16
Replying to @Rithesh17:
The current behavior is the right one. So nothing to do for #comment:13. There is however something to do for #comment:11 |
comment:17
Sorry Sir. I meant any suggestion on comment 12. |
comment:18
Check the |
comment:19
I went through the self.add_vertices(data.vertex_iterator())
self.add_edges(data.edge_iterator()) Now in the sage: g = digraphs.DeBruijn(2,2)
sage: for v in g.vertex_iterator():
....: print(v)
....:
11
10
00
01 But the labels are displayed in the case of sage: for v in g.edge_iterator():
....: print(v)
....:
('11', '10', '0')
('11', '11', '1')
('10', '00', '0')
('10', '01', '1')
('00', '00', '0')
('00', '01', '1')
('01', '10', '0')
('01', '11', '1') If we need to modify into the def vertex_iterator(self, vertices=None):
return self._backend.iterator_verts(vertices) I'll have to look into the Pyrex file |
comment:20
Please don't change the backend. What you must do is simply add |
comment:21
Yeah. That's a simpler solution. I had to also modify
Do I need to add a doctest for this? |
comment:22
Yes, you need to add a doctest with a pointer to this ticket, i.e., |
Author: Rithesh K |
New commits:
|
Commit: |
comment:24
Can you change the first example in digraph.py to only - sage: g = Graph()
+ sage: g = DiGraph() Also, add |
Reviewer: David Coudert |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:26
Just tested it over 8.8.beta3. LGTM. |
Changed stopgaps from wrongAnswerMarker to none |
Changed branch from u/gh-Rithesh17/vertex-labels-in-graph-digraph to |
Edge labels are remembered, though:
Component: graph theory
Author: Rithesh K
Branch/Commit:
e494dc5
Reviewer: David Coudert
Issue created by migration from https://trac.sagemath.org/ticket/14708
The text was updated successfully, but these errors were encountered: