Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#716 closed defect (fixed)

graph functions to_undirected and to_directed forget the loops and multiple edges

Reported by: Jason Grout Owned by: William Stein
Priority: major Milestone: sage-2.8.8
Component: combinatorics Keywords: graph, graphs
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

With a directed graph g

  • g.to_directed() forgets multiedges, remembers loops
  • g.to_undirected() forgets multiedges and loops

With an undirected graph g

  • g.to_directed() forgets multiedges and loops
  • g.to_undirected() forgets multiedges, remembers loops

In each of these cases, both multiedges and loops should be remembered.

sage: g=DiGraph({0:[0,1,1,2],1:[0,1]},loops=True,multiedges=True)
sage: g.to_directed().multiple_arcs()
False
sage: g.to_directed().loops()
True
sage: g.to_undirected().multiple_edges()
False
sage: g.to_undirected().loops()
False
sage: g=Graph({0:[0,1,1,2],1:[0,1]},loops=True,multiedges=True)
sage: g.to_directed().multiple_arcs()
False
sage: g.to_directed().loops()
False
sage: g.to_undirected().multiple_edges()
False
sage: g.to_undirected().loops()
True

Attachments (6)

init_and_to_simple.hg (1.1 KB) - added by Jason Grout 15 years ago.
deep_copy.hg (6.6 KB) - added by Robert Miller 15 years ago.
Fixes doctest failures and other strangeness
doc_changes.hg (7.4 KB) - added by Jason Grout 15 years ago.
arc_edges.hg (7.4 KB) - added by Robert Miller 15 years ago.
change_arc_to_edge.hg (11.4 KB) - added by Jason Grout 15 years ago.
combinat-arcs2edges.patch (2.8 KB) - added by Mike Hansen 15 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 15 years ago by Jason Grout

Apparently the copy doesn't preserve multiple edges settings.

sage: g=DiGraph({0:[0,1,1,2],1:[0,1]},loops=True,multiedges=True)
sage: g==g.copy()
False
sage: g.multiple_arcs()
True
sage: g.copy().multiple_arcs()
False

comment:2 Changed 15 years ago by Jason Grout

The real problem is that the init function tests for a superclass before a subclass. The attached patch fixes it (and also adds a to_simple function that _does_ forget multiple edges, loops, and directions on edges).

The attached patch may break some of the doctests in graph.py, though.

Changed 15 years ago by Jason Grout

Attachment: init_and_to_simple.hg added

Changed 15 years ago by Robert Miller

Attachment: deep_copy.hg added

Fixes doctest failures and other strangeness

Changed 15 years ago by Jason Grout

Attachment: doc_changes.hg added

Changed 15 years ago by Robert Miller

Attachment: arc_edges.hg added

Changed 15 years ago by Jason Grout

Attachment: change_arc_to_edge.hg added

Changed 15 years ago by Mike Hansen

Attachment: combinat-arcs2edges.patch added

comment:3 Changed 15 years ago by Robert Miller

Resolution: worksforme
Status: newclosed

comment:4 Changed 15 years ago by Jason Grout

As a side note, the above patches which were applied also changed all "arc" functions to "edge" functions. This, of course, broke backward compatibility.

comment:5 Changed 15 years ago by Michael Abshoff

Milestone: sage-2.9sage-2.8.9

I am curious if all those patches really were applied. They are over a months old, so I would assume so, but I do not understand why this ticket wasn't closed then.

Michael

comment:6 Changed 15 years ago by Michael Abshoff

Resolution: worksforme
Status: closedreopened

comment:7 Changed 15 years ago by Michael Abshoff

Milestone: sage-2.8.9sage-2.8.8
Resolution: fixed
Status: reopenedclosed

comment:8 Changed 15 years ago by Michael Abshoff

From Robert:

Michael,

Regarding ticket #716, these patches were incorporated a while ago,
and I closed the ticket last month when that happened. It looks like
the ticket has been closed, but in a future milestone, ever since...

Cheers,

Michael

Note: See TracTickets for help on using tickets.