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

degree() reports the degree of a self-loop vertex as contributing 1 to total degree #8395

Closed
sagetrac-mvngu mannequin opened this issue Feb 28, 2010 · 10 comments
Closed

Comments

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Feb 28, 2010

Note: When this ticket is closed, make sure to also close ticket #9809.

From sage-devel:

[mvngu@sage mvngu]$ sage
----------------------------------------------------------------------
| Sage Version 4.3.3, Release Date: 2010-02-21                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: G = Graph({1:[1]}); G
Looped graph on 1 vertex
sage: sum(G.degree())
1
sage: G.size()
0
sage: G = Graph({1:[1]}, loops=True); G
Looped graph on 1 vertex
sage: sum(G.degree())
1
sage: G.size()
0
sage: G = Graph({1:[1]}, loops=True, multiedges=True); G
Looped multi-graph on 1 vertex
sage: sum(G.degree())
1
sage: G.size()
0

The size of G is 1 because there is one edge, i.e. the single
self-loop. As shown by the above session, Sage reports the size of G
as 0. I believe this is a bug. 

See also the discussion at this other sage-devel thread. This also happens in the C graph backends for sparse and dense graphs:

[mvngu@sage ~]$ sage
----------------------------------------------------------------------
| Sage Version 4.3.5, Release Date: 2010-03-28                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: from sage.graphs.base.sparse_graph import SparseGraphBackend
sage: S = SparseGraphBackend(7)
sage: S.loops(True)
sage: S.add_edge(1, 1, None, directed=False)
sage: S.has_edge(1, 1, None)
True
sage: list(S.iterator_edges(range(7), None))
[(1, 1)]
sage: S.degree(1, directed=False)
1
sage: 
sage: reset()
sage: 
sage: 
sage: from sage.graphs.base.dense_graph import DenseGraphBackend
sage: D = DenseGraphBackend(78)
sage: D = DenseGraphBackend(7)
sage: D.loops(True)
sage: D.add_edge(1, 1, None, directed=False)
sage: D.has_edge(1, 1, None)
True
sage: list(D.iterator_edges(range(7), None))
[(1, 1)]
sage: D.degree(1, directed=False)
1

Notice that degree() reports the degree of a self-loop as one, when in fact it should be 2. That's because both SparseGraphBackend and DenseGraphBackend inherit the same degree() function from CGraphBackend. I think the implementation of degree() in CGraphBackend needs to take into account the existence of self-loops.

CC: @jasongrout @nathanncohen

Component: graph theory

Author: Minh Van Nguyen

Reviewer: Robert Miller, Minh Van Nguyen

Merged: sage-4.6.2.alpha0

Issue created by migration from https://trac.sagemath.org/ticket/8395

@sagetrac-mvngu sagetrac-mvngu mannequin added this to the sage-4.6.1 milestone Feb 28, 2010
@sagetrac-mvngu sagetrac-mvngu mannequin assigned rlmill Feb 28, 2010
@sagetrac-mvngu

This comment has been minimized.

@sagetrac-mvngu

This comment has been minimized.

@sagetrac-mvngu
Copy link
Mannequin Author

sagetrac-mvngu mannequin commented Dec 3, 2010

Author: Minh Van Nguyen

@sagetrac-mvngu

This comment has been minimized.

@sagetrac-mvngu
Copy link
Mannequin Author

sagetrac-mvngu mannequin commented Dec 3, 2010

comment:3

Attachment: trac-8395_degree.patch.gz

@sagetrac-mvngu sagetrac-mvngu mannequin added the s: needs review label Dec 3, 2010
@rlmill
Copy link
Mannequin

rlmill mannequin commented Dec 3, 2010

Attachment: trac_8395-part2.patch.gz

apply after previous patch

@rlmill
Copy link
Mannequin

rlmill mannequin commented Dec 3, 2010

comment:4

Minh,

Your patch looks good to me. If you approve of mine, please set this to positive review.

Thanks!

@sagetrac-mvngu
Copy link
Mannequin Author

sagetrac-mvngu mannequin commented Dec 4, 2010

Reviewer: Robert Miller, Minh Van Nguyen

@sagetrac-mvngu

This comment has been minimized.

@jdemeyer jdemeyer modified the milestones: sage-4.6.1, sage-4.6.2 Dec 5, 2010
@jdemeyer
Copy link

Merged: sage-4.6.2.alpha0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant