Repository navigation
Add DAG antichain width - #8654
Conversation
dschult
left a comment
There was a problem hiding this comment.
This seems reasonable and the main issue is whether it belongs in NetworkX.
The doc_string replaces the technical term "width of a partially ordered set" with other technical terms "size of a maximum antichain", or "minimum number of chains needed to cover all vertices". This then magically is computed using more technical terms: "a maximum bipartite matching on the transitive closure". Can you explain what a dag-antichain-width is more directly?
My understanding is that this is similar to our treewidth concept for undirected graphs. But that hasn't gotten much traction as far as we can tell. Can you help me with that by explaining why you are interested in dag-antichain-width? How did you come across it and what made you want to propose it for NetworkX?
Thanks!!
rossbar
left a comment
There was a problem hiding this comment.
Another high-level question, how does this compare to:
>>> longest_ac = max(nx.antichains(G, key=len))
>>> len(longest_ac)or, more concisely: len(max(nx.antichains(G, key=len))).
|
Thanks for the feedback.
The reason I thought this could fit NetworkX is that NetworkX already has def clique_number_exact(G):
return max((len(C) for C in nx.find_cliques(G)), default=0)On a sparse DAG with around 2000 nodes this approach was not practical on my machine (hours for 500 nodes sparse DAGs) while the Dilworth/matching-based method returned in a few seconds. About multigraphs, since the computation only depends on reachability parallel edges shouldn't change the result. I can add a test for MultiDiGraph to make that behavior explicit but if the preference is to keep the function limited to simple directed graphs I can also add @not_implemented_for("multigraph) Yes , |
|
Thanks for this description of where this PR is coming from. Do you know why your adviser is interested in finding the width of DAGs? |
|
My advisor doesn't need this alogirthm directly but needs it because we want to generate DAGs with a controlled width. So we need to be able to check the width quickly. In our case the width is a parameter of the graphs we want to generate. From what I understand it is connected to experiments on scheduling/precedence constraints and labeling problems. |
|
I see, so that's the application -- to check whether a generated graph has a dag-antichain-width within a desired range. Given that we have tree_width for undirected graphs, I'm leaning toward adding this. It makes sense that it is faster than an exhaustive search. And the width value itself makes sense as a quantity of interest for e.g. logistics or production pathways where the number of chains could relate to how many machines can work the production at the same time without duplicating or interfering. But this is just a guess. |
|
Yes, that's the idea. I can update the docstring to make this interpretation clearer and add a |
Agreed, I'm in favor of adding as well - thanks @pamedodji for providing the additional context. I'd propose to rename the function |
|
Thanks, that sounds good to me. One small question about the name, since the current function returns only the size of a maximum antichain would |
|
It looks like wikipedia antichain is a good reference for this terminology. It talks about the names: "height" of a "longest chain" and "width" of a "largest antichain". I guess this is orienting the chains vertically -- and then the antichains are sets of nodes not connected via chains so they spread out horizontally. Obviously this is an arbitrary way to lay it out and the names are thus arbitrary. But that's ok. We should go with what the literature uses. Our namespace for dags means we don't need/want Maybe a link to the wikipedia page for antichains could be added to the doc-string too. Actually, most of the functions in this module have no references(!!). So we could add links to wikipedia for many of them perhaps in a separate PR. That might help with the technical terminology too. So many definitions! :) |
|
Done. I renamed the function to |
rossbar
left a comment
There was a problem hiding this comment.
I took the liberty of pushing up some minor tweaks/improvements but overall this LGTM. Thanks @pamedodji !
|
The CI failures are unrelated and fixed on |
dschult
left a comment
There was a problem hiding this comment.
This looks good! Thanks @pamedodji !
I merged with main and changed "This" to "The width".
I think this is ready to merge.
* Add DAG antichain width * format dag_antichain_width * Renamed antichain width function * Keep antichain_width in dag namespace * DOC: ref guide alphabetical, for new fn at least. * STY: update calling pattern in tests. * DOC: Minor docstring tweaks. * STY: rm nodes property. * MAINT: node bipartite attr has no effect, so remove. * TST: Minor test improvements. * Use noun over pronon. --------- Co-authored-by: AMEDODJIpierre <[email protected]> Co-authored-by: Ross Barnowski <[email protected]> Co-authored-by: Dan Schult <[email protected]>
This adds 'dag_antichain_width' which returns the size of a maximum antichain in a directed acyclic graph. The implementation uses Dilworth's theorem, the width of the partial order represented by the DAG is computed from a maximum bipartite matching on its transitive closure. This gives a polynomial-time way to compute the width of a DAG. Tests cover chains, independent nodes, a diamond-shaped DAG, and invalid inputs.