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

btreeslackeval.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 "btreeslackeval.h"
00038 #include "debug.h"
00039 
00040 #include <vector>
00041 #include <algorithm>
00042 using namespace std;
00043 
00044 // ---------------------------------------------------------
00045 const vector<double>& BTreeSlackEval::evaluateXSlacks(const BTree& orig_btree)
00046 {
00047    const int NUM_BLOCKS = orig_btree.NUM_BLOCKS;
00048    _btree.build_orth_tree();   
00049 
00050    reverse_tree(_btree.orth_tree, _rev_orth_tree);
00051    _btree.evaluate(_rev_orth_tree);
00052 
00053    double width = orig_btree.totalWidth();
00054    for (int i = 0; i < NUM_BLOCKS; i++)
00055    {
00056       _xlocRight[i] = _btree.yloc(i);
00057       _xSlack[i] = width -
00058          orig_btree.width(i) - _xlocRight[i] - orig_btree.xloc(i);
00059    }
00060    return _xSlack;
00061 }
00062 // --------------------------------------------------------
00063 const vector<double>& BTreeSlackEval::evaluateYSlacks(const BTree& orig_btree)
00064 {
00065    reverse_tree(orig_btree.tree, _rev_tree);
00066    _btree.evaluate(_rev_tree);
00067 
00068    const int NUM_BLOCKS = _btree.NUM_BLOCKS;
00069    double height = orig_btree.totalHeight();
00070    for (int i = 0; i < NUM_BLOCKS; i++)
00071    {
00072       _ylocTop[i] = _btree.yloc(i);
00073       _ySlack[i] = height -
00074          orig_btree.height(i) - _ylocTop[i] - orig_btree.yloc(i);
00075    }
00076    return _ySlack;
00077 }
00078 // ---------------------------------------------------------
00079 void BTreeSlackEval::reverse_tree(const vector<BTree::BTreeNode>& tree,
00080                                   vector<BTree::BTreeNode>& rev_tree)
00081 {
00082    // assume "rev_tree" has the same size as "tree"
00083    BTree::clean_tree(rev_tree);
00084    
00085    static const int UNDEFINED =  BTree::UNDEFINED;   
00086    const int NUM_BLOCKS = tree.size() - 2;
00087    int tree_prev = NUM_BLOCKS;
00088    int tree_curr = tree[NUM_BLOCKS].left; // start with the first child of root
00089    vector<int> true_parent(tree.size(), UNDEFINED); // book-keeping variable
00090    while (tree_curr != NUM_BLOCKS)
00091    {
00092       if (tree_prev == tree[tree_curr].parent)
00093       {
00094          if (tree_curr == tree[tree_prev].left)
00095          {
00096             // left-child
00097             rev_tree[tree_prev].left = tree_curr;
00098             rev_tree[tree_curr].parent = tree_prev;
00099             rev_tree[tree_curr].block_index = tree[tree_curr].block_index;
00100             rev_tree[tree_curr].orient = tree[tree_curr].orient;
00101 
00102             true_parent[tree_curr] = tree_prev;
00103          }
00104          else
00105          {
00106             // right-child
00107             int tree_parent = true_parent[tree_prev];
00108             rev_tree[tree_parent].left = tree_curr; // prob. overwrite 
00109             rev_tree[tree_curr].parent = tree_parent;
00110             rev_tree[tree_curr].block_index = tree[tree_curr].block_index;
00111             rev_tree[tree_curr].orient = tree[tree_curr].orient;
00112                
00113             rev_tree[tree_prev].parent = tree_curr;
00114             rev_tree[tree_curr].right = tree_prev;
00115 
00116             true_parent[tree_curr] = tree_parent;
00117          }
00118          tree_prev = tree_curr;
00119          if (tree[tree_curr].right != UNDEFINED)
00120             tree_curr = tree[tree_curr].right;
00121          else if (tree[tree_curr].left != UNDEFINED)
00122             tree_curr = tree[tree_curr].left;
00123          else
00124             tree_curr = tree[tree_curr].parent;
00125       }
00126       else if (tree_prev == tree[tree_curr].right)
00127       {
00128          tree_prev = tree_curr;
00129          tree_curr = (tree[tree_curr].left != UNDEFINED)?
00130             tree[tree_curr].left : tree[tree_curr].parent; 
00131       }
00132       else
00133       {
00134          tree_prev = tree_curr;
00135          tree_curr = tree[tree_curr].parent;
00136       }
00137    }
00138 }
00139 // --------------------------------------------------------

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