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

plsptobtree.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 #include "plsptobtree.h"
00036 
00037 #include "btree.h"
00038 
00039 #include <vector>
00040 #include <cmath>
00041 #include <cfloat>
00042 #include <algorithm>
00043 using namespace std;
00044 
00045 const double PlSP2BTree::INFTY = basepacking_h::Dimension::INFTY;
00046 const int PlSP2BTree::UNDEFINED = BTree::UNDEFINED;
00047 // --------------------------------------------------------
00048 PlSP2BTree::PlSP2BTree(const vector<double>& n_xloc,
00049                        const vector<double>& n_yloc,
00050                        const vector<double>& n_widths,
00051                        const vector<double>& n_heights,
00052                        const vector<int>& XX,
00053                        const vector<int>& YY)
00054    : xloc(n_xloc),
00055      yloc(n_yloc),
00056      widths(n_widths),
00057      heights(n_heights),
00058      _blocknum(n_xloc.size()),
00059      _XX(XX),
00060      _YY(YY),
00061      _XXinverse(_blocknum),
00062      _YYinverse(_blocknum),
00063      _btree(_blocknum+2)
00064 {
00065    constructor_core();
00066 }
00067 // --------------------------------------------------------
00068 PlSP2BTree::PlSP2BTree(const vector<double>& n_xloc,
00069                        const vector<double>& n_yloc,
00070                        const vector<double>& n_widths,
00071                        const vector<double>& n_heights,
00072                        const vector<unsigned int>& XX,
00073                        const vector<unsigned int>& YY)
00074    : xloc(n_xloc),
00075      yloc(n_yloc),
00076      widths(n_widths),
00077      heights(n_heights),
00078      _blocknum(n_xloc.size()),
00079      _XX(_blocknum),
00080      _YY(_blocknum),
00081      _XXinverse(_blocknum),
00082      _YYinverse(_blocknum),
00083      _btree(_blocknum+2)
00084 {
00085    for (int i = 0; i < _blocknum; i++)
00086    {
00087       _XX[i] = int(XX[i]);
00088       _YY[i] = int(YY[i]);
00089    }
00090    constructor_core();
00091 }
00092 // --------------------------------------------------------
00093 void PlSP2BTree::build_tree()
00094 {
00095    for (int i = 0; i < _blocknum; i++)
00096    {
00097       int currBlock = _YY[i];
00098       int otree_parent = _blocknum; // left-edge initially
00099 
00100       double currXStart = xloc[currBlock];
00101       double minDistance = currXStart;
00102       int parentMaxIndex = _blocknum;
00103       for (int j = i-1; j >= 0; j--)
00104       {
00105          int tempBlock = _YY[j];
00106          if (SPleftof(tempBlock, currBlock))
00107          {
00108             if (_XXinverse[tempBlock] < parentMaxIndex)
00109             {
00110                double tempDistance =
00111                   currXStart - xloc[tempBlock] - widths[tempBlock];
00112                if (tempDistance < minDistance)
00113                {
00114                   minDistance = tempDistance;
00115                   otree_parent = tempBlock;
00116                }
00117             }
00118          }
00119          else // SPbelow(tempBlock, currBlock)
00120             parentMaxIndex = min(parentMaxIndex, _XXinverse[tempBlock]);
00121       }
00122       build_tree_add_block(currBlock, otree_parent);
00123    }
00124 }
00125 // --------------------------------------------------------
00126 void PlSP2BTree::build_tree_add_block(int currBlock,
00127                                       int otree_parent)
00128 {
00129 //    printf("block %d added with block %d as its otree-parent\n",
00130 //           currBlock, otree_parent);
00131    
00132    if (_btree[otree_parent].left == UNDEFINED)
00133    {
00134       _btree[otree_parent].left = currBlock;
00135       _btree[currBlock].parent = otree_parent;
00136    }
00137    else
00138    {
00139       int tree_prev = otree_parent;
00140       int tree_curr = _btree[otree_parent].left;
00141       while ((tree_curr != UNDEFINED) &&
00142              (yloc[tree_curr] < yloc[currBlock]))
00143       {
00144          tree_prev = tree_curr;
00145          tree_curr = _btree[tree_curr].right;
00146       }
00147 
00148 //       printf("tree_curr: %d tree_prev: %d\n", tree_curr, tree_prev);
00149 //       printf("YLOC: tree_curr: %.2lf currBlock: %.2lf tree_prev: %.2lf\n",
00150 //              (tree_curr != UNDEFINED)? yloc[tree_curr] : -1,
00151 //              yloc[currBlock], yloc[tree_prev]);
00152       
00153       if ((tree_curr != UNDEFINED) &&
00154           (tree_curr == _btree[tree_prev].left))
00155          _btree[tree_prev].left = currBlock;
00156       else
00157          _btree[tree_prev].right = currBlock;
00158       _btree[currBlock].parent = tree_prev;
00159 
00160       _btree[currBlock].right = tree_curr; // possibly UNDEFINED
00161       if (tree_curr != UNDEFINED)
00162          _btree[tree_curr].parent = currBlock;
00163    }
00164 }
00165 // --------------------------------------------------------
00166 void PlSP2BTree::constructor_core()
00167 {
00168    initializeTree();
00169    for (int i = 0; i < _blocknum; i++)
00170    {
00171       _XXinverse[_XX[i]] = i;
00172       _YYinverse[_YY[i]] = i;
00173    }
00174    build_tree();
00175 }
00176 // --------------------------------------------------------
00177 void PlSP2BTree::initializeTree()
00178 {
00179    int vec_size = int(_btree.size());
00180    for (int i = 0; i < vec_size; i++)
00181    {
00182       _btree[i].parent = _blocknum;
00183       _btree[i].left = UNDEFINED;
00184       _btree[i].right = UNDEFINED;
00185       _btree[i].block_index = i;
00186       _btree[i].orient = 0;
00187    }
00188 
00189    _btree[_blocknum].parent = UNDEFINED;
00190    _btree[_blocknum].left = UNDEFINED;
00191    _btree[_blocknum].right = UNDEFINED;
00192    _btree[_blocknum].block_index = _blocknum;
00193    _btree[_blocknum].orient = UNDEFINED;
00194 
00195    _btree[_blocknum+1].parent = _blocknum;
00196    _btree[_blocknum+1].left = UNDEFINED;
00197    _btree[_blocknum+1].right = UNDEFINED;
00198    _btree[_blocknum+1].block_index = _blocknum+1;
00199    _btree[_blocknum+1].orient = UNDEFINED;
00200 }
00201 // --------------------------------------------------------
00202 
00203    
00204 

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