Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

debug.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00037 #include "basepacking.h"
00038 #include "btree.h"
00039 #include "debug.h"
00040 #include "netlist.h"
00041 #include "btreecompact.h"
00042 #include "btreeanneal.h"
00043 // #include "btreefromsstree.h"
00044 // #include "btreecompactsstree.h"
00045 #include "btreeslackeval.h"
00046 #include "mixedpacking.h"
00047 #include "mixedpackingfromdb.h"
00048 
00049 #include "pltobtree.h"
00050 #include "plsptobtree.h"
00051 #include "plcompact.h"
00052 
00053 // #include "datastrbacksoftst.h"
00054 // #include "datastrfrontsoftst.h"
00055 
00056 #include "allparquet.h"
00057 #include "ABKCommon/paramproc.h"
00058 #include "ABKCommon/abktimer.h"
00059 
00060 #include <iostream>
00061 #include <fstream>
00062 #include <iomanip>
00063 #include <string>
00064 #include <ctime>
00065 #include <cstdlib>
00066 #include <algorithm>
00067 //#include <algo.h>
00068 using namespace std;
00069 using namespace basepacking_h;
00070 using parquetfp::DB;
00071 using parquetfp::Command_Line;
00072 using parquetfp::SPeval;
00073 using parquetfp::Pl2SP;
00074 
00075 // --------------------------------------------------------
00076 int main(int argc, char *argv[])
00077 {
00078 //    ifstream infile;
00079 
00080 //    infile.open(argv[1]);
00081 //    if (!infile.good())
00082 //    {
00083 //       cout << "ERROR: cannot read file " << argv[1] << endl;
00084 //       exit(1);
00085 //    }
00086 //    HardBlockInfoType blockinfo(infile);
00087 //    OutputHardBlockInfoType(cout, blockinfo);
00088 
00089 //    cout.setf(ios::fixed);
00090 //    cout.precision(0);
00091 //    cout << "blocknum:  " << blockinfo.blocknum() << endl;
00092 //    cout << "blockarea: " << blockinfo.blockArea() << endl;
00093 
00094 //   BTree bt(blockinfo);
00095 //   OutputBTree(cout, bt);
00096 
00097 //   DebugBits2Tree(argc, argv);
00098 //   DebugEvaluate(argc, argv);
00099 //   DebugSwap(argc, argv);
00100 //   DebugMove(argc, argv);
00101 
00102 //   DebugParseBlocks(argc, argv);
00103 //   DebugParseNets(argc, argv);
00104 //   DebugHPWL(argc, argv);
00105 
00106 //   DebugCopy(argc, argv);
00107 //   DebugCompact(argc, argv);
00108 //   DebugAnneal(argc, argv);
00109 //   DebugWireAnneal(argc, argv);
00110 //   DebugSSTreeToBTree(argc, argv);
00111 //   DebugParquetBTree(argc, argv);
00112 //   DebugBTreeSlack(argc, argv);
00113 //   DebugMixedPacking(argc, argv);
00114 //   DebugSoftPacking(argc, argv);
00115 //   DebugPltoSP(argc, argv);
00116 //   DebugPltoBTree(argc, argv);
00117 //   DebugPlSPtoBTree(argc, argv);
00118 //   DebugShiftBlock(argc, argv);
00119 //   DebugShiftLegalizer(argc, argv);
00120 //   DebugMixedBlockInfoTypeFromDB(argc, argv);
00121 //   DebugBTreeAnnealerFromDB(argc, argv);
00122    DebugDBCorner(argc, argv);
00123    return 0;
00124 }
00125 // --------------------------------------------------------
00126 void DebugDBCorner(int argc, char *argv[])
00127 {
00128    
00129 }
00130 // --------------------------------------------------------
00131 void DebugBTreeAnnealerFromDB(int argc, char *argv[])
00132 {
00133    BoolParam help1 ("h", argc, argv);
00134    BoolParam help2 ("help", argc, argv);
00135    NoParams  noParams(argc,argv);  // this acts as a flag
00136    Command_Line* params = new Command_Line(argc, (const char **)argv);
00137    params->printAnnealerParams();
00138 
00139    if (noParams.found() || help1.found() || help2.found())
00140    {
00141       params->printHelp(argc, const_cast<const char**>(argv));
00142       exit (0);
00143    }    
00144 
00145    Timer T;
00146    T.stop();
00147    double totalTime=0;
00148    double successTime = 0;
00149    double successAvgWL = 0;
00150    double successAvgArea = 0;
00151 
00152    double minArea=1e100;
00153    double minWS=1e100;
00154    double minWL=1e100;
00155    double aveArea=0;
00156    double aveWS=0;
00157    double aveWL=0;
00158    double currArea;
00159    double lastArea;
00160    double currWS;
00161    double currWL;
00162    double currXSize;
00163    double currYSize;
00164    double successAR=0;
00165                 
00166    for (int i=0; i<params->iterations; i++)
00167    {
00168       DB* db = new DB(params->inFileName);
00169       double blocksArea = db->getNodesArea();
00170       double reqdArea = (1+(params->maxWS/100))*blocksArea;
00171       double reqdWidth = sqrt(reqdArea*params->reqdAR);
00172       double reqdHeight = reqdWidth/params->reqdAR;
00173       bool gotBetterSol = false;
00174 
00175       string blocksfilename(params->inFileName);
00176       blocksfilename += ".blocks";
00177       MixedBlockInfoType blockinfo(blocksfilename, "blocks");     
00178 
00179       T.start(0.0);
00180       BTreeAreaWireAnnealer *annealer_ptr = NULL;
00181 
00182       if (!strcmp(argv[argc-1], "--db"))
00183          annealer_ptr = new BTreeAreaWireAnnealer(params, db);
00184       else          
00185          annealer_ptr = new BTreeAreaWireAnnealer(blockinfo, params, db);      
00186       BTreeAreaWireAnnealer& annealer = *annealer_ptr;
00187       
00188       annealer.go();
00189       annealer.currSolution().save_bbb("dummy_out");
00190       T.stop();
00191 
00192       totalTime += T.getUserTime();
00193       currXSize = annealer.currSolution().totalWidth();  // db->getXSize();
00194       currYSize = annealer.currSolution().totalHeight(); // db->getYSize();
00195       currArea = currXSize*currYSize;
00196       currWS = 100*(currArea - blocksArea)/blocksArea; // currArea;
00197       currWL = db->evalHPWL();
00198       aveArea += currArea;
00199       aveWS += currWS;
00200       aveWL += currWL;
00201       if(minArea > currArea)
00202       {
00203          minArea = currArea;
00204          gotBetterSol = true;
00205       }
00206       if(minWS > currWS)
00207          minWS = currWS;
00208       if(minWL > currWL)
00209          minWL = currWL;
00210 
00211       if(params->reqdAR != -9999 && ((currArea<=reqdArea && 
00212                                       currXSize<=reqdWidth && currYSize<=reqdHeight) || db->successAR))
00213       {
00214          ++successAR;
00215          successTime += T.getUserTime();
00216          successAvgWL += currWL;
00217          successAvgArea += currArea;
00218       }
00219       //plot and save the best solution
00220 
00221       if(gotBetterSol)
00222       {
00223          if(params->plot)
00224          {
00225             double currAR = currXSize/currYSize;
00226             bool plotSlacks = !params->plotNoSlacks;
00227             bool plotNets = !params->plotNoNets;
00228             bool plotNames = !params->plotNoNames;
00229             db->plot("out.plt", currArea, currWS, currAR, T.getUserTime(), 
00230                      currWL, plotSlacks, plotNets, plotNames);
00231          }
00232          if(params->savePl)
00233             db->getNodes()->savePl(params->outPlFile);
00234 
00235          if(params->saveCapoPl)
00236             db->getNodes()->saveCapoPl(params->capoPlFile);
00237 
00238          if(params->saveCapo)
00239             db->saveCapo(params->capoBaseFile, params->reqdAR);
00240 
00241          if(params->save)
00242             db->save(params->baseFile);
00243               
00244          //if(db->successAR)
00245          //db->saveBestCopyPl("best.pl");
00246       }
00247       cout<<endl;
00248       delete annealer_ptr;
00249    }
00250    aveArea /= params->iterations;
00251    aveWS /= params->iterations;
00252    aveWL /= params->iterations;
00253    totalTime /= params->iterations;
00254    successTime /= successAR;
00255    successAvgWL /= successAR;
00256    successAvgArea /= successAR;
00257    successAR /= params->iterations;
00258         
00259    cout<<endl<<"Average Area: "<<aveArea<<" Minimum Area: "<<minArea<<endl
00260        <<"Average HPWL: "<<aveWL<<" Minimum HPWL: "<<minWL<<endl
00261        <<"Average WhiteSpace: "<<aveWS<<"%"<<" Minimum WhiteSpace: "
00262        <<minWS<<"%"<<endl
00263        <<"Average Time: "<<totalTime<<endl;
00264    if(params->reqdAR != -9999)
00265    {
00266       cout<<endl<<"Success Rate of satisfying fixed outline: "
00267           <<100*successAR<<" %"<<endl;
00268       cout<<"Average Time for successfull AR runs: "<<successTime<<endl;
00269       cout<<"Average Area for successfull AR runs: "<<successAvgArea<<endl;
00270       cout<<"Average WL for successfull AR runs: "<<successAvgWL<<endl;
00271    }
00272 }
00273 // --------------------------------------------------------
00274 void DebugMixedBlockInfoTypeFromDB(int argc, char *argv[])
00275 {
00276    ifstream infile;
00277    string blocksfilename(argv[1]);
00278    blocksfilename += ".blocks";
00279    infile.open(blocksfilename.c_str());
00280    if (!infile.good())
00281    {
00282       cout << "ERROR: Cannot open file: " << blocksfilename << endl;
00283       exit(1);
00284    }
00285 
00286    MixedBlockInfoType blockinfoOne(blocksfilename, "blocks");
00287 
00288    DB db(argv[1]);
00289    MixedBlockInfoTypeFromDB blockinfoTwo(db);
00290 
00291    ofstream outfile1("dummy_file");
00292    ofstream outfile2("dummy_db");
00293 
00294    outfile1.setf(ios::fixed);
00295    outfile1.precision(1);
00296    OutputMixedBlockInfoType(outfile1, blockinfoOne);
00297 
00298    outfile2.setf(ios::fixed);
00299    outfile2.precision(1);
00300    OutputMixedBlockInfoType(outfile2, blockinfoTwo);
00301 }
00302 // --------------------------------------------------------
00303 // void DebugShiftLegalizer(int argc, char *argv[])
00304 // {
00305 //    ifstream infile;
00306 //    infile.open(argv[1]);
00307 
00308 //    OrientedPacking packing;
00309 //    Read_bbb(infile, packing);
00310 //    Save_bbb(cout, packing);
00311    
00312 //    double left_bound, right_bound, bottom_bound, top_bound;
00313 //    cout << "Enter boundary <xStart><xEnd><yStart><yEnd> ->";
00314 //    cin >> left_bound >> right_bound >> bottom_bound >> top_bound;
00315 
00316 //    ShiftLegalizer legalizer(packing.xloc, packing.yloc,
00317 //                             packing.width, packing.height,
00318 //                             left_bound, right_bound,
00319 //                             top_bound, bottom_bound);
00320 
00321    
00322 //    int blocknum = packing.xloc.size();
00323 
00324 //    vector<int> checkBlks;
00325 //    vector<int> badBlks;
00326 
00327 // //    for (int i = 0; i < blocknum; i++)
00328 // //       checkBlks.push_back((i) % blocknum);
00329 
00330 //    checkBlks.push_back(0);
00331 //    checkBlks.push_back(1);
00332 //    checkBlks.push_back(2);
00333 
00334 //    bool success = legalizer.legalizeAll(ShiftLegalizer::NAIVE,
00335 //                                         checkBlks, badBlks);
00336 //    cout << ((success)? "no overlap afterwards" : "still have overlaps")
00337 //         << endl;
00338 // //    while (cin.good())
00339 // //    {
00340 // //       int currBlk = -1;
00341 // //       cout << "Select a block (0-" << (blocknum-1) << ") ->";
00342 // //       cin >> currBlk;
00343 // //       if (!cin.good())
00344 // //          break;
00345 
00346 // //       ShiftBlock shift_block(legalizer.xloc(), legalizer.yloc(),
00347 // //                              legalizer.widths(), legalizer.heights(),
00348 // //                              legalizer.leftBound(), legalizer.rightBound(),
00349 // //                              legalizer.topBound(), legalizer.bottomBound());
00350       
00351 // //       vector<ShiftBlock::ShiftInfo> currShiftinfo;
00352 // //       shift_block(currBlk, currShiftinfo);
00353 
00354 // //       cout << "----currShiftInfo[" << currBlk << "]-----" << endl;
00355 // //       OutputShiftInfo(cout, currShiftinfo);
00356 
00357 // //       bool success = legalizer.legalizeBlock(currBlk);
00358 // //       cout << ((success)? "no overlap afterwards" : "still have overlap")
00359 // //            << endl;
00360 
00361 // //       OrientedPacking newPK;
00362 // //       newPK.xloc = legalizer.xloc();
00363 // //       newPK.yloc = legalizer.yloc();
00364 // //       newPK.width = legalizer.widths();
00365 // //       newPK.height = legalizer.heights();
00366 
00367 // //       Save_bbb(cout, newPK);
00368 // //    }
00369 //    OrientedPacking finalPK;
00370 //    finalPK.xloc = legalizer.xloc();
00371 //    finalPK.yloc = legalizer.yloc();
00372 //    finalPK.width = legalizer.widths();
00373 //    finalPK.height = legalizer.heights();
00374 
00375 //    ofstream outfile;
00376 //    outfile.open(argv[2]);
00377 //    Save_bbb(outfile, finalPK);
00378 // }     
00379 // // --------------------------------------------------------
00380 // void DebugShiftBlock(int argc, char *argv[])
00381 // {   
00382 //    ifstream infile;
00383 //    infile.open(argv[1]);
00384    
00385 //    OrientedPacking packing;
00386 //    Read_bbb(infile, packing);
00387 
00388 //    Save_bbb(cout, packing);
00389 
00390 //    double left_bound, right_bound, bottom_bound, top_bound;
00391 //    cout << "Enter boundary <xStart><xEnd><yStart><yEnd> ->";
00392 //    cin >> left_bound >> right_bound >> bottom_bound >> top_bound;
00393 
00394 //    ShiftBlock shift_block(packing.xloc, packing.yloc,
00395 //                           packing.width, packing.height,
00396 //                           left_bound, right_bound,
00397 //                           top_bound, bottom_bound);
00398    
00399 //    int blocknum = packing.xloc.size();
00400 //    while (cin.good())
00401 //    {
00402 //       int currBlk = -1;
00403 //       cout << "Select a block (0-" << (blocknum-1) << ") ->";
00404 //       cin >> currBlk;
00405 
00406 //       vector<ShiftBlock::ShiftInfo> currShiftinfo;
00407 //       shift_block(currBlk, currShiftinfo);
00408 
00409 //       cout << "----currShiftInfo[" << currBlk << "]-----" << endl;
00410 //       cout << "NORTH: " << endl;
00411 //       cout << "shiftRangeMin: "
00412 //            << currShiftinfo[ShiftBlock::NORTH].shiftRangeMin << endl;
00413 //       cout << "shiftRangeMax: "
00414 //            << currShiftinfo[ShiftBlock::NORTH].shiftRangeMax << endl;
00415 //       cout << "overlapMin: "
00416 //            << currShiftinfo[ShiftBlock::NORTH].overlapMin << endl;
00417 //       cout << "overlapMax: "
00418 //            << currShiftinfo[ShiftBlock::NORTH].overlapMax << endl;
00419 //       cout << endl;
00420 
00421 //       cout << "EAST: " << endl;
00422 //       cout << "shiftRangeMin: "
00423 //            << currShiftinfo[ShiftBlock::EAST].shiftRangeMin << endl;
00424 //       cout << "shiftRangeMax: "
00425 //            << currShiftinfo[ShiftBlock::EAST].shiftRangeMax << endl;
00426 //       cout << "overlapMin: "
00427 //            << currShiftinfo[ShiftBlock::EAST].overlapMin << endl;
00428 //       cout << "overlapMax: "
00429 //            << currShiftinfo[ShiftBlock::EAST].overlapMax << endl;
00430 //       cout << endl;
00431       
00432 //       cout << "SOUTH: " << endl;
00433 //       cout << "shiftRangeMin: "
00434 //            << currShiftinfo[ShiftBlock::SOUTH].shiftRangeMin << endl;
00435 //       cout << "shiftRangeMax: "
00436 //            << currShiftinfo[ShiftBlock::SOUTH].shiftRangeMax << endl;
00437 //       cout << "overlapMin: "
00438 //            << currShiftinfo[ShiftBlock::SOUTH].overlapMin << endl;
00439 //       cout << "overlapMax: "
00440 //            << currShiftinfo[ShiftBlock::SOUTH].overlapMax << endl;
00441 //       cout << endl;
00442 
00443 //       cout << "WEST: " << endl;
00444 //       cout << "shiftRangeMin: "
00445 //            << currShiftinfo[ShiftBlock::WEST].shiftRangeMin << endl;
00446 //       cout << "shiftRangeMax: "
00447 //            << currShiftinfo[ShiftBlock::WEST].shiftRangeMax << endl;
00448 //       cout << "overlapMin: "
00449 //            << currShiftinfo[ShiftBlock::WEST].overlapMin << endl;
00450 //       cout << "overlapMax: "
00451 //            << currShiftinfo[ShiftBlock::WEST].overlapMax << endl;
00452 //       cout << endl;
00453 //       cout << "--------" << endl;
00454 //    }
00455 // }     
00456 // // --------------------------------------------------------
00457 // void DebugPlSPtoBTree(int argc, char *argv[])
00458 // {
00459 //    srand(time(NULL));
00460 //    srand48(time(NULL));
00461    
00462 //    Timer tm1;
00463 //    tm1.stop();
00464 //    ifstream infile;
00465 //    infile.open(argv[1]);
00466    
00467 //    OrientedPacking packing;
00468 //    Read_bbb(infile, packing);
00469 
00470 //    //    cout << "-----before pl2sp-----" << endl;
00471 // //    tm1.start();
00472 // //    Pl2SP pl2sp(packing.xloc, packing.yloc,
00473 // //                packing.width, packing.height,
00474 // //                parquetfp::TCG_ALGO);
00475 // //    tm1.stop();
00476 // //    cout << "-----pls2sp(TCG_ALGO) takes: " << tm1.getUserTime() << endl;
00477 
00478 // //    if (packing.xloc.size() < 400)
00479 // //    {
00480 // //       cout << "XX: ";
00481 // //       for (unsigned int i = 0; i < packing.xloc.size(); i++)
00482 // //          cout << pl2sp.getXSP()[i] << " ";
00483 // //       cout << endl;
00484 // //       cout << "YY: ";
00485 // //       for (unsigned int i = 0; i < packing.xloc.size(); i++)
00486 // //          cout << pl2sp.getYSP()[i] << " ";
00487 // //       cout << endl;
00488 // //    }
00489 
00490 // //    tm1.start();
00491 // //    PlSP2BTree plsp2btree(packing.xloc, packing.yloc,
00492 // //                          packing.width, packing.height,
00493 // //                          pl2sp.getXSP(), pl2sp.getYSP());
00494 // //    tm1.stop();
00495 // //    cout << "-----plsp2btree takes: " << tm1.getUserTime() << endl;
00496 
00497 //    infile.clear();
00498 //    infile.close();
00499 //    infile.open(argv[1]);
00500 
00501 //    double width, height;
00502 //    infile >> width >> height;
00503 //    HardBlockInfoType blockinfo(infile, "txt");
00504 // // //   OutputHardBlockInfoType(cout, blockinfo);
00505    
00506 // //    BTree recon_btree(blockinfo);
00507 // //    recon_btree.evaluate(plsp2btree.btree());   
00508 // //    tm1.start();
00509 // //    Pl2BTree pl2btree(packing.xloc, packing.yloc,
00510 // //                      packing.width, packing.height,
00511 // //                      Pl2BTree::TCG);
00512 // //    tm1.stop();
00513 // //    cout << "-----TCG algo takes: " << tm1.getUserTime() << endl;
00514   
00515 //    tm1.start();
00516 //    Pl2BTree pl2btree2(packing.xloc, packing.yloc,
00517 //                       packing.width, packing.height,
00518 //                       Pl2BTree::HEURISTIC);
00519 //    tm1.stop();
00520 //    cout << "-----heuristic algo takes: " << tm1.getUserTime() << endl;
00521 
00522 // //    BTree recon_btree_tcg(blockinfo, 1e-10);
00523 // //    recon_btree_tcg.evaluate(pl2btree.btree());
00524    
00525 //    BTree recon_btree_heur(blockinfo, 1e-6);
00526 //    recon_btree_heur.evaluate(pl2btree2.btree());
00527 //    BTreeOrientedPacking bopacking(recon_btree_heur);
00528    
00529 //    ofstream outfile;
00530 //    outfile.open("dummy_out");
00531 //    outfile.precision(0);
00532 //    Save_bbb(outfile, bopacking);
00533 
00534 //    printf("orig width: %.2lf height: %.2lf\n", width, height);
00535 //    printf("heur width: %.2lf height: %.2lf\n",
00536 //           recon_btree_heur.totalWidth(), recon_btree_heur.totalHeight());
00537 
00538 // //    bool same = true;
00539 // //    for (unsigned int i = 0; i < plsp2btree.btree().size(); i++)
00540 // //    {
00541 // //       const BTree::BTreeNode& node1 = pl2btree.btree()[i];
00542 // //       const BTree::BTreeNode& node2 = pl2btree2.btree()[i];
00543 // //       same = (same &&
00544 // //               node1.parent == node2.parent &&
00545 // //               node1.left == node2.left &&
00546 // //               node1.right == node2.right &&
00547 // //               node1.block_index == node2.block_index &&
00548 // //               node1.orient == node2.orient);
00549 // //    }
00550    
00551 // //    cout << ((same)? "TCG and heur btree same" : "btree not the same") << endl;
00552 // //    printf("orig width: %.2lf height: %.2lf \n", width, height);
00553 // //    printf("TCG  width: %.2lf height: %.2lf \nHeuristic width: %.2lf height: %.2lf\n",
00554 // //           recon_btree_tcg.totalWidth(), recon_btree_tcg.totalHeight(),
00555 // //           recon_btree_heur.totalWidth(), recon_btree_heur.totalHeight());
00556 
00557 // //    // ----compare sequence-pairs-----
00558 // //    bool sp_same = true;
00559 // //    for (unsigned int i = 0; i < pl2sp.getXSP().size(); i++)
00560 // //    {
00561 // //       sp_same = (sp_same &&
00562 // //                  int(pl2sp.getXSP()[i]) == pl2btree.getXX()[i] &&
00563 // //                  int(pl2sp.getYSP()[i]) == pl2btree.getYY()[i]);
00564 // //    }
00565 // //    cout << ((sp_same)? "SP same" : "SP not same") << endl;
00566 
00567 // //    // ----verify sequence-pairs-----
00568 // //    SPeval sp_eval(packing.height, packing.width, false);
00569 // //    sp_eval.evaluate(const_cast< vector<unsigned>& >(pl2sp.getXSP()),
00570 // //                     const_cast< vector<unsigned>& >(pl2sp.getYSP()));
00571 // //    cout << "-----sequence-pairs-----" << endl;
00572 // //    printf("Pl2SP(TCG_ALOG) width: %.2lf height: %.2lf\n",
00573 // //           sp_eval.xSize, sp_eval.ySize);
00574 
00575 // //    vector<unsigned> XXus(pl2btree.getXX().size());
00576 // //    vector<unsigned> YYus(pl2btree.getYY().size());
00577 // //    for (unsigned int i = 0; i < pl2btree.getXX().size(); i++)
00578 // //    {
00579 // //       XXus[i] = pl2btree.getXX()[i];
00580 // //       YYus[i] = pl2btree.getYY()[i];
00581 // //    }   
00582 // //    sp_eval.evaluate(XXus, YYus);
00583 // //    printf("pl2btree (TCG) width: %.2lf height: %.2lf\n",
00584 // //           sp_eval.xSize, sp_eval.ySize);
00585 // }
00586 // // --------------------------------------------------------
00587 // void DebugPltoBTree(int argc, char *argv[])
00588 // {
00589 //    srand(time(NULL));
00590 //    srand48(time(NULL));
00591    
00592 //    ifstream infile;
00593 //    infile.open(argv[1]);
00594 
00595 //    OrientedPacking packing;
00596 //    Read_bbb(infile, packing);
00597 
00598 //    vector<unsigned int> XXrand(packing.xloc.size());
00599 //    vector<unsigned int> YYrand(packing.yloc.size());
00600 
00601 //    int trial_num = 1000;
00602 //    int numSuccess = 0;
00603 //    for (int i = 0; i < trial_num; i++)
00604 //    {
00605       
00606 //    for (unsigned int i = 0; i < packing.xloc.size(); i++)
00607 //    {
00608 //       XXrand[i] = i;
00609 //       YYrand[i] = i;
00610 //    }
00611 //    random_shuffle(XXrand.begin(), XXrand.end());
00612 //    random_shuffle(YYrand.begin(), YYrand.end());
00613 
00614 // //    cout << "XX: ";
00615 // //    for (unsigned int i = 0; i < packing.xloc.size(); i++)
00616 // //       cout << XXrand[i] << " ";
00617 // //    cout << endl;
00618 // //    cout << "YY: ";
00619 // //    for (unsigned int i = 0; i < packing.yloc.size(); i++)
00620 // //       cout << YYrand[i] << " ";
00621 // //    cout << endl;
00622 
00623 //    SPeval sp_eval(packing.height, packing.width, false);
00624 //    sp_eval.evaluate(XXrand, YYrand);
00625    
00626 // //    cout << "-----before pl2sp-----" << endl;
00627 //    Pl2SP pl2sp(sp_eval.xloc, sp_eval.yloc,
00628 //                packing.width, packing.height,
00629 //                parquetfp::TCG_ALGO);
00630 // //    cout << "-----after pl2sp-----" << endl;
00631 
00632 
00633 // //    cout << "-----before pl2btree-----" << endl;
00634 //    Pl2BTree pl2btree(sp_eval.xloc,
00635 //                      sp_eval.yloc,
00636 //                      packing.width,
00637 //                      packing.height,
00638 //                      Pl2BTree::TCG);
00639 // //    cout << "-----after pl2btree-----" << endl;
00640 
00641 //    vector<unsigned int> XXnew(pl2btree.getXX().size());
00642 //    vector<unsigned int> YYnew(pl2btree.getYY().size());
00643 //    for (unsigned int i = 0; i < XXnew.size(); i++)
00644 //    {
00645 //       XXnew[i] = pl2btree.getXX()[i];
00646 //       YYnew[i] = pl2btree.getYY()[i];
00647 //    }
00648 
00649 //    if (pl2sp.getXSP() == XXnew && pl2sp.getYSP() == YYnew)
00650 //       numSuccess++;
00651 // //    if (pl2sp.getXSP() == XXnew)
00652 // // //       cout << "XX ok" << endl;
00653 // // //    else
00654 // // //       cout << "XX's differ" << endl;
00655 
00656 // //    if (pl2sp.getYSP() == YYnew)
00657 // // //       cout << "YY ok" << endl;
00658 // // //    else
00659 // // //       cout << "YY's differ" << endl;
00660 //    }
00661 
00662 //    cout << "numSuccess / trial_num: " << numSuccess << " / " << trial_num << endl;
00663    
00664 // //   OutputHardBlockInfoType(cout, blockinfo);
00665 
00666 // //    BTree recon_btree(blockinfo);
00667 // //    recon_btree.evaluate(pl2btree.btree());
00668 // // //   OutputBTree(cout, recon_btree);
00669    
00670 // //    BTreeOrientedPacking bopacking(recon_btree);
00671    
00672 // //    ofstream outfile;
00673 // //    outfile.open("dummy_out");
00674 // //    outfile.precision(0);
00675 // //    Save_bbb(outfile, bopacking);
00676 // }
00677 // // --------------------------------------------------------
00678 // void DebugPltoSP(int argc, char *argv[])
00679 // {
00680 //    ifstream infile;
00681 //    infile.open(argv[1]);
00682 //    HardBlockInfoType blockinfo(infile, "txt");
00683 
00684 //    int blocknum = blockinfo.blocknum();
00685 //    vector<unsigned int> XX(blocknum);
00686 //    vector<unsigned int> YY(blocknum);
00687 //    for (int i = 0; i < blocknum; i++)
00688 //    {
00689 //       XX[i] = unsigned(i);
00690 //       YY[i] = unsigned(i);
00691 //    }
00692 //    random_shuffle(XX.begin(), XX.end());
00693 //    random_shuffle(YY.begin(), YY.end());
00694 
00695 //    vector<double> widths(blocknum);
00696 //    vector<double> heights(blocknum);
00697 //    for (int i = 0; i < blocknum; i++)
00698 //    {
00699 //       widths[i] = blockinfo[i].width[0];
00700 //       heights[i] = blockinfo[i].height[0];
00701 //    }
00702 
00703 //    SPeval sp_eval(heights, widths, false);
00704 //    sp_eval.evaluate(XX, YY);
00705 //    cout << "done evaluate" << endl;
00706 
00707 //    Pl2SP pl2sp(sp_eval.xloc, sp_eval.yloc,
00708 //                widths, heights, parquetfp::TCG_ALGO);
00709 //    cout << "done pl2sp" << endl;   
00710 // }
00711 // // --------------------------------------------------------
00712 // void DebugSoftPacking(int argc, char *argv[])
00713 // {
00714 //    BoolParam help1 ("h", argc, argv);
00715 //    BoolParam help2 ("help", argc, argv);
00716 //    NoParams  noParams(argc,argv);  // this acts as a flag
00717 //    Command_Line* params = new Command_Line(argc, (const char **)argv);
00718 //    params->printAnnealerParams();
00719 
00720 //    if (noParams.found() || help1.found() || help2.found())
00721 //    {
00722 //       params->printHelp ();
00723 //       exit (0);
00724 //    } 
00725 
00726 //    DB* db = new DB(params->inFileName);
00727 
00728 //    string blocksfilename(params->inFileName);
00729 //    blocksfilename += ".blocks";
00730 //    MixedBlockInfoType blockinfo(blocksfilename, "blocks");
00731    
00732 //    BTreeAreaWireAnnealer annealer(blockinfo, params, db);
00733    
00734 //    cout << "---before packSoftBlocks()-----" << endl;   
00735 //    cout << endl;
00736    
00737 //    const BTree& initSolution = annealer.currSolution();
00738 //    initSolution.save_bbb("dummy_init");
00739 
00740 //    cout << "right before packSoftBlocks()" << endl;
00741    
00742 //    double oldArea = annealer.currSolution().totalArea();
00743 //    double newArea = oldArea;
00744 //    int iter = 0;
00745 //    while (cin.good())
00746 //    {
00747 //       annealer.packSoftBlocks(2);
00748 //       newArea = annealer.currSolution().totalArea();
00749 //       printf("[%d] area %.2lf -> %.2lf\n",
00750 //              iter, oldArea, newArea);
00751 //       iter++;
00752 //       oldArea = newArea;
00753 //       cin.get();
00754 //    }
00755 //    cout << "right after packSoftBlocks()" << endl;
00756    
00757 //    const BTree& finalSolution = annealer.currSolution();
00758 //    finalSolution.save_bbb("dummy_final");
00759 
00760 //    cout << "---after packSoftBlocks()-----" << endl;
00761 //    cout << endl;
00762 // }  
00763 // // --------------------------------------------------------
00764 // void DebugMixedPacking(int argc, char *argv[])
00765 // {
00766 //    MixedBlockInfoType blockinfo(argv[1], "blocks");
00767 //    OutputMixedBlockInfoType(cout, blockinfo);
00768 // }
00769 // // --------------------------------------------------------
00770 // void DebugBTreeSlack(int argc, char *argv[])
00771 // {
00772 // //   srand(time(NULL)); // 2
00773    
00774 //    ifstream infile;
00775 //    infile.open(argv[1]);
00776 //    if (!infile.good())
00777 //    {
00778 //       cout << "ERROR: cannot read file " << argv[1] << endl;
00779 //       exit(1);
00780 //    }
00781 //    HardBlockInfoType blockinfo(infile, "txt");
00782 //    BTree btree(blockinfo);
00783 
00784 //    BTreeAreaWireAnnealer::GenerateRandomSoln(btree, btree.NUM_BLOCKS);
00785 //    OutputBTree(cout, btree.tree);
00786 
00787 //    vector<BTree::BTreeNode> rev_tree(btree.tree.size());
00788 //    BTreeSlackEval::reverse_tree(btree.tree, rev_tree);
00789 //    OutputBTree(cout, rev_tree);
00790 
00791 //    cout << "bit-vectors" << endl;
00792 //    int UNDEFINED = BTree::UNDEFINED;
00793 //    int tree_prev = btree.NUM_BLOCKS;
00794 //    int tree_curr = btree.tree[btree.NUM_BLOCKS].left;
00795 
00796 //    const vector<BTree::BTreeNode>& tree = btree.tree;
00797 //    vector<int> tree_bits;
00798 //    while (tree_curr != btree.NUM_BLOCKS)
00799 //    {
00800 //       if (tree_prev == tree[tree_curr].parent)
00801 //       {
00802 //          if (tree_curr == tree[tree_prev].left)
00803 //          {
00804 //             cout << "0";
00805 //             tree_bits.push_back(0);
00806 //          }
00807 //          else
00808 //          {
00809 //             cout << "10";
00810 //             tree_bits.push_back(1);
00811 //             tree_bits.push_back(0);
00812 //          }
00813 
00814 //          tree_prev = tree_curr;
00815 //          if (tree[tree_curr].left != UNDEFINED)
00816 //             tree_curr = tree[tree_curr].left;
00817 //          else if (tree[tree_curr].right != UNDEFINED)
00818 //             tree_curr = tree[tree_curr].right;
00819 //          else
00820 //             tree_curr = tree[tree_curr].parent;
00821 //       }
00822 //       else if (tree_prev == tree[tree_curr].left)
00823 //       {
00824 //          cout << "1";
00825 //          tree_bits.push_back(1);
00826 
00827 //          tree_prev = tree_curr;
00828 //          if (tree[tree_curr].right != UNDEFINED)
00829 //             tree_curr = tree[tree_curr].right;
00830 //          else
00831 //             tree_curr = tree[tree_curr].parent;
00832 //       }
00833 //       else
00834 //       {
00835 //          tree_prev = tree_curr;
00836 //          tree_curr = tree[tree_curr].parent;
00837 //       }
00838 //    }
00839 //    cout << "1" << endl;
00840 //    tree_bits.push_back(1);
00841 //    tree_prev = btree.NUM_BLOCKS;
00842 //    tree_curr = rev_tree[btree.NUM_BLOCKS].left;
00843 
00844 //    vector<int> rev_tree_bits;
00845 //    while (tree_curr != btree.NUM_BLOCKS)
00846 //    {
00847 //       if (tree_prev == rev_tree[tree_curr].parent)
00848 //       {
00849 //          if (tree_curr == rev_tree[tree_prev].left)
00850 //          {
00851 //             cout << "0";
00852 //             rev_tree_bits.push_back(0);
00853 //          }
00854 //          else
00855 //          {
00856 //             cout << "10";
00857 //             rev_tree_bits.push_back(1);
00858 //             rev_tree_bits.push_back(0);
00859 //          }
00860 
00861 //          tree_prev = tree_curr;
00862 //          if (rev_tree[tree_curr].left != UNDEFINED)
00863 //             tree_curr = rev_tree[tree_curr].left;
00864 //          else if (rev_tree[tree_curr].right != UNDEFINED)
00865 //             tree_curr = rev_tree[tree_curr].right;
00866 //          else
00867 //             tree_curr = rev_tree[tree_curr].parent;
00868 //       }
00869 //       else if (tree_prev == rev_tree[tree_curr].left)
00870 //       {
00871 //          cout << "1";
00872 //          rev_tree_bits.push_back(1);
00873 
00874 //          tree_prev = tree_curr;
00875 //          if (rev_tree[tree_curr].right != UNDEFINED)
00876 //             tree_curr = rev_tree[tree_curr].right;
00877 //          else
00878 //             tree_curr = rev_tree[tree_curr].parent;
00879 //       }
00880 //       else
00881 //       {
00882 //          tree_prev = tree_curr;
00883 //          tree_curr = rev_tree[tree_curr].parent;
00884 //       }
00885 //    }
00886 //    cout << "1" << endl;
00887 //    rev_tree_bits.push_back(1);
00888 
00889 //    for (unsigned int i = 0; i < rev_tree_bits.size(); i++)
00890 //       rev_tree_bits[i] = (rev_tree_bits[i] == 1)? 0 : 1;
00891 
00892 //    cout << endl << "compare" << endl;
00893 //    copy(tree_bits.begin(), tree_bits.end(), ostream_iterator<int>(cout, ""));
00894 //    cout << endl;
00895    
00896 //    reverse(rev_tree_bits.begin(), rev_tree_bits.end());
00897 //    copy(rev_tree_bits.begin(), rev_tree_bits.end(), ostream_iterator<int>(cout, ""));
00898 //    cout << endl;
00899 
00900 //    btree.evaluate(btree.tree);
00901 //    btree.save_bbb("dummy");
00902 
00903 //    btree.evaluate(rev_tree);
00904 //    btree.save_bbb("dummy_rev");
00905 
00906 //    BTreeSlackEval slackEval(btree);
00907 
00908 //    slackEval.evaluateSlacks(btree);
00909 //    const vector<double> xSlack = slackEval.xSlack();
00910 //    const vector<double> ySlack = slackEval.ySlack();
00911 //    for (int i = 0; i < btree.NUM_BLOCKS; i++)
00912 //       cout << i << ": " << xSlack[i] << ", " << ySlack[i] << endl;
00913 // }
00914 // // --------------------------------------------------------
00915 // void DebugParquetBTree(int argc, char *argv[])
00916 // {
00917 //    BoolParam help1 ("h", argc, argv);
00918 //    BoolParam help2 ("help", argc, argv);
00919 //    NoParams  noParams(argc,argv);  // this acts as a flag
00920 //    Command_Line* params = new Command_Line(argc, (const char **)argv);
00921 //    params->printAnnealerParams();
00922 
00923 //    if (noParams.found() || help1.found() || help2.found())
00924 //    {
00925 //       params->printHelp ();
00926 //       exit (0);
00927 //    } 
00928 
00929 //    Timer T;
00930 //    T.stop();
00931 //    double totalTime=0;
00932 //    double successTime = 0;
00933 //    double successAvgWL = 0;
00934 //    double successAvgArea = 0;
00935 
00936 //    double minArea=1e100;
00937 //    double minWS=1e100;
00938 //    double minWL=1e100;
00939 //    double aveArea=0;
00940 //    double aveWS=0;
00941 //    double aveWL=0;
00942 //    double currArea;
00943 //    double lastArea;
00944 //    double currWS;
00945 //    double currWL;
00946 //    double currXSize;
00947 //    double currYSize;
00948 //    double successAR=0;
00949                 
00950 //    for (int i=0; i<params->iterations; i++)
00951 //    {
00952 //       DB* db = new DB(params->inFileName);
00953 //       double blocksArea = db->getNodesArea();
00954 //       double reqdArea = (1+(params->maxWS/100))*blocksArea;
00955 //       double reqdWidth = sqrt(reqdArea*params->reqdAR);
00956 //       double reqdHeight = reqdWidth/params->reqdAR;
00957 //       bool gotBetterSol = false;
00958 
00959 //       string blocksfilename(params->inFileName);
00960 //       blocksfilename += ".blocks";
00961 //       MixedBlockInfoType blockinfo(blocksfilename, "blocks");     
00962 
00963 //       T.start(0.0);
00964 //       BTreeAreaWireAnnealer annealer(blockinfo, params, db);
00965 //       annealer.go();
00966 //       annealer.currSolution().save_bbb("dummy_out");
00967 //       T.stop();
00968 
00969 //       totalTime += T.getUserTime();
00970 //       currXSize = annealer.currSolution().totalWidth();  // db->getXSize();
00971 //       currYSize = annealer.currSolution().totalHeight(); // db->getYSize();
00972 //       currArea = currXSize*currYSize;
00973 //       currWS = 100*(currArea - blocksArea)/blocksArea; // currArea;
00974 //       currWL = db->evalHPWL();
00975 //       aveArea += currArea;
00976 //       aveWS += currWS;
00977 //       aveWL += currWL;
00978 //       if(minArea > currArea)
00979 //       {
00980 //          minArea = currArea;
00981 //          gotBetterSol = true;
00982 //       }
00983 //       if(minWS > currWS)
00984 //          minWS = currWS;
00985 //       if(minWL > currWL)
00986 //          minWL = currWL;
00987 
00988 //       if(params->reqdAR != -9999 && ((currArea<=reqdArea && 
00989 //                                       currXSize<=reqdWidth && currYSize<=reqdHeight) || db->successAR))
00990 //       {
00991 //          ++successAR;
00992 //          successTime += T.getUserTime();
00993 //          successAvgWL += currWL;
00994 //          successAvgArea += currArea;
00995 //       }
00996 //       //plot and save the best solution
00997 
00998 //       if(gotBetterSol)
00999 //       {
01000 //          if(params->plot)
01001 //          {
01002 //             double currAR = currXSize/currYSize;
01003 //             bool plotSlacks = !params->plotNoSlacks;
01004 //             bool plotNets = !params->plotNoNets;
01005 //             bool plotNames = !params->plotNoNames;
01006 //             db->plot("out.plt", currArea, currWS, currAR, T.getUserTime(), 
01007 //                      currWL, plotSlacks, plotNets, plotNames);
01008 //          }
01009 //          if(params->savePl)
01010 //             db->getNodes()->savePl(params->outPlFile);
01011 
01012 //          if(params->saveCapoPl)
01013 //             db->getNodes()->saveCapoPl(params->capoPlFile);
01014 
01015 //          if(params->saveCapo)
01016 //             db->saveCapo(params->capoBaseFile, params->reqdAR);
01017 
01018 //          if(params->save)
01019 //             db->save(params->baseFile);
01020               
01021 //          //if(db->successAR)
01022 //          //db->saveBestCopyPl("best.pl");
01023 //       }
01024 //       cout<<endl;
01025 //    }
01026 //    aveArea /= params->iterations;
01027 //    aveWS /= params->iterations;
01028 //    aveWL /= params->iterations;
01029 //    totalTime /= params->iterations;
01030 //    successTime /= successAR;
01031 //    successAvgWL /= successAR;
01032 //    successAvgArea /= successAR;
01033 //    successAR /= params->iterations;
01034         
01035 //    cout<<endl<<"Average Area: "<<aveArea<<" Minimum Area: "<<minArea<<endl
01036 //        <<"Average HPWL: "<<aveWL<<" Minimum HPWL: "<<minWL<<endl
01037 //        <<"Average WhiteSpace: "<<aveWS<<"%"<<" Minimum WhiteSpace: "
01038 //        <<minWS<<"%"<<endl
01039 //        <<"Average Time: "<<totalTime<<endl;
01040 //    if(params->reqdAR != -9999)
01041 //    {
01042 //       cout<<endl<<"Success Rate of satisfying fixed outline: "
01043 //           <<100*successAR<<" %"<<endl;
01044 //       cout<<"Average Time for successfull AR runs: "<<successTime<<endl;
01045 //       cout<<"Average Area for successfull AR runs: "<<successAvgArea<<endl;
01046 //       cout<<"Average WL for successfull AR runs: "<<successAvgWL<<endl;
01047 //    }
01048 // }
01049 // // --------------------------------------------------------
01050 // void DebugSSTreeToBTree(int argc, char *argv[])
01051 // {
01052 //    srand(time(NULL));
01053    
01054 // //    ifstream infile;
01055 // //    infile.open(argv[1]);
01056 // //    if (!infile.good())
01057 // //    {
01058 // //       cout << "ERROR: cannot read file " << argv[1] << endl;
01059 // //       exit(1);
01060 // //    }
01061 // //    HardBlockInfoType blockinfo(infile, "txt"); // didn't sort
01062 
01063 //    ifstream infile2;
01064 //    infile2.open(argv[1]);
01065 //    if (!infile2.good())
01066 //    {
01067 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01068 //       exit(1);
01069 //    }
01070 //    BlockInfoType softblockinfo(BlockInfoType::TXT, infile2); // sorted   
01071 //    SoftSTree sst(softblockinfo);
01072 
01073 //    cout << "DONE WITH I/O (blocknum: " << softblockinfo.BLOCK_NUM() << ")" << endl;
01074 //    int blocknum = softblockinfo.BLOCK_NUM();
01075 //    vector<int> perm(blocknum);
01076 //    for (int i = 0; i < blocknum; i++)
01077 //       perm[i] = i;
01078 //    random_shuffle(perm.begin(), perm.end());
01079 //    cout << "after random_shuffle (perm.size: " << perm.size() << ")" << endl;
01080 
01081 //    int perm_ptr = 0;
01082 //    for (int i = 0; i < 2*blocknum - 1; i++)
01083 //    {
01084 //       if (sst.balance() <= 1)
01085 //       {
01086 //          sst.push_operand(perm[perm_ptr]);
01087 //          // cout << perm.back() << " ";
01088 //          perm_ptr++;
01089 //       }
01090 //       else
01091 //       {
01092 //          double rand_num = double(rand()) / RAND_MAX;
01093 //          if (perm_ptr < perm.size())
01094 //          {
01095 //             if (rand_num < 0.55)
01096 //             {
01097 //                sst.push_operand(perm[perm_ptr]);
01098 //                // cout << perm.back() << " ";
01099 //                perm_ptr++;
01100 //             }
01101 //             else if (rand_num < 0.775)
01102 //             {
01103 //                sst.push_operator(SoftSTree::STAR);
01104 // //               cout << "* ";
01105 //             }
01106 //             else
01107 //             {
01108 //                sst.push_operator(SoftSTree::PLUS);
01109 //                // cout << "+ ";
01110 //             }
01111 //          }
01112 //          else
01113 //          {
01114 //             if (rand_num < 0.5)
01115 //             {
01116 //                sst.push_operator(SoftSTree::BOTH);
01117 //                // cout << "- ";
01118 //             }
01119 //             else
01120 //             {
01121 //                sst.push_operator(SoftSTree::BOTH);
01122 //                // cout << "- ";
01123 //             }
01124 //          }            
01125 //       }
01126 
01127 //       if (i % 100 == 0)
01128 //          cout << "i: " << i << endl;
01129 //    }
01130 
01131 //    cout << "DONE WITH RANDOM STUFF (blocknum: " << perm.size() << ")" << endl;
01132 //    SoftSliceRecord ssr(sst); cout << "set SoftSliceRecord" << endl;
01133 //    SoftPacking spk(ssr, softblockinfo); cout << "set SoftPacking" << endl;
01134 
01135 //    BTreeCompactSlice(spk, "dummy_compacted");
01136 // //    for (vector<int>::iterator ptr = spk.expression.begin();
01137 // //         ptr != spk.expression.end(); ptr++)
01138 // //    {
01139 // //       int sign = *ptr;
01140 // //       if (SoftSTree::isOperand(sign))
01141 // //          cout << sign << " ";
01142 // //       else if (sign == SoftSTree::PLUS)
01143 // //          cout << "+ ";
01144 // //       else if (sign == SoftSTree::STAR)
01145 // //          cout << "* ";
01146 // //       else if (sign == SoftSTree::BOTH)
01147 // //          cout << "- ";
01148 // //       else
01149 // //          cout << "? ";
01150 // //    }
01151 // //    cout << endl;
01152    
01153 // //    ExplicitSoftPacking espk(spk); cout << "set ExplicitSoftPacking" << endl;
01154 // // //    for (vector<int>::iterator ptr = espk.expression.begin();
01155 // // //         ptr != espk.expression.end(); ptr++)
01156 // // //    {
01157 // // //       int sign = *ptr;
01158 // // //       if (SoftSTree::isOperand(sign))
01159 // // //          cout << sign << " ";
01160 // // //       else if (sign == SoftSTree::PLUS)
01161 // // //          cout << "+ ";
01162 // // //       else if (sign == SoftSTree::STAR)
01163 // // //          cout << "* ";
01164 // // //       else if (sign == SoftSTree::BOTH)
01165 // // //          cout << "- ";
01166 // // //       else
01167 // // //          cout << "? ";
01168 // // //    }
01169 // // //    cout << endl;   
01170 // //    SoftPackingHardBlockInfoType softhardblockinfo(spk); cout << "set SoftPackingHardBlockInfoType" << endl;
01171 // //    BTreeFromSoftPacking btree(softhardblockinfo, espk); cout << "set BTreeFromSoftPacking" << endl;
01172 
01173 // //    ofstream outfile[2];
01174 
01175 // //    outfile[0].open("dummy_slice");
01176 // //    spk.output(outfile[0]);
01177 // //    printf("slicing packing area: %.2lf (%%%.2lf)\n",
01178 // //           spk.totalWidth * spk.totalHeight,
01179 // //           (((spk.totalWidth * spk.totalHeight) / spk.blockArea) - 1) * 100);
01180 
01181 // //    btree.save_bbb("dummy_btree");
01182 // //    printf("btree packing area:   %.2lf (%%%.2lf)\n",
01183 // //           btree.totalArea(), (btree.totalArea() / btree.blockArea() - 1) * 100);
01184 
01185 // //    BTreeCompactor compactor(btree); cout << "set BTreeCompactor" << endl;
01186 // //    BTree orig_tree(btree);
01187 // //    int numChanged = 0;
01188 // //    int i = 0;
01189 // //    do
01190 // //    {
01191 // //       numChanged = compactor.compact();
01192    
01193 // // //    cout << "-----compacted packing-----" << endl;
01194 // // //    OutputPacking(cout, BTreeOrientedPacking(compactor));
01195 // // //    cout << "area: " << compactor.totalArea() << endl << endl;
01196 
01197 // //       printf("[%d] changed %6d: %.2lf (%%%.2lf) -> %.2lf (%%%.2lf)\n",
01198 // //              i, numChanged, orig_tree.totalArea(),
01199 // //              (orig_tree.totalArea() / orig_tree.blockArea() - 1) * 100,
01200 // //              compactor.totalArea(),
01201 // //              (compactor.totalArea() / compactor.blockArea() - 1) * 100);
01202 // //       i++;
01203 // //       orig_tree = compactor;
01204 // //    } while (numChanged != 0);
01205 
01206 // //    ofstream outfile_done;
01207 // //    outfile_done.open("dummy_done");
01208 // //    Save_bbb(outfile_done, BTreeOrientedPacking(compactor));
01209 // //    outfile_done.close();
01210 // }
01211 // // --------------------------------------------------------
01212 // void DebugWireAnneal(int argc, char *argv[])
01213 // {
01214 //    cout << "Inside debugWireAnneal" << endl;
01215 
01216 //    ifstream infile;
01217 //    Command_Line *params = new Command_Line(argc, (const char **)argv);
01218 //    DB *db = new DB(params->inFileName);
01219 
01220 //    // read "blockinfo"
01221 //    string blocksfilename(params->inFileName);
01222 //    blocksfilename += ".blocks";
01223 //    infile.open(blocksfilename.c_str());
01224 //    if (!infile.good())
01225 //    {
01226 //       cout << "ERROR: cannot read file " << blocksfilename << endl;
01227 //       exit(1);
01228 //    }
01229 //    else
01230 //       cout << "Opened file " << blocksfilename << endl;
01231 //    MixedBlockInfoType blockinfo(blocksfilename, "blocks");      
01232          
01233 //    BTreeAreaWireAnnealer annealer(blockinfo, params, db);
01234 //    cout << "annealer initialized sucessfully" << endl;
01235 
01236 //    cout << endl << endl;
01237 //    params->printAnnealerParams();   
01238 //    annealer.go();
01239 
01240 //    cout << "Exit successfully" << endl;   
01241 // }
01242 // // --------------------------------------------------------
01243 // // void DebugAnneal(int argc, char *argv[])
01244 // // {
01245 // //    srand(time(NULL)); // 2
01246 
01247 // //    ifstream infile;
01248 // //    infile.open(argv[1]);
01249 // //    if (!infile.good())
01250 // //    {
01251 // //       cout << "ERROR: cannot read file " << argv[1] << endl;
01252 // //       exit(1);
01253 // //    }
01254 // //    HardBlockInfoType blockinfo(infile, "txt");
01255 
01256 // //    BTreeAreaAnnealer annealer(blockinfo);
01257    
01258 // //    BTree *final_ptr = annealer.go_free_outline();
01259 // // //   double blkArea = blockinfo.blockArea();
01260 // // //   double dspace = atof(argv[2]);
01261 // // //   double ar = atof(argv[3]);
01262 // // //   BTree *final_ptr = annealer.go_fixed_outline(sqrt((blkArea * (1+dspace)) * ar),
01263 // // //                                                sqrt((blkArea * (1+dspace)) / ar));
01264 
01265 // // //   printf("dspace: %.2lf%% ar: %.2lf\n", dspace*100, ar);
01266 // //    printf("blockArea:   %.0lf\n", final_ptr ->blockArea());
01267 // //    printf("totalArea:   %.0lf (%.2lf%%)\n",
01268 // //           final_ptr ->totalArea(), 
01269 // //           ((final_ptr ->totalArea() / final_ptr ->blockArea() - 1) * 100));
01270 // // //    printf("width:  %.2lf (%.2lf)\n",
01271 // // //           final_ptr ->totalWidth(), sqrt((blkArea * (1+dspace)) * ar));
01272 // // //    printf("height: %.2lf (%.2lf)\n",
01273 // // //           final_ptr ->totalHeight(), sqrt((blkArea * (1+dspace)) / ar));          
01274 
01275 // //    ofstream outfile;
01276 // //    outfile.open("dummy");
01277 // //    Save_bbb(outfile, BTreeOrientedPacking(*final_ptr));
01278 // //    outfile.close();
01279 
01280 // //    BTreeCompactor compactor(*final_ptr);
01281 
01282 // //    int changeCount = 0;
01283 // //    double orig_area = compactor.totalArea();
01284 // //    do
01285 // //    {
01286 // //       changeCount = compactor.compact();
01287 // //       printf("changeCount: %3d %.2lf -> %.2lf\n",
01288 // //              changeCount, orig_area, compactor.totalArea());
01289 // //       orig_area = compactor.totalArea();
01290 // //    } while (changeCount > 0);
01291 
01292 // //    delete final_ptr;
01293 // // }      
01294 // // -------------------------------------------------------- 
01295 // void DebugCompact(int argc, char *argv[]) 
01296 // {
01297 //    srand(time(NULL));
01298 
01299 //    ifstream infile;
01300 //    infile.open(argv[1]);
01301 //    if (!infile.good())
01302 //    {
01303 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01304 //       exit(1);
01305 //    }
01306 //    HardBlockInfoType blockinfo(infile, "txt");
01307 
01308 //    vector<int> tree_bits;
01309 //    vector<int> tree_perm;
01310 //    vector<int> tree_orient;
01311 //    int balance = 0;
01312 //    for (int i = 0; i < 2*blockinfo.blocknum(); i++)
01313 //    {
01314 //       bool assigned = false;
01315 //       while (!assigned)
01316 //       {
01317 //          double rand_num = double(rand()) / (RAND_MAX+1.0);
01318 //          double threshold;
01319 
01320 //          if (balance == 0)
01321 //             threshold = 1; // push_back "0" for sure
01322 //          else if (balance == blockinfo.blocknum()) 
01323 //             threshold = 0; // push_back "1" for sure
01324 //          else
01325 //             threshold = 1 / (rand_num * (balance - rand_num));
01326          
01327 //          if (rand_num >= threshold)
01328 //          {
01329 //             tree_bits.push_back(1);
01330 //             balance--;
01331 //             assigned = true;
01332 //          }
01333 //          else
01334 //          {
01335 //             tree_bits.push_back(0);
01336 //             balance++;
01337 //             assigned = true;
01338 //          }
01339 //       }
01340 //    }
01341 
01342 //    tree_perm.resize(blockinfo.blocknum());
01343 //    iota(tree_perm.begin(), tree_perm.end(), 0);
01344 //    random_shuffle(tree_perm.begin(), tree_perm.end());
01345 
01346 //    for (int i = 0; i < blockinfo.blocknum(); i++)
01347 //    {
01348 //       int rand_num = int(8 * (double(rand()) / (RAND_MAX + 1.0)));
01349 //       tree_orient.push_back(rand_num);
01350 //    }
01351 
01352 // //    cout << "tree_bits: ";
01353 // //    copy(tree_bits.begin(), tree_bits.end(), ostream_iterator<int>(cout));
01354 // //    cout << endl;
01355 
01356 // //    cout << "tree_perm: ";
01357 // //    copy(tree_perm.begin(), tree_perm.end(), ostream_iterator<int>(cout, " "));
01358 // //    cout << endl;
01359 
01360 // //    cout << "tree_orient: ";
01361 // //    copy(tree_orient.begin(), tree_orient.end(), ostream_iterator<int>(cout, " "));
01362 // //    cout << endl;
01363    
01364 //    BTree orig_tree(blockinfo);
01365 //    orig_tree.evaluate(tree_bits, tree_perm, tree_orient);
01366 
01367 // //    cout << "-----original packing-----" << endl;
01368 // //    OutputPacking(cout, BTreeOrientedPacking(orig_tree));
01369 // //    cout << "area: " << orig_tree.totalArea() << endl << endl;
01370 
01371 //    ofstream outfile;
01372 //    outfile.open("dummy");
01373 //    Save_bbb(outfile, BTreeOrientedPacking(orig_tree));
01374 //    outfile.close();
01375 
01376 //    BTreeCompactor compactor(orig_tree);
01377 //    int numChanged = 0;
01378 //    int i = 0;
01379 //    do
01380 //    {
01381 //       numChanged = compactor.compact();
01382    
01383 // //    cout << "-----compacted packing-----" << endl;
01384 // //    OutputPacking(cout, BTreeOrientedPacking(compactor));
01385 // //    cout << "area: " << compactor.totalArea() << endl << endl;
01386 
01387 //       printf("[%d] changed %6d: %.2lf (%%%.2lf) -> %.2lf (%%%.2lf)\n",
01388 //              i, numChanged, orig_tree.totalArea(),
01389 //              (orig_tree.totalArea() / orig_tree.blockArea() - 1) * 100,
01390 //              compactor.totalArea(),
01391 //              (compactor.totalArea() / compactor.blockArea() - 1) * 100);
01392 //       i++;
01393 //       orig_tree = compactor;
01394 //    } while (numChanged != 0);
01395 
01396 //    ofstream outfile_done;
01397 //    outfile_done.open("dummy_done");
01398 //    Save_bbb(outfile_done, BTreeOrientedPacking(compactor));
01399 //    outfile_done.close();
01400 // }
01401 // // --------------------------------------------------------
01402 // void DebugCopy(int argc, char *argv[])
01403 // {
01404 //    ifstream infile[3];
01405 //    string base_name(argv[1]);
01406 //    char filename[100];
01407 
01408 //    sprintf(filename, "%s.blocks", base_name.c_str());
01409 //    infile[0].open(filename);
01410 
01411 //    sprintf(filename, "%s.nets", base_name.c_str());
01412 //    infile[1].open(filename);
01413 
01414 //    sprintf(filename, "%s.pl", base_name.c_str());
01415 //    infile[2].open(filename);
01416 
01417 //    HardBlockInfoType blockinfo(infile[0], "blocks");
01418 //    NetListType netlist(infile[2], infile[1], blockinfo);
01419 
01420 //    vector<int> tree_bits;
01421 //    vector<int> tree_perm;
01422 //    vector<int> tree_orient;
01423 //    int balance = 0;
01424 //    for (int i = 0; i < 2*blockinfo.blocknum(); i++)
01425 //    {
01426 //       bool assigned = false;
01427 //       while (!assigned)
01428 //       {
01429 //          int rand_num = int(2 * (double(rand()) / (RAND_MAX+1.0)));
01430 //          if (rand_num == 1)
01431 //          {
01432 //             if (balance > 0)
01433 //             {
01434 //                tree_bits.push_back(rand_num);
01435 //                balance--;
01436 //                assigned = true;
01437 //             }
01438 //          }
01439 //          else
01440 //          {
01441 //             if (balance < blockinfo.blocknum())
01442 //             {
01443 //                tree_bits.push_back(rand_num);
01444 //                balance++;
01445 //                assigned = true;
01446 //             }
01447 //          }
01448 //       }
01449 //    }
01450 
01451 //    for (int i = 0; i < blockinfo.blocknum(); i++)
01452 //       tree_perm.push_back(i);
01453 //    random_shuffle(tree_perm.begin(), tree_perm.end());
01454 
01455 //    for (int i = 0; i < blockinfo.blocknum(); i++)
01456 //    {
01457 //       int rand_num = int(8 * (double(rand()) / (RAND_MAX + 1.0)));
01458 //       tree_orient.push_back(rand_num);
01459 //    }
01460 
01461 //    BTree oldTree(blockinfo);
01462 //    BTree newTree(oldTree);
01463    
01464 //    oldTree.evaluate(tree_bits, tree_perm, tree_orient);
01465 //    newTree.evaluate(tree_bits, tree_perm, tree_orient);
01466 
01467 //    cout << "-----old packing-----" << endl;
01468 //    OutputPacking(cout, BTreeOrientedPacking(oldTree));
01469 //    cout << endl << endl;
01470 
01471 //    cout << "-----new packing-----" << endl;
01472 //    OutputPacking(cout, BTreeOrientedPacking(newTree));
01473 //    cout << endl << endl;
01474    
01475 //    printf("oldHPWL: %lf newHPWL: %lf\n",
01476 //           netlist.getHPWL(BTreeOrientedPacking(oldTree)),
01477 //           netlist.getHPWL(BTreeOrientedPacking(newTree)));
01478 //    while (cin.good())
01479 //    {
01480 //       int blkA, blkB;
01481 //       cout << "block A ->";
01482 //       cin >> blkA;
01483 
01484 //       do
01485 //       {
01486 //          cout << "block B ->";
01487 //          cin >> blkB;
01488 //       } while (blkA == blkB);
01489 
01490 //       newTree.swap(blkA, blkB);
01491 //       printf("oldHPWL: %lf newHPWL: %lf\n",
01492 //              netlist.getHPWL(BTreeOrientedPacking(oldTree)),
01493 //              netlist.getHPWL(BTreeOrientedPacking(newTree)));
01494 
01495 //       oldTree = newTree;
01496 //    }
01497 // }  
01498 // // --------------------------------------------------------
01499 // void DebugHPWL(int argc, char *argv[])
01500 // {
01501 //    ifstream infile[3];
01502 //    ifstream infile_bbb;
01503 
01504 //    string base_name(argv[1]);
01505 //    string bbb_name(argv[2]);
01506 //    char filename[100];
01507 
01508 //    sprintf(filename, "%s.blocks", base_name.c_str());
01509 //    infile[0].open(filename);
01510 
01511 //    sprintf(filename, "%s.nets", base_name.c_str());
01512 //    infile[1].open(filename);
01513 
01514 //    sprintf(filename, "%s.pl", base_name.c_str());
01515 //    infile[2].open(filename);
01516 
01517 //    infile_bbb.open(bbb_name.c_str());
01518 
01519 //    HardBlockInfoType blockinfo(infile[0], "blocks");
01520 //    NetListType netlist(infile[2], infile[1], blockinfo);
01521 //    OrientedPacking packing;
01522 //    Read_bbb(infile_bbb, packing);
01523 
01524 //    for (int i = 0; i < 10000; i++)
01525 //    {
01526 //       double HPWL = netlist.getHPWL(packing);
01527 //       cout << i << endl;
01528 //    }
01529 // }
01530 // // --------------------------------------------------------
01531 // void DebugParseNets(int argc, char *argv[])
01532 // {
01533 //    ifstream infile_blocks, infile_nets, infile_pl;
01534 //    ofstream outfile;
01535 
01536 //    infile_blocks.open(argv[1]);
01537 //    if (!infile_blocks.good())
01538 //    {
01539 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01540 //       exit(1);
01541 //    }
01542 
01543 //    infile_nets.open(argv[2]);
01544 //    if (!infile_nets.good())
01545 //    {
01546 //       cout << "ERROR: cannot read file " << argv[2] << endl;
01547 //       exit(1);
01548 //    }
01549 
01550 //    infile_pl.open(argv[3]);
01551 //    if (!infile_pl.good())
01552 //    {
01553 //       cout << "ERROR: cannot read file " << argv[3] << endl;
01554 //       exit(1);
01555 //    }
01556 
01557 //    HardBlockInfoType blockinfo(infile_blocks, "blocks");
01558 //    NetListType netlist(infile_pl, infile_nets, blockinfo);
01559 
01560 //    ofstream outfile_recon;
01561 //    outfile_recon.open("recon_nets");
01562 
01563 //    outfile_recon << "NumNets : " << netlist.nets.size() << endl << endl;
01564 //    int numNets = netlist.nets.size();
01565 //    for (int i = 0; i < numNets; i++)
01566 //    {
01567 //       char line[100];
01568 //       int netDegree = netlist.nets[i].pins.size() + netlist.nets[i].pads.size();
01569 //       sprintf(line, "NetDegree : %d", netDegree);
01570 //       outfile_recon << line << endl;
01571 
01572 //       for (unsigned int k = 0; k < netlist.nets[i].pads.size(); k++)
01573 //       {
01574 //          string pad_name("default");
01575 //          for (unsigned int p = 0; p < netlist.padinfo.size(); p++)
01576 //             if ((netlist.nets[i].pads[k].xloc == netlist.padinfo[p].xloc) &&
01577 //                 (netlist.nets[i].pads[k].yloc == netlist.padinfo[p].yloc))
01578 //             {
01579 //                pad_name = netlist.padinfo[p].pad_name;
01580 //                break;
01581 //             }
01582 //          outfile_recon << pad_name << " B" << endl;
01583 //       }
01584 
01585 //       for (unsigned int k = 0; k < netlist.nets[i].pins.size(); k++)
01586 //       {
01587 //          int block = netlist.nets[i].pins[k].block;
01588 //          double x_percent = (netlist.nets[i].pins[k].x_offset / blockinfo[block].width[0]) * 200;
01589 //          double y_percent = (netlist.nets[i].pins[k].y_offset / blockinfo[block].height[0]) * 200;
01590 //          sprintf(line, "%s B \t: %%%.1lf %%%.1lf",
01591 //                  blockinfo.block_names[block].c_str(), x_percent, y_percent);
01592 //          outfile_recon << line << endl;
01593 //       }
01594 //    }
01595 // }
01596 // // --------------------------------------------------------
01597 // void DebugParseBlocks(int argc, char *argv[])
01598 // {
01599 //    ifstream infile, infile2;
01600 //    ofstream outfile, outfile2;
01601 
01602 //    infile.open(argv[1]);
01603 //    if (!infile.good())
01604 //    {
01605 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01606 //       exit(1);
01607 //    }
01608 //    outfile.open("out1");
01609 
01610 //    HardBlockInfoType blockinfo(infile, "blocks");
01611 //    OutputHardBlockInfoType(outfile, blockinfo);
01612 //    outfile.close();
01613 //    infile.close();
01614    
01615 //    infile2.open(argv[2]);
01616 //    if (!infile2.good())
01617 //    {
01618 //       cout << "ERROR: cannot open file " << argv[2] << endl;
01619 //       exit(1);
01620 //    }
01621 //    outfile2.open("out2");
01622    
01623 //    HardBlockInfoType bbb_info(infile2, "txt");
01624 //    OutputHardBlockInfoType(outfile2, bbb_info);
01625 //    outfile2.close();
01626 //    infile2.close();
01627 
01628 //    cout << "-----block_names-----" << endl;
01629 //    for (unsigned int i = 0; i < blockinfo.block_names.size(); i++)
01630 //       printf("[%d]: %s\n", i, blockinfo.block_names[i].c_str());
01631 
01632 //    cout << endl;
01633 //    cout << "-----block_names (txt)-----" << endl;
01634 //    for (unsigned int i = 0; i < bbb_info.block_names.size(); i++)
01635 //       printf("[%d]: %s\n", i, bbb_info.block_names[i].c_str());
01636 // }
01637 // // --------------------------------------------------------
01638 // void DebugMove(int argc, char *argv[])
01639 // {
01640 //    ifstream infile;
01641 
01642 //    infile.open(argv[1]);
01643 //    if (!infile.good())
01644 //    {
01645 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01646 //       exit(1);
01647 //    }
01648 //    HardBlockInfoType blockinfo(infile, "txt");
01649 
01650 //    vector<int> tree_bits;
01651 //    vector<int> perm;
01652 //    vector<int> orient;
01653 
01654 //    string bits_string(argv[2]);
01655 //    for (unsigned int i = 0; i < bits_string.length(); i++)
01656 //    {
01657 //       string dummy;
01658 //       dummy += bits_string[i];
01659 //       int this_bit = atoi(dummy.c_str());
01660 
01661 //       tree_bits.push_back(this_bit);
01662 //    }
01663 
01664 //    string orients_string(argv[3]);
01665 //    for (unsigned int i = 0; i < orients_string.length(); i++)
01666 //    {
01667 //       string dummy;
01668 //       dummy += orients_string[i];
01669 //       int this_orient = atoi(dummy.c_str());
01670 
01671 //       orient.push_back(this_orient);
01672 //    }
01673 
01674 //    if (tree_bits.size() != 2 * orient.size())
01675 //    {
01676 //       cout << "ERROR: the sizes of tree_bits and orient not consistent."
01677 //            << endl;
01678 //       cout << "tree: " << tree_bits.size() << " vz. orient: "
01679 //            << orient.size() << endl;
01680 //       exit(1);
01681 //    }
01682 
01683 //    for (unsigned int i = 0; i < orient.size(); i++)
01684 //    {
01685 //       int blk = i;
01686 //       perm.push_back(blk);
01687 //    }
01688    
01689 //    cout << "tree:   ";
01690 //    for (unsigned int i = 0; i < tree_bits.size(); i++)
01691 //       cout << tree_bits[i] << " ";
01692 //    cout << endl;
01693 
01694 //    cout << "perm:   ";
01695 //    for (unsigned int i = 0; i < perm.size(); i++)
01696 //       cout << perm[i] << " ";
01697 //    cout << endl;
01698 
01699 //    cout << "orient: ";
01700 //    for (unsigned int i = 0; i < orient.size(); i++)
01701 //       cout << orient[i] << " ";
01702 //    cout << endl;
01703 
01704 //    cout << endl;
01705 
01706 // //    vector<BTree::BTreeNode> btree;
01707 // //    BTree::bits2tree(tree_bits, perm, orient, btree);
01708 // //    OutputBTree(cout, btree);
01709 
01710 //    BTree bt(blockinfo);
01711 //    bt.evaluate(tree_bits, perm, orient);
01712 
01713 //    OutputBTree(cout, bt);
01714 
01715 //    int index, target, leftChild;
01716 //    cout << "----move-----" << endl;
01717 //    cout << "index ->";
01718 //    cin >> index;
01719 
01720 //    cout << "target ->";
01721 //    cin >> target;
01722 
01723 //    cout << "leftChild (0 for true, 1 for false)->";
01724 //    cin >> leftChild;
01725 
01726 //    bt.move(index, target, (leftChild == 0));
01727 //    OutputBTree(cout, bt);
01728 //    bt.save_bbb(argv[argc-1]);
01729 // }
01730 // // --------------------------------------------------------
01731 // void DebugSwap(int argc, char *argv[])
01732 // {
01733 //    ifstream infile;
01734 
01735 //    infile.open(argv[1]);
01736 //    if (!infile.good())
01737 //    {
01738 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01739 //       exit(1);
01740 //    }
01741 //    HardBlockInfoType blockinfo(infile, "txt");
01742 
01743 //    vector<int> tree_bits;
01744 //    vector<int> perm;
01745 //    vector<int> orient;
01746 
01747 //    string bits_string(argv[2]);
01748 //    for (unsigned int i = 0; i < bits_string.length(); i++)
01749 //    {
01750 //       string dummy;
01751 //       dummy += bits_string[i];
01752 //       int this_bit = atoi(dummy.c_str());
01753 
01754 //       tree_bits.push_back(this_bit);
01755 //    }
01756 
01757 //    string orients_string(argv[3]);
01758 //    for (unsigned int i = 0; i < orients_string.length(); i++)
01759 //    {
01760 //       string dummy;
01761 //       dummy += orients_string[i];
01762 //       int this_orient = atoi(dummy.c_str());
01763 
01764 //       orient.push_back(this_orient);
01765 //    }
01766 
01767 //    if (tree_bits.size() != 2 * orient.size())
01768 //    {
01769 //       cout << "ERROR: the sizes of tree_bits and orient not consistent."
01770 //            << endl;
01771 //       cout << "tree: " << tree_bits.size() << " vz. orient: "
01772 //            << orient.size() << endl;
01773 //       exit(1);
01774 //    }
01775 
01776 //    for (unsigned int i = 0; i < orient.size(); i++)
01777 //    {
01778 //       int blk = -1;
01779 //       cout << "Enter next block ->";
01780 //       cin >> blk;
01781          
01782 //       perm.push_back(blk);
01783 //    }
01784    
01785 //    cout << "tree:   ";
01786 //    for (unsigned int i = 0; i < tree_bits.size(); i++)
01787 //       cout << tree_bits[i] << " ";
01788 //    cout << endl;
01789 
01790 //    cout << "perm:   ";
01791 //    for (unsigned int i = 0; i < perm.size(); i++)
01792 //       cout << perm[i] << " ";
01793 //    cout << endl;
01794 
01795 //    cout << "orient: ";
01796 //    for (unsigned int i = 0; i < orient.size(); i++)
01797 //       cout << orient[i] << " ";
01798 //    cout << endl;
01799 
01800 //    cout << endl;
01801 
01802 // //    vector<BTree::BTreeNode> btree;
01803 // //    BTree::bits2tree(tree_bits, perm, orient, btree);
01804 // //    OutputBTree(cout, btree);
01805 
01806 //    BTree bt(blockinfo);
01807 //    bt.evaluate(tree_bits, perm, orient);
01808 
01809 //    OutputBTree(cout, bt);
01810 
01811 //    int indexOne, indexTwo;
01812 //    cout << "----swap-----" << endl;
01813 //    cout << "block One ->";
01814 //    cin >> indexOne;
01815 
01816 //    cout << "block Two ->";
01817 //    cin >> indexTwo;
01818 
01819 //    bt.swap(indexOne, indexTwo);
01820 //    OutputBTree(cout, bt);
01821 //    bt.save_bbb(argv[argc-1]);
01822 // }
01823 // // --------------------------------------------------------
01824 // void DebugEvaluate(int argc, char *argv[])
01825 // {
01826 //    ifstream infile;
01827 
01828 //    infile.open(argv[1]);
01829 //    if (!infile.good())
01830 //    {
01831 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01832 //       exit(1);
01833 //    }
01834 //    HardBlockInfoType blockinfo(infile, "txt");
01835 
01836 //    vector<int> tree_bits;
01837 //    vector<int> perm;
01838 //    vector<int> orient;
01839 
01840 //    string bits_string(argv[2]);
01841 //    for (unsigned int i = 0; i < bits_string.length(); i++)
01842 //    {
01843 //       string dummy;
01844 //       dummy += bits_string[i];
01845 //       int this_bit = atoi(dummy.c_str());
01846 
01847 //       tree_bits.push_back(this_bit);
01848 //    }
01849 
01850 //    string orients_string(argv[3]);
01851 //    for (unsigned int i = 0; i < orients_string.length(); i++)
01852 //    {
01853 //       string dummy;
01854 //       dummy += orients_string[i];
01855 //       int this_orient = atoi(dummy.c_str());
01856 
01857 //       orient.push_back(this_orient);
01858 //    }
01859 
01860 //    if (tree_bits.size() != 2 * orient.size())
01861 //    {
01862 //       cout << "ERROR: the sizes of tree_bits and orient not consistent."
01863 //            << endl;
01864 //       cout << "tree: " << tree_bits.size() << " vz. orient: "
01865 //            << orient.size() << endl;
01866 //       exit(1);
01867 //    }
01868 
01869 //    for (unsigned int i = 0; i < orient.size(); i++)
01870 //    {
01871 //       int blk = -1;
01872 //       cout << "Enter next block ->";
01873 //       cin >> blk;
01874          
01875 //       perm.push_back(blk);
01876 //    }
01877    
01878 //    cout << "tree:   ";
01879 //    for (unsigned int i = 0; i < tree_bits.size(); i++)
01880 //       cout << tree_bits[i] << " ";
01881 //    cout << endl;
01882 
01883 //    cout << "perm:   ";
01884 //    for (unsigned int i = 0; i < perm.size(); i++)
01885 //       cout << perm[i] << " ";
01886 //    cout << endl;
01887 
01888 //    cout << "orient: ";
01889 //    for (unsigned int i = 0; i < orient.size(); i++)
01890 //       cout << orient[i] << " ";
01891 //    cout << endl;
01892 
01893 //    cout << endl;
01894 
01895 // //    vector<BTree::BTreeNode> btree;
01896 // //    BTree::bits2tree(tree_bits, perm, orient, btree);
01897 // //    OutputBTree(cout, btree);
01898 
01899 //    BTree bt(blockinfo);
01900 //    bt.evaluate(tree_bits, perm, orient);
01901 
01902 //    OutputBTree(cout, bt);
01903 
01904 //    cout << "-----take 2-----" << endl;
01905 //    cout << "tree: ";
01906 //    for (int i = 0; i < 2*bt.NUM_BLOCKS; i++)
01907 //       cin >> tree_bits[i];
01908 
01909 //    cout << "perm: ";
01910 //    for (int i = 0; i < bt.NUM_BLOCKS; i++)
01911 //       cin >> perm[i];
01912 
01913 //    cout << "orient: ";
01914 //    for (int i = 0; i < bt.NUM_BLOCKS; i++)
01915 //       cin >> orient[i];
01916 
01917 //    bt.evaluate(tree_bits, perm, orient);
01918 //    OutputBTree(cout, bt);
01919 //    bt.save_bbb(argv[argc-1]);
01920 // }
01921 // // --------------------------------------------------------
01922 // void DebugBits2Tree(int argc, char *argv[])
01923 // {
01924 //    ifstream infile;
01925    
01926 //    infile.open(argv[1]);
01927 //    if (!infile.good())
01928 //    {
01929 //       cout << "ERROR: cannot read file " << argv[1] << endl;
01930 //       exit(1);
01931 //    }
01932 //    HardBlockInfoType blockinfo(infile, "txt");
01933 
01934 //    vector<int> tree_bits;
01935 //    vector<int> perm;
01936 //    vector<int> orient;
01937 
01938 //    string bits_string(argv[2]);
01939 //    for (unsigned int i = 0; i < bits_string.length(); i++)
01940 //    {
01941 //       string dummy;
01942 //       dummy += bits_string[i];
01943 //       int this_bit = atoi(dummy.c_str());
01944 
01945 //       tree_bits.push_back(this_bit);
01946 //    }
01947 
01948 //    string orients_string(argv[3]);
01949 //    for (unsigned int i = 0; i < orients_string.length(); i++)
01950 //    {
01951 //       string dummy;
01952 //       dummy += orients_string[i];
01953 //       int this_orient = atoi(dummy.c_str());
01954 
01955 //       orient.push_back(this_orient);
01956 //    }
01957 
01958 //    if (tree_bits.size() != 2 * orient.size())
01959 //    {
01960 //       cout << "ERROR: the sizes of tree_bits and orient not consistent."
01961 //            << endl;
01962 //       cout << "tree: " << tree_bits.size() << " vz. orient: "
01963 //            << orient.size() << endl;
01964 //       exit(1);
01965 //    }
01966 
01967 //    for (unsigned int i = 0; i < orient.size(); i++)
01968 //    {
01969 //       perm.push_back(i);
01970 //    }
01971 
01972 //    for (unsigned int i = 0; i < tree_bits.size(); i++)
01973 //       cout << tree_bits[i] << " ";
01974 //    cout << endl;
01975 
01976 //    for (unsigned int i = 0; i < perm.size(); i++)
01977 //       cout << perm[i] << " ";
01978 //    cout << endl;
01979 
01980 //    for (unsigned int i = 0; i < orient.size(); i++)
01981 //       cout << orient[i] << " ";
01982 //    cout << endl;
01983 
01984 //    vector<BTree::BTreeNode> btree;
01985 //    cout << "-----BEFORE-----" << endl;
01986 //    OutputBTree(cout, btree);
01987 //    cout << endl;
01988    
01989 //    BTree::bits2tree(tree_bits, perm, orient, btree);
01990 
01991 //    cout << "-----AFTER-----" << endl;
01992 //    OutputBTree(cout, btree);
01993 //    cout << endl;
01994 // }
01995 // // --------------------------------------------------------
01996 void OutputHardBlockInfoType(ostream& outs,
01997                              const HardBlockInfoType& blockinfo)
01998 {
01999    outs << "index:     ";
02000    for (int i = 0; i < blockinfo.blocknum()+2; i++)
02001       outs << setw(FIELD_WIDTH) << i;
02002    outs << endl << endl;
02003 
02004    for (int j = 0; j < HardBlockInfoType::ORIENT_NUM; j++)
02005    {
02006       outs << "width[" << j << "]:  ";
02007       for (int i = 0; i < blockinfo.blocknum()+2; i++)
02008          if (blockinfo[i].width[j] >= Dimension::INFTY)
02009             outs << " infty";
02010          else
02011             outs << setw(FIELD_WIDTH) << blockinfo[i].width[j];
02012       outs << endl;
02013 
02014       outs << "height[" << j << "]: ";
02015       for (int i = 0; i < blockinfo.blocknum()+2; i++)
02016          if (blockinfo[i].height[j] >= Dimension::INFTY)
02017             outs << " infty";
02018          else
02019             outs << setw(FIELD_WIDTH) << blockinfo[i].height[j];
02020       outs << endl << endl;
02021    }
02022 }
02023 // --------------------------------------------------------
02024 void OutputBTree(ostream& outs,
02025                  const vector<BTree::BTreeNode>& btree)
02026 {
02027    int btree_size = btree.size();
02028    outs << "btree_size: " << btree_size << endl;
02029    outs << "index:      ";
02030    for (int i = 0; i < btree_size; i++)
02031       outs << setw(FIELD_WIDTH) << i;
02032    outs << endl;
02033           
02034    outs << "tree.par:   ";
02035    for (int i = 0; i < btree_size; i++)
02036       OutputIndex(outs, btree[i].parent);
02037    outs << endl;
02038 
02039    outs << "tree.left:  ";
02040    for (int i = 0; i < btree_size; i++)
02041       OutputIndex(outs, btree[i].left);
02042    outs << endl;
02043 
02044    outs << "tree.right: ";
02045    for (int i = 0; i < btree_size; i++)
02046       OutputIndex(outs, btree[i].right);
02047    outs << endl;
02048 
02049    outs << "tree.bkind: ";
02050    for (int i = 0; i < btree_size; i++)
02051       OutputIndex(outs, btree[i].block_index);
02052    outs << endl;
02053 
02054    outs << "tree.orien: ";
02055    for (int i = 0; i < btree_size; i++)
02056       OutputIndex(outs, btree[i].orient);
02057    outs << endl;
02058 
02059    outs << endl;
02060 
02061 }
02062 // --------------------------------------------------------
02063 void OutputBTree(ostream& outs,
02064                  const BTree& bt)
02065 {
02066    outs << "NUM_BLOCKS: " << bt.NUM_BLOCKS << endl << endl;
02067    outs << "index:      ";
02068    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02069       OutputIndex(cout, i);
02070    outs << endl;
02071           
02072    outs << "tree.par:   ";
02073    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02074       OutputIndex(cout, bt.tree[i].parent);
02075    outs << endl;
02076 
02077    outs << "tree.left:  ";
02078    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02079       OutputIndex(cout, bt.tree[i].left);
02080    outs << endl;
02081 
02082    outs << "tree.right: ";
02083    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02084       OutputIndex(cout, bt.tree[i].right);
02085    outs << endl;
02086 
02087    outs << "tree.bkind: ";
02088    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02089       OutputIndex(cout, bt.tree[i].block_index);
02090    outs << endl;
02091 
02092    outs << "tree.orien: ";
02093    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02094       OutputIndex(cout, bt.tree[i].orient);
02095    outs << endl;
02096 
02097    outs << endl;
02098 
02099    outs << "cont.next:  ";
02100    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02101       OutputIndex(cout, bt.contour[i].next);
02102    outs << endl;
02103 
02104    outs << "cont.prev:  ";
02105    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02106       OutputIndex(cout, bt.contour[i].prev);
02107    outs << endl;
02108 
02109    outs << "cont.begin: ";
02110    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02111       OutputDouble(outs, bt.contour[i].begin);
02112    outs << endl;
02113 
02114    outs << "cont.end:   ";
02115    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02116       OutputDouble(outs, bt.contour[i].end);
02117    outs << endl;//    while (cin.good())
02118 
02119    outs << "cont.CTL:   ";
02120    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02121       OutputDouble(outs, bt.contour[i].CTL);
02122    outs << endl;
02123 
02124    outs << endl;
02125 
02126    outs << "xloc:       ";
02127    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02128       OutputDouble(outs, bt.xloc(i));
02129    outs << endl;
02130 
02131    outs << "yloc:       ";
02132    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02133       OutputDouble(outs, bt.yloc(i));
02134    outs << endl;
02135 
02136    outs << "width:      ";
02137    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02138       OutputDouble(outs, bt.width(i));
02139    outs << endl;
02140 
02141    outs << "height:     ";
02142    for (int i = 0; i < bt.NUM_BLOCKS+2; i++)
02143       OutputDouble(outs, bt.height(i));
02144    outs << endl;
02145 
02146    outs << endl;
02147 
02148    outs << "blockArea:   " << bt.blockArea() << endl;
02149    outs << "totalArea:   " << bt.totalArea() << endl;
02150    outs << "totalWidth:  " << bt.totalWidth() << endl;
02151    outs << "totalHeight: " << bt.totalHeight() << endl;
02152 
02153    outs << endl;
02154    outs << "-----contour (L to R)-----" << endl;
02155 
02156    outs << "index: ";
02157    int cPtr = bt.NUM_BLOCKS;
02158    while (cPtr != BTree::UNDEFINED)
02159    {
02160       outs << setw(FIELD_WIDTH) << cPtr;
02161       cPtr = bt.contour[cPtr].next;
02162    }
02163    outs << endl;
02164 
02165    outs << "begin: ";
02166    cPtr = bt.NUM_BLOCKS;
02167    while (cPtr != BTree::UNDEFINED)
02168    {
02169       OutputDouble(cout, bt.contour[cPtr].begin);
02170       cPtr = bt.contour[cPtr].next;
02171    }
02172    outs << endl;
02173 
02174    outs << "end:   ";
02175    cPtr = bt.NUM_BLOCKS;
02176    while (cPtr != BTree::UNDEFINED)
02177    {
02178       OutputDouble(cout, bt.contour[cPtr].end);
02179       cPtr = bt.contour[cPtr].next;
02180    }
02181    outs << endl;
02182 
02183    outs << "CTL:   ";
02184    cPtr = bt.NUM_BLOCKS;
02185    while (cPtr != BTree::UNDEFINED)
02186    {
02187       OutputDouble(cout, bt.contour[cPtr].CTL);
02188       cPtr = bt.contour[cPtr].next;
02189    }
02190    outs << endl;
02191 }
02192 // --------------------------------------------------------
02193 void OutputPacking(ostream& outs,
02194                    const OrientedPacking& pk)
02195 {
02196    int blocknum = pk.xloc.size();
02197    outs << setw(9) << "xloc: ";
02198    for (int i = 0; i < blocknum; i++)
02199       outs << setw(5) << pk.xloc[i];
02200    outs << endl;
02201 
02202    outs << setw(9) << "yloc: ";
02203    for (int i = 0; i < blocknum; i++)
02204       outs << setw(5) << pk.yloc[i];
02205    outs << endl;
02206 
02207    outs << setw(9) << "width: ";
02208    for (int i = 0; i < blocknum ; i++)
02209       outs << setw(5) << pk.width[i];
02210    outs << endl;
02211 
02212    outs << setw(9) << "height: ";
02213    for (int i = 0; i < blocknum; i++)
02214       outs << setw(5) << pk.height[i];
02215    outs << endl;
02216 
02217    outs << setw(9) << "orient: ";
02218    for (int i = 0; i < blocknum; i++)
02219       outs << setw(5) << pk.orient[i];
02220    outs << endl;
02221 }
02222 // --------------------------------------------------------
02223 void OutputDouble(ostream& outs, double d)
02224 {
02225    outs.setf(ios::fixed);
02226    outs.precision(1);
02227    if (d >= Dimension::INFTY)
02228       outs << setw(FIELD_WIDTH) << "infty";
02229 
02230    else if (d == Dimension::UNDEFINED)
02231       outs << setw(FIELD_WIDTH) << "-";
02232    else
02233       outs << setw(FIELD_WIDTH) << d;
02234 }
02235 // --------------------------------------------------------
02236 void OutputIndex(ostream& outs, int i)
02237 {
02238    if (i == Dimension::UNDEFINED)
02239       outs << setw(FIELD_WIDTH) << "-";
02240    else
02241       outs << setw(FIELD_WIDTH) << i;
02242 }
02243 // --------------------------------------------------------
02244 void OutputMixedBlockInfoType(ostream& outs,
02245                               const MixedBlockInfoType& blockinfo)
02246 {
02247    int vec_size = blockinfo.blockARinfo.size();
02248 
02249    outs << "_currDimensions: " << endl;
02250    outs << "name:     ";
02251    for (int i = 0; i < vec_size; i++)
02252    {
02253       char name[100];
02254       sprintf(name, "\"%s\"",
02255               blockinfo.currDimensions.block_names[i].c_str());
02256       outs << setw(FIELD_WIDTH) << name;
02257    }
02258    outs << endl;
02259    OutputHardBlockInfoType(outs, blockinfo.currDimensions);
02260    outs << endl;
02261 
02262    outs << "_blockARinfo: " << endl;
02263    outs.setf(ios::fixed);
02264    outs.precision(2);
02265    outs << "index:    ";
02266    for (int i = 0; i < vec_size; i++)
02267       OutputIndex(outs, i);
02268    outs << endl;
02269    for (int j = 0; j < MixedBlockInfoType::ORIENT_NUM; j++)
02270    {
02271       outs << "minAR[" << j << "]: ";      
02272       for (int i = 0; i < vec_size; i++)
02273          OutputDouble(outs, blockinfo.blockARinfo[i].minAR[j]);
02274       outs << endl;
02275       outs << "maxAR[" << j << "]: ";
02276       for (int i = 0; i < vec_size; i++)
02277          OutputDouble(outs, blockinfo.blockARinfo[i].maxAR[j]);
02278       outs << endl << endl;
02279    }
02280    outs << "area:  ";
02281    for (int i = 0; i < vec_size; i++)
02282       OutputDouble(outs, blockinfo.blockARinfo[i].area);
02283    outs << endl;
02284 
02285    outs << "isSoft: ";
02286    for (int i = 0; i < vec_size; i++)
02287       outs << setw(FIELD_WIDTH)
02288            << ((blockinfo.blockARinfo[i].isSoft)? "SOFT" : "HARD");
02289    outs << endl;
02290 }
02291 // --------------------------------------------------------
02292    
02293    
02294    

Generated on Mon Apr 25 01:09:24 2005 for Parquete by doxygen 1.3.2