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

btreeanneal.h

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 
00038 
00039 
00040 
00041 #ifndef BTREEANNEAL_H
00042 #define BTREEANNEAL_H 
00043 
00044 #include "basepacking.h"
00045 #include "mixedpacking.h"
00046 #include "btree.h"
00047 #include "btreeslackeval.h"
00048 #include "btreecompact.h"
00049 #include "baseannealer.h"
00050 
00051 #include "debug.h"
00052 
00053 // parquet data-structures
00054 // #include "FPcommon.h"
00055 // #include "DB.h"
00056 // #include "AnalSolve.h"
00057 // #include "CommandLine.h"
00058 #include "allparquet.h"
00059 
00060 #include <vector>
00061 #include <cfloat>
00062 using namespace std;
00063 
00064 // --------------------------------------------------------
00065 class BTreeAreaWireAnnealer : public BaseAnnealer
00066 {
00067 public:
00068    BTreeAreaWireAnnealer(const parquetfp::Command_Line *const params,
00069                          parquetfp::DB *const db);
00070    
00071    BTreeAreaWireAnnealer(MixedBlockInfoType& nBlockinfo,
00072                          const parquetfp::Command_Line *const params,
00073                          parquetfp::DB *const db);
00074    
00075    inline virtual ~BTreeAreaWireAnnealer();
00076 
00077    virtual bool go();
00078    bool anneal(); // WARNING: anneal() takes at least TWO blocks
00079                   //   use packOneBlock() to floorplan ONE block
00080    virtual bool packOneBlock();
00081    
00082    inline const BTree& currSolution() const;
00083    inline const BTree& bestSolution() const;
00084 
00085    virtual void takePlfromDB();
00086    virtual void compactSoln();
00087    
00088    int makeMove(int& indexOrient,
00089                 parquetfp::ORIENT& newOrient,
00090                 parquetfp::ORIENT& oldOrient); // returns 1,2,3,4,5 or -1
00091    int makeMoveSlacks();                     // returns 6
00092    int makeMoveSlacksOrient() { return 10; } // returns 10
00093    int makeMoveOrient() { return 10; }       // returns 10
00094    int makeARMove();                         // returns 7
00095    int makeSoftBlMove(int& index, double& newWidth, double& newHeight);
00096                                              // returns 11
00097    inline int makeIndexSoftBlMove(int index,
00098                                   double& newWidth, double& newHeight);
00099                                              // returns 11
00100    
00101    int makeHPWLMove();                       // returns 12
00102    int makeARWLMove();                       // returns 13
00103 
00104    int packSoftBlocks(int numIter);          // returns -1
00105    inline int compactBlocks();               // returns -1        
00106    
00107    inline static void sort_slacks(const vector<double>& slacks,
00108                                   vector<int>& indices_sorted);
00109    void GenerateRandomSoln(BTree& soln, int blocknum) const;
00110    
00111  protected:
00112    MixedBlockInfoType *const _blockinfo_cleaner;
00113    MixedBlockInfoType& _blockinfo;
00114 
00115  public:
00116    const MixedBlockInfoType& blockinfo;
00117 
00118  protected:
00119 
00120    BTree in_curr_solution;
00121    BTree in_next_solution; // sketch-board
00122    BTree in_best_solution;
00123 
00124    // (blockIndex, [0-7]) --> [0-7], constantly 0 if fixedOrient
00125    vector< vector<parquetfp::ORIENT> > _physicalOrient;
00126    
00127    BTreeSlackEval *const _slackEval;
00128 
00129    void constructor_core();
00130    inline BTree::MoveType get_move() const;
00131    inline void perform_swap();
00132    inline void perform_move();
00133    inline void perform_rotate();
00134    inline void perform_rotate(int& blk,
00135                               parquetfp::ORIENT& newOrient,
00136                               parquetfp::ORIENT& oldOrient);
00137    class SlackInfo
00138    {
00139    public:
00140       double slack;
00141       int index;
00142 
00143       inline bool operator <(const SlackInfo& si) const
00144          {   return slack < si.slack; }
00145    };
00146 
00147    void DBfromSoln(const BTree& soln); // update *_db from "soln"
00148    
00149    void makeMoveSlacksCore(bool); // used by "makeMoveSlacks" and "makeARMove"
00150    void locateSearchBlocks(int, vector<int>&); // used by HPWL and ARWL moves
00151 
00152    // the following -SoftBl- fcns assumes slacks are ALREADY EVAULATED
00153    int getSoftBlIndex(bool horizontal) const; // returns the index of the operand
00154    int getSoftBlNewDimensions(int index,
00155                               double& newWidth, double& newHeight) const; 
00156    // used by soft-block moves, returns 11
00157 
00158    BTreeAreaWireAnnealer(MixedBlockInfoType& nBlockinfo);
00159 
00160 };
00161 // --------------------------------------------------------
00162 
00163 // =========================
00164 //      IMPLEMENTATIONS
00165 // =========================
00166 BTreeAreaWireAnnealer::~BTreeAreaWireAnnealer()
00167 {
00168    if (_slackEval != NULL)
00169       delete _slackEval;
00170 
00171    if (_blockinfo_cleaner != NULL)
00172       delete _blockinfo_cleaner;
00173 }
00174 // --------------------------------------------------------
00175 const BTree& BTreeAreaWireAnnealer::currSolution() const
00176 {   return in_curr_solution; }
00177 // --------------------------------------------------------
00178 const BTree& BTreeAreaWireAnnealer::bestSolution() const
00179 {   return in_best_solution; }
00180 // --------------------------------------------------------
00181 int BTreeAreaWireAnnealer::makeIndexSoftBlMove(int index,
00182                                                double& newWidth,
00183                                                double& newHeight)
00184 {
00185    _slackEval->evaluateSlacks(in_curr_solution);
00186    return getSoftBlNewDimensions(index, newWidth, newHeight);
00187 }
00188 // --------------------------------------------------------
00189 int BTreeAreaWireAnnealer::compactBlocks()
00190 {
00191    BTreeCompactor compactor(in_curr_solution);
00192    compactor.compact();
00193    in_curr_solution = compactor;
00194    return MISC;
00195 }
00196 // --------------------------------------------------------
00197 void BTreeAreaWireAnnealer::sort_slacks(const vector<double>& slacks,
00198                                         vector<int>& indices_sorted)
00199 {
00200    int blocknum = slacks.size();
00201    vector<SlackInfo> slackinfo(blocknum);
00202    for (int i = 0; i < blocknum; i++)
00203    {
00204       slackinfo[i].slack = slacks[i];
00205       slackinfo[i].index = i;
00206    }
00207    sort(slackinfo.begin(), slackinfo.end());
00208 
00209    indices_sorted.resize(blocknum);
00210    for (int i = 0; i < blocknum; i++)
00211       indices_sorted[i] = slackinfo[i].index;
00212 }
00213 // --------------------------------------------------------
00214 BTree::MoveType BTreeAreaWireAnnealer::get_move() const
00215 {
00216    // 0 <= "rand_num" < 1
00217    double rand_num = rand() / (RAND_MAX + 1.0);
00218    if (rand_num < 0.3333)
00219       return BTree::SWAP;
00220    else if (rand_num < 0.6666)
00221       return BTree::ROTATE;
00222    else
00223       return BTree::MOVE;
00224 }
00225 // --------------------------------------------------------
00226 void BTreeAreaWireAnnealer::perform_swap()
00227 {
00228    int blocknum = blockinfo.currDimensions.blocknum();
00229    int blkA = int(blocknum * (rand() / (RAND_MAX + 1.0)));
00230    int blkB = int((blocknum-1) * (rand() / (RAND_MAX + 1.0)));
00231    blkB = (blkB >= blkA)? blkB+1 : blkB;
00232    
00233    in_next_solution = in_curr_solution;
00234    in_next_solution.swap(blkA, blkB);
00235 }
00236 // --------------------------------------------------------
00237 void BTreeAreaWireAnnealer::perform_rotate()
00238 {
00239    int blocknum = blockinfo.currDimensions.blocknum();
00240    int blk = int(blocknum * (rand() / (RAND_MAX + 1.0)));
00241    int blk_orient = in_curr_solution.tree[blk].orient;
00242    int new_orient = (blk_orient+1) % 8;
00243    new_orient = _physicalOrient[blk][new_orient];
00244 
00245    // in_next_solution = in_curr_solution;
00246    in_next_solution.setTree(in_curr_solution.tree);
00247    in_next_solution.rotate(blk, new_orient);
00248 }
00249 // --------------------------------------------------------
00250 void BTreeAreaWireAnnealer::perform_move()
00251 {
00252    int blocknum = blockinfo.currDimensions.blocknum();
00253    int blk = int(blocknum * (rand() / (RAND_MAX + 1.0)));
00254 
00255    int target_rand_num = int((2*blocknum-1) * (rand() / (RAND_MAX + 1.0)));
00256    int target = target_rand_num / 2;
00257    target = (target >= blk)? target+1 : target;
00258    
00259    int leftChild = target_rand_num % 2;
00260 
00261    // in_next_solution = in_curr_solution;
00262    in_next_solution.setTree(in_curr_solution.tree);
00263    in_next_solution.move(blk, target, (leftChild == 0));
00264 }
00265 // --------------------------------------------------------
00266 void BTreeAreaWireAnnealer::perform_rotate(int& blk,
00267                                            parquetfp::ORIENT& newOrient,
00268                                            parquetfp::ORIENT& oldOrient)
00269 {
00270    int blocknum = blockinfo.currDimensions.blocknum();
00271    blk = int(blocknum * (rand() / (RAND_MAX + 1.0)));
00272    int blk_orient = in_curr_solution.tree[blk].orient;
00273    int new_orient = blk_orient;
00274    if (_params->minWL)
00275    {
00276       while (new_orient == blk_orient)
00277          new_orient = (blk_orient + rand() % 8) % 8;
00278    }
00279    else
00280       new_orient = (blk_orient+1) % 8;
00281    new_orient = _physicalOrient[blk][new_orient];
00282 
00283    // in_next_solution = in_curr_solution;
00284    in_next_solution.setTree(in_curr_solution.tree);
00285    in_next_solution.rotate(blk, new_orient);
00286 
00287    newOrient = parquetfp::ORIENT(new_orient);
00288    oldOrient = parquetfp::ORIENT(blk_orient);
00289 }
00290 // ========================================================
00291 
00292 #endif

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