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 #ifndef PLTOBTREE_H
00036 #define PLTOBTREE_H
00037
00038 #include "basepacking.h"
00039 #include "btree.h"
00040
00041 #include <vector>
00042 using namespace std;
00043
00044
00045 class Pl2BTree
00046 {
00047 public:
00048 enum AlgoType {HEURISTIC, TCG};
00049
00050 inline Pl2BTree(const vector<double>& n_xloc,
00051 const vector<double>& n_yloc,
00052 const vector<double>& n_widths,
00053 const vector<double>& n_heights,
00054 AlgoType algo);
00055
00056 inline const vector<BTree::BTreeNode>& btree() const;
00057 inline const vector<int>& getXX() const;
00058 inline const vector<int>& getYY() const;
00059
00060 static const double INFTY;
00061 static const int UNDEFINED;
00062 static const double EPSILON_ACCURACY;
00063
00064 private:
00065 const vector<double>& _xloc;
00066 const vector<double>& _yloc;
00067 const vector<double>& _widths;
00068 const vector<double>& _heights;
00069 const int _blocknum;
00070 const double _epsilon;
00071
00072 vector<BTree::BTreeNode> _btree;
00073
00074 inline void initializeTree();
00075 inline double get_epsilon() const;
00076
00077
00078 class BuildTreeRecord
00079 {
00080 public:
00081 int parent;
00082 int treeLocIndex;
00083 double distance;
00084 double yDistance;
00085
00086 double xStart;
00087 double xEnd;
00088 double yStart;
00089 double yEnd;
00090 bool used;
00091
00092 bool operator <(const BuildTreeRecord& btr) const;
00093
00094 static double _epsilon;
00095 static double getDistance(const BuildTreeRecord& btr1,
00096 const BuildTreeRecord& btr2);
00097 };
00098
00099 class ValidCriterion
00100 {
00101 public:
00102 inline ValidCriterion(const vector<BuildTreeRecord>& new_btr_vec);
00103 bool operator ()(const BuildTreeRecord& btr1,
00104 const BuildTreeRecord& btr2) const;
00105
00106 const vector<BuildTreeRecord>& btr_vec;
00107 };
00108
00109 void heuristic_build_tree();
00110 void build_tree_add_block(const BuildTreeRecord& btr);
00111
00112
00113 int _count;
00114 vector<int> _XX;
00115 vector<int> _YY;
00116 void TCG_build_tree();
00117
00118
00119 void TCG_DP(vector< vector <bool> >& TCGMatrix);
00120 void TCGDfs(vector< vector <bool> >& TCGMatrix,
00121 const vector< vector <bool> >& adjMatrix,
00122 int v,
00123 vector<int>& pre);
00124
00125 class SPXRelation
00126 {
00127 public:
00128 SPXRelation(const vector< vector<bool> >& TCGMatrixHorizIP,
00129 const vector< vector<bool> >& TCGMatrixVertIP)
00130 : TCGMatrixHoriz(TCGMatrixHorizIP),
00131 TCGMatrixVert(TCGMatrixVertIP)
00132 {}
00133
00134 inline bool operator ()(int i, int j) const;
00135
00136 private:
00137 const vector< vector<bool> >& TCGMatrixHoriz;
00138 const vector< vector<bool> >& TCGMatrixVert;
00139 };
00140
00141 class SPYRelation
00142 {
00143 public:
00144 SPYRelation(const vector< vector<bool> >& TCGMatrixHorizIP,
00145 const vector< vector<bool> >& TCGMatrixVertIP)
00146 : TCGMatrixHoriz(TCGMatrixHorizIP),
00147 TCGMatrixVert(TCGMatrixVertIP)
00148 {}
00149
00150 inline bool operator ()(int i, int j) const;
00151
00152 private:
00153 const vector< vector<bool> >& TCGMatrixHoriz;
00154 const vector< vector<bool> >& TCGMatrixVert;
00155 };
00156 };
00157
00158
00159
00160
00161
00162 Pl2BTree::Pl2BTree(const vector<double>& n_xloc,
00163 const vector<double>& n_yloc,
00164 const vector<double>& n_widths,
00165 const vector<double>& n_heights,
00166 Pl2BTree::AlgoType algo)
00167 : _xloc(n_xloc),
00168 _yloc(n_yloc),
00169 _widths(n_widths),
00170 _heights(n_heights),
00171 _blocknum(n_xloc.size()),
00172 _epsilon(get_epsilon()),
00173 _btree(n_xloc.size()+2),
00174 _count(UNDEFINED),
00175 _XX(_blocknum, UNDEFINED),
00176 _YY(_blocknum, UNDEFINED)
00177 {
00178 initializeTree();
00179 switch (algo)
00180 {
00181 case HEURISTIC:
00182 heuristic_build_tree();
00183 break;
00184
00185 case TCG:
00186 TCG_build_tree();
00187 break;
00188
00189 default:
00190 cout << "ERROR: invalid algorithm specified for Pl2BTree()." << endl;
00191 exit(1);
00192 }
00193 }
00194
00195 void Pl2BTree::initializeTree()
00196 {
00197 int vec_size = int(_btree.size());
00198 for (int i = 0; i < vec_size; i++)
00199 {
00200 _btree[i].parent = _blocknum;
00201 _btree[i].left = UNDEFINED;
00202 _btree[i].right = UNDEFINED;
00203 _btree[i].block_index = i;
00204 _btree[i].orient = 0;
00205 }
00206
00207 _btree[_blocknum].parent = UNDEFINED;
00208 _btree[_blocknum].left = UNDEFINED;
00209 _btree[_blocknum].right = UNDEFINED;
00210 _btree[_blocknum].block_index = _blocknum;
00211 _btree[_blocknum].orient = UNDEFINED;
00212
00213 _btree[_blocknum+1].parent = _blocknum;
00214 _btree[_blocknum+1].left = UNDEFINED;
00215 _btree[_blocknum+1].right = UNDEFINED;
00216 _btree[_blocknum+1].block_index = _blocknum+1;
00217 _btree[_blocknum+1].orient = UNDEFINED;
00218 }
00219
00220 double Pl2BTree::get_epsilon() const
00221 {
00222 double ep = INFTY;
00223 for (int i = 0; i < _blocknum; i++)
00224 ep = min(ep, min(_widths[i], _heights[i]));
00225 ep /= EPSILON_ACCURACY;
00226 return ep;
00227 }
00228
00229 const vector<BTree::BTreeNode>& Pl2BTree::btree() const
00230 { return _btree; }
00231
00232 const vector<int>& Pl2BTree::getXX() const
00233 { return _XX; }
00234
00235 const vector<int>& Pl2BTree::getYY() const
00236 { return _YY; }
00237
00238 Pl2BTree::ValidCriterion::ValidCriterion(
00239 const vector<BuildTreeRecord>& new_btr_vec)
00240 : btr_vec(new_btr_vec)
00241 {}
00242
00243 bool Pl2BTree::SPXRelation::operator ()(int i, int j) const
00244 {
00245 if (TCGMatrixHoriz[i][j])
00246 return true;
00247 else if (TCGMatrixHoriz[j][i])
00248 return false;
00249 else if (TCGMatrixVert[j][i])
00250 return true;
00251 else if (TCGMatrixVert[i][j])
00252 return false;
00253 else
00254 return i < j;
00255 }
00256
00257 bool Pl2BTree::SPYRelation::operator ()(int i, int j) const
00258 {
00259 if (TCGMatrixHoriz[i][j])
00260 return true;
00261 else if (TCGMatrixHoriz[j][i])
00262 return false;
00263 else if (TCGMatrixVert[j][i])
00264 return false;
00265 else if (TCGMatrixVert[i][j])
00266 return true;
00267 else
00268 return i < j;
00269 }
00270
00271
00272 #endif