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
Linear time implementation of lex_BFS() #11736
Comments
This comment has been minimized.
This comment has been minimized.
comment:4
Hello Diego !!! Same comment (see #11738) for this patch about the "build/" folder. I also expect that this patch breaks doctests in Sage's library, so please check it too, correcting the doctests themselves if it makes sense Nathann |
Attachment: linear_lex_bfs.patch.gz |
comment:6
Replying to @nathanncohen: |
comment:7
Perhaps I can help you with this test problem ? The thing is that right now the patch does not seem to work :
On random interval graphs sometimes the is_interval function works, sometimes it does not... I tested you patch after having applied #11738 and #11735 but I do not think this is where the bug comes from. Could you also add some comments to your code, along with a reference to the paper you are following for this implementation ? Nathann |
comment:8
Replying to @nathanncohen: |
comment:30
Is it feasible to generate a small random graph, feed it to both algorithms, and check that their outputs agree in a doctest? That would go a long way towards ensuring that the newer implementation is correct (or at least as correct as the old one). |
comment:31
The difficulty is that we may have several valid orderings, even with same initial vertex, and that the 2 algorithms may produce different orderings
In this example, the last graph is not connected, but it's the same with connected graphs. One option could be to make an indirect doctest using But may be there is an other way to check that a lex BFS ordering is valid ? |
comment:32
Ok, I see the problem. The paper "LexBFS-orderings and powers of graphs" (doi:10.1007/3-540-62559-3_15) has a characterization of LBFS orderings in Lemma 1 that looks pretty easy to implement. What do you think about an |
comment:33
Minor comment outside of the scope of the ticket: You might be able to do this for a bit more speed: - def l_func(x):
- return code[x]
# The initial_vertex is at position 0 and so named 0 in sd
code[0].append(n + 1)
now = 1
while vertices:
- v = max(vertices, key=l_func)
+ v = max(vertices, key=code.__getitem__) |
comment:35
I have added a method to check that a lexBFS ordering is valid in (directed) graphs. |
comment:36
We're working on getting rid of this, but for now, you have to call |
comment:37
Example:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:39
Thank you. I didn't know that. |
comment:40
I've been playing around with this, here are a few more suggestions:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:42
I have implemented your suggestions. For the algorithm, I made a copy of the description without suppressing it from the cdef method. I think it is easier this way for someone interested in this code to understand it. |
comment:43
Thanks! Here are two more small things: First, in the documentation for
The opening curly brace isn't escaped, so the formula isn't showing up. Second, in
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:45
good catch. Hope it will be ok this time. |
Reviewer: Michael Orlitzky |
comment:46
This looks good to me now, unless anyone else wants to comment. I've checked the implementation of The implementation of |
comment:47
Thank you for your help. To understand the fast algorithm, you need to understand that a slice is nothing else than a label. When creating a subslice of a slice from position p to position q, you place the vertices of the sub slice on positions p...p+I, and the remaining vertices of the original slice at positions p+I+1...q. So the vertices in the sub slice have a larger label than the other vertices of the original slice. The tricks are to associate a position with the current slice name, to maintain the head (left most vertex of a slice) of each slice, and give a name to each newly created subslice. To check the property on directed graphs, its more tricky, but I'm convinced it is correct. An alternative to check the validity is to modify the slow algorith. That is, instead of selecting a vertex with largest label, we identify all candidates (vertices with same largest label), and check that the next vertex in the given order is in this pool of candidates, then select it, update labels of its neighbors and continue. |
This comment has been minimized.
This comment has been minimized.
Changed branch from public/graphs/11736_lex_bfs to |
The current implementation of lex_BFS() is quadratic, which is not optimal. The usual way to do it in linear time is through a clever use of doubly linked lists, but in (1) there is a way with static arrays, which I coded in Python.
There is one thing, though: in (2) there is a new algorithm for is_interval() that avoids PQ-trees, and just uses various passes of lex_BFS() (implemented with doubly linked lists).
So maybe in the long run it would be better to do it with doubly linked lists in Cython.
(1) Habib, McConnell, Paul and Viennot. Lex-BFS and Partition Refinement, with Applications to Transitive Orientation, Interval Graph Recognition and Consecutive Ones Testing. TCS 234, 2000.
(2) Corneil, Olariu and Stewart. The LBFS Structure and Recognition of Interval Graphs. SIAMDM 23(4), 2009.
CC: @dcoudert @kliem @orlitzky
Component: graph theory
Keywords: lexbfs
Author: Diego de Estrada, David Coudert
Branch/Commit:
332fb8b
Reviewer: Michael Orlitzky
Issue created by migration from https://trac.sagemath.org/ticket/11736
The text was updated successfully, but these errors were encountered: