aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/networkx/generators/cographs.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/networkx/generators/cographs.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are hereHEADmaster
Diffstat (limited to '.venv/lib/python3.12/site-packages/networkx/generators/cographs.py')
-rw-r--r--.venv/lib/python3.12/site-packages/networkx/generators/cographs.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/networkx/generators/cographs.py b/.venv/lib/python3.12/site-packages/networkx/generators/cographs.py
new file mode 100644
index 00000000..6635b32f
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/networkx/generators/cographs.py
@@ -0,0 +1,68 @@
+r"""Generators for cographs
+
+A cograph is a graph containing no path on four vertices.
+Cographs or $P_4$-free graphs can be obtained from a single vertex
+by disjoint union and complementation operations.
+
+References
+----------
+.. [0] D.G. Corneil, H. Lerchs, L.Stewart Burlingham,
+ "Complement reducible graphs",
+ Discrete Applied Mathematics, Volume 3, Issue 3, 1981, Pages 163-174,
+ ISSN 0166-218X.
+"""
+
+import networkx as nx
+from networkx.utils import py_random_state
+
+__all__ = ["random_cograph"]
+
+
+@py_random_state(1)
+@nx._dispatchable(graphs=None, returns_graph=True)
+def random_cograph(n, seed=None):
+ r"""Returns a random cograph with $2 ^ n$ nodes.
+
+ A cograph is a graph containing no path on four vertices.
+ Cographs or $P_4$-free graphs can be obtained from a single vertex
+ by disjoint union and complementation operations.
+
+ This generator starts off from a single vertex and performs disjoint
+ union and full join operations on itself.
+ The decision on which operation will take place is random.
+
+ Parameters
+ ----------
+ n : int
+ The order of the cograph.
+ seed : integer, random_state, or None (default)
+ Indicator of random number generation state.
+ See :ref:`Randomness<randomness>`.
+
+ Returns
+ -------
+ G : A random graph containing no path on four vertices.
+
+ See Also
+ --------
+ full_join
+ union
+
+ References
+ ----------
+ .. [1] D.G. Corneil, H. Lerchs, L.Stewart Burlingham,
+ "Complement reducible graphs",
+ Discrete Applied Mathematics, Volume 3, Issue 3, 1981, Pages 163-174,
+ ISSN 0166-218X.
+ """
+ R = nx.empty_graph(1)
+
+ for i in range(n):
+ RR = nx.relabel_nodes(R.copy(), lambda x: x + len(R))
+
+ if seed.randint(0, 1) == 0:
+ R = nx.full_join(R, RR)
+ else:
+ R = nx.disjoint_union(R, RR)
+
+ return R