#include <PlToSP.h>
Collaboration diagram for parquetfp::Pl2SP:

Public Member Functions | |
| Pl2SP (vector< double > &xloc, vector< double > &yloc, vector< double > &widths, vector< double > &heights, PL2SP_ALGO whichAlgo) | |
| ~Pl2SP () | |
| void | naiveAlgo (void) |
| void | TCGAlgo (void) |
| void | TCG_FM (vector< vector< bool > > &TCGMatrixHoriz, vector< vector< bool > > &TCGMatrixVert) |
| void | TCG_DP (vector< vector< bool > > &TCGMatrixHoriz, vector< vector< bool > > &TCGMatrixVert) |
| void | TCGDfs (vector< vector< bool > > &TCGMatrix, vector< vector< bool > > &adjMatrix, int v, vector< int > &pre) |
| const vector< unsigned > & | getXSP (void) const |
| const vector< unsigned > & | getYSP (void) const |
| void | print (void) const |
Private Attributes | |
| vector< double > | _xloc |
| vector< double > | _yloc |
| vector< double > | _widths |
| vector< double > | _heights |
| vector< unsigned > | _XX |
| vector< unsigned > | _YY |
| int | _cnt |
|
||||||||||||||||||||||||
|
Definition at line 55 of file PlToSP.cxx. References _heights, _widths, _xloc, _yloc, parquetfp::NAIVE_ALGO, naiveAlgo(), parquetfp::TCG_ALGO, and TCGAlgo().
00057 : _xloc(xloc), _yloc(yloc), 00058 _widths(widths), _heights(heights) 00059 { 00060 unsigned size = _xloc.size(); 00061 if(_yloc.size() != size || _widths.size() != size || _heights.size() != size) 00062 cout<<"ERROR: in Pl2SP. Sizes do not match"<<endl; 00063 00064 switch(whichAlgo) 00065 { 00066 case NAIVE_ALGO : 00067 naiveAlgo(); 00068 break; 00069 case TCG_ALGO: 00070 TCGAlgo(); 00071 break; 00072 } 00073 } |
Here is the call graph for this function:

|
|
Definition at line 68 of file PlToSP.h.
00068 {}
|
|
|
Definition at line 84 of file PlToSP.h. References _XX. Referenced by parquetfp::Annealer::takeSPfromDB().
00085 { return _XX; }
|
|
|
Definition at line 87 of file PlToSP.h. References _YY. Referenced by parquetfp::Annealer::takeSPfromDB().
00088 { return _YY; }
|
|
|
Definition at line 75 of file PlToSP.cxx. References _heights, _xloc, _XX, _yloc, _YY, parquetfp::RowElem::index, print(), and parquetfp::RowElem::xloc. Referenced by Pl2SP().
00076 {
00077 unsigned size = _xloc.size();
00078 double rowHeight = 1e100;
00079 double maxYLoc = -1e100;
00080
00081 for(unsigned i=0; i<size; ++i)
00082 {
00083 if(rowHeight > _heights[i])
00084 rowHeight = _heights[i];
00085
00086 if(maxYLoc < _yloc[i])
00087 maxYLoc = _yloc[i];
00088 }
00089
00090 unsigned numRows = unsigned(ceil(maxYLoc/rowHeight)+1);
00091
00092 //snap to y grid here
00093 for(unsigned i=0; i<size; ++i)
00094 {
00095 unsigned reqdRow = static_cast<unsigned>((_yloc[i]/rowHeight)+0.5);
00096 //unsigned reqdRow = unsigned(rint(_yloc[i]/rowHeight));
00097 _yloc[i] = reqdRow*rowHeight;
00098 }
00099
00100 vector< vector<RowElem> > rows;
00101 vector<RowElem> singleRow;
00102 RowElem tempRE;
00103
00104 double currHeight = 0;
00105
00106 for(unsigned i=0; i<numRows; ++i)
00107 {
00108 for(unsigned j=0; j<size; ++j)
00109 {
00110 if(fabs(_yloc[j]-currHeight)<0.0001)
00111 {
00112 tempRE.index = j;
00113 tempRE.xloc = _xloc[j];
00114 singleRow.push_back(tempRE);
00115 }
00116 }
00117
00118 currHeight += rowHeight;
00119
00120 std::stable_sort(singleRow.begin(), singleRow.end(), less_mag());
00121 rows.push_back(singleRow);
00122 singleRow.clear();
00123 }
00124
00125 //form the X and Y sequence pairs now
00126 for(unsigned i=0; i<rows.size(); ++i)
00127 {
00128 for(unsigned j=0; j<rows[i].size(); ++j)
00129 {
00130 _YY.push_back(rows[i][j].index);
00131 }
00132 }
00133 for(int i=rows.size()-1; i>=0; --i)
00134 {
00135 for(unsigned j=0; j<rows[i].size(); ++j)
00136 {
00137 _XX.push_back(rows[i][j].index);
00138 }
00139 }
00140
00141 if(_XX.size() != _xloc.size() || _YY.size() != _xloc.size())
00142 {
00143 cout<<"ERROR: generated sequence pair of not correct sizes "<<_XX.size()<<" & "<<_YY.size()<<" vs "<<size<<endl;
00144 print();
00145 }
00146
00147 }
|
Here is the call graph for this function:

