Пример #1
0
/*************************************************************************
* Let the game begin
**************************************************************************/
int main(int argc, char *argv[])
{
  GraphType graph;
  char filename[256];
  idxtype wgtflag;

  if (argc != 2) {
    mprintf("Usage: %s <GraphFile>\n", argv[0]);
    exit(0);
  }
    
  strcpy(filename, argv[1]);

  ReadGraph(&graph, filename, &wgtflag);
  if (graph.nvtxs == 0) {
    mprintf("Empty graph!\n");
    exit(0);
  }

  mprintf("**********************************************************************\n");
  mprintf("%s", METISTITLE);
  mprintf("Graph Information ---------------------------------------------------\n");
  mprintf("  Name: %s, #Vertices: %D, #Edges: %D\n\n", filename, graph.nvtxs, graph.nedges/2);
  mprintf("Checking Graph... ---------------------------------------------------\n");

  if (CheckGraph(&graph))
    mprintf("   The format of the graph is correct!\n");
  else
    mprintf("   The format of the graph is incorrect!\n");

  mprintf("\n**********************************************************************\n");


  gk_free((void **)&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM);
}  
Пример #2
0
void ReadGraphAsymmErrors(const char *name, Int_t igr, Double_t *gx, Double_t *gy, Double_t *egy)
{
  TFile *f = new TFile(name);
  TGraphAsymmErrors *gr = (TGraphAsymmErrors*)f->Get(Form("gr_%d",igr));
  ReadGraph(gr, gx, gy, egy);
  f->Close();

  return;
}
Пример #3
0
int main(int argc, char **argv)
{
   Graph *g1, *g2;
   LabelList *labelList = NULL;
   BOOLEAN directed = TRUE; // 'e' edges are considered directed
   ULONG maxVertices;
   VertexMap *mapping;
   double matchCost;

   if (argc != 3) 
   {
      fprintf(stderr, "usage: %s <graph file> <graph file>\n", argv[0]);
      exit(1);
   }
   labelList = AllocateLabelList();
   g1 = ReadGraph(argv[1], labelList, directed);
   g2 = ReadGraph(argv[2], labelList, directed);

   if (g1->numVertices < g2->numVertices) 
   {
      maxVertices = g2->numVertices;
      mapping = (VertexMap *) malloc(sizeof(VertexMap) * maxVertices);
      matchCost = InexactGraphMatch(g2, g1, labelList, MAX_DOUBLE, mapping);
   } 
   else 
   {
      maxVertices = g1->numVertices;
      mapping = (VertexMap *) malloc(sizeof(VertexMap) * maxVertices);
      matchCost = InexactGraphMatch(g1, g2, labelList, MAX_DOUBLE, mapping);
   }

   printf("Match Cost = %f\n", matchCost);
   PrintMapping(mapping, maxVertices);

   free(mapping);

   return 0;
}
Пример #4
0
/*************************************************************************
* Let the game begin
**************************************************************************/
int main(int argc, char *argv[])
{
  idx_t i;
  idx_t *perm, *iperm;
  graph_t *graph;
  params_t params;
  size_t maxlnz, opc;

  if (argc != 3) {
    printf("Usage: %s <GraphFile> <PermFile\n", argv[0]);
    exit(0);
  }
    
  params.filename = gk_strdup(argv[1]);
  graph = ReadGraph(&params);
  if (graph->nvtxs <= 0) {
    printf("Empty graph. Nothing to do.\n");
    exit(0);
  }
  if (graph->ncon != 1) {
    printf("Ordering can only be applied to graphs with one constraint.\n");
    exit(0);
  }


  /* Read the external iperm vector */
  perm  = imalloc(graph->nvtxs, "main: perm");
  iperm = imalloc(graph->nvtxs, "main: iperm");
  ReadPOVector(graph, argv[2], iperm);

  for (i=0; i<graph->nvtxs; i++)
    perm[iperm[i]] = i;

  printf("**********************************************************************\n");
  printf("%s", METISTITLE);
  printf("Graph Information ---------------------------------------------------\n");
  printf("  Name: %s, #Vertices: %"PRIDX", #Edges: %"PRIDX"\n\n", argv[1], 
      graph->nvtxs, graph->nedges/2);
  printf("Fillin... -----------------------------------------------------------\n");

  ComputeFillIn(graph, perm, iperm, &maxlnz, &opc);
  
  printf("  Nonzeros: %6.3le \tOperation Count: %6.3le\n", (double)maxlnz, (double)opc);


  printf("**********************************************************************\n");

  FreeGraph(&graph);
}  
Пример #5
0
int main(int argc, char *argv[]) {
    graph_t *graph, *fgraph;
    char filename[256];
    idx_t wgtflag;
    params_t params;

    if (argc != 2 && argc != 3) {
        printf("Usage: %s <GraphFile> [FixedGraphFile (for storing the fixed graph)]\n", argv[0]);
        exit(0);
    }

    memset((void *) &params, 0, sizeof(params_t));
    params.filename = gk_strdup(argv[1]);

    graph = ReadGraph(&params);
    if (graph->nvtxs == 0) {
        printf("Empty graph!\n");
        exit(0);
    }

    printf("**********************************************************************\n");
    printf("%s", METISTITLE);
    printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);
    printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n",
           8 * sizeof(idx_t), 8 * sizeof(real_t), 8 * sizeof(idx_t * ));
    printf("\n");
    printf("Graph Information ---------------------------------------------------\n");
    printf("  Name: %s, #Vertices: %"PRIDX", #Edges: %"PRIDX"\n\n",
           params.filename, graph->nvtxs, graph->nedges / 2);
    printf("Checking Graph... ---------------------------------------------------\n");

    if (CheckGraph(graph, 1, 1)) {
        printf("   The format of the graph is correct!\n");
    } else {
        printf("   The format of the graph is incorrect!\n");
        if (argc == 3) {
            fgraph = FixGraph(graph);
            WriteGraph(fgraph, argv[2]);
            FreeGraph(&fgraph);
            printf("   A corrected version was stored at %s\n", argv[2]);
        }
    }

    printf("\n**********************************************************************\n");

    FreeGraph(&graph);
    gk_free((void **) &params.filename, &params.tpwgtsfile, &params.tpwgts, LTERM);
}  
Пример #6
0
int main(int argc, char* argv[]) {
  TStr InFile,OutFile;
  int Dimensions, WalkLen, NumWalks, WinSize, Iter;
  double ParamP, ParamQ;
  bool Directed, Weighted, Verbose, OutputWalks;
  ParseArgs(argc, argv, InFile, OutFile, Dimensions, WalkLen, NumWalks, WinSize,
   Iter, Verbose, ParamP, ParamQ, Directed, Weighted, OutputWalks);
  PWNet InNet = PWNet::New();
  TIntFltVH EmbeddingsHV;
  TVVec <TInt, int64> WalksVV;
  ReadGraph(InFile, Directed, Weighted, Verbose, InNet);
  node2vec(InNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize, Iter, 
   Verbose, OutputWalks, WalksVV, EmbeddingsHV);
  WriteOutput(OutFile, EmbeddingsHV, WalksVV, OutputWalks);
  return 0;
}
Пример #7
0
/* initializeScheduler
 * Initializes scheduler if it has not been initialized yet.
 * Returns 0 if the scheduler was initialized correctly.
 * Returns 1 if the scheduler already exists.
 * Returns -1 if the initialization was unsuccessful.
 */
