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 BASEPACKING_H
00036 #define BASEPACKING_H
00037
00038 #include <fstream>
00039 #include <string>
00040 #include <iostream>
00041 #include <iomanip>
00042 #include <vector>
00043 using namespace std;
00044
00045
00046
00047 class BasePacking
00048 {
00049 public:
00050 vector<double> xloc;
00051 vector<double> yloc;
00052 vector<double> width;
00053 vector<double> height;
00054 };
00055
00056 class OrientedPacking : public BasePacking
00057 {
00058 public:
00059 enum ORIENT {N, E, S, W, FN, FE, FS, FW, UNDEFINED = -1};
00060 vector<ORIENT> orient;
00061
00062 inline static ORIENT toOrient(char* orient);
00063 inline static char* toChar(ORIENT orient);
00064 inline static ORIENT flip(ORIENT orient);
00065
00066 };
00067 inline ostream& operator << (ostream& outs, OrientedPacking::ORIENT);
00068 inline void Save_bbb(ostream& outs, const OrientedPacking& pk);
00069 inline void Read_bbb(istream& ins, const OrientedPacking& pk);
00070
00071 namespace basepacking_h
00072 {
00073 class Dimension
00074 {
00075 public:
00076 vector<double> width;
00077 vector<double> height;
00078
00079 static const double INFTY;
00080 static const double EPSILON_ACCURACY;
00081 static const int UNDEFINED;
00082 static const int ORIENT_NUM;
00083 };
00084 }
00085
00086 class HardBlockInfoType
00087 {
00088 public:
00089 HardBlockInfoType(ifstream& ins,
00090 const string& format);
00091 const vector<basepacking_h::Dimension>& blocks;
00092 const vector<string>& block_names;
00093 inline const basepacking_h::Dimension& operator [](int index) const;
00094 inline int blocknum() const;
00095 inline double blockArea() const;
00096
00097 static const int ORIENT_NUM;
00098
00099 friend class MixedBlockInfoType;
00100 friend class MixedBlockInfoTypeFromDB;
00101
00102 protected:
00103 vector<basepacking_h::Dimension> in_blocks;
00104 vector<string> in_block_names;
00105
00106 void set_dimensions(int i, double w, double h);
00107 void ParseTxt(ifstream& ins);
00108 void ParseBlocks(ifstream& ins);
00109
00110 HardBlockInfoType(int blocknum)
00111 : blocks(in_blocks),
00112 block_names(in_block_names),
00113 in_blocks(blocknum+2),
00114 in_block_names(blocknum+2) {}
00115
00116 HardBlockInfoType(const HardBlockInfoType&);
00117 };
00118
00119 inline void PrintDimensions(double width, double height);
00120 inline void PrintAreas(double deadspace, double blockArea);
00121 inline void PrintUtilization(double deadspace, double blockArea);
00122
00123
00124
00125
00126
00127 inline ostream& operator << (ostream& outs,
00128 OrientedPacking::ORIENT orient)
00129 {
00130 switch (orient)
00131 {
00132 case OrientedPacking::N:
00133 outs << "N";
00134 break;
00135 case OrientedPacking::E:
00136 outs << "E";
00137 break;
00138 case OrientedPacking::S:
00139 outs << "S";
00140 break;
00141 case OrientedPacking::W:
00142 outs << "W";
00143 break;
00144 case OrientedPacking::FN:
00145 outs << "FN";
00146 break;
00147 case OrientedPacking::FE:
00148 outs << "FE";
00149 break;
00150 case OrientedPacking::FS:
00151 outs << "FS";
00152 break;
00153 case OrientedPacking::FW:
00154 outs << "FW";
00155 break;
00156 case OrientedPacking::UNDEFINED:
00157 outs << "--";
00158 break;
00159 default:
00160 cout << "ERROR in outputting orientations." << endl;
00161 exit(1);
00162 break;
00163 }
00164 return outs;
00165 }
00166
00167 inline void Save_bbb(ostream& outs,
00168 const OrientedPacking& pk)
00169 {
00170 double totalWidth = 0;
00171 double totalHeight = 0;
00172 int blocknum = pk.xloc.size();
00173 for (int i = 0; i < blocknum; i++)
00174 {
00175 totalWidth = max(totalWidth, pk.xloc[i]+pk.width[i]);
00176 totalHeight = max(totalHeight, pk.yloc[i]+pk.height[i]);
00177 }
00178
00179 outs << totalWidth << endl;
00180 outs << totalHeight << endl;
00181 outs << blocknum << endl;
00182 for (int i = 0; i < blocknum; i++)
00183 outs << pk.width[i] << " " << pk.height[i] << endl;
00184 outs << endl;
00185
00186 for (int i = 0; i < blocknum; i++)
00187 outs << pk.xloc[i] << " " << pk.yloc[i] << endl;
00188 }
00189
00190 inline void Read_bbb(istream& ins,
00191 OrientedPacking& pk)
00192 {
00193 double width, height;
00194 ins >> width >> height;
00195
00196 int blocknum = -1;
00197 ins >> blocknum;
00198
00199 pk.xloc.resize(blocknum);
00200 pk.yloc.resize(blocknum);
00201 pk.width.resize(blocknum);
00202 pk.height.resize(blocknum);
00203 pk.orient.resize(blocknum);
00204 for (int i = 0; i < blocknum; i++)
00205 {
00206 ins >> pk.width[i] >> pk.height[i];
00207 pk.orient[i] = OrientedPacking::N;
00208 }
00209
00210 for (int i = 0; i < blocknum; i++)
00211 ins >> pk.xloc[i] >> pk.yloc[i];
00212 }
00213
00214 inline OrientedPacking::ORIENT OrientedPacking::flip(OrientedPacking::ORIENT
00215 orient)
00216 {
00217 switch(orient)
00218 {
00219 case N: return FE;
00220 case E: return FN;
00221 case S: return FW;
00222 case W: return FS;
00223 case FN: return E;
00224 case FE: return N;
00225 case FS: return W;
00226 case FW: return S;
00227 case UNDEFINED: return UNDEFINED;
00228 default:
00229 cout << "ERROR: invalid orientation: " << orient << endl;
00230 exit(1);
00231 break;
00232 }
00233 }
00234
00235 inline OrientedPacking::ORIENT OrientedPacking::toOrient(char* orient)
00236 {
00237 if(!strcmp(orient, "N"))
00238 return N;
00239 if(!strcmp(orient, "E"))
00240 return E;
00241 if(!strcmp(orient, "S"))
00242 return S;
00243 if(!strcmp(orient, "W"))
00244 return W;
00245 if(!strcmp(orient, "FN"))
00246 return FN;
00247 if(!strcmp(orient, "FE"))
00248 return FE;
00249 if(!strcmp(orient, "FS"))
00250 return FS;
00251 if(!strcmp(orient, "FW"))
00252 return FW;
00253 if (!strcmp(orient, "--"))
00254 return UNDEFINED;
00255
00256 cout << "ERROR: in converting char* to ORIENT" << endl;
00257 exit(1);
00258 return UNDEFINED;
00259 }
00260
00261 inline char* OrientedPacking::toChar(ORIENT orient)
00262 {
00263 if(orient == N)
00264 return("N");
00265 if(orient == E)
00266 return("E");
00267 if(orient == S)
00268 return("S");
00269 if(orient == W)
00270 return("W");
00271 if(orient == FN)
00272 return("FN");
00273 if(orient == FE)
00274 return("FE");
00275 if(orient == FS)
00276 return("FS");
00277 if(orient == FW)
00278 return("FW");
00279 if (orient == UNDEFINED)
00280 return("--");
00281
00282 cout << "ERROR in converting ORIENT to char* " << endl;
00283 exit(1);
00284 return "--";
00285 }
00286
00287 inline const basepacking_h::Dimension& HardBlockInfoType::operator [](int index) const
00288 { return in_blocks[index]; }
00289
00290 inline int HardBlockInfoType::blocknum() const
00291 { return (in_blocks.size()-2); }
00292
00293 inline double HardBlockInfoType::blockArea() const
00294 {
00295 double sum = 0;
00296 for (int i = 0; i < blocknum(); i++)
00297 sum += in_blocks[i].width[0] * in_blocks[i].height[0];
00298 return sum;
00299 }
00300
00301 void PrintDimensions(double width, double height)
00302 {
00303 cout << "width: " << width << endl;
00304 cout << "height: " << height << endl;
00305 }
00306
00307 void PrintAreas(double deadspace, double blockArea)
00308 {
00309 cout << "total area: " << setw(11)
00310 << deadspace + blockArea << endl;
00311 cout << "block area: " << setw(11) << blockArea << endl;
00312 cout << "dead space: " << setw(11) << deadspace
00313 << " (" << (deadspace / blockArea) * 100 << "%)" << endl;
00314 }
00315
00316 void PrintUtilization(double deadspace, double blockArea)
00317 {
00318 double totalArea = deadspace + blockArea;
00319 cout << "area usage (wrt. total area): "
00320 << ((1 - (deadspace / totalArea)) * 100) << "%" << endl;
00321 cout << "dead space % (wrt. total area): "
00322 << ((deadspace / totalArea) * 100) << "%" << endl;
00323 cout << "---------------------------" << endl;
00324 }
00325
00326
00327 #endif