#include "generate.h" /* Title: Graph Color Hider file: randgraph.c Does: Generates a quasi-random k-coloring. Each vertex is assigned a certain color (several different methods of assigning colors may be used). Calling functions must pass a permutation of the vertices to prevent easy finding of the coloring. Source: Joseph Culberson's Coloring Page http://web.cs.ualberta.ca/~joe/Coloring/index.html Author: Joseph Culberson (original algorithms) Adam Beacham. Putting them all in one place, May 1995 Denis Papp. Numerous other vital modifications, May 1995 email: joe@cs.ualberta.ca abeacham@cs.ualberta.ca dpapp@cs.ualberta.ca Compilation: C Code Inputs: block - the blocking graph. Color sets in the graph to be genenerated appear as cliques in this graph. order - number of vertices numpart - number of color sets perm - a permutation of vertices. variab - variability, a parameter used in several types of k-colorings. (double) type - type of k-coloring to hide. (See comment for function initblock() ) Outputs: Returns the blocking graph in the parameter block. Stores the color of each vertex in the global array partset. Copyright: Joseph Culberson. Permission is granted to use and distribute freely for non-commercial purposes with appropriate attribution. Warranty: NONE! Special Instructions: Have fun! Part of: The k-colorable graph generator program. */ /* * firstclass() * GIVEN: partition # (c), order, number of partitions (numpart), delta value * RETURNS: the index of the first vertex of the partition-class c */ long firstclass(long c,long order,long numpart,long delta) { double m,v; if (c==0) return((long) 0); m = (double) (order *c)/((double) numpart); v = (double) (delta * c *(numpart-c)) / ((double) (numpart-1)); if (v > m) v=m; return((long) (m-v)); } /* * lastclass() * GIVEN: partition # (c), order, number of partitions (numpart), delta value * RETURNS: the index of the last+1 vertex of the partition-class c */ long lastclass(long c,long order,long numpart,long delta) { return(firstclass(c+1,order,numpart,delta)); } /* * initblock() * GIVEN: block graph, order, numpartitions, vertex permutation (perm), * variability, type of hidden coloring * DESC: creates a hidden coloring and assigns blocking edges to block * * type: 0 - equipartite (also used for random) * 1 - k-colorable * 2 - k-colorable (smooth) * 3 - delta * * NOTE: The global variable partset[], (defined in the * file cheat.c) is set by this function. * * Global variable partitionflag is set. * */ void initblock(char block[MAX_NR_VERTICES][MAX_NR_VERTICESdiv8], int order, int numpart, int *perm, double variab, int type) { int i, j, r; int firstv,lastv; double x, z, z1; /* Used in k-colorable (smooth) */ int colorcount[MAX_NR_VERTICES]; /* A count of colors used */ switch( type ) { case EQUIPARTITE: /* equipartite */ for( i=0; i