Closed jasongrout closed 13 years ago
Attachment: sage0.png
It looks like there's a bigger problem here:
sage: a=BipartiteGraph(matrix(2,2,[1,0,1,0]))
sage: a
Bipartite graph on 3 vertices
sage: a.vertices()
[0, 2, 3]
It can't be a coincidence that the missing vertex in a.vertices() is also the vertex missing a label. Of course, this may raise the question of why the fourth vertex is being drawn in the first place; however, I don't know enough about how graphs are drawn to be certain of that.
The problem seems to be that the reduced adjacency matrix code does the following:
else:
for ii in range(ncols):
for jj in range(nrows):
if arg1[jj][ii] != 0:
self.add_edge((ii, jj + ncols))
This is fine if the graph is has no isolated vertices. However, any graphs with isolated vertices will cause the similar problems:
sage: n = matrix(4,4,[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0])
[1 1 1 1]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
sage: g = BipartiteGraph(n)
sage: g
Bipartite graph on 5 vertices
sage: g.left, g.right
(set([0, 1, 2, 3]), set([4, 5, 6, 7]))
Attachment: trac_10356_fix_bipartite_graphs_isolated_vertex_reduced_adjacency_matrix.patch.gz
It looks to me like gbe did all the hard work! Patch attached, which simply makes sure that the vertices are directly added to the graph, instead of relying on the side effect of adding an edge to the vertex. This fixes the label problem too.
Reviewer: Nathann Cohen
Author: Geoffrey Ehrman, Douglas McNeil
To the point. And good to go ! :-)
Nathann
Merged: sage-4.7.1.alpha0
In Sage 4.6, I see
gives a graph where vertex "1" is not labeled (see attached picture).
Component: graph theory
Author: Geoffrey Ehrman, Douglas McNeil
Reviewer: Nathann Cohen
Merged: sage-4.7.1.alpha0
Issue created by migration from https://trac.sagemath.org/ticket/10356