Opened 15 months ago
Closed 14 months ago
#30214 closed enhancement (fixed)
Add to_digraph method to Permutation
Reported by: | slelievre | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-9.2 |
Component: | combinatorics | Keywords: | permutation, graph |
Cc: | slelievre | Merged in: | |
Authors: | David Coudert | Reviewers: | Sébastien Labbé |
Report Upstream: | N/A | Work issues: | |
Branch: | 12cadec (Commits, GitHub, GitLab) | Commit: | 12cadec9a8d01e5b7b804ee90e5a2df16dfef7a5 |
Dependencies: | Stopgaps: |
Description (last modified by )
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:
Change History (11)
comment:1 Changed 15 months ago by
- Branch set to public/combinat/30214_to_digraph
- Commit set to 498f093b7c0edfd61c16b1a9ec563a8563f8ec5b
- Status changed from new to needs_review
comment:2 Changed 15 months ago by
- Summary changed from Add graph method to permutations to Add to_digraph method to Permutation
comment:3 follow-up: ↓ 5 Changed 15 months ago by
Personally, I would do
-E = [(i + 1, self[i]) for i in range(len(self))] +E = list(enumerate(self, start=1)))
Do you agree?
comment:4 Changed 15 months ago by
- Reviewers set to Sébastien Labbé
comment:5 in reply to: ↑ 3 Changed 15 months ago by
Replying to 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?
+1
comment:6 Changed 15 months ago by
- Commit changed from 498f093b7c0edfd61c16b1a9ec563a8563f8ec5b to 12cadec9a8d01e5b7b804ee90e5a2df16dfef7a5
comment:7 Changed 15 months ago by
Indeed a better solution. I'm also avoiding the creation of the list.
comment:8 Changed 15 months ago by
- 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 15 months ago by
When the input format is specified, you can give an iterator. Otherwise...
comment:10 Changed 15 months ago by
- Description modified (diff)
comment:11 Changed 14 months ago by
- 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.
This should do what you want.
New commits:
trac #30214: add method to_digraph to Permutation