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

ShiftLegalizer Class Reference

#include <plcompact.h>

Collaboration diagram for ShiftLegalizer:

Collaboration graph
[legend]
List of all members.

Public Types

enum  AlgoType { NAIVE }

Public Member Functions

 ShiftLegalizer (const vector< double > &n_xloc, const vector< double > &n_yloc, const vector< double > &n_widths, const vector< double > &n_heights, double left_bound, double right_bound, double top_bound, double bottom_bound)
bool legalizeAll (AlgoType algo, const vector< int > &checkBlks, vector< int > &badBlks)
bool naiveLegalize (const vector< int > &checkBlks, vector< int > &badBlks)
bool legalizeBlock (int currBlk)
void putBlockIntoCore (int currBlk)
const vector< double > & xloc () const
const vector< double > & yloc () const
const vector< double > & widths () const
const vector< double > & heights () const
double leftBound () const
double rightBound () const
double topBound () const
double bottomBound () const
bool shiftDecider (ShiftBlock::Directions currDir, const vector< ShiftBlock::ShiftInfo > &shiftinfo, ShiftRotateDecision &decision) const
bool rotateDecider (int currBlk, const vector< ShiftBlock::ShiftInfo > &shiftinfo, ShiftRotateDecision &decision) const

Static Public Attributes

const double INFTY = basepacking_h::Dimension::INFTY
const int UNDEFINED = basepacking_h::Dimension::UNDEFINED

Private Member Functions

void adjustBlock (int currBlk, const ShiftRotateDecision &decision)

Private Attributes

int _blocknum
vector< double > _xloc
vector< double > _yloc
vector< double > _widths
vector< double > _heights
double _epsilon
const double _leftBound
const double _rightBound
const double _topBound
const double _bottomBound

Member Enumeration Documentation

enum ShiftLegalizer::AlgoType
 

Enumeration values:
NAIVE 

Definition at line 98 of file plcompact.h.

00098 {NAIVE};


Constructor & Destructor Documentation

ShiftLegalizer::ShiftLegalizer const vector< double > &  n_xloc,
const vector< double > &  n_yloc,
const vector< double > &  n_widths,
const vector< double > &  n_heights,
double  left_bound,
double  right_bound,
double  top_bound,
double  bottom_bound
 

Definition at line 52 of file plcompact.cxx.

References _blocknum, _epsilon, _heights, _widths, and basepacking_h::Dimension::EPSILON_ACCURACY.

00060    : _blocknum(n_xloc.size()),
00061      _xloc(n_xloc),
00062      _yloc(n_yloc),
00063      _widths(n_widths),
00064      _heights(n_heights),
00065      _epsilon(ShiftBlock::INFTY),
00066      _leftBound(left_bound),
00067      _rightBound(right_bound),
00068      _topBound(top_bound),
00069      _bottomBound(bottom_bound)
00070 {
00071    for (int i = 0; i < _blocknum; i++)
00072       _epsilon = min(_epsilon, min(_widths[i], _heights[i]));
00073 
00074    _epsilon /= basepacking_h::Dimension::EPSILON_ACCURACY;
00075 }


Member Function Documentation

void ShiftLegalizer::adjustBlock int  currBlk,
const ShiftRotateDecision decision
[private]
 

Definition at line 218 of file plcompact.cxx.

References _heights, _widths, _xloc, _yloc, ShiftBlock::EAST, ShiftBlock::NORTH, ShiftLegalizer::ShiftRotateDecision::rotate, ShiftLegalizer::ShiftRotateDecision::shiftDir, ShiftLegalizer::ShiftRotateDecision::shiftExtent, ShiftBlock::SOUTH, and ShiftBlock::WEST.

Referenced by legalizeBlock().

00220 {
00221    if (decision.rotate)
00222       swap(_widths[currBlk], _heights[currBlk]);
00223    
00224    switch (decision.shiftDir)
00225    {
00226    case ShiftBlock::NORTH:
00227       _yloc[currBlk] += decision.shiftExtent;
00228       break;
00229 
00230    case ShiftBlock::EAST:
00231       _xloc[currBlk] -= decision.shiftExtent;
00232       break;
00233 
00234    case ShiftBlock::SOUTH:
00235       _yloc[currBlk] -= decision.shiftExtent;
00236       break;
00237 
00238    case ShiftBlock::WEST:
00239       _xloc[currBlk] += decision.shiftExtent;
00240       break;
00241 
00242    default:
00243       cout << "ERROR: invalid direction specified in moveblock()"
00244            << endl;
00245       exit(1);
00246    }
00247 }

double ShiftLegalizer::bottomBound  )  const [inline]
 

Definition at line 182 of file plcompact.h.

References _bottomBound.

00183 {   return _bottomBound; }

const vector< double > & ShiftLegalizer::heights  )  const [inline]
 

Definition at line 170 of file plcompact.h.

References _heights.

00171 {   return _heights; }

double ShiftLegalizer::leftBound  )  const [inline]
 

Definition at line 173 of file plcompact.h.

References _leftBound.

00174 {   return _leftBound; }

bool ShiftLegalizer::legalizeAll AlgoType  algo,
const vector< int > &  checkBlks,
vector< int > &  badBlks
 

Definition at line 77 of file plcompact.cxx.

References NAIVE, and naiveLegalize().

00080 {
00081    switch (algo)
00082    {
00083    case NAIVE:
00084       return naiveLegalize(checkBlks, badBlks);
00085       
00086    default:
00087       cout << "ERROR: invalid algo specified in ShiftLegalizer::legalizeAll()"
00088            << endl;
00089       exit(1);
00090       break;
00091    }
00092 }

Here is the call graph for this function:

bool ShiftLegalizer::legalizeBlock int  currBlk  ) 
 

Definition at line 113 of file plcompact.cxx.

References _bottomBound, _epsilon, _heights, _leftBound, _rightBound, _topBound, _widths, _xloc, _yloc, adjustBlock(), ShiftBlock::DIR_NUM, ShiftBlock::Directions, ShiftBlock::EAST, ShiftLegalizer::ShiftRotateDecision::rotate, shiftDecider(), ShiftLegalizer::ShiftRotateDecision::shiftDir, ShiftLegalizer::ShiftRotateDecision::shiftExtent, and UNDEFINED.

Referenced by naiveLegalize().

