Пример #1
0
// Test subgraphs
void TestSubTUNGraphs() {
  PUNGraph Graph;
  PUNGraph Graph1;
  PUNGraph Graph2;
  PUNGraph Graph3;
  int i;
  TIntV NIdV;
  TIntV NIdV1;

  Graph = GetTestTUNGraph();
  PrintGraph("TUNGraph", Graph);

  for (i = 10; i < 15; i++) {
    NIdV.Add(i);
  }

  Graph1 = TSnap::GetSubGraph(Graph, NIdV);
  PrintGraph("TUNGraph1", Graph1);

  Graph2 = TSnap::GetSubGraph(Graph, NIdV, true);
  PrintGraph("TUNGraph2", Graph2);

  for (i = 0; i < 20; i += 2) {
    NIdV1.Add(i);
  }

  Graph3 = TSnap::GetSubGraph(Graph, NIdV1, true);
  PrintGraph("TUNGraph3", Graph3);
}
Пример #2
0
// Test subgraphs
void TestSubTNEGraphs() {
  PNEGraph Graph;
  PNEGraph Graph1;
  PNEGraph Graph2;
  PNEGraph Graph3;
  int i;
  TIntV NIdV;
  TIntV NIdV1;
  TIntV EIdV;

  Graph = GetTestTNEGraph();
  PrintGraph("TNEGraph", Graph);

  for (i = 10; i < 15; i++) {
    NIdV.Add(i);
  }

  Graph1 = TSnap::GetSubGraph(Graph, NIdV);
  PrintGraph("TNEGraph1", Graph1);

  for (i = 0; i < 20; i += 2) {
    NIdV1.Add(i);
  }

  Graph2 = TSnap::GetSubGraph(Graph, NIdV1);
  PrintGraph("TNEGraph2", Graph2);

  for (i = 0; i < 120; i += 2) {
    EIdV.Add(i);
  }

  Graph3 = TSnap::GetESubGraph(Graph, EIdV);
  PrintGraph("TNEGraph3", Graph3);
}
Пример #3
0
void DisplayGraph(void)
{
  if (Event == EV_FUNC_FIRST)
  {
    LcdBlank(); /* Clear screen */
    GlobalDiapason = 0xFF;
    PrintGraph();
    return;
  }
  if ( (Event& EV_MASK) == EV_KEY_PRESSED )
  {
    switch (Event & KEY_MASK)
    {
      case KEY_ENTER:
        CurrentFunc(StartFunction);
        return;
      case KEY_DOWN:
      case KEY_UP:
        CurrentFunc(SetupGraph);
        return;
      case KEY_ADC:
      {
        int16_t ValueMin;
        int16_t ValueMax;
        uint8_t Next;


        ValueMin = GraphData.GraphArray[GraphCurrentPoint].Min;
        ValueMax = GraphData.GraphArray[GraphCurrentPoint].Max;
        if (ValueMin < GlobalMin || ValueMax > GlobalMax || /* Larger diapason */
            GraphCurrentPoint == GlobalMaxPoint || GraphCurrentPoint == GlobalMinPoint) /* Check Diapason */
        {
          PrintGraph();
          return;
        }

        Next = GraphCurrentPoint + 1;
        if ( Next >= GRAPH_SIZE)
          Next = 0;

        OutOneColumn(GraphData.GraphArray, GraphCurrentPoint);
        OutOneColumn(GraphData.GraphArray, Next);

        return;
      }
    }
  }
  return;
}
Пример #4
0
main()
{
 /* 此处添加你自己的代码 */
 OLGraph olg;
 CreateOLG(&olg);
 PrintGraph(&olg);
getch();
}
Пример #5
0
void PrintSub(Substructure *sub, Parameters *parameters)
{
   // parameters used
   LabelList *labelList = parameters->labelList;
   ULONG outputLevel = parameters->outputLevel;

   if (sub != NULL) 
   {
      printf("Substructure: value = %.*g", NUMERIC_OUTPUT_PRECISION,
             sub->value);
      // print instance/example statistics if output level high enough
      if (outputLevel > 2) 
      {
         printf("\n                  pos instances = %lu",sub->numInstances);
         if (parameters->incremental)
            printf(", pos examples = %lu\n",(ULONG) sub->posIncrementValue);
         else
            printf(", pos examples = %lu\n",sub->numExamples);

         printf("\n                  neg instances = %lu",sub->numNegInstances);
         if (parameters->incremental)
            printf(", neg examples = %lu\n",(ULONG) sub->negIncrementValue);
         else
            printf(", neg examples = %lu\n",sub->numNegExamples);
      } 
      else 
      {
         if ((parameters->incremental) && (parameters->evalMethod == EVAL_SETCOVER))
            printf(", pos examples = %lu, neg examples = %lu\n",
               (ULONG) sub->posIncrementValue, (ULONG) sub->negIncrementValue);
         else
            printf(", pos instances = %lu, neg instances = %lu\n",
                   sub->numInstances, sub->numNegInstances);
      }
      // print subgraph
      if (sub->definition != NULL) 
      {
         PrintGraph(sub->definition, labelList);
      }
      if (sub->recursive) 
      {
         printf("    re ");
         PrintLabel(sub->recursiveEdgeLabel, labelList);
         printf("\n");
      }
      // print instances if output level high enough
      if (outputLevel > 2) 
      {
         printf("\n  Positive instances:\n");
         PrintPosInstanceList(sub, parameters);
         if (sub->numNegInstances > 0) 
         {
            printf("\n  Negative instances:\n");
            PrintNegInstanceList(sub, parameters);
         }
      }
   }
}
Пример #6
0
int main()
{
	//그래프 생성
	Graph* G = CreateGraph();

	// 정점 생성
	Vertex* V1 = CreateVertex('1');
	Vertex* V2 = CreateVertex('2');
	Vertex* V3 = CreateVertex('3');
	Vertex* V4 = CreateVertex('4');
	Vertex* V5 = CreateVertex('5');

	// 그래프에 정점을 추가
	AddVertex(G, V1);
	AddVertex(G, V2);
	AddVertex(G, V3);
	AddVertex(G, V4);
	AddVertex(G, V5);

	// 정점과 정점을 간선으로 잇기
	AddEdge(V1, CreateEdge(V1, V2, 0));
	AddEdge(V1, CreateEdge(V1, V3, 0));
	AddEdge(V1, CreateEdge(V1, V4, 0));
	AddEdge(V1, CreateEdge(V1, V5, 0));

	AddEdge(V2, CreateEdge(V2, V1, 0));
	AddEdge(V2, CreateEdge(V2, V2, 0));
	AddEdge(V2, CreateEdge(V2, V5, 0));

	AddEdge(V3, CreateEdge(V3, V1, 0));
	AddEdge(V3, CreateEdge(V3, V2, 0));

	AddEdge(V4, CreateEdge(V4, V1, 0));
	AddEdge(V4, CreateEdge(V4, V5, 0));

	AddEdge(V5, CreateEdge(V5, V1, 0));
	AddEdge(V5, CreateEdge(V5, V2, 0));
	AddEdge(V5, CreateEdge(V5, V4, 0));

	PrintGraph(G);

	// 그래프 소멸
	DestroyGraph(G);

	return 0;
}
Пример #7
0
int main( void )
{
    /*  그래프 생성     */
    Graph* G = CreateGraph();
    
    /*  정점 생성 */
    Vertex* V1 = CreateVertex( '1' );
    Vertex* V2 = CreateVertex( '2' );
    Vertex* V3 = CreateVertex( '3' );
    Vertex* V4 = CreateVertex( '4' );
    Vertex* V5 = CreateVertex( '5' );

    /*  그래프에 정점을 추가 */
    AddVertex( G, V1 );
    AddVertex( G, V2 );
    AddVertex( G, V3 );
    AddVertex( G, V4 );
    AddVertex( G, V5 );

    /*  정점과 정점을 간선으로 잇기 */
    AddEdge( V1, CreateEdge(V1, V2, 0) );
    AddEdge( V1, CreateEdge(V1, V3, 0) );
    AddEdge( V1, CreateEdge(V1, V4, 0) );
    AddEdge( V1, CreateEdge(V1, V5, 0) );

    AddEdge( V2, CreateEdge(V2, V1, 0) );
    AddEdge( V2, CreateEdge(V2, V3, 0) );
    AddEdge( V2, CreateEdge(V2, V5, 0) );

    AddEdge( V3, CreateEdge(V3, V1, 0) );
    AddEdge( V3, CreateEdge(V3, V2, 0) );

    AddEdge( V4, CreateEdge(V4, V1, 0) );
    AddEdge( V4, CreateEdge(V4, V5, 0) );

    AddEdge( V5, CreateEdge(V5, V1, 0) );
    AddEdge( V5, CreateEdge(V5, V2, 0) );
    AddEdge( V5, CreateEdge(V5, V4, 0) );

    PrintGraph( G );

    /*  그래프 소멸 */
    DestroyGraph( G );

    return 0;
}
Пример #8
0
void test1()
{
  matrix *dmx;
  NewMatrix(&dmx, 4, 4);
  G *graph;

  dmx->data[0][1] = dmx->data[1][0] = 0.3;
  dmx->data[0][2] = dmx->data[2][0] = 0.4;
  dmx->data[0][3] = dmx->data[3][0] = 0.7;
  dmx->data[1][2] = dmx->data[2][1] = 0.9;
  dmx->data[1][3] = dmx->data[3][1] = 0.2;
  dmx->data[2][3] = dmx->data[3][2] = 0.1;
  PrintMatrix(dmx);
  NewGraph(&graph);
  GenerateAdjMX(dmx, 0.8, &graph);
  PrintGraph(graph);
  DelMatrix(&dmx);
  DelGraph(&graph);
}
Пример #9
0
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);

}
Пример #10
0
//--------------------------------------------------------------------------------------------------------赛题入口
void search_route(char *graphStream[5000], int edge_num, char *conditionsStream)
{
    Graph graph;
    EdgeInfoDict edgeInfoDict;
    int source;
    int dest;
    Conditions conditions;
    ShortestPathDict pathDict;


    ReadGraphData(graphStream, graph, edgeInfoDict);
    ReadConditionsData(conditionsStream, source, dest, conditions);

    std::set<int> without;
    without.insert(1);
    without.insert(2);
    Dijkstra(graph, edgeInfoDict, 1, pathDict);

    PrintGraph(graph, edgeInfoDict);
    PrintConditions(source, dest, conditions);
    PrintShortestPathDict(pathDict);
}
Пример #11
0
    static void PrintGraph(FunctionPtr function, int spaces, bool useName = false)
    {
        if (function->Inputs().size() == 0)
        {
            cout << string(spaces, '.') + "(" + ToString(useName ? function->Name() : function->Uid()) + ")" + ToString(function->AsString()) << std::endl;
            return;
        }

        for (auto input : function->Inputs())
        {
            cout << string(spaces, '.') + "(" + ToString(useName ? function->Name() : function->Uid()) + ")" + "->" +
                "(" + ToString(useName ? input.Name() : input.Uid()) + ")" + ToString(input.AsString()) << std::endl;
        }

        for (auto input : function->Inputs())
        {
            if (input.Owner() != NULL)
            {
                FunctionPtr f = input.Owner();
                PrintGraph(f, spaces + 4, useName);
            }
        }
    }
void sig_handler(int signum){
	printf("Caught signal %d\n", signum);
	//char filename[100] = "dump_";
	//char str_num[32];
	//sprintf(str_num, "%d.%d", g_size_latest, g_count_latest);
	//strcat(filename, str_num);
	if(g_latest != NULL){
		printf("Printing current graph with size: %d and count: %ld\n", g_size_latest, g_count_latest);
		PrintGraph(g_latest, g_size_latest);
		fflush(stdout);
	}
	else {
		printf("No graph to print :(\n");
	}
	if(signum == SIGINT){
		printf("Continuing..\n");
		fflush(stdout);
	}
	else if(signum == SIGTERM){
		printf("Exiting..\n");
		exit(signum);
		fflush(stdout);
	}
}
Пример #13
0
int main()
{
	/* Define the Graph */
	int Size;
	Size = GetSize( GRAPH_DATA );

	Graph G;
	G = MakeGraph( Size );

	/* Append Arcs */
	GetArcs(G, GRAPH_DATA);

	/* Print Graph */
	PrintGraph(G);

	/* Topological Sort */
	VertexType *Degree;
	Degree = InDegree(G);

	puts("\nDepth First Topological Sort");
	DfsTopSort(Degree, G);

	return 0;
}
Пример #14
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_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);

}
Пример #15
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);

}
Пример #16
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);

}
Пример #17
0
/*
partial version:
assuming the counter example is embeded
in the graph one size bigger
*/
void tabu_search_part(){
    int *g;
    int *new_g;
    int gsize;
    int count;
    int i;
    int j;
    int best_count;
    int best_i;
    int best_j;
    
    /*
    init tabu list which is made up by 1 set and 1 queue
    */
    std::set<int> ban_s;
    std::queue<int> ban_q;
    

    /*
    best_counts collector
    */
    std::vector<int> best_k;
    int best_start = 0;

    /*
    start with graph of size 8
    */
    gsize = 8;
    g = (int *)malloc(gsize*gsize*sizeof(int));
    if(g == NULL) exit(1);
    
    /*
    start out with a counter example
    */
    memset(g, 0, gsize*gsize*sizeof(int));
    g[0*gsize + 2] = 1;
    g[1*gsize + 4] = 1;
    
    /*
    search
    */
    int ra1;
    while(gsize < MAXSIZE){
        /*
        find how we are doing
        */
        count = CliqueCountPart(g, gsize);
        
        /*
        reset collecor
        */
        best_k.clear();
        best_start = 0;

        /*
        if we get a counter example
        */
        if(count == 0){
            printf("22222....Euraka! Counter 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++){
                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;
                }

            }

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

            /*
            reset the taboo list for the new graph
            */
            ban_s.clear();
            clearQ(ban_q);

            /*
            keep going
            */
            continue;
        
        }

        /*
        otherwise, random flip
        */
        best_count = BIGCOUNT;
        int key;
        size_t sz;

        /*
        unlike tabu_search_full, here we only
        flip the new edge, which is the last row
        amd last column
        */
        j = gsize - 1;
        for(i=0; i<gsize-1; i++){
            ra1 = rand() % 2;
            if(ra1 == 0){

                /*
                flip it
                */
                g[i*gsize + j] = 1 - g[i*gsize + j];
                count = CliqueCountPart(g, gsize);

                /*
                is it better and the i,j,count not tabu?
                */
                key = getKey(i, j);

                if(count <= best_count && ban_s.count(key) == 0){

                    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;

                }

                /*
                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
        */
        sz = best_k.size();
        ra1 = rand() % (sz - best_start);
        ra1 += 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];


        /*
        tabu this graph configuration so that we do not visit
        it again
        */
        if(ban_q.size() == TABOOSIZE_PART){
            ban_s.erase(ban_q.front());
            ban_q.pop();
        }

        ban_q.push(key);
        ban_s.insert(key);

    
        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
        */          
    
    }

}
Пример #18
0
int main(int argc, char *argv[])
{
  int i, option, paramsPrinted=0, supp;
  double SUPP;
  gnGraph **coherentDenseSubGraphs;
  
  /* pipeline parameters
  DO_MI          mutual information flag, either 0 or 1 for all runs
  DO_Z           z-score flag, used for PC & MI, 0 or 1 for all runs
  CO_DENSITY     minimum density for a dense subgraph in coherent dense subgraphs
  SG_DENSITY     minimum density for a dense subgraph in summary graph dense subgraphs
  SO_DENSITY     minimum density for a dense subgraph in second order dense subgraphs
  GENE_THRESHOLD gene threshold: average concentration a gene has to exceed to
                 be considered 'on' in Pearson's correlation
  PC_CUTOFF      minimum PC score for an edge to be included in a 1st-order graph:
                 for simple Pearson's, values >= PC are an edge
                 for DOZ, values >= PC and in top z-score slice are an edge
  SOG_CUTOFF     minimum similarity score for an edge to be included in a 
                 2nd-order graph for GenerateSecondOrderGraph()
  SUPPORT        an edge must exist in at least 'support' of the microarray 
                 data sets in order to be included in the summary graph 
                   
  ZPC_SLICE      z-score cutoff for PC
  ZMI_SLICE      z-score cutoff for MI
  
  mutual information
  DIM            joint probability matrix Dimension, mod 32 = 0
  MI_CUTOFF,     score that MI must be >= for an edge to be considered:
                 for DO_Z, values >= MI_CUTOFF and in top z-score slice are an edge
                 for simple mutual information, values >= MI_CUTOFF are an edge
  NEG_CUTOFF,    1) if using Mutual Information and only positive Pearson's 
                    Correlation to infer an edge, it must be above this value, 
                    i.e. no strong negative Pearson's should infer an edge, 
                    even if MI is high (the usual mode) 
                 2) if using negative Pearson's Correlation to infer an edge, it 
                    must be below this value (future experimental feature, only 
                    do positive PC for now)
  PEAK           central max of kernel density function
  SFACT          factor by which the sum of one gene's expression levels must
                 be less than the other for an MI calculation to proceed
  */

  FILE *fout;
  
  /* options parsing */
  while((option = getopt(argc, argv, "hV")) > 0)
  {
    switch(option)
    {
      case 'h':
        usage();
        return 0;
     
      case 'V':
        printf("ver: %s\n", VERSION);
        return 0;
       
      default: break;
    }
  }
  
  if(argc == 2)
  {
    /* start with SUPP high, and ratchet down until modules are detected */
    for(supp=9; supp>0; supp--)
    {
      SUPP = (double)supp * 0.1;
  
      fout = fopen("parameters", "w");
      if(fout==NULL)
      {
        fprintf(stderr, "codense: Error opening parameters file, exiting...\n");
        fflush(NULL);
        return 1;
      }
      
      /* set the pipeline parameters */
      fprintf(fout, "#define DO_MI             1\n");
      fprintf(fout, "#define DO_Z              1\n");
      fprintf(fout, "#define CO_DENSITY        0.7\n");
      fprintf(fout, "#define SG_DENSITY        0.7\n");
      fprintf(fout, "#define SO_DENSITY        0.7\n");
      fprintf(fout, "#define GENE_THRESHOLD    0.005\n");
      fprintf(fout, "#define PC_CUTOFF         0.7\n");
      fprintf(fout, "#define SOG_CUTOFF        0.5\n");
      fprintf(fout, "#define SUPPORT           %3.1lf\n", SUPP);
      fprintf(fout, "#define PLUS_CORREL       1\n");
      fprintf(fout, "#define COMINNODES        4\n");
      fprintf(fout, "#define SGMINNODES        4\n");
      fprintf(fout, "#define SOMINNODES        4\n");
      fprintf(fout, "#define ZPC_SLICE         0.015\n");
      fprintf(fout, "#define ZMI_SLICE         0.015\n");

      /* pipeline mutual information parameters */
      fprintf(fout, "#define DIM               512\n");
      fprintf(fout, "#define MI_CUTOFF         3.0\n");
      fprintf(fout, "#define NEG_CUTOFF        -0.25\n");
      fprintf(fout, "#define PEAK              256.0\n");
      fprintf(fout, "#define SFACT             10.0\n");
      fclose(fout);
      
      if(! paramsPrinted)
      {
        printf("\nparameters file:\n");
        system("cat parameters");
        paramsPrinted = 1;
      }
      
      printf("\ncomputing for SUPPORT = %3.1lf:\n", SUPP);
      
      coherentDenseSubGraphs = CodenseMI(argv[1]);
      if(coherentDenseSubGraphs != NULL)
      {
        i = 0;
        printf("coherentDenseSubGraphs returned:\n\n");
        while(coherentDenseSubGraphs[i])
          PrintGraph(coherentDenseSubGraphs[i++]);
	
        /* free coherentDenseSubGraphs */
        i = 0;
        while(coherentDenseSubGraphs[i])
          FreeGraph(coherentDenseSubGraphs[i++]);
	
        free(coherentDenseSubGraphs);
        printf("\n\n");
      }
      else
        printf("no coherentDenseSubGraphs returned\n\n");
    }
  }
  else usage();
  
  return 0;
}
Пример #19
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);

}
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);

}
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);

}
Пример #22
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
        */
    }


}
Пример #23
0
Файл: ft.c Проект: 8l/csolve
void
main(int argc, char *argv[])
{
  int            nVertex;
  int            nEdge;
  Vertices *  graph;
  struct rusage * rUBuf1;
  struct rusage * rUBuf2;

  nVertex = DEFAULT_N_VERTEX;
  nEdge = DEFAULT_N_EDGE;

  if(argc > 1)
  {
    nVertex = atoi(argv[1]);
    if(argc > 2)
    {
      nEdge = atoi(argv[2]);
      if(argc > 3)
      {
        srandom(atoi(argv[3]));
      }
    }
  }

  rUBuf1 = (struct rusage *)malloc(sizeof(struct rusage));
  assert(rUBuf1 != NULL);
  rUBuf2 = (struct rusage *)malloc(sizeof(struct rusage));
  assert(rUBuf1 != NULL);

  if(debug)
  {
    printf("Generating a connected graph ... ");
  }

  graph = GenGraph(nVertex, nEdge);

  if(debug)
  {
    printf("done\nFinding the mininmum spanning tree ... ");
  }

  getrusage(RUSAGE_SELF, rUBuf1);

  graph = MST(graph);

  getrusage(RUSAGE_SELF, rUBuf2);

  if(debug)
  {
    printf("done\nThe graph:\n");
    PrintGraph(graph);
    printf("The minimum spanning tree:\n");
    PrintMST(graph);
  }

  if(debug)
  {
    printf("Time spent in finding the mininum spanning tree:\n");
  }
  PrintRUsage(rUBuf1, rUBuf2);
#ifdef PLUS_STATS
  PrintDerefStats(stderr);
  PrintHeapSize(stderr);
#endif /* PLUS_STATS */
  exit(0);
}
Пример #24
0
gnGraph * CreateSummaryGraph(gnGraph **graphSet, 
                             int numberOfDataSets, 
                             double support)
{
  long i, j, k, edgeBufLen=0, numEdgeBufEdges, numLabels, numUniq, sum;
  char **edgeBuf, **uniqBuf, **uniqLabels;
  void *hit;
  double *edgeWghtBuf, sumOfWeights, threshold;
  gnGraph *sg;
  graphNode *tmp;
  
  threshold = support * numberOfDataSets;

#ifdef DEBUG_CSG
  printf("threshold = %lf = support = %lf * numberOfDataSets = %d\n",
          threshold, support, numberOfDataSets);
#endif

  /* temporary buffers to hold summary graph edges and weights */
  edgeBuf     = (char **)  malloc(BUFLEN*sizeof(char *));
  edgeWghtBuf = (double *) malloc(BUFLEN*sizeof(double));
  if(edgeBuf==NULL || edgeWghtBuf==NULL)
  {
    fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
    return NULL;
  }
  edgeBufLen = BUFLEN;

  /* count all labels */
  sum = 0;
  for(i=0; i<numberOfDataSets; i++)
    sum += graphSet[i]->numNodes;
    
  uniqLabels = (char **) malloc(sum*sizeof(char *));
  if(uniqLabels==NULL)
  {
    fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
    return NULL;
  }
  
  /* get all the labels from the datasets */
  k = 0;
  for(i=0; i<numberOfDataSets; i++)
    for(j=0; j<graphSet[i]->numNodes; j++)
      if(graphSet[i]->gnList)
        uniqLabels[k++] = graphSet[i]->gnList[j]->label;
  numLabels = k;
  
  /* uniq the list of all vertex labels */
  qsort((void *) uniqLabels, numLabels, sizeof(char *), compString);
  j = 0;
  for(i=j+1; i<numLabels; i++)
  {
    while(i<numLabels && !strcasecmp(uniqLabels[j], uniqLabels[i])) i++;
    if(i<numLabels) uniqLabels[++j] = uniqLabels[i];
  }
  numLabels = j+1;
  
  /* sort each gnList on labels so it can be searched with bsearch */
  for(i=0; i<numberOfDataSets; i++)
  {
#ifdef DEBUG_CSG
    printf("unsorted graph\n==============\n"); PrintGraph(graphSet[i]);
#endif
    qsort((void *) graphSet[i]->gnList,
                   graphSet[i]->numNodes,
                   sizeof(graphNode *), compGN);
#ifdef DEBUG_CSG
    printf("sorted graph\n============\n"); PrintGraph(graphSet[i]);
#endif
  }

  /* the summary graph */
  sg = (gnGraph *) malloc(sizeof(gnGraph));
  if(sg==NULL)
  {
    fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
    return NULL;
  }
  
  /* init graph with vertices */
  sg->numNodes  = numLabels;
  sg->gnList = (graphNode **) malloc(numLabels * sizeof(graphNode *));
  if((sg->gnList)==NULL)
  {
    fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
    return NULL;
  }
  
  for(i=0; i<numLabels; i++)
  {
    sg->gnList[i] = (graphNode *) malloc(sizeof(graphNode));
    if((sg->gnList[i])==NULL)
    {
      fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
      return NULL;
    }
    
    sg->gnList[i]->label = (char *) malloc(strlen(uniqLabels[i])+1);
    if((sg->gnList[i]->label)==NULL)
    {
      fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
      return NULL;
    }

    strcpy(sg->gnList[i]->label, uniqLabels[i]);
    sg->gnList[i]->numEdges = 0;
    
    sg->gnList[i]->edges       = NULL;
    sg->gnList[i]->edgeWeights = NULL;
  }

  /*
   We now have each graph of graphSet and the summary graph sorted on labels
   (since uniqLabels is sorted, summary graph is sorted).
   Add edges to the summary graph only if they occur enough times across
   the graphSet, i.e. the sum of the edge weights for an edge exceeds 
   threshold = support * numberOfDataSets
   So for every uniqLabel:
   1) look for that label in every graph of graphset
   2) collect all edges attached to it in every graph
   3) sum the edge weights for each edge.
  */
  for(i=0; i<numLabels; i++)
  {
    edgeBuf[0] = NULL;
    numEdgeBufEdges = 0;
    for(j=0; j<numberOfDataSets; j++)
    {
      hit = (void *)(graphSet[j]->gnList);
      hit = bsearch((void *)uniqLabels[i], hit, graphSet[j]->numNodes,    /* 1 */
                     sizeof(graphNode *), compStrGN);
      
      if(hit) /* collect edges attached to this vertex */
      {
        tmp = *(graphNode **)hit;
        for(k=0; k<tmp->numEdges; k++)
        {
          if(edgeBufLen < numEdgeBufEdges + tmp->numEdges)
          {
            edgeBuf     = (char **)  realloc(edgeBuf, 
                                            (numEdgeBufEdges+tmp->numEdges+BUFLEN) *
                                             sizeof(char *));
            edgeWghtBuf = (double *) realloc(edgeWghtBuf, 
                                            (numEdgeBufEdges+tmp->numEdges+BUFLEN) *
                                             sizeof(double));
            if(edgeBuf==NULL || edgeWghtBuf==NULL)
            {
              fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
              return NULL;
            }
            edgeBufLen = numEdgeBufEdges + tmp->numEdges + BUFLEN;
          }
          
          edgeBuf[numEdgeBufEdges]       = tmp->edges[k];                 /* 2 */
          edgeWghtBuf[numEdgeBufEdges++] = tmp->edgeWeights[k];
        }
      }
    }
    
    /*
     edgeBuf contains pointers to every vertex in graphSet that is connected to 
     the same label as the current vertex in the summary graph. Add those edges
     to the summary graph that exceed 'threshold', using as their weight the 
     average.
    */
    
    if(edgeBuf[0] != NULL) /* edges exist */
    { 
      /* uniq the list of vertices in edgeBuf */
      uniqBuf = (char **)  malloc(numEdgeBufEdges*sizeof(char *));
      if(uniqBuf==NULL)
      {
        fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
        return NULL;
      }
      
      for(k=0; k<numEdgeBufEdges; k++)
        uniqBuf[k] = edgeBuf[k];
        
      qsort((void *) uniqBuf, numEdgeBufEdges, sizeof(char *), compString);
      
      j = 0;
      for(k=1; k<numEdgeBufEdges; k++)
      {
        while(k<numEdgeBufEdges && !strcasecmp(uniqBuf[j], uniqBuf[k])) k++;
        if(k<numEdgeBufEdges) uniqBuf[++j] = uniqBuf[k];
      }
      numUniq = j+1;
      
      /* count support for each edge */
      for(j=0; j<numUniq; j++)
      {
        sumOfWeights = 0.0;
        
        for(k=0; k<numEdgeBufEdges; k++)
        {
          if(!strcasecmp(uniqBuf[j], edgeBuf[k]))
            sumOfWeights += edgeWghtBuf[k];
        }
        
        /* add edge to vertex uniqBuf[j] from vertex uniqLabels[i] */
        if(sumOfWeights >= threshold)
        {
#ifdef DEBUG_CSG
          printf("edge to %s will be added to sg\n", uniqBuf[j]);
#endif
          /* go to node uniqLabels[i] in sg */
          hit = (void *)(sg->gnList);
          hit = bsearch((void *)uniqLabels[i], hit, sg->numNodes,
                         sizeof(graphNode *), compStrGN);
          tmp = *(graphNode **)hit;
          
          /* allocate space */
          if(tmp->numEdges == 0)
          {
            tmp->edges       = (char **)  malloc(sizeof(char *));
            tmp->edgeWeights = (double *) malloc(sizeof(double));
            if((tmp->edges)==NULL || (tmp->edgeWeights)==NULL)
            {
              fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
              return NULL;
            }
          }
          else
          {
            tmp->edges       = (char **)  realloc(tmp->edges, 
                                                 (tmp->numEdges + 1) *
                                                  sizeof(char *));
            tmp->edgeWeights = (double *) realloc(tmp->edgeWeights, 
                                                 (tmp->numEdges + 1) *
                                                  sizeof(double));
            if((tmp->edges)==NULL || (tmp->edgeWeights)==NULL)
            {
              fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
              return NULL;
            }
          }
#ifdef DEBUG_CSG
          printf("adding %s to %s\n", uniqBuf[j], tmp->label);
#endif
          /* finally add the edge */
          tmp->edges[tmp->numEdges] = (char *) malloc(strlen(uniqBuf[j])+1);
          if((tmp->edges[tmp->numEdges])==NULL)
          {
            fprintf(stderr, "CreateSummaryGraph: malloc error, returning...\n");
            return NULL;
          }
          strcpy(tmp->edges[tmp->numEdges], uniqBuf[j]);
          
          tmp->edgeWeights[tmp->numEdges] = sumOfWeights/numberOfDataSets;
#ifdef DEBUG_CSG
          printf("added %s with weight %lf\n", tmp->edges[tmp->numEdges],
                                               tmp->edgeWeights[tmp->numEdges]);
#endif
          tmp->numEdges++;
        }
      }
      
      free(uniqBuf);
    }
  }
  
#ifdef DEBUG_CSG
  PrintGraph(sg);
#endif

  free(edgeBuf);
  free(edgeWghtBuf);
  free(uniqLabels);

  return sg;
}