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

Graph library passes almost surelly erroneous calls without an exception #12540

Open
sagetrac-brunellus mannequin opened this issue Feb 19, 2012 · 3 comments
Open

Graph library passes almost surelly erroneous calls without an exception #12540

sagetrac-brunellus mannequin opened this issue Feb 19, 2012 · 3 comments

Comments

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Feb 19, 2012

  1. Dense backend doesn't support edge labels, but add_edge(1, 2, 3) passes and behaves like add_edge(1, 2, None). (Everything is not well with dense graph backends #12387)
  2. Adding a loop to a graph with allows_loops=False do nothing.
  3. Adding an already present edge to a graph with allows_multiedges=False do nothing.
  4. (Other?)

Is this the proper behavior?

CC: @vbraun @nathanncohen

Component: graph theory

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

@sagetrac-brunellus sagetrac-brunellus mannequin added this to the sage-5.11 milestone Feb 19, 2012
@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@pelegm
Copy link
Contributor

pelegm commented Nov 29, 2016

comment:5

No answer here, so I ask explicitly again about (2).

In SparseGraphBackend, for example, the following lines appear in the add_edge method:

        if (not self.loops(None)) and u_int == v_int:
            return

This means that if the backend does not allow loops, the add_edge method silently ignore the added edge. By default, SparseGraphBackend does not allow loops.

Is this a wanted behaviour?

If not, there are couple of ways to handle this:

  1. raise from inside the backend method
  2. warn (somehow) from inside the backend method
  3. let the backend return False (or whatever) in case the edge was not added, and let the graph itself notice it and raise/warn

@dcoudert

This comment has been minimized.

@dcoudert
Copy link
Contributor

dcoudert commented Dec 8, 2021

comment:7

The behavior for loops has change and the default behavior is now to raise an error by default.

sage: G = Graph([(0, 0)], loops=None, data_structure="sparse")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...
ValueError: cannot add edge from 0 to 0 in graph without loops
sage:
sage: G = Graph([(0, 0)], loops=None, data_structure="dense")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...
ValueError: cannot add edge from 0 to 0 in graph without loops
sage:
sage: G = Graph([(0, 0)], loops=False, data_structure="sparse")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...
ValueError: cannot add edge from 0 to 0 in graph without loops
sage:
sage: G = Graph([(0, 0)], loops=False, data_structure="dense")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...
ValueError: cannot add edge from 0 to 0 in graph without loops

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

5 participants