00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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;
00089 vector<int> true_parent(tree.size(), UNDEFINED);
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
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
00107 int tree_parent = true_parent[tree_prev];
00108 rev_tree[tree_parent].left = tree_curr;
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