int initializeScheduler(void) {
	if(_Scheduler == NULL) {
		_Scheduler = (Scheduler*) malloc(sizeof(Scheduler));
		if(_Scheduler == NULL)
			return -1;

		/* Set the Scheduler pointer to be shared */
#ifdef __APPLE__
		_Scheduler = mmap(NULL, sizeof(_Scheduler), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
#else
		_Scheduler = mmap(NULL, sizeof(_Scheduler), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
#endif

		/* Initialize fields */
		_Scheduler->counterExamples = new_dllist();
		_Scheduler->listSize = 0;

		/* Load best graph counterexamples */
		int file_count;
		char **CEfiles = getCounterExamplesFromFolder("../../../counterexamples/more121", &file_count);
		int i;
		for(i = 0; i < file_count; i++) {
			int *g;
			char *fname;
			asprintf(&fname, "../../../counterexamples/more121/%s", CEfiles[i]);
			if(ReadGraph(fname, &g, &(_Scheduler->currCEsize))) {
				fprintf(stderr, "Loaded graph %s successfully!\n", fname);
				addCounterExample(g);
			}
		}
		/*Print list size*/
		fprintf(stderr, "List size after initialization: %d\n", _Scheduler->listSize);
		/* Initialize current list pointer */
		_Scheduler->currPtr = dll_first(_Scheduler->counterExamples);

		/* free CEfiles */
		for(i = 0; i < _Scheduler->listSize; i++) {
			free(CEfiles[i]);
		}
		free(CEfiles);

		return 0;
	}
	else
		return 1;
}
Пример #8
0
void Read(const QString& fileName, SignalData& data, PlotInfo& plotInfo, std::function<void(Signal&&)> onSignal, std::function<void()> onAfterSignalRead)
{
	QFile in(fileName);
	if (!in.open(QIODevice::ReadOnly | QFile::Text))
	{
		auto mex = QString("Cannot open specified file -> %1").arg(fileName);
		QMessageBox::critical(nullptr, "Anvedi", mex);
		throw std::exception(mex.toUtf8().data());
	}
	const auto json = QJsonDocument::fromJson(in.readAll()).object();

	auto backgroundIt = json.find("background");
	if (backgroundIt != json.end())
	{
		plotInfo.setBackgroundColor(backgroundIt->toString());
	}
	auto graphIt = json.find("signals");
	if ((graphIt != json.end()) && graphIt->isArray())
	{
		for (const auto& elem : graphIt->toArray())
		{
			if (elem.isObject())
			{
				onSignal(ReadGraph(elem.toObject()));
			}
		}
	}
	
	onAfterSignalRead();

	auto domainIt = json.find("domain");
	if (domainIt != json.end())
	{
		const auto domainName = domainIt->toString();
		try
		{
			data.setAsDomain(domainName);
		}
		catch (const std::exception&){}
	}
}
Пример #9
0
void draw_BR()
{
  gROOT->ProcessLine(".L ReadGraph.C");

  TFile *f = new TFile("particles.root");
  TH2 *h2_particles = (TH2*)f->Get("h2_particles");
  TH1* h_others = h2_particles->ProjectionX("h_others", 2, 3);
  TH1* h_pion = h2_particles->ProjectionX("h_pion", 1, 1);

  TCanvas *c = new TCanvas("c", "Canvas", 600, 600);
  gStyle->SetOptStat(0);

  TGraphAsymmErrors *gr = new TGraphAsymmErrors(h_others, h_pion);
  gr->SetTitle("Two photons acceptance");
  gr->GetXaxis()->SetTitle("p_{T} [GeV]");
  gr->GetYaxis()->SetTitle("#frac{#eta+#omega}{#pi^{0}}");
  gr->GetXaxis()->SetRangeUser(0., 12.);
  gr->GetYaxis()->SetRangeUser(0., 0.5);
  gr->Draw("AP");

  c->Print("BR.pdf");

  Double_t gx[30], gy[30], egy[30];
  ReadGraph(gr, gx, gy, egy);

  Double_t nothers = h_others->Integral(11,30);
  Double_t npion = h_pion->Integral(11,30);
  Double_t BRbar = nothers / npion;
  Double_t eBRbar = BRbar * sqrt( 1./nothers + 1./npion ); 
  for(Int_t ipt=10; ipt<30; ipt++)
  {
    gy[ipt] = BRbar;
    egy[ipt] = eBRbar;
  }

  TGraphErrors *grout = new TGraphErrors(30, gx, gy, 0, egy);
  grout->SetName("gr_0");
  TFile *fout = new TFile("BR.root", "RECREATE");
  grout->Write();
  fout->Close();
}
Пример #10
0
int main(int argc, char *argv[])
{
	int i, npart;
	idxtype *part;
	float ncut=0;
	GraphType graph;
	char filename[256],outputFile[256];
	int wgtflag = 0, addSelfLoop=1, outputFileGiven=0, txtFormat=0 ;
	int randomInit = 0;
	idxtype minEdgeWeight = 0;
	Options opt;
	timer TOTALTmr, METISTmr, IOTmr;

	initOptions(&opt);

	if (argc < 2) {
		print_help(argv[0]);
		exit(0);
	}
	
	for (argv++; *argv != NULL; argv++){
	    if ((*argv)[0] == '-')
		{
			int temp;
	      	switch ((*argv)[1])
			{
			case 'b':
			case 'B':
			  opt.penalty_power=atof(*(++argv));
			  break;
			case 'i':
			case 'I':
			  opt.gamma=atof(*(++argv));
			  break;
			case 'o':
			case 'O':
			  strcpy(outputFile,*(++argv));
			  outputFileGiven=1;
			  break;
			case 'D'://quality threshold. This is a post-processing step proposed in SR-MCL. If you dont want post-processing (this is what original MLR-MCL, R-MCL, MCL do, please set "-d 0"  
			case 'd':
			  opt.quality_threshold = atof(*(++argv));
			  break;
			case 'w':
			case 'W':
		          opt.weighted_density = true; 
			  break;

			case 'c':
			case 'C':
			  opt.coarsenTo= atoi(*(++argv));
			  break;
			default:
			  printf("Invalid option %s\n", *argv);
			  print_help(argv[0]);
			  exit(0);
			}
		}
	    else
		{
	      strcpy(filename, *argv);
	    }
	}  

	if ( randomInit > 0 )
		InitRandom(time(NULL));
	else
		InitRandom(-1);

	cleartimer(TOTALTmr);
	cleartimer(METISTmr);
	cleartimer(IOTmr);

	starttimer(TOTALTmr);
	starttimer(IOTmr);

	ReadGraph(&graph, filename, &wgtflag, addSelfLoop, txtFormat);

	if ( opt.matchType == MATCH_UNSPECIFIED )
	{
//		opt.matchType = (graph.nvtxs>50000) ? MATCH_POWERLAW_FC :
//							MATCH_SHEMN;
		opt.matchType = MATCH_SHEMN;
	}
	
	stoptimer(IOTmr);

	if (graph.nvtxs <= 0) {
	  printf("Empty graph. Nothing to do.\n");
	  exit(0);
	}

	int noOfSingletons = 0; 
	GraphType *noSingletonGraph ;
	idxtype* nodeMap = lookForSingletons(&graph, &noOfSingletons);
	if ( noOfSingletons > 0 )
	{
		getSubgraph(&graph, nodeMap, graph.nvtxs-noOfSingletons, 
						wgtflag, &noSingletonGraph);
		GKfree((void**)&(graph.xadj), (void**)&(graph.adjncy), LTERM);
		if ( wgtflag&1 > 0 )
			GKfree( (void**)&(graph.adjwgt), LTERM);
//		free(graph.gdata);
		printf("Found %d singleton nodes in the", noOfSingletons);
		printf(" input graph. Removing them.\n");
	}

	if ( !outputFileGiven )
	{
		strcpy(outputFile, filename);

		sprintf(outputFile,"%s.c%d.i%1.1f.b%1.1f",outputFile,opt.coarsenTo,opt.gamma,opt.penalty_power);
	}
	
	printf("Input graph information ---------------------------------------------------\n");
	printf("  Name: %s, #Vertices: %d, #Edges: %d\n", filename, graph.nvtxs, graph.nedges/2);
	printf("Output shall be placed in the file %s\n",
	outputFile);
	fflush(stdout);

	part = idxmalloc(graph.nvtxs, "main: part");

	printf("------------------------------------------------\n");
	printf("Clustering....\n");
	fflush(stdout);
	starttimer(METISTmr);         //YK: main algorithm starts here!

	if ( noOfSingletons > 0 )
	{
		
		mlmcl(&(noSingletonGraph->nvtxs), noSingletonGraph->xadj, noSingletonGraph->adjncy,
			noSingletonGraph->vwgt,noSingletonGraph->adjwgt, &wgtflag, part, opt ); 
	}
	else	
	{
		mlmcl(&graph.nvtxs, graph.xadj, graph.adjncy,graph.vwgt,
			graph.adjwgt, &wgtflag, part, opt ); 
	}

	stoptimer(METISTmr); 

	printf("------------------------------------------------\n");
	if ( noOfSingletons > 0 )
	{
		npart=mapPartition(part,noSingletonGraph->nvtxs);
		ncut=ComputeNCut(noSingletonGraph, part,npart);
//		printf("In graph that does not include singletons,");
//		printf("No. of Clusters: %d, N-Cut value: %.2f\n",npart,ncut);


		idxtype *clusterSizes = histogram(part,
					graph.nvtxs-noOfSingletons, npart);

		int maxSize = clusterSizes[idxamax(npart, clusterSizes)];
		float avgClusterSize =
						(graph.nvtxs-noOfSingletons)*1.0/(npart);
		float balance =	(maxSize*1.0) /
				((graph.nvtxs-noOfSingletons)*1.0/npart);
		float stdDevn = stdDeviation(clusterSizes, npart);
		float avgNcut = ncut * 1.0/npart;
		float normStdDevn = stdDevn/avgClusterSize;

	// Warning: This computation only works if the singletons
	// have been placed in their own clusters. This works for
	// MLR-MCL, in other words, because it is guaranteed to
	// place singletons in their own clusters.
		printf("Output statistics for graph without singletons\n");
		printf("Clusters: %d N-Cut: %.3f", 
					npart, ncut);
		printf(" AvgN-Cut: %.3f Balance in cluster sizes: %.2f ",avgNcut,
					balance); 
		printf("Std_Deviation in cluster sizes: %.2f ", stdDevn);
		printf("Coefficient_of_Variation: %.2f\n", normStdDevn);

		free( clusterSizes );

		npart += noOfSingletons;
	//	ncut += noOfSingletons;
		printf("Output statistics for original graph\n");

		mapIndices(part, nodeMap, graph.nvtxs, npart-noOfSingletons);
	}
	else
	{
		npart=mapPartition(part,graph.nvtxs);
		ncut=ComputeNCut(&graph, part,npart);
	}

	idxtype* clusterSizes = histogram(part, graph.nvtxs, npart);
	int maxSize = clusterSizes[idxamax(npart, clusterSizes)];
	float avgClusterSize = (graph.nvtxs)*1.0/(npart);
	float balance = (maxSize*1.0)/(graph.nvtxs*1.0/npart);
	float stdDevn = stdDeviation(clusterSizes, npart);
	float avgNcut = ncut * 1.0/npart;
	float normStdDevn = stdDevn/avgClusterSize;
	
	printf("Clusters: %d N-Cut: %.3f AvgN-Cut: %.3f", npart,
						ncut, avgNcut );
	printf(" Balance in cluster sizes: %.2f Std.Deviation in cluster sizes: %.2f ",
				 balance, stdDevn);
	printf("Coefficient_of_Variation: %.2f\n", normStdDevn);

	starttimer(IOTmr);
	my_WritePartition(outputFile, part, graph.nvtxs, opt.gamma); 
	if ( noOfSingletons > 0 )
	{
		free(nodeMap);
		nodeMap = NULL;
	}

	printf("\nOutput is written to file: %s\n", outputFile);
	stoptimer(IOTmr);
	stoptimer(TOTALTmr);
	
	printf("\nTiming Information --------------------------------------------------\n");
	printf("  I/O:          \t\t %7.3f\n", gettimer(IOTmr));
	printf("  Partitioning: \t\t %7.3f   (MLR-MCL time)\n", gettimer(METISTmr));
	printf("  Total:        \t\t %7.3f\n", gettimer(TOTALTmr));
	printf("**********************************************************************\n");


	GKfree((void**)&graph.xadj, (void**)&graph.adjncy, (void**)&graph.vwgt, 
				(void**)&graph.adjwgt, (void**)&part, LTERM);
}  
Пример #11
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);

}
Пример #12
0
/*************************************************************************
* Let the game begin
**************************************************************************/
main(int argc, char *argv[])
{
  int i, options[10];
  idxtype *perm, *iperm;
  GraphType graph;
  char filename[256];
  int numflag = 0, wgtflag;
  timer TOTALTmr, METISTmr, IOTmr, SMBTmr;


  if (argc != 2) {
    printf("Usage: %s <GraphFile>\n",argv[0]);
    exit(0);
  }
    
  strcpy(filename, argv[1]);

  cleartimer(TOTALTmr);
  cleartimer(METISTmr);
  cleartimer(IOTmr);
  cleartimer(SMBTmr);

  starttimer(TOTALTmr);
  starttimer(IOTmr);
  ReadGraph(&graph, filename, &wgtflag);
  if (graph.nvtxs <= 0) {
    printf("Empty graph. Nothing to do.\n");
    exit(0);
  }
  if (graph.ncon != 1) {
    printf("Ordering can only be applied to graphs with one constraint.\n");
    exit(0);
  }
  stoptimer(IOTmr);

  /* Ordering does not use weights! */
  GKfree(&graph.vwgt, &graph.adjwgt, LTERM);

  printf("**********************************************************************\n");
  printf("%s", METISTITLE);
  printf("Graph Information ---------------------------------------------------\n");
  printf("  Name: %s, #Vertices: %d, #Edges: %d\n\n", filename, graph.nvtxs, graph.nedges/2);
  printf("Node-Based Ordering... ----------------------------------------------\n");

  perm = idxmalloc(graph.nvtxs, "main: perm");
  iperm = idxmalloc(graph.nvtxs, "main: iperm");
  options[0] = 0;

  starttimer(METISTmr);
  METIS_NodeND(&graph.nvtxs, graph.xadj, graph.adjncy, &numflag, options, perm, iperm);
  stoptimer(METISTmr);

  starttimer(IOTmr);
  WritePermutation(filename, iperm, graph.nvtxs); 
  stoptimer(IOTmr);

  starttimer(SMBTmr);
  ComputeFillIn(&graph, iperm);
  stoptimer(SMBTmr);

  stoptimer(TOTALTmr);

  printf("\nTiming Information --------------------------------------------------\n");
  printf("  I/O:                     \t %7.3f\n", gettimer(IOTmr));
  printf("  Ordering:                \t %7.3f   (ONMETIS time)\n", gettimer(METISTmr));
  printf("  Symbolic Factorization:  \t %7.3f\n", gettimer(SMBTmr));
  printf("  Total:                   \t %7.3f\n", gettimer(TOTALTmr));
  printf("**********************************************************************\n");


  GKfree(&graph.xadj, &graph.adjncy, &perm, &iperm, LTERM);
}  
Пример #13
0
/*************************************************************************
* Let the game begin
**************************************************************************/
main(int argc, char *argv[])
{
  int i, nparts, options[10];
  idxtype *part;
  float rubvec[MAXNCON], lbvec[MAXNCON];
  GraphType graph;
  char filename[256];
  int numflag = 0, wgtflag = 0, edgecut;
  timer TOTALTmr, METISTmr, IOTmr;

  if (argc != 3) {
    printf("Usage: %s <GraphFile> <Nparts>\n",argv[0]);
    exit(0);
  }
    
  strcpy(filename, argv[1]);
  nparts = atoi(argv[2]);

  if (nparts < 2) {
    printf("The number of partitions should be greater than 1!\n");
    exit(0);
  }

  cleartimer(TOTALTmr);
  cleartimer(METISTmr);
  cleartimer(IOTmr);

  starttimer(TOTALTmr);
  starttimer(IOTmr);
  ReadGraph(&graph, filename, &wgtflag);
  if (graph.nvtxs <= 0) {
    printf("Empty graph. Nothing to do.\n");
    exit(0);
  }
  stoptimer(IOTmr);

  printf("**********************************************************************\n");
  printf("%s", METISTITLE);
  printf("Graph Information ---------------------------------------------------\n");
  printf("  Name: %s, #Vertices: %d, #Edges: %d, #Parts: %d\n", filename, graph.nvtxs, graph.nedges/2, nparts);
  if (graph.ncon > 1)
    printf("  Balancing Constraints: %d\n", graph.ncon);
  printf("\nK-way Partitioning... -----------------------------------------------\n");

  part = idxmalloc(graph.nvtxs, "main: part");
  options[0] = 0;

  starttimer(METISTmr);
  if (graph.ncon == 1) {
    METIS_PartGraphKway(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, 
          &wgtflag, &numflag, &nparts, options, &edgecut, part);
  }
  else {
    for (i=0; i<graph.ncon; i++)
      rubvec[i] = HORIZONTAL_IMBALANCE;

    METIS_mCPartGraphKway(&graph.nvtxs, &graph.ncon, graph.xadj, graph.adjncy, graph.vwgt, 
          graph.adjwgt, &wgtflag, &numflag, &nparts, rubvec, options, &edgecut, part);
  }
  stoptimer(METISTmr);

  ComputePartitionBalance(&graph, nparts, part, lbvec);

  printf("  %d-way Edge-Cut: %7d, Balance: ", nparts, edgecut);
  for (i=0; i<graph.ncon; i++)
    printf("%5.2f ", lbvec[i]);
  printf("\n");

  starttimer(IOTmr);
  WritePartition(filename, part, graph.nvtxs, nparts); 
  stoptimer(IOTmr);
  stoptimer(TOTALTmr);

  printf("\nTiming Information --------------------------------------------------\n");
  printf("  I/O:          \t\t %7.3f\n", gettimer(IOTmr));
  printf("  Partitioning: \t\t %7.3f   (KMETIS time)\n", gettimer(METISTmr));
  printf("  Total:        \t\t %7.3f\n", gettimer(TOTALTmr));
  printf("**********************************************************************\n");


  GKfree(&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, &part, LTERM);
}  
Пример #14
0
idx_t* gpmetis( int argc, char **argv )
/*************************************************************************/
/*! Let the game begin! */
/*************************************************************************/
//int main(int argc, char *argv[])
{
  idx_t i;
  char *curptr, *newptr;
  idx_t options[METIS_NOPTIONS];
  graph_t *graph;
  idx_t *part;
  idx_t objval;
  params_t *params;
  int status=0;

  gk_optind = 0;

  //printf( "argc: %d\n", argc );
  //printf( "gk_optind %d\n", gk_optind );
  fflush( stdout );

    for( i = 0; i < argc; i++ )
    {
        //printf( "%s*\n", argv[ i ] );
    }


  params = parse_cmdline(argc, argv);
  //printf( "gk_optind %d\n", gk_optind );
  //fflush( stdout );
  //return NULL;

  gk_startcputimer(params->iotimer);
  graph = ReadGraph(params);

  ReadTPwgts(params, graph->ncon);
  gk_stopcputimer(params->iotimer);

  /* Check if the graph is contiguous */
  if (params->contig && !IsConnected(graph, 0)) {
    printf("***The input graph is not contiguous.\n"
           "***The specified -contig option will be ignored.\n");
    params->contig = 0;
  }

  /* Get ubvec if supplied */
  if (params->ubvecstr) {
    params->ubvec = rmalloc(graph->ncon, "main");
    curptr = params->ubvecstr;
    for (i=0; i<graph->ncon; i++) {
      params->ubvec[i] = strtoreal(curptr, &newptr);
      if (curptr == newptr)
        errexit("Error parsing entry #%"PRIDX" of ubvec [%s] (possibly missing).\n",
            i, params->ubvecstr);
      curptr = newptr;
    }
  }

  /* Setup iptype */
  if (params->iptype == -1) {
    if (params->ptype == METIS_PTYPE_RB) {
      if (graph->ncon == 1)
        params->iptype = METIS_IPTYPE_GROW;
      else
        params->iptype = METIS_IPTYPE_RANDOM;
    }
  }

  GPPrintInfo(params, graph);

  part = imalloc(graph->nvtxs, "main: part");

  METIS_SetDefaultOptions(options);
  options[METIS_OPTION_OBJTYPE] = params->objtype;
  options[METIS_OPTION_CTYPE]   = params->ctype;
  options[METIS_OPTION_IPTYPE]  = params->iptype;
  options[METIS_OPTION_RTYPE]   = params->rtype;
  options[METIS_OPTION_MINCONN] = params->minconn;
  options[METIS_OPTION_CONTIG]  = params->contig;
  options[METIS_OPTION_SEED]    = params->seed;
  options[METIS_OPTION_NITER]   = params->niter;
  options[METIS_OPTION_NCUTS]   = params->ncuts;
  options[METIS_OPTION_UFACTOR] = params->ufactor;
  options[METIS_OPTION_DBGLVL]  = params->dbglvl;

  gk_malloc_init();
  gk_startcputimer(params->parttimer);

  switch (params->ptype) {
    case METIS_PTYPE_RB:
      status = METIS_PartGraphRecursive(&graph->nvtxs, &graph->ncon, graph->xadj,
                   graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
                   &params->nparts, params->tpwgts, params->ubvec, options,
                   &objval, part);
      break;

    case METIS_PTYPE_KWAY:
      status = METIS_PartGraphKway(&graph->nvtxs, &graph->ncon, graph->xadj,
                   graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
                   &params->nparts, params->tpwgts, params->ubvec, options,
                   &objval, part);
      break;

  }

  gk_stopcputimer(params->parttimer);

  if (gk_GetCurMemoryUsed() != 0)
    printf("***It seems that Metis did not free all of its memory! Report this.\n");
  params->maxmemory = gk_GetMaxMemoryUsed();
  gk_malloc_cleanup(0);


  if (status != METIS_OK) {
    printf("\n***Metis returned with an error.\n");
  }
  else {
    if (!params->nooutput) {
      /* Write the solution */
      gk_startcputimer(params->iotimer);
      WritePartition(params->filename, part, graph->nvtxs, params->nparts);
      gk_stopcputimer(params->iotimer);
    }

    GPReportResults(params, graph, part, objval);
  }

  idx_t *r_part = ( idx_t* ) calloc( graph->nvtxs, sizeof( idx_t ) );

  for( i = 0; i < graph->nvtxs; i++ )
  {
       r_part[ i ] = part[ i ];
  }

  FreeGraph(&graph);
  gk_free((void **)&part, LTERM);
  gk_free((void **)&params->filename, &params->tpwgtsfile, &params->tpwgts,
      &params->ubvecstr, &params->ubvec, &params, LTERM);

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

}
Пример #16
0
/*************************************************************************
* multi-level weighted kernel k-means main function
**************************************************************************/
Graclus normalizedCut(char* filename, int nparts)
{
  Graclus ncData;
  int options[11];
  idxtype *part;  // cluster result stored in array part
  float rubvec[MAXNCON], lbvec[MAXNCON];
  GraphType graph;
  int numflag = 0, wgtflag = 0, edgecut, chain_length = 0;
  int no_args = 1, levels = 0;


  no_args = 0;
  
  if (nparts < 2) 
  {
    printf("The number of partitions should be greater than 1!\n");
    exit(0);
  }

  ReadGraph(&graph, filename, &wgtflag);
  if (graph.nvtxs <= 0) 
  {
    puts("Empty graph. Nothing to do.\n");
    exit(0);
  }

	levels = amax((graph.nvtxs)/(40*log2_metis(nparts)), 20*(nparts));
  
  // if(graph.ncon > 1)
  //   printf("  Balancing Constraints: %d\n", graph.ncon);

  part = idxmalloc(graph.nvtxs, "main: part");
  options[0] = 0;

  // printf("#Clusters: %d\n", nparts);
  if (graph.ncon == 1) 
  {
    MLKKM_PartGraphKway(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, 
			  &wgtflag, &numflag, &nparts, &chain_length, options, &edgecut, part, levels);
  }
  else 
  {
    int i;
    for (i = 0; i < graph.ncon; i++)
      rubvec[i] = HORIZONTAL_IMBALANCE;
  }

  ComputePartitionBalance(&graph, nparts, part, lbvec);
  ComputeNCut(&graph, part, nparts);
  
  //for(int i = 0; i < graph.nvtxs; i++) printf("%d\n", part[i]);
  //int clusterNum = graph.nvtxs;

  ncData.part = part;
  ncData.clusterNum = graph.nvtxs;

  //GKfree((void **) &graph.xadj, (void **) &graph.adjncy, (void **) &graph.vwgt, (void **) &graph.adjwgt, (void **) &part, LTERM);
  GKfree((void **) &graph.xadj, (void **) &graph.adjncy, (void **) &graph.vwgt, (void **) &graph.adjwgt, LTERM);  

  return ncData;
}
Пример #17
0
int main()
{
    Set<nodeT *> graph;
    Map<nodeT *> graphMap;
    
	InitGraphics();
	SetWindowTitle("Pathfinder");
    
    string backgroundFile;
    bool timeToQuit = false;
    
    
    cout << "This masterful piece of work is a graph extravaganza!" << endl;
    
    while (true) {
        
        cout << "Your options are:" << endl;
        cout << "(1) Choose a new graph data file" << endl;
        cout << "(2) Find shortest path using Dijkstra's algorithm" << endl;
        cout << "(3) Compute the minimal spanning tree using Kruskal's algorithm" << endl;
        cout << "(4) Determine if the graph has cycles" << endl;
        cout << "(5) Quit" << endl;
        cout << "Enter choice: ";
        
        int choice = GetInteger();
        string datafile;
        void UpdateDisplay();
        
        switch (choice) {
            case 1:
                cout << "Enter the name of the data file: ";
                datafile = GetLine();
                //datafile = "Small.txt";
                //datafile = "USA.txt";
                //datafile = "Stanford.txt";
                graph.clear();
                graphMap.clear();
                backgroundFile = ReadGraph(graph, graphMap, datafile);
                break;
            case 2:
                if (backgroundFile == "") {
                    cout << "No file is specified" << endl;
                }
                else {
                    UpdateDisplay();
                    MovePen(0,0);
                    DrawNamedPicture(backgroundFile);
                    DrawNodesAndArcs(graph);
                    cout << "(2) Finding shortest path using Dijkstra's algorithm" << endl;
                    HandleShortestPath(graph);
                }
                break;
            case 3:
                if (backgroundFile == "") {
                    cout << "No file is specified" << endl;
                }
                else {
                    cout << "(3) Computing the minimal spanning tree using Kruskal's algorithm" << endl;
                    UpdateDisplay();
                    MovePen(0,0);
                    DrawNamedPicture(backgroundFile);
                    //DrawNodesAndArcs(graph);
                    minimumSpanningTree(graph, graphMap);
                }
                break;
            case 4:
                if (backgroundFile == "") {
                    cout << "No file is specified" << endl;
                }
                else {
                    graphT graph2;
                    graph2.allNodes = graph;
                    
                    cout << "(4) Determining if the graph has cycles" << endl;
                    if (IsCyclicGraph(graph2))
                        cout << "Yes, it is cyclic" << endl;
                    else
                        cout << "No, it is not cyclic" << endl;
                }
                break;
            case 5:
                cout << "Thanks for using Pathfinder. Bye!" << endl;
                timeToQuit = true;
                break;
                
            default:
                cout << "Invalid choice" << endl;
                break;
        }
        
        if (timeToQuit) break;
        
    }
    return (0);
}
Пример #18
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);

}
Пример #19
0
sparse_matrix* graph_partition(LIST *list , partition_t* partition_info)
{
	graph_t* graph;
	params_t *params;
	idx_t options[METIS_NOPTIONS], status;
	idx_t objval;

	sparse_matrix* matrix = (sparse_matrix*)malloc(sizeof(sparse_matrix));

	graph = ReadGraph(list);

	params = bmalloc(sizeof(*params), "Allocating memory for params");

	METIS_SetDefaultOptions(options);
	METIS_init_params(params, graph->ncon);
	options[METIS_OPTION_OBJTYPE] = params->objtype;
	options[METIS_OPTION_CTYPE]   = params->ctype;
	options[METIS_OPTION_IPTYPE]  = params->iptype;
	options[METIS_OPTION_RTYPE]   = params->rtype;
	options[METIS_OPTION_NO2HOP]  = params->no2hop;
	options[METIS_OPTION_MINCONN] = params->minconn;
	options[METIS_OPTION_CONTIG]  = params->contig;
	options[METIS_OPTION_SEED]    = params->seed;
	options[METIS_OPTION_NITER]   = params->niter;
	options[METIS_OPTION_NCUTS]   = params->ncuts;
	options[METIS_OPTION_UFACTOR] = params->ufactor;
	options[METIS_OPTION_DBGLVL]  = params->dbglvl;

	//print_input_data(graph,params);

	params->tpwgts = NULL;
	params->ubvec = NULL;
	partition_info->partion_table = imalloc(graph->nvtxs, "Allocate memory for part");

	switch (params->ptype) {
	    case METIS_PTYPE_RB:
	      status = METIS_PartGraphRecursive(&graph->nvtxs, &graph->ncon, graph->xadj,
	                   graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
	                   &params->nparts, params->tpwgts, params->ubvec, options,
	                   &objval, partition_info->partion_table);
	      break;

	    case METIS_PTYPE_KWAY:
	      status = METIS_PartGraphKway(&graph->nvtxs, &graph->ncon, graph->xadj,
	                   graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
	                   &params->nparts, params->tpwgts, params->ubvec, options,
	                   &objval, partition_info->partion_table);
	      break;

	}
	if (status != METIS_OK) {
		fprintf(stderr,"\n***Metis returned with an error.***\n");
		return NULL;
	}
    partition_info->size = graph->nvtxs;
    partition_info->noOfParts = params->nparts;
    WritePartition(params->filename, partition_info->partion_table, graph->nvtxs, params->nparts);

	printf("Objval: %d\n",objval);

	matrix->nz = -1;
	matrix->n = graph->nvtxs;
	matrix->p = graph->xadj;
	matrix->i = graph->adjncy;
	matrix->x = NULL;


	return matrix;
}
Пример #20
0
int main(int argc, char **argv)
{
   Parameters *parameters;
   ULONG numLabels;
   Graph *g1;
   Graph *g2;
   Graph *g2compressed;
   InstanceList *instanceList;
   ULONG numInstances;
   ULONG subSize, graphSize, compressedSize;
   double subDL, graphDL, compressedDL;
   double value;
   Label label;

   parameters = GetParameters(argc, argv);
   g1 = ReadGraph(argv[argc - 2], parameters->labelList,
                  parameters->directed);
   g2 = ReadGraph(argv[argc - 1], parameters->labelList,
                  parameters->directed);
   instanceList = FindInstances(g1, g2, parameters);
   numInstances = CountInstances(instanceList);
   printf("Found %lu instances.\n\n", numInstances);
   g2compressed = CompressGraph(g2, instanceList, parameters);

   // Compute and print compression-based measures
   subSize = GraphSize(g1);
   graphSize = GraphSize(g2);
   compressedSize = GraphSize(g2compressed);
   value = ((double) graphSize) /
           (((double) subSize) + ((double) compressedSize));
   printf("Size of graph = %lu\n", graphSize);
   printf("Size of substructure = %lu\n", subSize);
   printf("Size of compressed graph = %lu\n", compressedSize);
   printf("Value = %f\n\n", value);

   // Compute and print MDL based measures
   numLabels = parameters->labelList->numLabels;
   subDL = MDL(g1, numLabels, parameters);
   graphDL = MDL(g2, numLabels, parameters);
   numLabels++; // add one for new "SUB" vertex label
   if ((parameters->allowInstanceOverlap) &&
       (InstancesOverlap(instanceList)))
      numLabels++; // add one for new "OVERLAP" edge label
   compressedDL = MDL(g2compressed, numLabels, parameters);
   // add extra bits to describe where external edges connect to instances
   compressedDL += ExternalEdgeBits(g2compressed, g1, numInstances);
   value = graphDL / (subDL + compressedDL);
   printf("DL of graph = %f\n", graphDL);
   printf("DL of substructure = %f\n", subDL);
   printf("DL of compressed graph = %f\n", compressedDL);
   printf("Value = %f\n\n", value);

   if (parameters->outputToFile)
   {
      // first, actually add "SUB" and "OVERLAP" labels
      label.labelType = STRING_LABEL;
      label.labelValue.stringLabel = SUB_LABEL_STRING;
      StoreLabel(& label, parameters->labelList);
      label.labelValue.stringLabel = OVERLAP_LABEL_STRING;
      StoreLabel(& label, parameters->labelList);
      parameters->posGraph = g2compressed;
      WriteGraphToDotFile(parameters->outFileName, parameters);
      printf("Compressed graph written to dot file %s\n",
             parameters->outFileName);
   }

   FreeGraph(g2compressed);
   FreeInstanceList(instanceList);
   FreeGraph(g1);
   FreeGraph(g2); 
   FreeParameters(parameters);

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

}