passagemath-rankwidth 10.6.39__cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of passagemath-rankwidth might be problematic. Click here for more details.
- passagemath_rankwidth/__init__.py +3 -0
- passagemath_rankwidth-10.6.39.dist-info/METADATA +113 -0
- passagemath_rankwidth-10.6.39.dist-info/RECORD +11 -0
- passagemath_rankwidth-10.6.39.dist-info/WHEEL +7 -0
- passagemath_rankwidth-10.6.39.dist-info/top_level.txt +3 -0
- passagemath_rankwidth.libs/librw-afb892c6.so.0.0.0 +0 -0
- sage/all__sagemath_rankwidth.py +4 -0
- sage/graphs/all__sagemath_rankwidth.py +1 -0
- sage/graphs/graph_decompositions/all__sagemath_rankwidth.py +1 -0
- sage/graphs/graph_decompositions/rankwidth.cpython-311-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/rankwidth.pyx +333 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: passagemath-rankwidth
|
|
3
|
+
Version: 10.6.39
|
|
4
|
+
Summary: passagemath: Rankwidth and rank decompositions of graphs with rw
|
|
5
|
+
Author-email: The Sage Developers <sage-support@googlegroups.com>
|
|
6
|
+
Maintainer: Matthias Köppe, passagemath contributors
|
|
7
|
+
License-Expression: GPL-2.0-or-later
|
|
8
|
+
Project-URL: release notes, https://github.com/passagemath/passagemath/releases
|
|
9
|
+
Project-URL: repo (upstream), https://github.com/sagemath/sage
|
|
10
|
+
Project-URL: repo, https://github.com/passagemath/passagemath
|
|
11
|
+
Project-URL: documentation, https://passagemath.org/docs/latest
|
|
12
|
+
Project-URL: homepage (upstream), https://www.sagemath.org
|
|
13
|
+
Project-URL: discourse, https://passagemath.discourse.group
|
|
14
|
+
Project-URL: tracker (upstream), https://github.com/sagemath/sage/issues
|
|
15
|
+
Project-URL: tracker, https://github.com/passagemath/passagemath/issues
|
|
16
|
+
Classifier: Development Status :: 6 - Mature
|
|
17
|
+
Classifier: Intended Audience :: Education
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Operating System :: POSIX
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
22
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
23
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
28
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
29
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
30
|
+
Requires-Python: <3.15,>=3.10
|
|
31
|
+
Description-Content-Type: text/x-rst
|
|
32
|
+
Requires-Dist: passagemath-graphs
|
|
33
|
+
Provides-Extra: test
|
|
34
|
+
Requires-Dist: passagemath-repl; extra == "test"
|
|
35
|
+
|
|
36
|
+
========================================================================
|
|
37
|
+
passagemath: Rankwidth and rank decompositions of graphs with rw
|
|
38
|
+
========================================================================
|
|
39
|
+
|
|
40
|
+
`passagemath <https://github.com/passagemath/passagemath>`__ is open
|
|
41
|
+
source mathematical software in Python, released under the GNU General
|
|
42
|
+
Public Licence GPLv2+.
|
|
43
|
+
|
|
44
|
+
It is a fork of `SageMath <https://www.sagemath.org/>`__, which has been
|
|
45
|
+
developed 2005-2025 under the motto “Creating a Viable Open Source
|
|
46
|
+
Alternative to Magma, Maple, Mathematica, and MATLAB”.
|
|
47
|
+
|
|
48
|
+
The passagemath fork uses the motto "Creating a Free Passage Between the
|
|
49
|
+
Scientific Python Ecosystem and Mathematical Software Communities."
|
|
50
|
+
It was created in October 2024 with the following goals:
|
|
51
|
+
|
|
52
|
+
- providing modularized installation with pip,
|
|
53
|
+
- establishing first-class membership in the scientific Python
|
|
54
|
+
ecosystem,
|
|
55
|
+
- giving `clear attribution of upstream
|
|
56
|
+
projects <https://groups.google.com/g/sage-devel/c/6HO1HEtL1Fs/m/G002rPGpAAAJ>`__,
|
|
57
|
+
- providing independently usable Python interfaces to upstream
|
|
58
|
+
libraries,
|
|
59
|
+
- offering `platform portability and integration testing
|
|
60
|
+
services <https://github.com/passagemath/passagemath/issues/704>`__
|
|
61
|
+
to upstream projects,
|
|
62
|
+
- inviting collaborations with upstream projects,
|
|
63
|
+
- `building a professional, respectful, inclusive
|
|
64
|
+
community <https://groups.google.com/g/sage-devel/c/xBzaINHWwUQ>`__,
|
|
65
|
+
- `empowering Sage users to participate in the scientific Python ecosystem
|
|
66
|
+
<https://github.com/passagemath/passagemath/issues/248>`__ by publishing packages,
|
|
67
|
+
- developing a port to `Pyodide <https://pyodide.org/en/stable/>`__ for
|
|
68
|
+
serverless deployment with Javascript,
|
|
69
|
+
- developing a native Windows port.
|
|
70
|
+
|
|
71
|
+
`Full documentation <https://passagemath.org/docs/latest/html/en/index.html>`__ is
|
|
72
|
+
available online.
|
|
73
|
+
|
|
74
|
+
passagemath attempts to support and provides binary wheels suitable for
|
|
75
|
+
all major Linux distributions and recent versions of macOS.
|
|
76
|
+
|
|
77
|
+
Binary wheels for native Windows (x86_64) are are available for a subset of
|
|
78
|
+
the passagemath distributions. Use of the full functionality of passagemath
|
|
79
|
+
on Windows currently requires the use of Windows Subsystem for Linux (WSL)
|
|
80
|
+
or virtualization.
|
|
81
|
+
|
|
82
|
+
The supported Python versions in the passagemath 10.6.x series are 3.10.x-3.13.x.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
About this pip-installable distribution package
|
|
86
|
+
-----------------------------------------------
|
|
87
|
+
|
|
88
|
+
This pip-installable distribution ``passagemath-rankwidth`` is a small
|
|
89
|
+
optional distribution for use with `passagemath-graphs <https://pypi.org/project/passagemath-graphs>`_.
|
|
90
|
+
|
|
91
|
+
It provides a Cython interface to `rw <https://sourceforge.net/projects/rankwidth/>`_ by
|
|
92
|
+
Philipp Klaus Krause, which calculates rank width and rank decompositions.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
What is included
|
|
96
|
+
----------------
|
|
97
|
+
|
|
98
|
+
- `Cython interface to rw <https://passagemath.org/docs/latest/html/en/reference/graphs/sage/graphs/graph_decompositions/rankwidth.html>`_
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
Examples
|
|
102
|
+
--------
|
|
103
|
+
|
|
104
|
+
::
|
|
105
|
+
|
|
106
|
+
$ pipx run --pip-args="--prefer-binary" --spec "passagemath-rankwidth[test]" ipython
|
|
107
|
+
|
|
108
|
+
In [1]: from passagemath_rankwidth import *
|
|
109
|
+
|
|
110
|
+
In [2]: g = graphs.PetersenGraph()
|
|
111
|
+
|
|
112
|
+
In [3]: g.rank_decomposition()
|
|
113
|
+
Out[3]: (3, Graph on 19 vertices)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
passagemath_rankwidth/__init__.py,sha256=R8c9YuGWpzmOs0rd6XMhmHjC8OLrFv95lX0IqU146Wg,92
|
|
2
|
+
passagemath_rankwidth.libs/librw-afb892c6.so.0.0.0,sha256=E6fm24N5iHJge9nQzdseU3oGx78Xmgl-FJ7RsbRQ6Jg,330705
|
|
3
|
+
sage/all__sagemath_rankwidth.py,sha256=9OKCYFCtD-gDbbKmGnvLqMUg3gaTZ4wvHq8dv5kTdUU,109
|
|
4
|
+
sage/graphs/all__sagemath_rankwidth.py,sha256=8AgBFcKFGDJyb66yQXgMGdZE8BK4Q0Mj3r0uHtIvCJg,48
|
|
5
|
+
sage/graphs/graph_decompositions/all__sagemath_rankwidth.py,sha256=8AgBFcKFGDJyb66yQXgMGdZE8BK4Q0Mj3r0uHtIvCJg,48
|
|
6
|
+
sage/graphs/graph_decompositions/rankwidth.cpython-311-aarch64-linux-gnu.so,sha256=ck0y-L-9nPOjd0Ois8ep__5fTiL2fSOs0dgfyCUZzDQ,923057
|
|
7
|
+
sage/graphs/graph_decompositions/rankwidth.pyx,sha256=XLgr3jaejMtypTubVJBHVrLLTmr0XYyBZeLSNTssV5c,10031
|
|
8
|
+
passagemath_rankwidth-10.6.39.dist-info/METADATA,sha256=YVOVCyAolv77Sp8Ll-XyDcUY6Tb4ZDERP_ttELiwSeU,4925
|
|
9
|
+
passagemath_rankwidth-10.6.39.dist-info/WHEEL,sha256=nENvFvUt2sTxh7qTwFTbrHft1Jd6WkcTog-2x3-pWGY,193
|
|
10
|
+
passagemath_rankwidth-10.6.39.dist-info/top_level.txt,sha256=fBLflVh_5kF3NqatPHMMyKd3Ygl7dHOfaBaLFrvPtHA,28
|
|
11
|
+
passagemath_rankwidth-10.6.39.dist-info/RECORD,,
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-rankwidth
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-rankwidth
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-rankwidth
|
|
2
|
+
# cython: binding=True
|
|
3
|
+
# distutils: libraries = rw
|
|
4
|
+
r"""
|
|
5
|
+
Rank Decompositions of graphs
|
|
6
|
+
|
|
7
|
+
This module wraps C code from Philipp Klaus Krause computing an optimal
|
|
8
|
+
rank-decomposition.
|
|
9
|
+
|
|
10
|
+
**Definitions :**
|
|
11
|
+
|
|
12
|
+
Given a graph `G` and a subset `S\subseteq V(G)` of vertices, the *rank-width*
|
|
13
|
+
of `S` in `G`, denoted `rw_G(S)`, is equal to the rank in `GF(2)` of the `|S|
|
|
14
|
+
\times (|V|-|S|)` matrix of the adjacencies between the vertices of `S` and
|
|
15
|
+
`V\backslash S`. By definition, `rw_G(S)` is equal to `rw_G(\overline S)` where
|
|
16
|
+
`\overline S` is the complement of `S` in `V(G)`.
|
|
17
|
+
|
|
18
|
+
A *rank-decomposition* of `G` is a tree whose `n` leaves are the elements of
|
|
19
|
+
`V(G)`, and whose internal nodes have degree 3. In a tree, any edge naturally
|
|
20
|
+
corresponds to a bipartition of the vertex set : indeed, the removal of any edge
|
|
21
|
+
splits the tree into two connected components, thus splitting the set of leaves
|
|
22
|
+
(i.e. vertices of `G`) into two sets. Hence we can define for any edge `e\in
|
|
23
|
+
E(G)` a width equal to the value `rw_G(S)` or `rw_G(\overline S)`, where
|
|
24
|
+
`S,\overline S` is the bipartition obtained from `e`. The *rank-width*
|
|
25
|
+
associated to the whole decomposition is then set to the maximum of the width of
|
|
26
|
+
all the edges it contains.
|
|
27
|
+
|
|
28
|
+
A *rank-decomposition* is said to be optimal for `G` if it is the decomposition
|
|
29
|
+
achieving the minimal *rank-width*.
|
|
30
|
+
|
|
31
|
+
**RW -- The original source code :**
|
|
32
|
+
|
|
33
|
+
RW is a program that calculates rank-width and
|
|
34
|
+
rank-decompositions. It is based on ideas from:
|
|
35
|
+
|
|
36
|
+
* "Computing rank-width exactly" by Sang-il Oum [Oum2009]_
|
|
37
|
+
* "Sopra una formula numerica" by Ernesto Pascal
|
|
38
|
+
* "Generation of a Vector from the Lexicographical Index" by B.P. Buckles
|
|
39
|
+
and M. Lybanon [BL1977]_
|
|
40
|
+
* "Fast additions on masked integers" by Michael D. Adams and David S. Wise
|
|
41
|
+
[AW2006]_
|
|
42
|
+
|
|
43
|
+
**OUTPUT:**
|
|
44
|
+
|
|
45
|
+
The rank decomposition is returned as a tree whose vertices are subsets of
|
|
46
|
+
`V(G)`. Its leaves, corresponding to the vertices of `G` are sets of 1 elements,
|
|
47
|
+
i.e. singletons.
|
|
48
|
+
|
|
49
|
+
::
|
|
50
|
+
|
|
51
|
+
sage: g = graphs.PetersenGraph()
|
|
52
|
+
sage: rw, tree = g.rank_decomposition()
|
|
53
|
+
sage: all(len(v)==1 for v in tree if tree.degree(v) == 1)
|
|
54
|
+
True
|
|
55
|
+
|
|
56
|
+
The internal nodes are sets of the decomposition. This way, it is easy to deduce
|
|
57
|
+
the bipartition associated to an edge from the tree. Indeed, two adjacent
|
|
58
|
+
vertices of the tree are comparable sets : they yield the bipartition obtained
|
|
59
|
+
from the smaller of the two and its complement.
|
|
60
|
+
|
|
61
|
+
::
|
|
62
|
+
|
|
63
|
+
sage: g = graphs.PetersenGraph()
|
|
64
|
+
sage: rw, tree = g.rank_decomposition()
|
|
65
|
+
sage: u = Set([8, 9, 3, 7])
|
|
66
|
+
sage: v = Set([8, 9])
|
|
67
|
+
sage: tree.has_edge(u,v)
|
|
68
|
+
True
|
|
69
|
+
sage: m = min(u,v)
|
|
70
|
+
sage: bipartition = (m, Set(g.vertices(sort=False)) - m)
|
|
71
|
+
sage: bipartition
|
|
72
|
+
({8, 9}, {0, 1, 2, 3, 4, 5, 6, 7})
|
|
73
|
+
|
|
74
|
+
.. WARNING::
|
|
75
|
+
|
|
76
|
+
* The current implementation cannot handle graphs of `\geq 32` vertices.
|
|
77
|
+
|
|
78
|
+
* A bug that has been reported upstream make the code crash immediately on
|
|
79
|
+
instances of size `30`. If you experience this kind of bug please report
|
|
80
|
+
it to us, what we need is some information on the hardware you run to know
|
|
81
|
+
where it comes from !
|
|
82
|
+
|
|
83
|
+
EXAMPLES::
|
|
84
|
+
|
|
85
|
+
sage: g = graphs.PetersenGraph()
|
|
86
|
+
sage: g.rank_decomposition()
|
|
87
|
+
(3, Graph on 19 vertices)
|
|
88
|
+
|
|
89
|
+
AUTHORS:
|
|
90
|
+
|
|
91
|
+
- Philipp Klaus Krause : Implementation of the C algorithm
|
|
92
|
+
- Nathann Cohen : Interface with Sage and documentation
|
|
93
|
+
|
|
94
|
+
Methods
|
|
95
|
+
-------
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
# ****************************************************************************
|
|
99
|
+
# Copyright (C) 2011 Nathann Cohen <nathann.cohen@gmail.com>
|
|
100
|
+
#
|
|
101
|
+
# This program is free software: you can redistribute it and/or modify
|
|
102
|
+
# it under the terms of the GNU General Public License as published by
|
|
103
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
104
|
+
# (at your option) any later version.
|
|
105
|
+
# https://www.gnu.org/licenses/
|
|
106
|
+
# ****************************************************************************
|
|
107
|
+
|
|
108
|
+
from cysignals.memory cimport check_allocarray, sig_free
|
|
109
|
+
from cysignals.signals cimport *
|
|
110
|
+
|
|
111
|
+
from libc.string cimport memset
|
|
112
|
+
|
|
113
|
+
cdef list id_to_vertices
|
|
114
|
+
cdef dict vertices_to_id
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def rank_decomposition(G, verbose=False):
|
|
118
|
+
r"""
|
|
119
|
+
Compute an optimal rank-decomposition of the given graph.
|
|
120
|
+
|
|
121
|
+
This function is available as a method of the :class:`Graph
|
|
122
|
+
<sage.graphs.graph>` class. See :meth:`rank_decomposition
|
|
123
|
+
<sage.graphs.graph.Graph.rank_decomposition>`.
|
|
124
|
+
|
|
125
|
+
INPUT:
|
|
126
|
+
|
|
127
|
+
- ``verbose`` -- boolean (default: ``False``); whether to display progress
|
|
128
|
+
information while computing the decomposition
|
|
129
|
+
|
|
130
|
+
OUTPUT:
|
|
131
|
+
|
|
132
|
+
A pair ``(rankwidth, decomposition_tree)``, where ``rankwidth`` is a
|
|
133
|
+
numerical value and ``decomposition_tree`` is a ternary tree describing the
|
|
134
|
+
decomposition (cf. the module's documentation).
|
|
135
|
+
|
|
136
|
+
EXAMPLES::
|
|
137
|
+
|
|
138
|
+
sage: from sage.graphs.graph_decompositions.rankwidth import rank_decomposition
|
|
139
|
+
sage: g = graphs.PetersenGraph()
|
|
140
|
+
sage: rank_decomposition(g)
|
|
141
|
+
(3, Graph on 19 vertices)
|
|
142
|
+
|
|
143
|
+
On more than 32 vertices::
|
|
144
|
+
|
|
145
|
+
sage: g = graphs.RandomGNP(40, .5)
|
|
146
|
+
sage: rank_decomposition(g)
|
|
147
|
+
Traceback (most recent call last):
|
|
148
|
+
...
|
|
149
|
+
RuntimeError: the rank decomposition cannot be computed on graphs of >= 32 vertices
|
|
150
|
+
|
|
151
|
+
The empty graph::
|
|
152
|
+
|
|
153
|
+
sage: g = Graph()
|
|
154
|
+
sage: rank_decomposition(g)
|
|
155
|
+
(0, Graph on 0 vertices)
|
|
156
|
+
"""
|
|
157
|
+
cdef int n = G.order()
|
|
158
|
+
|
|
159
|
+
if n >= 32:
|
|
160
|
+
raise RuntimeError("the rank decomposition cannot be computed "
|
|
161
|
+
"on graphs of >= 32 vertices")
|
|
162
|
+
|
|
163
|
+
elif not n:
|
|
164
|
+
from sage.graphs.graph import Graph
|
|
165
|
+
return (0, Graph())
|
|
166
|
+
|
|
167
|
+
cdef int i
|
|
168
|
+
|
|
169
|
+
if sage_graph_to_matrix(G):
|
|
170
|
+
raise RuntimeError("there has been a mistake while converting the Sage "
|
|
171
|
+
"graph to a C structure, the memory is probably "
|
|
172
|
+
"insufficient (2^(n+1) is a *LOT*)")
|
|
173
|
+
|
|
174
|
+
for i in range(n + 1):
|
|
175
|
+
|
|
176
|
+
if verbose:
|
|
177
|
+
print("Calculating for subsets of size ", i, "/", n + 1)
|
|
178
|
+
|
|
179
|
+
# We want to properly deal with exceptions, in particular
|
|
180
|
+
# KeyboardInterrupt. Whatever happens, when this code fails the memory
|
|
181
|
+
# *HAS* to be freed, as it is particularly greedy (a graph of 29
|
|
182
|
+
# vertices already requires more than 1GB of memory).
|
|
183
|
+
|
|
184
|
+
if not sig_on_no_except():
|
|
185
|
+
destroy_rw()
|
|
186
|
+
cython_check_exception()
|
|
187
|
+
|
|
188
|
+
# Actual computation
|
|
189
|
+
calculate_level(i)
|
|
190
|
+
sig_off()
|
|
191
|
+
|
|
192
|
+
cdef int rank_width = <int> get_rw()
|
|
193
|
+
|
|
194
|
+
# Original way of displaying the decomposition
|
|
195
|
+
# print_rank_dec(0x7ffffffful >> (31 - num_vertices), 0)
|
|
196
|
+
g = mkgraph(n)
|
|
197
|
+
|
|
198
|
+
# Free the memory
|
|
199
|
+
destroy_rw()
|
|
200
|
+
|
|
201
|
+
return (rank_width, g)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
cdef int sage_graph_to_matrix(G) noexcept:
|
|
205
|
+
r"""
|
|
206
|
+
Convert the given Sage graph as an adjacency matrix.
|
|
207
|
+
"""
|
|
208
|
+
global id_to_vertices
|
|
209
|
+
global vertices_to_id
|
|
210
|
+
global adjacency_matrix
|
|
211
|
+
global cslots
|
|
212
|
+
|
|
213
|
+
cdef int num_vertices = G.order()
|
|
214
|
+
|
|
215
|
+
# Prepares the C structure for the computation
|
|
216
|
+
if init_rw_dec(num_vertices):
|
|
217
|
+
# The original code does not completely frees the memory in case of
|
|
218
|
+
# error
|
|
219
|
+
destroy_rw()
|
|
220
|
+
return 1
|
|
221
|
+
|
|
222
|
+
memset(adjacency_matrix, 0, sizeof(subset_t) * num_vertices)
|
|
223
|
+
|
|
224
|
+
# Initializing the lists of vertices
|
|
225
|
+
cdef int i
|
|
226
|
+
id_to_vertices = list(G)
|
|
227
|
+
vertices_to_id = {v: i for i, v in enumerate(id_to_vertices)}
|
|
228
|
+
|
|
229
|
+
# Filling the matrix
|
|
230
|
+
for u, v in G.edge_iterator(labels=False):
|
|
231
|
+
if u == v:
|
|
232
|
+
continue
|
|
233
|
+
set_am(vertices_to_id[u], vertices_to_id[v], 1)
|
|
234
|
+
|
|
235
|
+
# All is fine.
|
|
236
|
+
return 0
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
cdef uint_fast32_t bitmask(int i) noexcept:
|
|
240
|
+
return (1ul << i)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
cdef void set_am(int i, int j, int val) noexcept:
|
|
244
|
+
r"""
|
|
245
|
+
Set/Unset an arc between vertices i and j
|
|
246
|
+
|
|
247
|
+
(this function is a copy of what can be found in rankwidth/rw.c)
|
|
248
|
+
"""
|
|
249
|
+
global adjacency_matrix
|
|
250
|
+
|
|
251
|
+
adjacency_matrix[i] &= ~bitmask(j)
|
|
252
|
+
adjacency_matrix[j] &= ~bitmask(i)
|
|
253
|
+
|
|
254
|
+
if val:
|
|
255
|
+
adjacency_matrix[i] |= bitmask(j)
|
|
256
|
+
adjacency_matrix[j] |= bitmask(i)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
cdef void print_rank_dec(subset_t s, int l) noexcept:
|
|
260
|
+
r"""
|
|
261
|
+
Print the current rank decomposition as a text
|
|
262
|
+
|
|
263
|
+
This function is a copy of the C routine printing the rank-decomposition is
|
|
264
|
+
the original source code. It s not used at the moment, but can still prove
|
|
265
|
+
useful when debugging the code.
|
|
266
|
+
"""
|
|
267
|
+
global cslots
|
|
268
|
+
|
|
269
|
+
print('\t' * l, end="")
|
|
270
|
+
|
|
271
|
+
print("cslot: ", <unsigned int> s)
|
|
272
|
+
if not cslots[s]:
|
|
273
|
+
return
|
|
274
|
+
print_rank_dec(cslots[s], l + 1)
|
|
275
|
+
print_rank_dec(s & ~cslots[s], l + 1)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def mkgraph(int num_vertices):
|
|
279
|
+
r"""
|
|
280
|
+
Return the graph corresponding to the current rank-decomposition.
|
|
281
|
+
|
|
282
|
+
(This function is for internal use)
|
|
283
|
+
|
|
284
|
+
EXAMPLES::
|
|
285
|
+
|
|
286
|
+
sage: from sage.graphs.graph_decompositions.rankwidth import rank_decomposition
|
|
287
|
+
sage: g = graphs.PetersenGraph()
|
|
288
|
+
sage: rank_decomposition(g)
|
|
289
|
+
(3, Graph on 19 vertices)
|
|
290
|
+
"""
|
|
291
|
+
global cslots
|
|
292
|
+
global id_to_vertices
|
|
293
|
+
|
|
294
|
+
cdef subset_t s
|
|
295
|
+
|
|
296
|
+
from sage.graphs.graph import Graph
|
|
297
|
+
g = Graph()
|
|
298
|
+
|
|
299
|
+
cdef subset_t * tab = <subset_t *>check_allocarray(2 * num_vertices - 1, sizeof(subset_t))
|
|
300
|
+
tab[0] = 0x7ffffffful >> (31 - num_vertices)
|
|
301
|
+
|
|
302
|
+
cdef int beg = 0
|
|
303
|
+
cdef int end = 1
|
|
304
|
+
|
|
305
|
+
while beg != end:
|
|
306
|
+
|
|
307
|
+
s = tab[beg]
|
|
308
|
+
beg += 1
|
|
309
|
+
|
|
310
|
+
if not cslots[s]:
|
|
311
|
+
continue
|
|
312
|
+
|
|
313
|
+
g.add_edge(bitset_to_vertex_set(s), bitset_to_vertex_set(s & ~cslots[s]))
|
|
314
|
+
g.add_edge(bitset_to_vertex_set(s), bitset_to_vertex_set(cslots[s]))
|
|
315
|
+
|
|
316
|
+
tab[end] = s & ~cslots[s]
|
|
317
|
+
end += 1
|
|
318
|
+
tab[end] = cslots[s]
|
|
319
|
+
end += 1
|
|
320
|
+
|
|
321
|
+
sig_free(tab)
|
|
322
|
+
return g
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
cdef bitset_to_vertex_set(subset_t s):
|
|
326
|
+
"""
|
|
327
|
+
Return as a Set object the set corresponding to the given subset_t
|
|
328
|
+
variable.
|
|
329
|
+
"""
|
|
330
|
+
from sage.rings.integer import Integer
|
|
331
|
+
from sage.sets.set import Set
|
|
332
|
+
from sage.data_structures.bitset import FrozenBitset
|
|
333
|
+
return Set(list(FrozenBitset((Integer(<unsigned int> s).binary())[::-1])))
|