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

btree.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 #ifndef BTREE_H
00036 #define BTREE_H
00037 
00038 #include "basepacking.h"
00039 
00040 #include <iostream>
00041 #include <vector>
00042 using namespace std;
00043 
00044 // --------------------------------------------------------
00045 class BTree
00046 {
00047 public:
00048    BTree(const HardBlockInfoType& blockinfo);
00049    BTree(const HardBlockInfoType& blockinfo, double nTolerance);
00050    inline BTree(const BTree& newBTree);
00051    inline bool operator =(const BTree& newBTree); // true if succeeds
00052 
00053    class BTreeNode;
00054    class ContourNode;
00055    const vector<BTreeNode>& tree;
00056    const vector<ContourNode>& contour;
00057 
00058    inline const vector<double>& xloc() const;
00059    inline const vector<double>& yloc() const;
00060    inline double xloc(int index) const;
00061    inline double yloc(int index) const;
00062    inline double width(int index) const;
00063    inline double height(int index) const;
00064    
00065    inline double blockArea() const;
00066    inline double totalArea() const;
00067    inline double totalWidth() const;
00068    inline double totalHeight() const;
00069 
00070    inline void setTree(const vector<BTreeNode>& ntree);
00071    void evaluate(const vector<BTreeNode>& ntree); 
00072    void evaluate(const vector<int>& tree_bits,    // assume the lengths of
00073                  const vector<int>& perm,         // these 3 are compatible 
00074                  const vector<int>& orient);      // with size of old tree
00075    static void bits2tree(const vector<int>& tree_bits, // assume lengths of 
00076                          const vector<int>& perm,      // these 3 compatible
00077                          const vector<int>& orient,
00078                          vector<BTreeNode>& ntree);
00079    inline static void clean_tree(vector<BTreeNode>& otree);
00080    inline static void clean_contour(vector<ContourNode>& oContour);
00081 
00082    // perturb the tree, evaluate contour from scratch
00083    enum MoveType {SWAP, ROTATE, MOVE};
00084    
00085    void swap(int indexOne, int indexTwo); 
00086    inline void rotate(int index, int newOrient);
00087    void move(int index, int target, bool leftChild); // target = 0..n
00088 
00089    const int NUM_BLOCKS;
00090    static const int UNDEFINED; // = basepacking_h::Dimension::UNDEFINED;
00091 
00092    class BTreeNode
00093    {
00094    public:
00095       int parent;
00096       int left;
00097       int right;
00098       
00099       int block_index;
00100       int orient;
00101    };
00102 
00103    class ContourNode
00104    {
00105    public:
00106       int next;
00107       int prev;
00108       
00109       double begin;
00110       double end;
00111       double CTL;
00112    };
00113 
00114    // -----output functions-----
00115    void save_bbb(const string& filename) const;
00116    
00117 protected:
00118    const HardBlockInfoType& in_blockinfo;
00119    vector<BTreeNode> in_tree;
00120    vector<ContourNode> in_contour;
00121 
00122    // blah[i] refers the attribute of in_tree[i].
00123    vector<double> in_xloc;
00124    vector<double> in_yloc;
00125    vector<double> in_width;
00126    vector<double> in_height;
00127 
00128    double in_blockArea;
00129    double in_totalArea;
00130    double in_totalWidth;
00131    double in_totalHeight;
00132 
00133    const double TOLERANCE;
00134 
00135    void contour_evaluate();
00136    void contour_add_block(int treePtr);
00137 
00138    void swap_parent_child(int parent, bool isLeft);
00139    void remove_left_up_right_down(int index);
00140 };   
00141 // --------------------------------------------------------
00142 class BTreeOrientedPacking : public OrientedPacking
00143 {
00144 public:
00145    inline BTreeOrientedPacking() {}
00146    inline BTreeOrientedPacking(const BTree& bt);
00147 
00148    inline void operator =(const BTree& bt);
00149 };
00150 // --------------------------------------------------------
00151 
00152 // =========================
00153 //      Implementations
00154 // =========================
00155 inline BTree::BTree(const BTree& newBtree)
00156    : tree(in_tree),
00157      contour(in_contour),
00158      NUM_BLOCKS(newBtree.NUM_BLOCKS),
00159      in_blockinfo(newBtree.in_blockinfo),
00160      in_tree(newBtree.in_tree),
00161      in_contour(newBtree.in_contour),
00162      
00163      in_xloc(newBtree.in_xloc),
00164      in_yloc(newBtree.in_yloc),
00165      in_width(newBtree.in_width),
00166      in_height(newBtree.in_height),
00167      
00168      in_blockArea(newBtree.in_blockArea),
00169      in_totalArea(newBtree.in_totalArea),
00170      in_totalWidth(newBtree.in_totalWidth),
00171      in_totalHeight(newBtree.in_totalHeight),
00172 
00173      TOLERANCE(newBtree.TOLERANCE)
00174 {}
00175 // --------------------------------------------------------
00176 inline bool BTree::operator =(const BTree& newBtree)
00177 {
00178    if (NUM_BLOCKS == newBtree.NUM_BLOCKS)
00179    {
00180       in_tree = newBtree.in_tree;
00181       in_contour = newBtree.in_contour;
00182 
00183       in_xloc = newBtree.in_xloc;
00184       in_yloc = newBtree.in_yloc;
00185       in_width = newBtree.in_width;
00186       in_height = newBtree.in_height;
00187 
00188       in_blockArea = newBtree.in_blockArea;
00189       in_totalArea = newBtree.in_totalArea;
00190       in_totalWidth = newBtree.in_totalWidth;
00191       in_totalHeight = newBtree.in_totalHeight;
00192       
00193       return true;
00194    }
00195    else
00196       return false;
00197 }
00198 // --------------------------------------------------------
00199 inline const vector<double>& BTree::xloc() const
00200 {  return in_xloc; }
00201 // --------------------------------------------------------
00202 inline const vector<double>& BTree::yloc() const
00203 {  return in_yloc; }
00204 // --------------------------------------------------------
00205 inline double BTree::xloc(int index) const
00206 {  return in_xloc[index]; }
00207 // --------------------------------------------------------
00208 inline double BTree::yloc(int index) const
00209 {  return in_yloc[index]; }
00210 // --------------------------------------------------------
00211 inline double BTree::width(int index) const
00212 {  return in_width[index]; }
00213 // --------------------------------------------------------
00214 inline double BTree::height(int index) const
00215 {  return in_height[index]; }
00216 // --------------------------------------------------------
00217 inline double BTree::blockArea() const
00218 {  return in_blockArea; }
00219 // --------------------------------------------------------
00220 inline double BTree::totalArea() const
00221 {  return in_totalArea; }
00222 // --------------------------------------------------------
00223 inline double BTree::totalWidth() const
00224 {  return in_totalWidth; }
00225 // --------------------------------------------------------
00226 inline double BTree::totalHeight() const
00227 {  return in_totalHeight; }
00228 // --------------------------------------------------------
00229 inline void BTree::setTree(const vector<BTreeNode>& ntree)
00230 {   in_tree = ntree; }
00231 // --------------------------------------------------------
00232 inline void BTree::clean_tree(vector<BTreeNode>& otree)
00233 {
00234    int vec_size = otree.size();
00235    for (int i = 0; i < vec_size; i++)
00236    {
00237       otree[i].parent = UNDEFINED;
00238       otree[i].left = UNDEFINED;
00239       otree[i].right = UNDEFINED;
00240    }
00241    otree[vec_size-2].block_index = vec_size-2;
00242    otree[vec_size-1].block_index = vec_size-1;
00243 
00244    otree[vec_size-2].orient = UNDEFINED;
00245    otree[vec_size-1].orient = UNDEFINED;
00246 }
00247 // --------------------------------------------------------
00248 inline void BTree::clean_contour(vector<ContourNode>& oContour)
00249 {
00250    int vec_size = oContour.size();
00251    int Ledge = vec_size-2;
00252    int Bedge = vec_size-1;
00253 
00254    oContour[Ledge].next = Bedge;
00255    oContour[Ledge].prev = UNDEFINED;
00256    oContour[Ledge].begin = 0;
00257    oContour[Ledge].end = 0;
00258    oContour[Ledge].CTL = basepacking_h::Dimension::INFTY;
00259 
00260    oContour[Bedge].next = UNDEFINED;
00261    oContour[Bedge].prev = Ledge;
00262    oContour[Bedge].begin = 0;
00263    oContour[Bedge].end = basepacking_h::Dimension::INFTY;
00264    oContour[Bedge].CTL = 0;
00265 }
00266 // --------------------------------------------------------
00267 inline void BTree::rotate(int index,
00268                           int newOrient)
00269 {
00270    in_tree[index].orient = newOrient;
00271    contour_evaluate();
00272 }
00273 // ========================================================
00274 inline BTreeOrientedPacking::BTreeOrientedPacking(const BTree& bt)
00275 {
00276    int blocknum = bt.NUM_BLOCKS;
00277 
00278    xloc.resize(blocknum);
00279    yloc.resize(blocknum);
00280    width.resize(blocknum);
00281    height.resize(blocknum);
00282    orient.resize(blocknum);
00283    for (int i = 0; i < blocknum; i++)
00284    {
00285       xloc[i] = bt.xloc(i);
00286       yloc[i] = bt.yloc(i);
00287       width[i] = bt.width(i);
00288       height[i] = bt.height(i);
00289       orient[i] = OrientedPacking::ORIENT(bt.tree[i].orient);
00290    }
00291 }
00292 // --------------------------------------------------------
00293 inline void BTreeOrientedPacking::operator =(const BTree& bt)
00294 {
00295    int blocknum = bt.NUM_BLOCKS;
00296 
00297    xloc.resize(blocknum);
00298    yloc.resize(blocknum);
00299    width.resize(blocknum);
00300    height.resize(blocknum);
00301    orient.resize(blocknum);
00302    for (int i = 0; i < blocknum; i++)
00303    {
00304       xloc[i] = bt.xloc(i);
00305       yloc[i] = bt.yloc(i);
00306       width[i] = bt.width(i);
00307       height[i] = bt.height(i);
00308       orient[i] = OrientedPacking::ORIENT(bt.tree[i].orient);
00309    }
00310 }  
00311 // ========================================================
00312 
00313 #endif

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