예제 #1
0
/* parseResult
 * Parses a message containing the graph adjacency matrix
 * Message format "[graphsize]:[graph adjacency matrix]"
 */
static void parseResult(char *pch) {
	/* Get gsize */
	pch = strtok(NULL, ":");
	int gsize = atoi(pch);

	/* Get Clique Count */
	pch = strtok(NULL, ":");
	int clCount = atoi(pch);

	/* Get matrix */
	pch = strtok(NULL, ":");
	int *g = ChartoGraph(pch, gsize);

	/* Verify integrity of g */
	int realCount = CliqueCount(g, gsize);

	/* Message is invalid */
	if (realCount != clCount) {
		fprintf(stderr, "Message could not be validated!\n");
		fprintf(stderr, "Clique count from message: %d, actual clique count: %d!\n", clCount, realCount);
		return;
	}

	/* Update scheduler */
	if(clCount == 0) {
		fprintf(stderr, "Counterexample successfully received!\n");
		if(gsize > _Scheduler->currCEsize) { /* Found a counterexample */
			/* Update Scheduler */
			_Scheduler->currCEsize = gsize;
			/* clear list and add new counterexample */
			free_dllist(_Scheduler->counterExamples);
			_Scheduler->counterExamples = new_dllist();
			_Scheduler->listSize = 0;
			addCounterExample(g);
			/* Update current pointer */
			_Scheduler->currPtr = dll_first(_Scheduler->counterExamples);
			/*print only when save a counterexample*/
			fprintf(stderr, "get a counterexample with bigger size, size: %d\n, currCEsize: %d\n", gsize, _Scheduler->currCEsize);
			/* Save counterexample into a file */
			SaveGraph(g,gsize, "../../../counterexamples");
		}
		/* Just add new counterexample */
		else if(gsize == _Scheduler->currCEsize) {
				fprintf(stderr, "Saving a counterexample with same size\n");
				addCounterExample(g);
				SaveGraph(g,gsize, "../../../counterexamples");
		}
	}
}
예제 #2
0
파일: mining_2.c 프로젝트: fenghuo/RichCoin
void GoodCopy(int*o,int os,int*n,int ns)
{
	int i,count,c;
	int * ng = (int *)malloc((ns)*(ns)*sizeof(int));
	count=IMAX;
	for(i=0;i<ns/10;i++)
	{
		CopyGraph(o,os,ng,ns);
		c = CliqueCount(ng,ns);
		printf("%d\n",c);
		if(c<count)
		{
			memcpy(n,ng,ns*ns*sizeof(int));
			count=c;
		}
	}
	free(ng);
}
예제 #3
0
void try_flip_2_edge(int *g, int gsize, int &best_count_2, std::vector<int> &best_K, int best_start, int *nd, bool flip_new){
    int i;
    int j;
    int k;
    int l;
    int cnt;
    size_t m;
    size_t n;
    size_t sz = best_K.size();

    best_count_2 = BIGCOUNT;

    for(m=best_start; m<sz; m++){
        for(n=m+1; n<sz; n++){
            /*
            flip
            */
            i = getI(best_K[m]);
            j = getJ(best_K[m]);
            k = getI(best_K[n]);
            l = getJ(best_K[n]);
            g[ i*gsize + j ] = 1 - g[ i*gsize + j ];
            g[ k*gsize + l ] = 1 - g[ k*gsize + l ];
            cnt = CliqueCount(g, gsize, flip_new);

            if( cnt < best_count_2 ){
                best_count_2 = cnt;
                nd[0] = i;
                nd[1] = j;
                nd[2] = k;
                nd[3] = l;
            }


            /*
            unflip
            */
            g[ i*gsize + j ] = 1 - g[ i*gsize + j ];
            g[ k*gsize + l ] = 1 - g[ k*gsize + l ];            

        }
    }

}
예제 #4
0
파일: paley.c 프로젝트: fenghuo/RichCoin
int
main(int argc,char *argv[])
{

	srand (time(NULL));

	/*
	 * start with graph of size 8
	 */

	//ReadDump(g);
	
	
	/*
	int og=gsize;
        gsize=100;
        new_g=(int*)malloc(gsize*gsize*sizeof(int));
        CopyGraph(g,og,new_g,gsize);
        free(g);
        g=new_g;
	draw(g,gsize);
	*/

	gsize=125 ;

	printf(" -- \n");

	g=build(gsize);

	PrintGraph(g,gsize);
	WriteGraph(g,gsize);

	count = CliqueCount(g,gsize);

	printf("%d : %d \n",gsize,count);


	return(0);

}
예제 #5
0
/*
flip 1 edge
*/
void flip_1_edge(int *g, int gsize, int i, int j, std::set<int> &ban_s, std::vector<int> &best_K, int &best_start, int &best_count, bool flip_new_edge_only){
    int key = getKey(i, j);
    int count;
    size_t sz;
    if(ban_s.count(key) == 0){
        /*
        flip
        */
        g[ i*gsize + j ] = 1 - g[ i*gsize + j ];
        count = CliqueCount(g, gsize, flip_new_edge_only );

        if(count <= best_count){

            if(count == best_count){
                best_K.push_back(key);
            }

            else{
                sz = best_K.size();
                if(sz == 0){
                    best_K.push_back(key);
                }
                else{
                    best_K[sz - 1] = key;
                    best_start = sz - 1;
                }

                best_count = count;
            }

        }
        /*
        unflip
        */ 
        g[ i*gsize + j ] = 1 - g[ i*gsize + j ];
    }   
}
예제 #6
0
int
main(int argc,char *argv[])
{
	int *g;
	int *new_g;
	int gsize;
	int count;
	int i;
	int j;
	int best_count;
	int best_i;
	void *f;
	char *key;

	/*
	 * start with graph of size 8
	 */
	gsize = 8;
	g = (int *)malloc(gsize*gsize*sizeof(int));
	if(g == NULL)
		exit(1);

	/*
	 * start out with all zeros
	 */
	memset(g,0,gsize*gsize*sizeof(int));

	/*
	 * make a fifo for the tabu list
	 */

	f = FIFOInitGraph(100000);

	if(f == NULL)
		exit(1);

	/*
	 * while we do not have a publishable result
	 */
	while(gsize < 102)
	{
		/*
		 * find out how we are doing
		 */
		count = CliqueCount(g,gsize);

		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
			printf("Eureka!  Counter-example found!\n");
			PrintGraph(g,gsize);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			CopyGraph(g,gsize,new_g,gsize+1);

			/*
			 * zero out the last column and last row
			 */
			for(i=0; i < (gsize+1); i++)
			{
				new_g[i*(gsize+1) + gsize] = 0; // last column
				new_g[gsize*(gsize+1) + i] = 0; // last row
			}

			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			f = FIFOResetGraph(f);

			/*
			 * keep going
			 */
			continue;
		}

		/*
		 * otherwise, we need to consider flipping an edge
		 *
		 * let's speculative flip each edge, record the new count,
		 * and unflip the edge.  We'll then remember the best flip and
		 * keep it next time around
		 *
		 * only need to work with upper triangle of matrix =>
		 * notice the indices
		 */
		best_count = 9999999;
		for(i=1; i <= gsize/2; i++)
		{
			/*
			 * flip the edges corresponding to this distance
			 */
			Recolor(g,gsize,i);
			count = CliqueCount(g,gsize);

			/*
			 * is it better and not already tabu?
			 */
			if((count < best_count) &&
				!FIFOFindGraph(f,g,gsize))
			{
				best_count = count;
				best_i = i;
			}

			/*
			 * flip it back
			 */
			Recolor(g,gsize,i);
		}
		
		/*
		 * keep the best flip we saw
		 */
		Recolor(g,gsize,best_i);
printf("size: %d best_count: %d, best distance: %d, color: %d, size: %d\n",
			gsize,
			best_count,
			best_i,
			g[0*gsize+best_i],
			FIFOCount(f));

		/*
		 * add this edge to the fifo
		 */
		if(best_count != 0)
			FIFOInsertGraph(f,g,gsize);

		MakeGraphKey(g,gsize,&key);
		free(key);


		/*
		 * rinse and repeat
		 */
	}

	FIFODeleteGraph(f);


	return(0);

}
예제 #7
0
파일: mining_2.c 프로젝트: fenghuo/RichCoin
int
main(int argc,char *argv[])
{
	int *g;
	int *new_g;
	int gsize;
	int count;
	int i;
	int j;
	int best_count;
	int best_i;
	int best_j;
	int best_x;
	int best_y;
	void *taboo_list;

	srand (time(NULL));

	/*
	 * start with graph of size 8
	 */
	gsize = 54;
	g = (int *)malloc(gsize*gsize*sizeof(int));
	if(g == NULL) {
		exit(1);
	}

	/*
	 * make a fifo to use as the taboo list
	 */
	taboo_list = FIFOInitEdge(TABOOSIZE);
	if(taboo_list == NULL) {
		exit(1);
	}

	/*
	 * start out with all zeros
	 */
	memset(g,0,gsize*gsize*sizeof(int));
	ReadGraph(g,gsize);

	/*
	int ns=gsize+10;

	new_g = (int *)malloc((ns)*(ns)*sizeof(int));
	//CopyGraph(g,gsize,new_g,ns);
	GoodCopy(g,gsize,new_g,ns);
	PrintGraph(new_g,ns);
	count = CliqueCount(new_g,ns);
	printf("%d\n",count);
	return ;
	*/
	/*
	 * while we do not have a publishable result
	 */

	int flag=1;
	int lastcount=IMAX;

	while(gsize < 102)
	{
		/*
		 * find out how we are doing
		 */
		count = CliqueCount(g,gsize);

		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
			printf("Eureka!  Counter-example found!\n");
			PrintGraph(g,gsize);
			WriteGraph(g,gsize);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			//CopyGraph(g,gsize,new_g,gsize+1);
			GoodCopy(g,gsize,new_g,gsize+1);

			/*
			 * zero out the last column and last row
			for(i=0; i < (gsize+1); i++)
			{
				new_g[i*(gsize+1) + gsize] = 0; // last column
				new_g[gsize*(gsize+1) + i] = 0; // last row
			}

			*/
			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			/*
			 * reset the taboo list for the new graph
			 */
			taboo_list = FIFOResetEdge(taboo_list);

			/*
			 * keep going
			 */
			continue;
		}

		/*
		 * otherwise, we need to consider flipping an edge
		 *
		 * let's speculative flip each edge, record the new count,
		 * and unflip the edge.  We'll then remember the best flip and
		 * keep it next time around
		 *
		 * only need to work with upper triangle of matrix =>
		 * notice the indices
		 */

		int x,y;
		best_count = BIGCOUNT;
		for(x=0; x < gsize*gsize; x++)
		{
			for(y=x; y < gsize*gsize; y++)
			{
				if(y%gsize < x%gsize)
					continue;
				// swap
				if(g[x]==g[y] && x!=y)
					continue;
					
				swap(g,x,y);

				count = CliqueCount(g,gsize);

				// * is it better and the i,j,count not taboo?
				if((count < best_count) && 
					!FIFOFindEdge(taboo_list,x,y))
//					!FIFOFindEdgeCount(taboo_list,i,j,count))
				{
					best_count = count;
					best_x = x;
					best_y = y;
				}

				// * flip it back
				swap(g,x,y);
			}
		}

		/*
		best_count = BIGCOUNT;
		for(i=0; i < gsize; i++)
		{
			for(j=i+1; j < gsize; j++)
			{
				// flip it
				g[i*gsize+j] = 1 - g[i*gsize+j];
				count = CliqueCount(g,gsize);

				// * is it better and the i,j,count not taboo?
				if((count < best_count) && 
					!FIFOFindEdge(taboo_list,i,j))
//					!FIFOFindEdgeCount(taboo_list,i,j,count))
				{
					best_count = count;
					best_i = i;
					best_j = j;
				}

				// * flip it back
				g[i*gsize+j] = 1 - g[i*gsize+j];
			}
		}
		*/
		if(best_count == BIGCOUNT) {
			printf("no best edge found, terminating\n");
			exit(1);
		}
	
		/*
		 * keep the best flip we saw
		 */
		//g[best_i*gsize+best_j] = 1 - g[best_i*gsize+best_j];

		swap(g,best_x,best_y);

		/*
		 * taboo this graph configuration so that we don't visit
		 * it again
		 */
		count = CliqueCount(g,gsize);
//		FIFOInsertEdge(taboo_list,best_i,best_j);
		FIFOInsertEdgeCount(taboo_list,best_i,best_j,count);
//		FIFOInsertEdge(taboo_list,best_x,best_y);

		/*		
		printf("ce size: %d, best_count: %d, swap: (%d,%d)\n",
			gsize,
			best_count,
			best_x,
			best_y
			);
		*/
		/*
		printf("ce size: %d, best_count: %d, best edge: (%d,%d), new color: %d\n",
			gsize,
			best_count,
			best_i,
			best_j,
			g[best_i*gsize+best_j]);
		*/
		/*
		 * rinse and repeat
		 */
	}

	FIFODeleteGraph(taboo_list);


	return(0);

}
예제 #8
0
int
main(int argc,char *argv[])
{
	int *g;
	int *new_g;
	int gsize;
	int count;
	int i;
	int j;
	int best_count;
	int best_i;
	int best_j;
	int best_k;
	void *taboo_list;
	int val,iter,jter;
	/*
	 * start with graph of size 8
	 */

	if (argc < 2) {
		gsize = 8;
		g = (int *)malloc(gsize*gsize*sizeof(int));
		if(g == NULL) {
			exit(1);
		}

	/*
	 * start out with all zeros
	 */
		memset(g,0,gsize*gsize*sizeof(int));
		val = 0, iter = 0, jter=0;
		for( iter=0; iter<gsize; iter++){
			for( jter = 0; jter< gsize; jter++){
				g[iter*gsize + jter]  = val;
				val = 1 - val; 
			}
		}
		PrintGraph(g, gsize);

	} else {

		gsize = atoi(argv[1]);
		g = (int *)malloc(gsize*gsize*sizeof(int));
		if(g == NULL) {
			exit(1);
        	}
		g = PaleyGraph(gsize);
	}
	/*
	 *make a fifo to use as the taboo list
	 */
        taboo_list = FIFOInitGraph(TABOOSIZE);
        if(taboo_list == NULL) {
                exit(1);
        }


	/*
	 * while we do not have a publishable result
	 */
	while(gsize < 206)
	{
		/*
		 * find out how we are doing
		 */
		count = CliqueCount(g,gsize);

		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
			printf("Eureka!  Counter-example found!\n");
			PrintGraph(g,gsize);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			CopyGraph(g,gsize,new_g,gsize+1);

			/*
			 * zero out the last column and last row
			 */
			for(i=0; i < (gsize+1); i++)
			{
				if(drand48() > 0.5) {
					new_g[i*(gsize+1) + gsize] = 0; // last column
					new_g[gsize*(gsize+1) + i] = 0; // last row
				}
				else
				{
					new_g[i*(gsize+1) + gsize] = 1; // last column
					new_g[gsize*(gsize+1) + i] = 1; // last row
				}
			}

			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			/*
			 * reset the taboo list for the new graph
			 */
			taboo_list = FIFOResetGraph(taboo_list);

			/*
			 * keep going
			 */
			continue;
		}

		/*
		 * otherwise, we need to consider flipping an edge
		 *
		 * let's speculative flip each edge, record the new count,
		 * and unflip the edge.  We'll then remember the best flip and
		 * keep it next time around
		 *
		 * only need to work with upper triangle of matrix =>
		 * notice the indices
		 */
		best_count = BIGCOUNT;
		for(i=0; i < gsize; i++)
		{
			for(j=i+1; j < gsize; j++)
			{
				/*
				 * flip two edges (i,j), (i,random(j) + 1) 
				 */
				int k = getRandomJ(gsize);
				g[i*gsize+j] = 1 - g[i*gsize+j];
				if (k == j)
					k = j + 1;
				g[i*gsize + k] = 1 - g[i*gsize + k];
				count = CliqueCount(g,gsize);

				/*
				 * is it better and the i,j,count not taboo?
				 */
				if((count < best_count) && 
					!FIFOFindGraph(taboo_list,g,gsize))
//					!FIFOFindEdgeCount(taboo_list,i,j,count) &&
//					!FIFOFindEdgeCount(taboo_list,i,k, count))
				{
					/* no need to store j + 1 */
					best_count = count;
					best_i = i;
					best_j = j;
					best_k = k;
				}

				/*
				 * flip it back
				 */
				g[i*gsize+j] = 1 - g[i*gsize+j];
				g[i*gsize+k] = 1 - g[i*gsize+k];
			}
		}

		if(best_count == BIGCOUNT) {
			printf("no best edge found, terminating\n");
			exit(1);
		}
		
		/*
		 * keep the best flip we saw
		 */
		g[best_i*gsize+best_j] = 1 - g[best_i*gsize+best_j];
		g[best_i*gsize + best_k] = 1 - g[best_i*gsize + best_k];

		/*
		 * taboo this graph configuration so that we don't visit
		 * it again
		 */
		count = CliqueCount(g,gsize);
		FIFOInsertGraph(taboo_list,g,gsize);
//		FIFOInsertEdgeCount(taboo_list,best_i,best_j,count);
//		FIFOInsertEdgeCount(taboo_list,best_i,best_k,count);

		printf("ce size: %d, best_count: %d, best edges: (%d,%d) (%d,%d), new colors: %d %d\n",
			gsize,
			best_count,
			best_i,
			best_j,
			best_i,
			best_k,
			g[best_i*gsize+best_j],
			g[best_i*gsize+best_k]);

		/*
		 * rinse and repeat
		 */
	}

	FIFODeleteGraph(taboo_list);


	return(0);

}
예제 #9
0
/*
search
flip new edge first
if stuck
flip all
*/
void tabu_search(){
    int *g;
    int *new_g;
    int gsize;
    int count;
    int i;
    int j;
    int best_count;
    int best_i;
    int best_j;

    /*
    some vars for storing result of flip_2_edge
    */
    int best_count_2;
    int node[4];    


    /*
    start with a graph of size 8
    */
    if( !ReadGraph("204.ce", &g, &gsize) ){
        fprintf(stderr, "cannot read\n" );
        fflush(stderr);
        exit(1);
    }




    bool flip_new_edge_only = true;
    int tabu_size;
    int stuck_num;
    int stuck_cnt;
    int stuck_threshold = 10;


    /*
    tabu list
    */
    std::set<int> ban_s;
    std::queue<int> ban_q;


    /*
    best_count's collector
    */
    std::vector<int> best_K;
    int best_start = 0;


    /*
    search
    */
    int ra1;
    int ra2;
    while(gsize < MAXSIZE){

        count = CliqueCount( g, gsize, flip_new_edge_only );

        best_K.clear();
        best_start = 0;


        if( count == 0 ){
            printf("...Euraka! Counter example FOUND!\n");
            PrintGraph(g, gsize);

            new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
            if(new_g == NULL) exit(1);

            CopyGraph( g, gsize, new_g, gsize + 1 );
 
            for(i=0; i<gsize+1; i++){
                ra1 = rand() % 2;
                if(ra1 == 0){
                    new_g[i*(gsize+1) + gsize] = 0;
                    new_g[gsize*(gsize+1) + i] = 0;
                }
                else{
                    new_g[i*(gsize+1) + gsize] = 1;
                    new_g[gsize*(gsize+1) + i] = 1;
                }
            }

            free(g);
            g = new_g;
            gsize++;

            ban_s.clear();
            clearQ(ban_q);


            flip_new_edge_only = true;
            stuck_num = 0;
            stuck_cnt = 0;

            continue;
        }


        best_count = BIGCOUNT;
        int key;
        size_t sz;

        best_count_2 = BIGCOUNT;

        if( flip_new_edge_only ){
            j = gsize - 1;
            for(i=0; i<gsize-1; i++){

                flip_1_edge(g, gsize, i, j, ban_s, best_K, best_start, best_count, true);
              
            }


        }

        else{

            /*
            flip 1 edge
            */
            for(i=0; i<gsize; i++){
                for(j=i+1; j<gsize; j++){
                    ra1 = rand() % 30;
                    if(ra1 == 0){
                        flip_1_edge(g, gsize, i, j, ban_s, best_K, best_start, best_count, false);
                    }
                }

            }

        }


        if(best_count == BIGCOUNT){
            printf("no best found, terminating..\n");
            exit(1);
        }

        
        sz = best_K.size();
        if(best_start < sz - 1){
            try_flip_2_edge(g, gsize, best_count_2, best_K, best_start, node, flip_new_edge_only);
        }



        tabu_size = (flip_new_edge_only)? gsize/4 : gsize + gsize;
        if(best_count <= best_count_2){
            /*
            flip 1 edge
            */

            ra1 = (best_start == sz - 1)? best_start : best_start + rand() % (sz - best_start);
            key = best_K[ra1];
            best_i = getI(key);
            best_j = getJ(key);
            g[ best_i*gsize + best_j ] = 1 - g[ best_i*gsize + best_j ];


            put_to_tabu_list(ban_q, ban_s, tabu_size, key);

            /*
            stuck?
            */
            if( flip_new_edge_only ){
                i = stuck_num - best_count;
                if( i < 0 ) i = -i;
                
                if( i < 3 ){
                    stuck_cnt++;
                    
                    if(stuck_cnt == stuck_threshold){
                        printf("stucked..\n.\n");
                        flip_new_edge_only = false;
                        stuck_cnt = 0;
                        stuck_num = 0;
                    }
                }
                else{
                    stuck_num = best_count;
                    stuck_cnt = 0;
                }
            }

            printf("ce size: %d, best_count: %d, best edge: (%d, %d), new color: %d\n", gsize, best_count, best_i, best_j, g[best_i*gsize + best_j]);

        }
        else{
            /*
            flip 2 edge
            */

            g[ node[0]*gsize + node[1] ] = 1 - g[ node[0]*gsize + node[1] ];
            g[ node[2]*gsize + node[3] ] = 1 - g[ node[2]*gsize + node[3] ];

            put_to_tabu_list(ban_q, ban_s, tabu_size, getKey(node[0], node[1]));
            put_to_tabu_list(ban_q, ban_s, tabu_size, getKey(node[0], node[1]));

            printf("ce size: %d, best_count: %d, best edge: (%d, %d), (%d, %d)\n", gsize, best_count_2, node[0], node[1], node[2], node[3]);

        }


        /*
        rinse and repeat
        */
    }


}
int
main(int argc,char *argv[])
{
	int *g;
	int *new_g;
	int gsize;
	int count;
	int i;
	int j;
	int best_count;
	int best_i;
	int best_j;
	int best_k;
	void *taboo_list;
	int val,iter,jter;
	char fname[255];
	FILE *fp;
    char bc[255];
    int fd;
	/*
	 * start with graph of size 8
	 */

	if (argc < 2) {
		gsize = 8;
		g = (int *)malloc(gsize*gsize*sizeof(int));
		if(g == NULL) {
			exit(1);
		}

	/*
	 * start out with all zeros
	 */
		memset(g,0,gsize*gsize*sizeof(int));
		val = 0, iter = 0, jter=0;
		for( iter=0; iter<gsize; iter++){
			for( jter = 0; jter< gsize; jter++){
				g[iter*gsize + jter]  = val;
				val = 1 - val; 
			}
		}
	//	PrintGraph(g, gsize);

	} else if (argc == 2) {

		gsize = atoi(argv[1]);
		g = (int *)malloc(gsize*gsize*sizeof(int));
		if(g == NULL) {
			exit(1);
        	}
		g = PaleyGraph(gsize);
	}
    else {
        char graphfile[256];
        strcpy(graphfile, argv[2]);
        gsize = atoi(argv[1]);
        //printf("gsize=%d", gsize);
        g = (int *)malloc(gsize*gsize*sizeof(int));
        ReadGraph(graphfile, &g, &gsize);
        printf("\nStarting from given graph of size %d\n.", gsize);
        fflush(stdout);
    }
	/*
	 *make a fifo to use as the taboo list
	 */
        taboo_list = FIFOInitEdge(TABOOSIZE);
        if(taboo_list == NULL) {
                exit(1);
        }


	/*
	 * while we do not have a publishable result
	 */
    
	while(gsize < 206)
	{
		/*
		 * find out how we are doing
		 */
		count = CliqueCount(g,gsize);

		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
		//	printf("Eureka! i Counter-example found!\n");
			sprintf(fname,"solutions/CE-%d.txt",gsize);
			fp = fopen(fname,"w");
			char *key;
			(void)MakeGraphKey(g,gsize,&key);
            PrintGraph(g,gsize,fp, key);    
            fclose(fp);
            /*
			if(gsize == 31)
			{
				FILE *fp;
				char buf[100];
				bzero(buf, 100);
				sprintf(buf, "graph_%d.state", gsize);
				printf("Filename: %s", buf); 
				fp = fopen(buf, "w+");
				PrintGraphToFile(g, gsize, fp);
				fclose(fp);
			}
            */
			free(key);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			CopyGraph(g,gsize,new_g,gsize+1);

			/*
			 * zero out the last column and last row
			 */
			for(i=0; i < (gsize+1); i++)
			{
				if(drand48() > 0.5) {
					new_g[i*(gsize+1) + gsize] = 0; // last column
					new_g[gsize*(gsize+1) + i] = 0; // last row
				}
				else
				{
					new_g[i*(gsize+1) + gsize] = 1; // last column
					new_g[gsize*(gsize+1) + i] = 1; // last row
				}
			}

			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			/*
			 * reset the taboo list for the new graph
			 */
			taboo_list = FIFOResetEdge(taboo_list);

			/*
			 * keep going
			 */
			continue;
		}

		/*
		 * otherwise, we need to consider flipping an edge
		 *
		 * let's speculative flip each edge, record the new count,
		 * and unflip the edge.  We'll then remember the best flip and
		 * keep it next time around
		 *
		 * only need to work with upper triangle of matrix =>
		 * notice the indices
		 */
		best_count = BIGCOUNT;
		for(i=0; i < gsize; i++)
		{
			for(j=i+1; j < gsize; j++)
			{
				/*
				 * flip two edges (i,j), (i,random(j) + 1) 
				 */
				int k = getRandomJ(gsize);
				g[i*gsize+j] = 1 - g[i*gsize+j];
				if (k == j)
					k = j + 1;
				g[i*gsize + k] = 1 - g[i*gsize + k];
				count = CliqueCount(g,gsize);

				/*
				 * is it better and the i,j,count not taboo?
				 */
				if((count < best_count) && 
//					!FIFOFindEdge(taboo_list,i,j))
					!FIFOFindEdgeCount(taboo_list,i,j,count) &&
					!FIFOFindEdgeCount(taboo_list,i,k, count))
				{
					/* no need to store j + 1 */
					best_count = count;
					best_i = i;
					best_j = j;
					best_k = k;
				}

				/*
				 * flip it back
				 */
				g[i*gsize+j] = 1 - g[i*gsize+j];
				g[i*gsize+k] = 1 - g[i*gsize+k];
			}
		}

		if(best_count == BIGCOUNT) {
			printf("no best edge found, terminating\n");
			exit(1);
		}
		
		/*
		 * keep the best flip we saw
		 */
		g[best_i*gsize+best_j] = 1 - g[best_i*gsize+best_j];
		g[best_i*gsize + best_k] = 1 - g[best_i*gsize + best_k];

		/*
		 * taboo this graph configuration so that we don't visit
		 * it again
		 */
		count = CliqueCount(g,gsize);
//		FIFOInsertEdge(taboo_list,best_i,best_j);
		FIFOInsertEdgeCount(taboo_list,best_i,best_j,count);
		FIFOInsertEdgeCount(taboo_list,best_i,best_k,count);
/*
		printf("ce size: %d, best_count: %d, best edges: (%d,%d) (%d,%d), new colors: %d %d\n",
			gsize,
			best_count,
			best_i,
			best_j,
			best_i,
			best_k,
			g[best_i*gsize+best_j],
			g[best_i*gsize+best_k]);
*/	
        /* write update to file */	
	    sprintf(fname,"solutions/CE-%d-upd.txt",gsize);
        sprintf(bc,"%d",best_count);
        fp = fopen(fname, "w+");
        if (fp == NULL) {
            printf("\n Ah file error ? \n");
            exit(0);
    
        }
        fd = fileno(fp);
        ftruncate(fd, 0);
        PrintGraph(g,gsize,fp, bc);
	    fclose(fp);	
		/*
		 * rinse and repeat
		 */
	}

	FIFODeleteGraph(taboo_list);


	return(0);

}
예제 #11
0
int main(int argc,char *argv[])
{
	printf("Setting up signals \n");
	signal(SIGINT, sig_handler);
	signal(SIGTERM, sig_handler);

	int *g;
	int *new_g;
	int gsize;
	int count;
	int i;
	int j;
	int best_count;
	int best_i;
	int best_j;
	void *taboo_list;
	int val,iter,jter;
	int gt[2];
	int t=INITEM;
	int sock = -1;

	char Fname[255];	
	char c; 
	
	int ilim = 8;
	while((c = getopt(argc,argv,ARGS)) !=  EOF)
	{
		switch(c)
		{
			case 'f':
				strncpy(Fname,optarg,sizeof(Fname));
				break;
			
			case 'l':
				printf("optarg: %s", optarg);
				ilim = atoi(optarg);
				break;

			default:
				fprintf(stderr,
				"test_clique_count  unrecognized argument: %c\n",c);
				fflush(stderr);
				break;
		}
	}


	if(!ReadGraph(Fname,&g,&gsize))
	{
		gsize = ilim;
		g = PaleyGraph(ilim);
	}

	/*
	 * make a fifo to use as the taboo list
	 */
	taboo_list = FIFOInitEdge(TABOOSIZE);
	if(taboo_list == NULL) {
		exit(1);
	}


	int best_clique = INITEM;
	int flag = 0; int min_count = BIGCOUNT;
	//int term = atoi(argv[1]);

	/*
	 * while we do not have a publishable result
	 */
	while(gsize <= ilim)
	{

		printf("Graph size is %d\n", gsize);
		/*
		 * find out how we are doing
		 */
		count = CliqueCount(g,gsize);
		int * cliques = (int*)malloc( (gsize)* (gsize) *sizeof(int));
		memset (cliques,INICLI,(gsize)* (gsize));
		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
			printf("Eureka!  Counter-example found!\n");
			min_count = BIGCOUNT;

			FILE *fp;
			//printf("Filename: %s", buf);
			fp = fopen("result.state", "w");
			PrintGraphToFile(g, gsize, fp);
			fclose(fp);

			//socket_upload_2(sock, -1, -1, count, gsize, g);
			

			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			CopyGraph(g,gsize,new_g,gsize+1);

			/*
			 * zero out the last column and last row
			 */
			for(i=0; i < (gsize+1); i++)
			{
				if(drand48() > 0.5) {
					new_g[i*(gsize+1) + gsize] = 0; // last column
					new_g[gsize*(gsize+1) + i] = 0; // last row
				}
				else
				{
					new_g[i*(gsize+1) + gsize] = 1; // last column
					new_g[gsize*(gsize+1) + i] = 1; // last row
				}
			}

			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			/*
			 * reset the taboo list for the new graph
			 */
			taboo_list = FIFOResetEdge(taboo_list);

			/*
			 * keep going
			 */
			continue;
		}

		/*
		 * otherwise, we need to consider flipping an edge
		 *
		 * let's speculative flip each edge, record the new count,
		 * and unflip the edge.  We'll then remember the best flip and
		 * keep it next time around
		 *
		 * only need to work with upper triangle of matrix =>
		 * notice the indices
		 */
		best_clique = INICLI;		

		time_t tim;
		srand((unsigned) time(&tim));

		// Introducing randomization into system
		int choice = rand() % 10;
		printf("choice: %d \n", choice);
		if (choice == 0){
			i=rand()%gsize;
			j=rand()%gsize;
			while (FIFOFindEdge(taboo_list,i,j)){
				i=rand()%gsize;
				j=rand()%gsize;
			}
			gt[0]=i;
			gt[1]=j;
			g[gt[0]*gsize+gt[1]] = 1 - g[gt[0]*gsize+gt[1]];

			// Getting clique count of edges on flipping - assuming random move is best
			best_clique=CliqueCount_D(g,gsize,gt[0],gt[1], 0);

			g[gt[0]*gsize+gt[1]] = 1 - g[gt[0]*gsize+gt[1]];
		}
		else{

			for(i=0; i < gsize; i++)
			{
				for(j=i+1; j < gsize; j++)
				{
					if(!FIFOFindEdge(taboo_list,i,j)){
						// Clique Count without flip
						int old_clique = CliqueCount_D(g,gsize,i,j, 0);

						// Clique Count with flip
						int new_clique = CliqueCount_D(g,gsize,i,j, 1);

						// Improvement with flip
						cliques[i*gsize+j] = count + new_clique - old_clique;

					}
				}
			}

			// Finding edges in clique
			for(i=0; i < gsize; i++)
			{
				for(j=i+1; j < gsize; j++)
				{
					if(!FIFOFindEdge(taboo_list,i,j) )
					{
						if(cliques[i*gsize+j] < best_clique )
						{
							best_clique = cliques[i*gsize+j];
							gt[0] = i;
							gt[1] = j;
						}
					}
				}

			}
		}

		printf("2\n");

		if(min_count > count)
		{
			min_count = count;
		}

		if (best_clique <= count){
			g[gt[0]*gsize+gt[1]] = 1 - g[gt[0]*gsize+gt[1]];

			if( CliqueCount(g, gsize) > count)
			{
				g[gt[0]*gsize+gt[1]] = 1 - g[gt[0]*gsize+gt[1]];				
			}
		}

		printf("3\n");

		FIFOInsertEdge(taboo_list,gt[0],gt[1]);
		
		printf("4\n");		
		
		t-=DTEM;	
		if (t==0){
			t=INITEM;
		}

		printf("5\n");		
		
		//socket_upload_2(sock, gt[0], gt[1], count, gsize, g);
		printf("size: %d, temperature: %d, count: %d, best_clique: %d\n", gsize, t, count, best_clique);

		free(cliques);

		g_latest = g;
		g_size_latest = gsize;
		g_count_latest = count;
	}

	FIFODeleteGraph(taboo_list);


	return(0);

}
int
main(int argc,char *argv[])
{
	signal(SIGINT, sig_handler);
	signal(SIGTERM, sig_handler);
	
	int *g;
	int *new_g;
	int gsize;
	long count;
	long count_1;
	long count_2;
	long count_3;
	int i;
	int j;
	int k;
	long best_count;
	long prev_best_count;
	int best_i;
	int best_j;
	int best_k;
	int best_l;
	void *taboo_list;
	int* taboo_array;
	int val,iter,jter;
	int multi = 0;
	/*
	 * start with graph of size 8
	 */

	if (argc < 2) {
		gsize = 8;
		g = (int *)malloc(gsize*gsize*sizeof(int));
		if(g == NULL) {
			exit(1);
		}

	/*
	 * start out with all zeros
	 */
		memset(g,0,gsize*gsize*sizeof(int));
		val = 0, iter = 0, jter=0;
		for( iter=0; iter<gsize; iter++){
			for( jter = 0; jter< gsize; jter++){
				g[iter*gsize + jter]  = val;
				val = 1 - val; 
			}
		}
		PrintGraph(g, gsize);

	} else if (argc == 2) {

		gsize = atoi(argv[1]);
		g = (int *)malloc(gsize*gsize*sizeof(int));
		if(g == NULL) {
			exit(1);
        	}
		g = PaleyGraph(gsize);
		int* row = (int *)malloc(gsize*sizeof(int));
		memcpy(row, g, gsize*sizeof(int));
		create_sgraph(&g, gsize, row);
		taboo_array = (int*)malloc(sizeof(int)*gsize);
		memset(taboo_array, 0, gsize*sizeof(int));
		printf("Starting from Paley graph of size %d\n.", gsize);
		fflush(stdout);
		free(row);
	}
	else {
		gsize = atoi(argv[1]);
		g = (int *)malloc(gsize*gsize*sizeof(int));
		ReadGraph(argv[2], &g, &gsize);
		count = CliqueCount(g,gsize);
		if (count == 0)
		{
			printf("Eureka!  Sym Counter-example found!\n");
			PrintGraph(g,gsize);
			fflush(stdout);
			
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			
			int* row = (int *)malloc((gsize+1)*sizeof(int));
			memcpy(row, g, gsize*sizeof(int));
			free(g);
			gsize = gsize+1;
			create_sgraph(&new_g, gsize, row);
			free(row);
			//CopyGraph(g,gsize,new_g,gsize+1);
			set_sedge(&new_g, gsize, gsize-1, 0);
			long count0  = CliqueCount(new_g, gsize);
			set_sedge(&new_g, gsize, gsize-1, 1);
			long count1  = CliqueCount(new_g, gsize);
			if(count0 < count1)
				set_sedge(&new_g, gsize, gsize-1, 0);
			taboo_array = (int*) malloc(sizeof(int)*gsize);
			memset(taboo_array, 0, sizeof(int)*gsize);
			g = new_g;
			
		}
		else
		{
			int* row = (int *)malloc(gsize*sizeof(int));
			memcpy(row, g, gsize*sizeof(int));
			create_sgraph(&g, gsize, row);
			taboo_array = (int*)malloc(sizeof(int)*gsize);
			memset(taboo_array, 0, gsize*sizeof(int));
			printf("Starting from given graph of size %d\n.", gsize);
			fflush(stdout);
			free(row);
		}
	}

	/*
	 *make a fifo to use as the taboo list
	 */
        taboo_list = FIFOInitEdge(TABOOSIZE);
        if(taboo_list == NULL) {
                exit(1);
        }


	/*
	 * while we do not have a publishable result
	 */
  while(gsize<206)
  {

	best_count = BIGCOUNT;
	while(gsize < 206)
	{
		best_j = -1;
		count = CliqueCount(g,gsize);
		if(count == 0)
		{
			printf("Eureka!  Sym Counter-example found!\n");
			PrintGraph(g,gsize);
			fflush(stdout);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			
			int* row = (int *)malloc((gsize+1)*sizeof(int));
			memcpy(row, g, gsize*sizeof(int));
			free(g);
			gsize = gsize+1;
			create_sgraph(&new_g, gsize, row);
			free(row);
			//CopyGraph(g,gsize,new_g,gsize+1);
			set_sedge(&new_g, gsize, gsize-1, 0);
			long count0  = CliqueCount(new_g, gsize);
			set_sedge(&new_g, gsize, gsize-1, 1);
			long count1  = CliqueCount(new_g, gsize);
			if(count0 < count1)
				set_sedge(&new_g, gsize, gsize-1, 0);
			taboo_array = (int*) malloc(sizeof(int)*gsize);
			memset(taboo_array, 0, sizeof(int)*gsize);
			g = new_g;

			best_count = BIGCOUNT;
			/*
			 * reset the taboo list for the new graph
			 */
			//taboo_list = FIFOResetEdge(taboo_list);
			free(taboo_array);
			taboo_array = (int*) malloc(sizeof(int)*gsize);
			memset(taboo_array, 0, sizeof(int)*gsize);

			continue;
		}
		

		//best_count = BIGCOUNT;
		prev_best_count = best_count;
		if(multi<5){
				for(i=0; i < gsize; i++)
				{
					
					flip_sedge(&g, gsize, i);
					count = CliqueCount(g,gsize);
					if(count<best_count && !taboo_array[i]){
					//if(count<best_count ){
						best_count = count;
						best_i = i;
					}
					flip_sedge(&g, gsize, i);
				}
		}
		else{
			for(i=0; i<gsize; i++){
				for(j=i+1; j<gsize; j++){
					flip_sedge(&g, gsize, i);
					flip_sedge(&g, gsize, j);
					count = CliqueCount(g,gsize);
					if(count<best_count){
						best_count = count;
						best_i = i;
						best_j = j;
					}
					flip_sedge(&g, gsize, i);
					flip_sedge(&g, gsize, j);
				}
			}
		}

		if(best_count == BIGCOUNT || best_count==prev_best_count) {
			if(multi>=5)
			{
				printf("no best edge found, continuing with taboo\n");
				fflush(stdout);
				break;
			}
			else
			{
				printf("single flip exhausted. starting singleflip again.", multi);
				fflush(stdout);
				memset(taboo_array, 0, sizeof(int)*gsize);
				multi ++;
				continue;
			}
			//flip_sedge(g, gsize, i);
		}
		flip_sedge(&g, gsize, best_i);
		count = best_count;
		if(multi)
			flip_sedge(&g, gsize, best_j);
		taboo_array[best_i] = 1;
		printf("sym ce size: %d, best_count: %ld, best edge(s): (%d), (%d)\n", gsize, best_count, best_i, best_j);
		g_latest = g;
		g_size_latest = gsize;
		g_count_latest = count;
		fflush(stdout);
	}

	while(gsize < 206)
	{
		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
			printf("Eureka!  Counter-example found!\n");
			PrintGraph(g,gsize);
			fflush(stdout);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			CopyGraph(g,gsize,new_g,gsize+1);

			/*
			 * zero out the last column and last row
			 */
			for(i=0; i < (gsize+1); i++)
			{
				if(drand48() > 0.5) {
					new_g[i*(gsize+1) + gsize] = 0; // last column
					new_g[gsize*(gsize+1) + i] = 0; // last row
				}
				else
				{
					new_g[i*(gsize+1) + gsize] = 1; // last column
					new_g[gsize*(gsize+1) + i] = 1; // last row
				}
			}

			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			/*
			 * reset the taboo list for the new graph
			 */
			taboo_list = FIFOResetEdge(taboo_list);

			/*
			 * keep going
			 */
			//continue;
			break; //Go to first while loop
		}

		/*
		 * otherwise, we need to consider flipping an edge
		 *
		 * let's speculative flip each edge, record the new count,
		 * and unflip the edge.  We'll then remember the best flip and
		 * keep it next time around
		 *
		 * only need to work with upper triangle of matrix =>
		 * notice the indices
		 */
		best_count = BIGCOUNT;
		for(i=0; i < gsize; i++)
		{
			for(j=i+1; j < gsize; j++)
			{
				/*
				 * flip two edges (i,j), (i,random(j) + 1) 
				 */
				int k = getRandomJ(gsize);
				int l = getRandomJ(gsize);

				g[i*gsize+j] = 1 - g[i*gsize+j];
				count_1 = CliqueCount(g,gsize);

				if (k == j)
					k = j + 1;
				g[i*gsize + k] = 1 - g[i*gsize + k];
				count_2 = CliqueCount(g,gsize);

				if (l == j)
					l = j + 1;
				if (l == k)
					l = (k + 1) % gsize;

				g[i*gsize + l] = 1 - g[i*gsize + l];
				count_3 = CliqueCount(g,gsize);

                                count = (count_1 < count_2) ? count_1 : count_2 ;
				count = (count_3 < count) ? count_3 : count ;

				/*
				 * is it better and the i,j,count not taboo?
				 */
				if(count < best_count){
					if(count == count_1
//#ifdef USE_TABOO
						&& !FIFOFindEdgeCount(taboo_list,i,j,count)
//#endif
						)
					{
						best_count = count;
						best_i = i;
						best_j = j;
						best_k = best_l = -1;
					}
					else if(count == count_2
//#ifdef USE_TABOO
						&& (!FIFOFindEdgeCount(taboo_list,i,j,count)
						|| !FIFOFindEdgeCount(taboo_list,i,k, count))
//#endif
						)
					{
						best_count = count;
						best_i = i;
						best_j = j;
						best_k = k;
						best_l = -1;
					}
					else if(count == count_3
//#ifdef USE_TABOO
						&& (!FIFOFindEdgeCount(taboo_list,i,j,count)
						|| !FIFOFindEdgeCount(taboo_list,i,k, count)
						|| !FIFOFindEdgeCount(taboo_list,i,l, count))
//#endif
						)
					{
						best_count = count;
						best_i = i;
						best_j = j;
						best_k = k;
						best_l = l;
					}
				} 

				/*
				 * flip it back
				 */
				g[i*gsize+j] = 1 - g[i*gsize+j];
				g[i*gsize+k] = 1 - g[i*gsize+k];
				g[i*gsize+l] = 1 - g[i*gsize+l];
			}
		}

		if(best_count == BIGCOUNT) {
			printf("no best edge found, terminating\n");
			exit(1);
		}
		
		/*
		 * keep the best flip we saw
		 */
		g[best_i*gsize + best_j] = 1 - g[best_i*gsize + best_j];
		if (best_k != -1)
			g[best_i*gsize + best_k] = 1 - g[best_i*gsize + best_k];
		if (best_l != -1)
			g[best_i*gsize + best_l] = 1 - g[best_i*gsize + best_l];

		/*
		 * taboo this graph configuration so that we don't visit
		 * it again
		 */
		//count = CliqueCount(g,gsize);
		count = best_count;
//#ifdef USE_TABOO
//		FIFOInsertEdge(taboo_list,best_i,best_j);
		FIFOInsertEdgeCount(taboo_list,best_i,best_j,count);
		if (best_k != -1)
			FIFOInsertEdgeCount(taboo_list,best_i,best_k,count);
		if (best_l != -1)
			FIFOInsertEdgeCount(taboo_list,best_i,best_l,count);
//#endif
		printf("ce size: %d, best_count: %ld, best edges: (%d,%d) (%d,%d) (%d,%d), new colors: %d %d\n",
			gsize,
			best_count,
			best_i,
			best_j,
			best_i,
			best_k,
			best_i,
			best_l,
			g[best_i*gsize+best_j],
			g[best_i*gsize+best_k]);

		fflush(stdout);
		g_latest = g;
		g_size_latest = gsize;
		g_count_latest = count;
		/*
		 * rinse and repeat
		 */
	}
  }

	FIFODeleteGraph(taboo_list);


	return(0);

}
예제 #13
0
int
main(int argc,char *argv[])
{
	int *g;
	int *new_g;
	int *new_edges;
	int seed = 1;
	int gsize;
	int count;
	int i;
	int j;
	int k;
	int best_count;
	int best_i;
	int best_j;
	void *taboo_list;

	/*
	 * start with graph of size 15
	 */
	gsize = 15;
	g = (int *)malloc(gsize*gsize*sizeof(int));
	if(g == NULL) {
		exit(1);
	}

	/*
	 * make a fifo to use as the taboo list
	 */
	taboo_list = FIFOInitEdge(TABOOSIZE);
	if(taboo_list == NULL) {
		exit(1);
	}

	/*
	 * start out with half 1 and half 0.
	 */
	InitGraph(g, gsize, seed);

	/*
	 * while we do not have a publishable result
	 */
	while(gsize < 102)
	{
		/*
		 * find out how we are doing
		 */
		count = CliqueCount(g,gsize);

		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
			printf("Eureka!  Counter-example found!\n");
			PrintGraph(g,gsize);
			OutputGraph(g,gsize, seed);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			CopyGraph(g,gsize,new_g,gsize+1);

			/*
			 * half-half the last column and zero out the last row
			 */
			new_edges = (int *)malloc(gsize*sizeof(int));
			InitEdges(new_edges, gsize, seed);
			k = 0;
			for(i=0; i < gsize; i++)
			{
				new_g[i*(gsize+1) + gsize] = new_edges[k]; // last column
				new_g[gsize*(gsize+1) + i] = 0; // last row
				k ++;
			}
			new_g[(gsize+1)*(gsize+1)] = 0;
			free(new_edges);

			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			/*
			 * reset the taboo list for the new graph
			 */
			taboo_list = FIFOResetEdge(taboo_list);

			/*
			 * keep going
			 */
			continue;
		}

		/*
		 * otherwise, we need to consider flipping an edge
		 *
		 * let's speculative flip each edge, record the new count,
		 * and unflip the edge.  We'll then remember the best flip and
		 * keep it next time around
		 *
		 * only need to work with upper triangle of matrix =>
		 * notice the indices
		 */
		best_count = BIGCOUNT;
		for(i=0; i < gsize; i++)
		{
			for(j=i+1; j < gsize; j++)
			{
				/*
				 * flip it
				 */
				g[i*gsize+j] = 1 - g[i*gsize+j];
				//printf("The best count is %d, and the count is %d.", best_count, count);
				count = CliqueCount_EA(g,gsize,best_count);
				//count = CliqueCount(g, gsize);
				/*
				 * is it better and the i,j,count not taboo?
				 */
				if((count < best_count) && 
//					!FIFOFindEdge(taboo_list,i,j))
				!FIFOFindEdgeCount(taboo_list,i,j,count))
				{
					best_count = count;
					best_i = i;
					best_j = j;
				}

				/*
				 * flip it back
				 */
				g[i*gsize+j] = 1 - g[i*gsize+j];
			}
		}

		if(best_count == BIGCOUNT) {
			printf("no best edge found, terminating\n");
			exit(1);
		}
		
		/*
		 * keep the best flip we saw
		 */
		g[best_i*gsize+best_j] = 1 - g[best_i*gsize+best_j];

		/*
		 * taboo this graph configuration so that we don't visit
		 * it again
		 */
		count = CliqueCount(g,gsize);
//		FIFOInsertEdge(taboo_list,best_i,best_j);
		FIFOInsertEdgeCount(taboo_list,best_i,best_j,count);

		printf("ce size: %d, best_count: %d, best edge: (%d,%d), new color: %d\n",
			gsize,
			best_count,
			best_i,
			best_j,
			g[best_i*gsize+best_j]);

		/*
		 * rinse and repeat
		 */
	}

	FIFODeleteGraph(taboo_list);


	return(0);

}