Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/graphs/graph_decompositions/rankwidth_c/rw.h
8819 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
subset_t *adjacency_matrix;
38
39
// Output rank-decomposition
40
// This array is meant to contain max{f(Y), w(f, Y)} at the position corresponding to Y.
41
static uint_fast8_t *slots;
42
subset_t *cslots;
43
44
// Initialization (for getting rank-width only). Returns 0 on success.
45
//int init_rw(uint_fast8_t n);
46
47
// Initialization (for getting both rank-width and rank-decomposition). Returns 0 on success.
48
int init_rw_dec(uint_fast8_t n);
49
50
// Free memory allocated during initialization.
51
void destroy_rw(void);
52
53
// Calculate everything. May take some time.
54
void calculate_all(void);
55
56
// Calculate a single level only
57
void calculate_level(uint_fast8_t subset_size);
58
59
// Get the rank-width.
60
uint_fast8_t get_rw(void);
61
62
static uint_fast8_t subset_size;
63
64
static uint_fast8_t num_vertices;
65
66