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

Prepare for turning chordal_graph_cliques into a generator #4162

Merged
merged 2 commits into from Aug 16, 2020

Conversation

jarrodmillman
Copy link
Member

@jarrodmillman jarrodmillman commented Aug 15, 2020

See #4004.

@dschult
Copy link
Member

dschult commented Aug 16, 2020

I agree that a generator makes the most sense here.
Code like (from @jarrodmillman in #4004

for C in (G.subgraph(c).copy() for c in connected_components(G)):
        if C.number_of_nodes() == 1:
            yield frozenset(C.nodes())
        else:
            unnumbered = set(C.nodes())
            v = arbitrary_element(C)
            unnumbered.remove(v)
            numbered = {v}
            clique_wanna_be = {v}
            while unnumbered:
                v = _max_cardinality_node(C, unnumbered, numbered)
                unnumbered.remove(v)
                numbered.add(v)
                new_clique_wanna_be = set(C.neighbors(v)) & numbered
                sg = C.subgraph(clique_wanna_be)
                if _is_complete_graph(sg):
                    new_clique_wanna_be.add(v)
                    if not new_clique_wanna_be >= clique_wanna_be:
                        yield frozenset(clique_wanna_be)
                    clique_wanna_be = new_clique_wanna_be
                else:
                    raise nx.NetworkXError("Input graph is not chordal.")
            yield frozenset(clique_wanna_be)
and delete _connected_chordal_graph_cliques.

I believe this also makes the cliques deterministic. The connected components are ordered and while the nodes within each clique are not ordered, the cliques should be yielded in the same order. Nice!!

@jarrodmillman
Copy link
Member Author

I already added the code from #4004 to a new internal function _chordal_graph_cliques and now chordal_graph_cliques is just the warning and

return {c for c in _chordal_graph_cliques(G)}

Before 3.0, we just need to replace chordal_graph_cliques with _chordal_graph_cliques.

@dschult If this looks OK to you, please go ahead and merge.

@dschult dschult merged commit f67089b into networkx:master Aug 16, 2020
@jarrodmillman jarrodmillman deleted the chordal_graph_cliques_iter branch August 16, 2020 16:07
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
…4162)

* Prepare for turning chordal_graph_cliques into a generator

* Clean up docstrings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants