Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/graphs/graph_decompositions/rankwidth_c/rw.h
4097 views
1
// Calculate rank-width and rank-decompositions of graphs.
2
3
// Philipp Klaus Krause, [email protected], [email protected], 2009 - 2011
4
// Copyright (c) 2009-2011 Philipp Klaus Krause
5
6
// This program is free software; you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
10
//
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License along
17
// with this program; if not, write to the Free Software Foundation, Inc.,
18
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
// This is a program that calculates rank-width and rank-decompositions. It is based on ideas from "Computing rank-width exactly" by Sang-il Oum, "Sopra una formula numerica" by Ernesto Pascal and "Generation of a Vector from the Lexicographical Index" by B.P. Buckles and M. Lybanon.
21
// On 2009's computers it works quite well up to graph sizes of about 28 nodes.
22
// It is an implementation of the trivial algorithm from "Computing rank-width exactly". For larger graphs (more than about 40 nodes) the more algorithm based on fast subset convolution from the same paper would probably be faster.
23
24
#include <stdint.h>
25
26
// Use data type uint_leastN_t. N is an upper limit on the size of the graphs that can be handled. N=32 seems to be a good compromise for now (the code works well with other values of N).
27
// uint_leastN_t is faster than uint_fastN_t here, since the bottleneck is cache misses.
28
#ifndef __RANKWIDTH_H_SUBSET_T__
29
#define __RANKWIDTH_H_SUBSET_T__
30
typedef uint_least32_t subset_t;
31
#endif
32
33
#define MAX_VERTICES 32
34
35
// Input graph.
36
//extern subset_t adjacency_matrix[NUM_VERTICES];
37
extern subset_t *adjacency_matrix;
38
39
// Output rank-decomposition
40
extern subset_t *cslots;
41
42
// Initialization (for getting rank-width only). Returns 0 on success.
43
//int init_rw(uint_fast8_t n);
44
45
// Initialization (for getting both rank-width and rank-decomposition). Returns 0 on success.
46
int init_rw_dec(uint_fast8_t n);
47
48
// Free memory allocated during initialization.
49
void destroy_rw(void);
50
51
// Calculate everything. May take some time.
52
void calculate_all(void);
53
54
// Calculate a single level only
55
void calculate_level(uint_fast8_t subset_size);
56
57
// Get the rank-width.
58
uint_fast8_t get_rw(void);
59
60
61