Path: blob/master/sage/graphs/graph_decompositions/rankwidth_c/rw.h
4097 views
// Calculate rank-width and rank-decompositions of graphs.12// Philipp Klaus Krause, [email protected], [email protected], 2009 - 20113// Copyright (c) 2009-2011 Philipp Klaus Krause45// This program is free software; you can redistribute it and/or modify6// it under the terms of the GNU General Public License as published by7// the Free Software Foundation; either version 2 of the License, or8// (at your option) any later version.9//10// This program is distributed in the hope that it will be useful,11// but WITHOUT ANY WARRANTY; without even the implied warranty of12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13// GNU General Public License for more details.14//15// You should have received a copy of the GNU General Public License along16// with this program; if not, write to the Free Software Foundation, Inc.,17// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.1819// 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.20// On 2009's computers it works quite well up to graph sizes of about 28 nodes.21// 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.2223#include <stdint.h>2425// 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).26// uint_leastN_t is faster than uint_fastN_t here, since the bottleneck is cache misses.27#ifndef __RANKWIDTH_H_SUBSET_T__28#define __RANKWIDTH_H_SUBSET_T__29typedef uint_least32_t subset_t;30#endif3132#define MAX_VERTICES 323334// Input graph.35//extern subset_t adjacency_matrix[NUM_VERTICES];36extern subset_t *adjacency_matrix;3738// Output rank-decomposition39extern subset_t *cslots;4041// Initialization (for getting rank-width only). Returns 0 on success.42//int init_rw(uint_fast8_t n);4344// Initialization (for getting both rank-width and rank-decomposition). Returns 0 on success.45int init_rw_dec(uint_fast8_t n);4647// Free memory allocated during initialization.48void destroy_rw(void);4950// Calculate everything. May take some time.51void calculate_all(void);5253// Calculate a single level only54void calculate_level(uint_fast8_t subset_size);5556// Get the rank-width.57uint_fast8_t get_rw(void);58596061