Remove one of the dancing links implementations

134 views
Skip to first unread message

Nils Bruin

unread,
Feb 22, 2025, 2:20:18 PM2/22/25
to sage-devel
I noticed that sage presently has two implementations of DLX:

 - a toy one implemented in python:

- a wrapper of a C++ implementation:

The toy one actually shows up more prominently in the documentation:
whereas the wrapper is only documented as "internal":

As far as I can see, the two are almost drop-in replacements. The C++ implementation does seem to be the one in wider use in the rest of the library. Perhaps convert the documentation for "dlx" to use the (almost certainly) much more efficient C++ wrapper, and perhaps remove the toy implementation?

I happened to need a dlx solver and after searching found the python implementation in sage. Unaware of the C++ alternative I nearly went with using the python one, which would probably have performed badly.

Changing this over could be a nice introductory project for someone interested in familiarizing themselves with sage development.

Nils Bruin

unread,
Feb 22, 2025, 10:00:17 PM2/22/25
to sage-devel
For historical reference, both implementations were incorporated in sage in feb/march 2008:


It looks like implementing DLX is a finnish thing :-). From the thread, I don't get the impression there is any reason to prefer the python implementation. Neither author seems to be still involved, so we've inherited the code anyway. It's simple code, though, and useful.

Sébastien Labbé

unread,
Feb 24, 2025, 10:43:53 AM2/24/25
to sage-devel
I have been using the c++ implementation of dancing links a lot during the last decade for fun [1,2] and for research. There were some issues in the original C++ code that are now fixed (providing a empty set of rows was crashing sage, also, we can now reset the search from the start, reduction to sat and reduction to milp, etc). I forgot about the existence of the Python implementation, since I always use the C++ one.


That being said, Franco Saliola from Montreal told me a few years ago that the code written by Knuth in recent years is faster (for some problems that Franco was working on) than the implementation currently in Sage. There are heuristics on the choice of the next column to deal with in the search that can be better suited for some problems. This is something on my TODO list since many years to check this out and maybe provide this in Sage if copyrights allows it.

Sincerely,

Sébastien
Reply all
Reply to author
Forward
0 new messages