?? main_floor.cpp
字號:
/* File: main.cpp * Author: Dan Gibson * ECE 556 HW 3 * Contents: * The main function of a simulated annealing based * floorplanning algorithm. * * Last modified: * Development platforms: Solaris 9, MS-DOS, WINNT * Intended platforms: Solaris 9 */#include <stdio.h>#include <stdlib.h>#include <time.h>#include <math.h>#include "Floorplan.h"#include "SA_floor.h"
/********************************************************** * Function name: main() * Author: Dan Gibson * * Parameters: * initial_solution * A Floorplan object representing a starting * solution. * initial_temperature * A double representing the initial temperature * of the system. * alpha A double representing the cooling rate of the * system. 0 < alpha < 1 * beta A double representing the change in metropolis * parameter M over time. beta >= 1 * M A double representing the metropolis parameter * which controls Metropolis's effort and controls * how quickly time elapses. M >= 1 * Maxtime An unsigned integer representing the current time. * * Return value * * Zero indicates normal exit conditions * Nonzero indicated abnormal exit conditions * **********************************************************/int main(int argc, char * argv[]) { if(argc<2||argc>8) { fprintf(stdout,"Usage:\nfloorplan <infile> [lambda] [T0] [Tf] [prob M1] [prob M2] [prob M3]\n"); fprintf(stdout,"<infile> - name of file containing floorplan data\n"); fprintf(stdout,"<lambda> - cooling parameter (0<lambda<1) = 0.85\n"); fprintf(stdout,"[T0] - initial temperature = 2^(N+6), N=# modules\n"); fprintf(stdout,"[Tf] - final temperature = 10.0\n"); fprintf(stdout,"[prob M1] - incidence of M1 moves = 1\n"); fprintf(stdout,"[prob M2] - incidence of M2 moves = 1\n"); fprintf(stdout,"[prob M3] - incidence of M3 moves = 1\n"); return -1; }
srand(time(NULL));
// do argument processing Floorplan * f = ReadFloorplanFromFile(argv[1]); if(f==NULL) { fprintf(stderr,"Unable to open file: %s\n",argv[1]); return -1; } double lambda = 0.85; double T0 = pow(2.0,f->getModuleCount()+6); double Tf = 10.0; int prob_M1 = 1; int prob_M2 = 1; int prob_M3 = 1; switch(argc) { case 8: prob_M3 = atoi(argv[7]); case 7: prob_M2 = atoi(argv[6]); case 6: prob_M1 = atoi(argv[5]); case 5: Tf = strtod(argv[4],NULL); case 4: T0 = strtod(argv[3],NULL); case 3: lambda = strtod(argv[2],NULL); } // floorplan/lambda/prob M1/prob M2/prob M3 4 2 1 SimulatedAnnealing(f,lambda,T0,Tf,prob_M1,prob_M2,prob_M3);
/* srand(time(NULL)); double r; double sum = 0.0; double max = 0.0; double min = 1.0; for(int i=0;i<10000000;i++) { r = Rand01(); sum += r; if(r>max) max = r; if(r<min) min = r; if(r>=1.0 || r<0.0) fprintf(stdout,"Out of bounds, i=%i and r=%d\n",i,r); } fprintf(stdout,"Avg = %f\nMin = %f\nMax = %f\n",sum/10000000.0,min,max); *//* Floorplan * f = new Floorplan(1,2,3,2,2,2); // add more modules to play with f->AddModule(3,1,3);
f->AddModule(4,2,3);
f->AddModule(5,1,2);
f->AddModule(6,2,2); f->M1(1); f->M2(0); f->M2(1);
f->M2(3);
f->M3(4);
f->M3(8);
f->M3(6);
f->M3(7);
f->M2(1);
f->dumpTree();
fprintf(stdout,"\n");
fprintf(stdout,"Cost = %i\n",f->getArea());
delete f;
*//* f->M1(3); f->dumpList(); f->dumpTree(); fprintf(stdout,"\n"); int retval = f->M3(6); switch(retval) { case 0: fprintf(stdout,"Swap successful.\n"); break; default: fprintf(stdout,"Swap failed, code %i\n",retval); break; } f->dumpList(); f->dumpTree(); fprintf(stdout,"\n"); retval = f->M3(4); switch(retval) { case 0: fprintf(stdout,"Swap successful.\n"); break; default: fprintf(stdout,"Swap failed, code %i\n",retval); break; } f->dumpList(); f->dumpTree(); fprintf(stdout,"\n"); retval = f->M3(5); switch(retval) { case 0: fprintf(stdout,"Swap successful.\n"); break; default: fprintf(stdout,"Swap failed, code %i\n",retval); break; } f->dumpList(); f->dumpTree(); fprintf(stdout,"\n"); f->M2(0); f->dumpList(); f->dumpTree(); fprintf(stdout,"\n"); f->M2(2); f->dumpList(); f->dumpTree(); fprintf(stdout,"\n"); fprintf(stdout,"Area: %u\n",f->getArea());
delete f;*/ return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -