Opened 10 months ago

Closed 9 months ago

# Add to_digraph method to Permutation

Reported by: Owned by: slelievre major sage-9.2 combinatorics permutation, graph slelievre David Coudert Sébastien Labbé N/A 12cadec 12cadec9a8d01e5b7b804ee90e5a2df16dfef7a5

Before this ticket, the `show` method for a permutation

• computes a graph corresponding to that permutation
• displays it
• but does not return it

This ticket adds a `to_digraph` method to return the graph and changes the `show` method to use it.

This allows the following:

```sage: p = Permutation([3, 1, 2])
sage: g = p.to_digraph()
sage: g.edges(labels=False)
[(1, 3), (2, 1), (3, 2)]
```

Inspired by a question by Ask Sage user magviana:

### comment:1 Changed 10 months ago by dcoudert

• Authors set to David Coudert
• Branch set to public/combinat/30214_to_digraph
• Commit set to 498f093b7c0edfd61c16b1a9ec563a8563f8ec5b
• Status changed from new to needs_review

This should do what you want.

New commits:

 ​498f093 `trac #30214: add method to_digraph to Permutation`

### comment:2 Changed 10 months ago by dcoudert

• Summary changed from Add graph method to permutations to Add to_digraph method to Permutation

### comment:3 follow-up: ↓ 5 Changed 9 months ago by slabbe

Personally, I would do

```-E = [(i + 1, self[i]) for i in range(len(self))]
+E = list(enumerate(self, start=1)))
```

Do you agree?

Last edited 9 months ago by slelievre (previous) (diff)

### comment:4 Changed 9 months ago by slabbe

• Reviewers set to Sébastien Labbé

### comment:5 in reply to: ↑ 3 Changed 9 months ago by slelievre

Personally, I would do

```-E = [(i + 1, self[i]) for i in range(len(self))]
+E = list(enumerate(self, start=1)))
```

Do you agree?

+1

### comment:6 Changed 9 months ago by git

• Commit changed from 498f093b7c0edfd61c16b1a9ec563a8563f8ec5b to 12cadec9a8d01e5b7b804ee90e5a2df16dfef7a5

Branch pushed to git repo; I updated commit sha1. New commits:

 ​08c3e05 `trac #30214: merged with 9.2.beta8` ​12cadec `trac #30214: use enumerate and avoid creation of list`

### comment:7 Changed 9 months ago by dcoudert

Indeed a better solution. I'm also avoiding the creation of the list.

### comment:8 Changed 9 months ago by slabbe

• Status changed from needs_review to positive_review

good, I was not sure if it takes an iterable as well. even better.

### comment:9 Changed 9 months ago by dcoudert

When the input format is specified, you can give an iterator. Otherwise...

### comment:10 Changed 9 months ago by slelievre

• Description modified (diff)

### comment:11 Changed 9 months ago by vbraun

• Branch changed from public/combinat/30214_to_digraph to 12cadec9a8d01e5b7b804ee90e5a2df16dfef7a5
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.