00114 {
00115    printf("-----Block %d-----\n", currBlk);
00116    
00117    // move only if it resolves ALL overlaps
00118    ShiftBlock shift_block(_xloc, _yloc, _widths, _heights,
00119                           _leftBound, _rightBound,
00120                           _topBound, _bottomBound);
00121    vector<ShiftBlock::ShiftInfo> shiftinfo;
00122    shift_block(currBlk, shiftinfo);
00123 
00124    bool existsOverlaps = false;
00125    bool success = false; // only makes sense when "existsOverlaps"
00126    ShiftRotateDecision decision; // initialized
00127    for (int i = 0; i < ShiftBlock::DIR_NUM; i++)
00128    {
00129       // if overlap occurs
00130       if (fabs(shiftinfo[i].shiftRangeMin) > _epsilon)
00131       {
00132          bool tempSuccess = shiftDecider(ShiftBlock::Directions(i),
00133                                          shiftinfo, decision);
00134 
00135          decision.rotate = false;
00136          success = success || tempSuccess;
00137          existsOverlaps = true;
00138       }
00139    }
00140 
00141    // -----try rotating the block if no move works so far-----
00142    if (existsOverlaps && !success)
00143    {
00144       // temporarily change the info
00145       swap(_widths[currBlk], _heights[currBlk]);
00146       double orig_xloc = _xloc[currBlk];
00147       double orig_yloc = _yloc[currBlk];
00148 
00149       // apply the same procedures to find moves
00150       ShiftBlock shift_block_rotated(_xloc, _yloc, _widths, _heights,
00151                                      _leftBound, _rightBound,
00152                                      _topBound, _bottomBound);
00153       vector<ShiftBlock::ShiftInfo> shiftinfo_rotated;
00154       shift_block_rotated(currBlk, shiftinfo_rotated);
00155 
00156       existsOverlaps = false;
00157       for (int i = 0; i < ShiftBlock::DIR_NUM; i++)
00158       {
00159          // if overlap occurs
00160          if (fabs(shiftinfo_rotated[i].shiftRangeMin) > _epsilon)
00161          {
00162             bool tempSuccess = shiftDecider(ShiftBlock::Directions(i),
00163                                             shiftinfo_rotated, decision);
00164 
00165             decision.rotate = true;
00166             success = success || tempSuccess;
00167             existsOverlaps = true;
00168          }
00169       }
00170 
00171       // special case when "rotating" helps already
00172       if (!existsOverlaps)
00173       {
00174          decision.rotate = true;
00175          decision.shiftDir = ShiftBlock::EAST;
00176          decision.shiftExtent = 0;
00177          
00178          success = true;
00179       }
00180 
00181       // restore the global details even when succeed
00182       swap(_widths[currBlk], _heights[currBlk]);
00183       _xloc[currBlk] = orig_xloc;
00184       _yloc[currBlk] = orig_yloc;
00185    }
00186 
00187    // move towards the direction that needs least fix
00188    if (decision.shiftDir != UNDEFINED)
00189    {
00190       adjustBlock(currBlk, decision);
00191       return true;
00192    }
00193    else if (!existsOverlaps)
00194       return true;
00195    else
00196       return false;
00197 }

Here is the call graph for this function:

bool ShiftLegalizer::naiveLegalize const vector< int > &  checkBlks,
vector< int > &  badBlks
 

Definition at line 94 of file plcompact.cxx.

References legalizeBlock(), and putBlockIntoCore().

Referenced by legalizeAll().

00096 {
00097    int checkBlkNum = checkBlks.size();
00098    bool success = true;
00099    
00100    for (int i = 0; i < checkBlkNum; i++)
00101       putBlockIntoCore(i);
00102 
00103    for (int i = 0; i < checkBlkNum; i++)
00104    {
00105       bool thisSuccess = legalizeBlock(checkBlks[i]);
00106       if (!thisSuccess)
00107          badBlks.push_back(checkBlks[i]);
00108       success = success && thisSuccess;
00109    }
00110    return success;
00111 }

Here is the call graph for this function:

void ShiftLegalizer::putBlockIntoCore int  currBlk  ) 
 

Definition at line 249 of file plcompact.cxx.

References _bottomBound, _heights, _leftBound, _rightBound, _topBound, _widths, _xloc, and _yloc.

Referenced by naiveLegalize().

00250 {
00251    _xloc[currBlk] = max(_xloc[currBlk], _leftBound);
00252    _xloc[currBlk] = min(_xloc[currBlk], _rightBound-_widths[currBlk]);
00253 
00254    _yloc[currBlk] = max(_yloc[currBlk], _bottomBound);
00255    _yloc[currBlk] = min(_yloc[currBlk], _topBound-_heights[currBlk]);
00256 }

double ShiftLegalizer::rightBound  )  const [inline]
 

Definition at line 176 of file plcompact.h.

References _rightBound.

00177 {   return _rightBound; }

bool ShiftLegalizer::rotateDecider int  currBlk,
const vector< ShiftBlock::ShiftInfo > &  shiftinfo,
ShiftRotateDecision decision
const
 

bool ShiftLegalizer::shiftDecider ShiftBlock::Directions  currDir,
const vector< ShiftBlock::ShiftInfo > &  shiftinfo,
ShiftRotateDecision decision
const
 