|
|
Definition at line 447 of file PlToSP.cxx. Referenced by naiveAlgo().
|
|
||||||||||||
|
Definition at line 477 of file PlToSP.cxx. References _cnt, and TCGDfs(). Referenced by TCGAlgo().
00479 {
00480 int size = TCGMatrixHoriz[0].size();
00481 vector< vector <bool> > adjMatrixHoriz = TCGMatrixHoriz;
00482 vector< vector <bool> > adjMatrixVert = TCGMatrixVert;
00483 vector<int> pre(size, -1);
00484
00485 int i;
00486 for(i=0; i<size; ++i)
00487 {
00488 fill(TCGMatrixHoriz[i].begin(), TCGMatrixHoriz[i].end(), false);
00489 fill(TCGMatrixVert[i].begin(), TCGMatrixVert[i].end(), false);
00490 }
00491
00492 _cnt = 0;
00493 for(i=0; i<size; ++i)
00494 if(pre[i] == -1)
00495 TCGDfs(TCGMatrixHoriz, adjMatrixHoriz, i, pre);
00496
00497 _cnt = 0;
00498 fill(pre.begin(), pre.end(), -1);
00499 for(i=0; i<size; ++i)
00500 if(pre[i] == -1)
00501 TCGDfs(TCGMatrixVert, adjMatrixVert, i, pre);
00502 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 458 of file PlToSP.cxx.
00460 {
00461 unsigned size = TCGMatrixHoriz[0].size();
00462 for(unsigned k=0; k<size; ++k)
00463 {
00464 for(unsigned i=0; i<size; ++i)
00465 {
00466 for(unsigned j = 0; j<size; ++j)
00467 {
00468 TCGMatrixHoriz[i][j] = TCGMatrixHoriz[i][j] |
00469 (TCGMatrixHoriz[i][k] & TCGMatrixHoriz[k][j]);
00470 TCGMatrixVert[i][j] = TCGMatrixVert[i][j] |
00471 (TCGMatrixVert[i][k] & TCGMatrixVert[k][j]);
00472 }
00473 }
00474 }
00475 }
|
|
|
Definition at line 149 of file PlToSP.cxx. References _heights, _widths, _xloc, _XX, _yloc, _YY, and TCG_DP(). Referenced by Pl2SP().
00150 {
00151 unsigned size = _xloc.size();
00152
00153 vector< vector<bool> > TCGMatrixVert;
00154 vector< vector<bool> > TCGMatrixHoriz;
00155
00156 TCGMatrixVert.resize(size);
00157 TCGMatrixHoriz.resize(size);
00158
00159 for(unsigned i=0; i<size; ++i)
00160 {
00161 TCGMatrixVert[i].resize(size, false);
00162 TCGMatrixHoriz[i].resize(size, false);
00163 }
00164
00165 double ebsilon = 1e100;
00166 for(unsigned i=0; i<size; ++i) //pick min dimension
00167 {
00168 if(ebsilon > _widths[i])
00169 ebsilon = _widths[i];
00170 if(ebsilon > _heights[i])
00171 ebsilon = _heights[i];
00172 }
00173 ebsilon /= 1000;
00174
00175 //set up the immediate constraints
00176 for(unsigned i=0; i<size; ++i)
00177 {
00178 for(unsigned j=0; j<=i; ++j)
00179 {
00180 double iXStart, iXEnd, jXStart, jXEnd;
00181 double iYStart, iYEnd, jYStart, jYEnd;
00182
00183 double horizOverlap = 0;
00184 double vertOverlap = 0;
00185 unsigned vertOverlapDir = 0;
00186 unsigned horizOverlapDir = 0;
00187
00188
00189 if (i == j)
00190 {
00191 TCGMatrixHoriz[i][j] = 1;
00192 TCGMatrixVert[i][j] = 1;
00193 continue;
00194 }
00195
00196 TCGMatrixHoriz[i][j] = 0;
00197 TCGMatrixVert[i][j] = 0;
00198 TCGMatrixHoriz[j][i] = 0;
00199 TCGMatrixVert[j][i] = 0;
00200
00201 iXStart = _xloc[i];
00202 iXEnd = _xloc[i] + _widths[i];
00203 jXStart = _xloc[j];
00204 jXEnd = _xloc[j] + _widths[j];
00205
00206 iYStart = _yloc[i];
00207 iYEnd = _yloc[i] + _heights[i];
00208 jYStart = _yloc[j];
00209 jYEnd = _yloc[j] + _heights[j];
00210
00211 //horizontal constraint
00212 if(jYStart < iYStart + ebsilon && jYEnd < iYEnd + ebsilon &&
00213 jYEnd > iYStart + ebsilon)
00214 {
00215 vertOverlap = jYEnd - iYStart; //lower overlap
00216 vertOverlapDir = 0;
00217 }
00218 else if(jYStart > iYStart + ebsilon && jYEnd < iYEnd + ebsilon)
00219 {
00220 vertOverlap = jYEnd - jYStart; //inner overlap
00221 if(iYEnd-jYEnd > jYStart-iYStart)
00222 vertOverlapDir = 0;
00223 else
00224 vertOverlapDir = 1;
00225 }
00226 else if(jYStart > iYStart + ebsilon && jYStart < iYEnd + ebsilon &&
00227 jYEnd > iYEnd + ebsilon)
00228 {
00229 vertOverlap = iYEnd - jYStart; //upper overlap
00230 vertOverlapDir = 1;
00231 }
00232 else if(jYStart < iYStart + ebsilon && jYEnd > iYEnd + ebsilon)
00233 {
00234 vertOverlap = iYEnd - iYStart; //outer overlap
00235 if(jYEnd-iYEnd > iYStart-jYStart)
00236 vertOverlapDir = 1;
00237 else
00238 vertOverlapDir = 0;
00239 }
00240 else
00241 TCGMatrixHoriz[i][j] = 0;
00242
00243
00244 //vertical constraint
00245 if(jXStart < iXStart + ebsilon && jXEnd < iXEnd + ebsilon &&
00246 jXEnd > iXStart + ebsilon)
00247 {
00248 horizOverlap = jXEnd - iXStart; //right overlap
00249 horizOverlapDir = 0;
00250 }
00251 else if(jXStart > iXStart + ebsilon && jXEnd < iXEnd + ebsilon)
00252 {
00253 horizOverlap = jXEnd - jXStart; //inner overlap
00254 if(iXEnd-jXEnd > jXStart-iXStart)
00255 horizOverlapDir = 0;
00256 else
00257 horizOverlapDir = 1;
00258 }
00259 else if(jXStart > iXStart + ebsilon && jXStart < iXEnd + ebsilon &&
00260 jXEnd > iXEnd + ebsilon)
00261 {
00262 horizOverlap = iXEnd - jXStart; //left overlap
00263 horizOverlapDir = 1;
00264 }
00265 else if(jXStart < iXStart + ebsilon && jXEnd > iXEnd + ebsilon)
00266 {
00267 horizOverlap = iXEnd - iXStart; //outer overlap
00268 if(jXEnd-iXEnd > iXStart-jXStart )
00269 horizOverlapDir = 1;
00270 else
00271 horizOverlapDir = 0;
00272 }
00273 else
00274 TCGMatrixVert[i][j] = 0;
00275
00276 if(vertOverlap > ebsilon && horizOverlap <= ebsilon)
00277 {
00278 if(iXStart <= jXStart)
00279 TCGMatrixHoriz[i][j] = 1;
00280 else
00281 TCGMatrixHoriz[j][i] = 1;
00282 }
00283 else if(horizOverlap > ebsilon && vertOverlap <= ebsilon)
00284 {
00285 if(iYStart <= jYStart)
00286 TCGMatrixVert[i][j] = 1;
00287 else
00288 TCGMatrixVert[j][i] = 1;
00289 }
00290 //overlapping
00291 else if(horizOverlap > ebsilon && vertOverlap > ebsilon)
00292 {
00293 if(vertOverlap >= horizOverlap)
00294 {
00295 if(horizOverlapDir == 1)
00296 TCGMatrixHoriz[i][j] = 1;
00297 else
00298 TCGMatrixHoriz[j][i] = 1;
00299 }
00300 else
00301 {
00302 if(vertOverlapDir == 1)
00303 TCGMatrixVert[i][j] = 1;
00304 else
00305 TCGMatrixVert[j][i] = 1;
00306 }
00307 }
00308 }
00309 }
00310
00311 //floyd marshal to find transitive closure
00312 //TCG_FM(TCGMatrixHoriz, TCGMatrixVert);
00313
00314 //dynamic programming DFS algo to find transitive closure
00315 TCG_DP(TCGMatrixHoriz, TCGMatrixVert);
00316
00317 //find ties and break them
00318 for(unsigned i=0; i<size; ++i)
00319 {
00320 for(unsigned j=0; j<i; ++j)
00321 {
00322 if(i==j)
00323 continue;
00324 if(TCGMatrixHoriz[i][j] == 1 && TCGMatrixHoriz[j][i] == 1)
00325 {
00326 cout<<"ERROR in TCG 1 "<<i<<"\t"<<j<<endl;
00327 }
00328 if(TCGMatrixVert[i][j] == 1 && TCGMatrixVert[j][i] == 1)
00329 {
00330 cout<<"ERROR in TCG 2 "<<i<<"\t"<<j<<endl;
00331 }
00332 unsigned ctr = 0;
00333 if(TCGMatrixHoriz[i][j] == 1)
00334 ++ctr;
00335 if(TCGMatrixHoriz[j][i] == 1)
00336 ++ctr;
00337 if(TCGMatrixVert[i][j] == 1)
00338 ++ctr;
00339 if(TCGMatrixVert[j][i] == 1)
00340 ++ctr;
00341
00342 if(ctr > 1)
00343 {
00344 unsigned dir = rand()%2;
00345 if(dir == 0) //H constraint
00346 {
00347 TCGMatrixVert[i][j] = 0;
00348 TCGMatrixVert[j][i] = 0;
00349 }
00350 else //V constraint
00351 {
00352 TCGMatrixHoriz[i][j] = 0;
00353 TCGMatrixHoriz[j][i] = 0;
00354 }
00355 /*
00356 cout<<"ERROR in TCG 3 "<<i<<"\t"<<j<<"\t";
00357 if(TCGMatrixHoriz[i][j] == 1)
00358 cout<<"H\t";
00359 if(TCGMatrixHoriz[j][i] == 1)
00360 cout<<"InvH\t";
00361 if(TCGMatrixVert[i][j] == 1)
00362 cout<<"V\t";
00363 if(TCGMatrixVert[j][i] == 1)
00364 cout<<"InvV\t";
00365 cout<<endl;
00366 */
00367 }
00368
00369 //no constraint between the blocks
00370 if(TCGMatrixHoriz[i][j] == 0 && TCGMatrixHoriz[j][i] == 0 &&
00371 TCGMatrixVert[i][j] == 0 && TCGMatrixVert[j][i] == 0)
00372 {
00373 if(_xloc[i] < _xloc[j])
00374 TCGMatrixHoriz[i][j] = 1;
00375 else
00376 TCGMatrixHoriz[j][i] = 1;
00377
00378 /*
00379 unsigned dir = rand()%2;
00380 if(dir == 0) //H constraint
00381 {
00382 if(_xloc[i] < _xloc[j])
00383 TCGMatrixHoriz[i][j] = 1;
00384 else
00385 TCGMatrixHoriz[j][i] = 1;
00386 }
00387 else //V constraint
00388 {
00389 if(_yloc[i] < _yloc[j])
00390 TCGMatrixVert[i][j] = 1;
00391 else
00392 TCGMatrixVert[j][i] = 1;
00393 }
00394 */
00395 }
00396 }
00397 }
00398 //get the sequence pair now
00399 _XX.resize(size);
00400 _YY.resize(size);
00401 for(unsigned i=0; i<size; ++i)
00402 {
00403 _XX[i] = i;
00404 _YY[i] = i;
00405 }
00406
00407 SPXRelation SPX(TCGMatrixHoriz, TCGMatrixVert);
00408 SPYRelation SPY(TCGMatrixHoriz, TCGMatrixVert);
00409
00410 std::sort(_XX.begin(), _XX.end(), SPX);
00411 std::sort(_YY.begin(), _YY.end(), SPY);
00412
00413 /*
00414 cout<<"TCGMatrixHoriz"<<endl;
00415 cout<<"\t";
00416 for(unsigned i=0; i<size; ++i)
00417 cout<<i<<" ";
00418 cout<<endl;
00419 for(unsigned i=0; i<size; ++i)
00420 {
00421 cout<<i<<"\t";
00422 for(unsigned j=0; j<size; ++j)
00423 {
00424 cout<<TCGMatrixHoriz[i][j]<<" ";
00425 }
00426 cout<<endl;
00427 }
00428 cout<<"TCGMatrixVert"<<endl;
00429 cout<<"\t";
00430 for(unsigned i=0; i<size; ++i)
00431 cout<<i<<" ";
00432 cout<<endl;
00433 for(unsigned i=0; i<size; ++i)
00434 {
00435 cout<<i<<"\t";
00436 for(unsigned j=0; j<size; ++j)
00437 {
00438 cout<<TCGMatrixVert[i][j]<<" ";
00439 }
00440 cout<<endl;
00441 }
00442 print();
00443 */
00444 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 504 of file PlToSP.cxx. References _cnt. Referenced by TCG_DP().
00506 {
00507 int u, i;
00508 pre[v] = _cnt++;
00509 int size = adjMatrix[0].size();
00510
00511 for(u=0; u<size; ++u)
00512 {
00513 if(adjMatrix[v][u])
00514 {
00515 TCGMatrix[v][u] = true;
00516 if(pre[u] > pre[v]) continue;
00517
00518 if(pre[u] == -1)
00519 TCGDfs(TCGMatrix, adjMatrix, u, pre);
00520
00521 for(i=0; i<size; ++i)
00522 if(TCGMatrix[u][i] == 1)
00523 TCGMatrix[v][i] = 1;
00524 }
00525 }
00526 }
|
|
|
|
|
|
Definition at line 58 of file PlToSP.h. Referenced by naiveAlgo(), Pl2SP(), and TCGAlgo(). |
|
|
|
|
|
Definition at line 55 of file PlToSP.h. Referenced by naiveAlgo(), Pl2SP(), and TCGAlgo(). |
|
|
Definition at line 60 of file PlToSP.h. Referenced by getXSP(), naiveAlgo(), print(), and TCGAlgo(). |
|
|
Definition at line 56 of file PlToSP.h. Referenced by naiveAlgo(), Pl2SP(), and TCGAlgo(). |
|
|
Definition at line 61 of file PlToSP.h. Referenced by getYSP(), naiveAlgo(), print(), and TCGAlgo(). |
1.3.2