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

New implementation for the lexicographic unranking of combinations #29258

Closed
agenitrini mannequin opened this issue Feb 28, 2020 · 3 comments
Closed

New implementation for the lexicographic unranking of combinations #29258

agenitrini mannequin opened this issue Feb 28, 2020 · 3 comments

Comments

@agenitrini
Copy link
Mannequin

agenitrini mannequin commented Feb 28, 2020

I propose to implement a new algorithm for the unranking of combinations in the lexicographic order, cf. sage.combinat.combination algorithm from_rank.
The actual implementation is related to McCaffrey's blog.
In a recent paper I have written, cf. https://hal.archives-ouvertes.fr/hal-02462764v1
I compare this method to other from the literature and a new one I have developed with my co-authors. The paper is actually under review.

If possible I would like to commit this new implementation. My function has the same signature from the previous one.

Regards.
Antoine

Example :
Actual implementation (on my laptop : core i7 32GiB Ubuntu Linux)

---
n = 100
k = 50
set_random_seed(12345678987654321)
r = randint(0, binomial(n,k)-1)
%time A = combination.from_rank(r,n,k)
---
CPU times: user 1.55 ms, sys: 0 ns, total: 1.55 ms
Wall time: 1.06 ms

## With my algorithm
## (in the commit the function replace from_rank(.,.,.))
%time B = unrank_combi_direct(r, n, k)   
---
CPU times: user 297 µs, sys: 53 µs, total: 350 µs
Wall time: 296 µs

## Finally
---
A==B
---
True


## A second example with greater values
---
n = 10000
k = 5000
set_random_seed(12345678987654321)
r = randint(0, binomial(n,k)-1)
%time A = combination.from_rank(r,n,k)
---
CPU times: user 2.9 s, sys: 9.69 ms, total: 2.91 s
Wall time: 2.85 s

## With my algorithm
%time B = unrank_combi_direct(r, n, k)
---
CPU times: user 22.4 ms, sys: 4.45 ms, total: 26.9 ms
Wall time: 21 ms

## Finally
---
A==B
---
True

Component: combinatorics

Keywords: combination unranking

Author: Antoine Genitrini

Reviewer: Dave Morris

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

@agenitrini agenitrini mannequin added this to the sage-9.1 milestone Feb 28, 2020
@agenitrini
Copy link
Mannequin Author

agenitrini mannequin commented Feb 28, 2020

comment:1

I have not pushed anything yet.

@agenitrini
Copy link
Mannequin Author

agenitrini mannequin commented Mar 1, 2020

comment:2

This ticket can be closed or removed, because it is not associated to any branch.

The adequate ticket for this issue and the associated branch are given in the ticket #29262.
Sorry for the trouble.

@DaveWitteMorris
Copy link
Member

Reviewer: Dave Morris

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

2 participants