Definition at line 199 of file plcompact.cxx.

References _epsilon, ShiftLegalizer::ShiftRotateDecision::shiftDir, and ShiftLegalizer::ShiftRotateDecision::shiftExtent.

Referenced by legalizeBlock().

00203 {
00204    if (shiftinfo[currDir].shiftRangeMin <
00205        shiftinfo[currDir].shiftRangeMax + _epsilon)
00206    {
00207       if (shiftinfo[currDir].shiftRangeMin < decision.shiftExtent)
00208       {
00209          decision.shiftDir = currDir;
00210          decision.shiftExtent = shiftinfo[currDir].shiftRangeMin;
00211       }
00212       return true;
00213    }
00214    else
00215       return false; // "f" ==> exists unresolvable overlap (not converse)
00216 }

double ShiftLegalizer::topBound  )  const [inline]
 

Definition at line 179 of file plcompact.h.

References _topBound.

00180 {   return _topBound; }

const vector< double > & ShiftLegalizer::widths  )  const [inline]
 

Definition at line 167 of file plcompact.h.

References _widths.

00168 {   return _widths; }

const vector< double > & ShiftLegalizer::xloc  )  const [inline]
 

Definition at line 161 of file plcompact.h.

References _xloc.

00162 {   return _xloc; }

const vector< double > & ShiftLegalizer::yloc  )  const [inline]
 

Definition at line 164 of file plcompact.h.

References _yloc.

00165 {   return _yloc; }


Member Data Documentation

int ShiftLegalizer::_blocknum [private]
 

Definition at line 140 of file plcompact.h.

Referenced by ShiftLegalizer().

const double ShiftLegalizer::_bottomBound [private]
 

Definition at line 150 of file plcompact.h.

Referenced by bottomBound(), legalizeBlock(), and putBlockIntoCore().

double ShiftLegalizer::_epsilon [private]
 

Definition at line 145 of file plcompact.h.

Referenced by legalizeBlock(), shiftDecider(), and ShiftLegalizer().

vector<double> ShiftLegalizer::_heights [private]
 

Definition at line 144 of file plcompact.h.

Referenced by adjustBlock(), heights(), legalizeBlock(), putBlockIntoCore(), and ShiftLegalizer().

const double ShiftLegalizer::_leftBound [private]
 

Definition at line 147 of file plcompact.h.

Referenced by leftBound(), legalizeBlock(), and putBlockIntoCore().

const double ShiftLegalizer::_rightBound [private]
 

Definition at line 148 of file plcompact.h.

Referenced by legalizeBlock(), putBlockIntoCore(), and rightBound().

const double ShiftLegalizer::_topBound [private]
 

Definition at line 149 of file plcompact.h.

Referenced by legalizeBlock(), putBlockIntoCore(), and topBound().

vector<double> ShiftLegalizer::_widths [private]
 

Definition at line 143 of file plcompact.h.

Referenced by adjustBlock(), legalizeBlock(), putBlockIntoCore(), ShiftLegalizer(), and widths().

vector<double> ShiftLegalizer::_xloc [private]
 

Definition at line 141 of file plcompact.h.

Referenced by adjustBlock(), legalizeBlock(), putBlockIntoCore(), and xloc().

vector<double> ShiftLegalizer::_yloc [private]
 

Definition at line 142 of file plcompact.h.

Referenced by adjustBlock(), legalizeBlock(), putBlockIntoCore(), and yloc().

const double ShiftLegalizer::INFTY = basepacking_h::Dimension::INFTY [static]
 

Definition at line 45 of file plcompact.cxx.

const int ShiftLegalizer::UNDEFINED = basepacking_h::Dimension::UNDEFINED [static]
 

Definition at line 46 of file plcompact.cxx.

Referenced by legalizeBlock().


The documentation for this class was generated from the following files:
Generated on Mon Apr 25 01:15:42 2005 for Parquete by doxygen 1.3.2