The very_nauty graph library - version 1.0

This is a C library of graph algorithms, especially targeted at exact clique number and chromatic number computation. The name comes from the fact that it is designed to be compatible with Brendan McKay's nauty software, which is mainly concerned with graph generation and isomorphism testing. Also, since the problems here are NP-complete, it's a bit naughty to even attempt them. But the basic philosophy is that such calculations become more and more feasible as computers get faster. This gives us powerful ways of checking conjectures in graph theory, and also for checking the accuracy of asymptotic formulas. In practice, it's possible to use the exact algorithms on graphs with up to a few hundred nodes. For some results computed with this software see:

basic graph functions and macros

All graphs are simple and undirected. They are represented internally by (dense) adjacency lists.

graph_ttype of a graph
graph_t graph_new(unsigned int n);return a new empty graph with n nodes labelled 0..n-1
void graph_clear(graph_t g);destroy a graph
void graph_empty(graph_t g);set to the empty graph
void graph_add_edge(graph_t g,node_t i,node_t j);add undirected edge i--j to the graph
void graph_add_node(graph_t g);add a node to the graph
nnodes(g)number of nodes in g
nedges(g)number of edges in g
graph_node_degree(graph_t g, node_t i);degree of a node
int graph_max_degree(graph_t g);maximum degree of a node in g
double graph_mean_degree(graph_t g);return mean degree of the nodes of g
void graph_show(graph_t g);list edges of g to stdout
void graph_make_dotfile(graph_t g, char* fn);write a dotfile suitable for processing by graphviz
void graph_make_dotfile_colored(graph_t g, char* fn);write a colored dotfile suitable for processing by graphviz
void graph_to_dimacs(graph_t g, char* fn);write graph to a file named fn in DIMACS format
void graph_to_theta(graph_t g, char* fn);write graph to a file named fn in a format suitable for reading by Benson's Lovász theta program
int graph_nclusters(graph_t g);the number of clusters (connected components) in g
int graph_connected(graph_t g);1 if g is connected, else 0
cluster(g,i)cluster to which node i belongs (valid only after a call to graph_greedy_color)

random graph generation

void graph_gnp(graph_t g,double p);generate an instance of the Bernoulli random graph G(n,p)
void graph_grg(graph_t g,double r);generate an instance of the geometric random graph GRG(n,r). This has n nodes in the unit square, with each pair linked if their separation is less than r
void graph_grg_torus(graph_t g,double r);as the previous function, in a unit-area torus instead of a square

clique number (ω) computation

int graph_clique_number(graph_t g);compute the exact clique number of g. Warning: this can take a long time for large graphs

coloring and chromatic number (χ) computation

int graph_greedy_color(graph_t g,int perm[]);color the nodes of g in the node order given by perm, which must be a permutation of 0..nnodes(g)-1, or NULL, in which case the identity permutation is used. This returns a rapidly computable upper bound to the chromatic number
int graph_sequential_color(graph_t g,int perm[],int ub);color the nodes of g in node order given by perm, aborting as soon as more than ub colors are used (in which case -1 is returned). This returns an upper bound to the chromatic number
int graph_sequential_color_repeat(graph_t g, int n);color g's nodes n times in different random orders, and return the number of colors used in the best coloring found. The larger n is, the tighter the upper bound to the chromatic number is likely to be
int graph_chromatic_number(graph_t g,clock_t timeout);compute the exact chromatic number of g. If the timeout value (in seconds) is not zero and is reached, return 0. Warning: this can take a long time for large graphs
color(g,i)color of node i in g (valid only after calling one of the coloring functions)
int graph_ncolors(graph_t g);number of colors used in a coloring of g
int graph_check_coloring(graph_t g);check that a node coloring is valid

histogram functions

Some convenience functions for collecting statistics (data restricted to non-negative integer values)...

histogram_t histogram_new(char* lbl);make a new histogram labelled lbl
void histogram_add(histogram_t h, int i);add datum i to h
void histogram_clear(histogram_t h);destroy h
void histogram_show(histogram_t h);print h to stdout
void histogram_write(FILE*,histogram_t h);write h to file
double histogram_mean(histogram_t h);compute the mean of h
unsigned int histogram_mode(histogram_t h);compute the mode of h
int histogram_biggest_done(histogram_t h, double eps);return 1 if the modal value has relative standard error less than eps, else 0
int histogram_mean_done(histogram_t h, double eps);return 1 if the mean has relative standard error less than eps, else 0
double histogram_quantile(histogram_t h, double q);compute the qth quantile of h (q=0.5 for the median)
histogram_t graph_geng_reader(FILE* f, int op(graph_t), char* lbl);iterate over graphs in file f (in graph6 or sparse6 format), applying op to each and returning a histogram
histogram_t graph_showg_reader(FILE* f, int op(graph_t), char* lbl);iterate over graphs in file f (in "showg -l0 -e" format), applying op to each and returning a histogram

download & installation

simple library usage example

stand-alone programs

The programs vn_graph_omega and vn_graph_chi are provided for computing clique and chromatic number of geng output. Examples:

acknowledgements