⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btree_main.cpp

📁 两种btree算法
💻 CPP
字号:
// Project: B*-tree based placement/floorplanning
// Advisor: Yao-Wen Chang  <ywchang@cis.nctu.edu.tw>
// Authors: Jer-Ming Hsu   <barz@cis.nctu.edu.tw>
// 	    Hsun-Cheng Lee <gis88526@cis.nctu.edu.tw>
// Sponsors: NSC, Taiwan; Arcadia, Inc.; UMC.
// Version 1.0
// Date:    7/19/2000

//---------------------------------------------------------------------------
#include <iostream>             
#include <cstring>
#include <ctime>
#include <cmath>
using namespace std;

#include "btree.h"
#include "sa.h"
//---------------------------------------------------------------------------

int main(int argc,char **argv)
{
   char filename[80],outfile[80]="";
   int times=400, local=7;
   double init_temp=0.9, term_temp=0.1;
   double alpha=1;
   double k3=1.0;

   int rand_seed = -1;

   // fixed-outline parameters
   double deadSpace = 0.15;
   double ar = -1;

   int format = 0;

   if(argc<=1)
   {
     printf( "Usage: btree <filename> [option]\n" );
	 printf( "Option: \n" );
	 printf( "   -simple      use simple format instead of MCNC format\n" );
	 printf( "   -seed d      rand seed \n" );
	 printf( "   -ar f        fixed-outline aspect ratio (default= %f)\n", ar );
	 printf( "   -maxWS f     fixed-outline maximum white space (default= %f)\n", deadSpace );
	 printf( "   -alpha f     area weight (wire weight = 1 - alpha) (default= %f)\n", alpha );
	 printf( "   -k3 f        AR weight (default= %.2f)\n", k3 );
	 printf( "   -P f         intial acceptance rate \n" );
	 //printf( "   -lamda f     simulated annealing lamda \n" );
     printf( "   -t d         # pertubations for each temperature (default= %d)\n", times );
     printf( "   -local d     # local searches (default= %d)\n", local );
     return 0;
   }
   else
   {
     int argi=1;
     if(argi < argc) strcpy(filename, argv[argi++]);

	 while( argi<argc )
	 {
	    string s = argv[argi++];
		if( s == "-n" )	// times
		{
			times = atoi( argv[argi++] );
		}
		else if( s == "-P" )
		{
			P = atof(argv[argi++]);
		}
		//else if( s == "-lamda" ) 
		//{
		//	lamda = atof(argv[argi++]);
		//} 
		else if( s == "-seed" )
		{
			rand_seed = atoi( argv[argi++] );
		}
		else if( s == "-ar" )
		{
			ar = atof( argv[argi++] );
		}
		else if( s == "-maxWS" )
		{
			deadSpace = atof( argv[argi++] );
		}
		else if( s == "-simple" )
		{
			format = 1;
		}
		else if( s == "-local" )
		{
			local = atoi( argv[argi++] );
		}
		else if( s == "-t" )
		{
			times = atoi( argv[argi++] );
		}
        else if( s == "-alpha" )
        {
            alpha = atof( argv[argi++] );
        }
        else if( s == "-k3" )
        {
            k3 = atof( argv[argi++] );
        }
		else
		{
			cout << "Wrong argument: " << s << endl;
			return 0;
		}
	 }

     //if(argi < argc) times=atoi(argv[argi++]);
     //if(argi < argc) local=atoi(argv[argi++]);
     //if(argi < argc) avg_ratio=atof(argv[argi++]);
     //if(argi < argc) alpha=atof(argv[argi++]);
     //if(argi < argc) lamda=atof(argv[argi++]);
     //if(argi < argc) term_temp=atof(argv[argi++]);
     //if(argi < argc) strcpy(outfile, argv[argi++]);
   }

   if( rand_seed == -1 )
   {
	   rand_seed = (unsigned)time( NULL );
	   srand( rand_seed );
   }

	cout << "\n circuit = " << filename 
		 << "\n format  = " << format 
		 << "\n seed    = " << rand_seed 
		 << "\n AR      = " << ar 
		 << "\n maxWS   = " << deadSpace 
		 << "\n alpha   = " << alpha
         << "\n k3      = " << k3
		 << "\n P       = " << P
		 << "\n lamda   = " << lamda 
		 << "\n local   = " << local 
		 << "\n times   = " << times 
		 << endl;

	//return 0;


   //try
   //{

     double time = seconds();
     B_Tree fp(alpha);
	 
	 switch( format )
	 {
	 case 0:
		 fp.read(filename);
		 break;
	 case 1:
		 fp.read_simple(filename );
		 break;
	 }


     fp.k3 = k3;
     if( ar >= 0 )
     {
        fp.outline_height = sqrt( (1.0+deadSpace) * ar * fp.getTotalArea() );
        fp.outline_width = sqrt( (1.0+deadSpace) / ar * fp.getTotalArea() );
        fp.outline_ratio = ar;
        printf( "outline: H %.2f   W %.2f\n", fp.outline_height, fp.outline_width );
     }
     else
     {
         fp.outline_ratio = -1;
     }

     fp.setOrientation();
     //fp.show_modules();
     fp.init();
	 
     //Random_Floorplan( fp, 100 );
	 fp.normalize_cost( 1000 );

     double last_time =  SA_Floorplan(fp, times, local, term_temp);
     //Random_Floorplan(fp,times);
     fp.list_information();

     { // log performance and quality
       if(strlen(outfile)==0)
         strcpy(outfile,strcat(filename,".res"));

       last_time = last_time - time;
	   double total_cpu = seconds() - time;
       printf("CPU time       = %.2f\n", total_cpu);
       printf("Last CPU time  = %.2f\n", last_time);
       FILE *fs= fopen(outfile,"a+");
       

       fprintf(fs,"CPU1= %5.2f, CPU2= %5.2f, Cost= %.6f, Area= %.0f, Dead= %.4f, Wire= %.0f, Seed= %d ",
               total_cpu,
		       last_time,
			   double(fp.getCost()),  
			   double(fp.getArea()),
			   double(fp.getDeadSpace()), 
               double(fp.getWireLength()), 
			   rand_seed );
       fprintf(fs," : %d %.2f %.4f \n", times, P, avg_ratio );

       // PS:
	   // avg_ratio <== avg delta cost


       fclose(fs);
     }

   //}
   //catch(...)
   //{
	  // printf( "Exception occured\n" );
   //}
   return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -