Opened 15 years ago

Closed 15 years ago

# graph functions to_undirected and to_directed forget the loops and multiple edges

Reported by: Owned by: Jason Grout William Stein major sage-2.8.8 combinatorics graph, graphs N/A

### 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
```

### 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 Robert Miller

Fixes doctest failures and other strangeness

### comment:3 Changed 15 years ago by Robert Miller

Resolution: → worksforme new → closed

### 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.9 → sage-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 closed → reopened

### comment:7 Changed 15 years ago by Michael Abshoff

Milestone: sage-2.8.9 → sage-2.8.8 → fixed reopened → closed

### 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.