示例#1
0
int
main(int argc,
     char *argv[])
{
    ulong      	done;
    ulong	fail;
    ulong	net;
    ulong	insert;
    int		netsLeft;
int TIMELOOP;
for (TIMELOOP = 0; TIMELOOP < 20; ++TIMELOOP) {

    Option(argc, argv);

    BuildChannel();
    BuildVCG();
    AcyclicVCG();
    BuildHCG();

    do {
	/*
	 * Setup.
	 */
	AllocAssign();
	NetsAssign();
	InitAllocMaps();

	/*
	 * Copy the nets assign.
	 */
	channelTracksCopy = channelTracks;
	for (net = 1; net <= channelNets; net++) {
	    netsAssignCopy[net] = netsAssign[net];
	}

	/*
	 * Route, adding a row if necessary.
	 */
	fail = 0;
	do {
	    done = TRUE;
	    if ((netsLeft = DrawNets()) != 0) {
		printf("Assignment could not route %d columns, trying maze1...\n",
		       netsLeft);
		if ((netsLeft = Maze1()) != 0) {
		    printf("Maze1 could not route %d columns, trying maze2...\n",
			   netsLeft);
		    if ((netsLeft = Maze2()) != 0) {
			printf("Maze2 could not route %d columns, trying maze3...\n",
			       netsLeft);
			if ((netsLeft = Maze3()) != 0) {
			    printf("Maze3 could not route %d columns, adding a track...\n",
				   netsLeft);
			    /* PrintChannel(); */
			    if (! fail) {
				channelTracks++;
			    }
			    fail++;

			    /*
			     * Restore the nets assign.
			     */
			    for (net = 1; net <= channelNets; net++) {
				netsAssign[net] = netsAssignCopy[net];
			    }

			    /*
			     * Damn!
			     */
			    done = FALSE;
			}
		    }
		}
	    }

	    /*
	     * Add a track at track # fail, thereby shifting
	     * all tracks at that point down one track.
	     */
	    if ((! done) && fail) {
#ifdef VERBOSE
		printf("\n*** fail (insert track at %d) ***\n", fail);
#endif
		for (insert = 1; insert <= channelNets; insert++) {
		    if (netsAssign[insert] >= fail) {
			netsAssign[insert]++;
		    }
		}
	    }
	} while ((! done) && (fail <= channelTracksCopy + 1));

	/*
	 * Did adding a row within existing assignment work?
	 * If not, just start over.
	 */
	if (! done) {
	    FreeAllocMaps();
	    FreeAssign();
	    assert(channelTracks == channelTracksCopy + 1);
	}
    } while (! done);

    printf("\n");
    PrintChannel();
#ifdef PLUS_STATS
    PrintDerefStats(stderr);
    PrintHeapSize(stderr);
#endif /* PLUS_STATS */
}
    exit(0);
}
示例#2
0
文件: KS-2.c 项目: 8l/csolve
int     // sm: silence warning
main(int argc, char **argv)
{
    unsigned long p, iMax;
    float gMax, lastGMax;
    ModuleRecPtr mr;
    ;

    /* parse argument */
    if (argc != 2) {
	fprintf(stderr, "Usage: KL <input_file>\n");
        ;
	exit(1);
    }

    /* prepare the data structures */
    ReadNetList(argv[1]);
    NetsToModules();
    ComputeNetCosts();

    assert((numModules % 2) == 0);

    /* initial partition */
    InitLists();
    lastGMax = 0;

    /* do until we don't make any progress */
    do {

#ifndef KS_MODE
	/* compute the swap costs */
	ComputeDs(&(groupA), GroupA, SwappedToA);
	ComputeDs(&(groupB), GroupB, SwappedToB);
#endif /* !KS_MODE */

	/* for all pairs of nodes in A,B */
	for (p = 0; p<numModules/2; p++) {

#ifdef KS_MODE
	    /* compute the swap costs */
	    ComputeDs(&(groupA), GroupA, SwappedToA);
	    ComputeDs(&(groupB), GroupB, SwappedToB);
#endif /* KS_MODE */

	    /* find the max swap opportunity, and swap */
	    GP[p] = FindMaxGpAndSwap();

	}
	/* lists should both be empty now */
	assert(groupA.head == NULL && groupA.tail == NULL);
	assert(groupB.head == NULL && groupB.tail == NULL);

	gMax = FindGMax(&iMax);

	/* debug/statistics */
	if (lastGMax == gMax)
	    fprintf(stdout, "No progress: gMax = %f\n", gMax);
	lastGMax = gMax;
	fprintf(stdout, "gMax = %f, iMax = %lu\n", gMax, iMax);

	if (gMax > 0.0)
	    SwapSubsetAndReset(iMax);
	PrintResults(0);
    } while (gMax > 0.0);	/* progress made? */

    /* all swaps rejected */
    groupA = swapToB;
    for (mr = groupA.head; mr != NULL; mr = (*mr).next)
	moduleToGroup[(*mr).module] = GroupA;
    groupB = swapToA;
    for (mr = groupB.head; mr != NULL; mr = (*mr).next)
	moduleToGroup[(*mr).module] = GroupB;

    ;

    /* all done, show results */
    PrintResults(1);
#ifdef PLUS_STATS
    PrintDerefStats(stderr);
    PrintHeapSize(stderr);
#endif /* PLUS_STATS */
    exit(0);
    return 0;     // sm: silence warning
}
示例#3
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);
}