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 #include "btreecompactsstree.h"
00036 #include "basepacking.h"
00037 #include "btreecompact.h"
00038 #include "btreefromsstree.h"
00039
00040 #include <fstream>
00041 #include <string>
00042 #include <iomanip>
00043 using namespace std;
00044
00045
00046 double BTreeCompactSlice(const SoftPacking& spk,
00047 const string& outfilename)
00048 {
00049 SoftPackingHardBlockInfoType hardblockinfo(spk);
00050 BTreeFromSoftPacking btree(hardblockinfo, spk,
00051 getTolerance(hardblockinfo));
00052 BTreeCompactor compactor(btree);
00053
00054 int numChanged = 0;
00055 int i = 0;
00056
00057 double orig_totalArea = compactor.totalArea();
00058 double orig_blockArea = compactor.blockArea();
00059 double spk_totalArea = spk.totalWidth * spk.totalHeight;
00060 printf("converted to B*-Tree: %.2lf (%.2lf%%) -> %.2lf (%.2lf%%)\n",
00061 spk_totalArea, (spk.deadspace / spk.blockArea) * 100,
00062 orig_totalArea, (orig_totalArea / orig_blockArea - 1)* 100);
00063 do
00064 {
00065 numChanged = compactor.compact();
00066
00067 printf("round %d: %6d blks changed: %.2lf (%.2lf%%) -> %.2lf (%.2lf%%)\n",
00068 i, numChanged, orig_totalArea,
00069 (orig_totalArea / orig_blockArea - 1) * 100,
00070 compactor.totalArea(),
00071 (compactor.totalArea() / compactor.blockArea() - 1) * 100);
00072 i++;
00073 orig_totalArea = compactor.totalArea();
00074 orig_blockArea = compactor.blockArea();
00075 } while (numChanged != 0);
00076
00077 double final_blkArea = compactor.blockArea();
00078 double final_deadspace = compactor.totalArea() - final_blkArea;
00079 cout << endl;
00080 cout << "After compaction, " << endl;
00081 cout << "blkArea: " << setw(11) << final_blkArea
00082 << " deadspace: " << setw(11) << final_deadspace
00083 << " (" << ((final_deadspace / final_blkArea) * 100) << "%)" << endl;
00084
00085 cout << endl;
00086 PrintDimensions(compactor.totalWidth(), compactor.totalHeight());
00087 PrintAreas(final_deadspace, final_blkArea);
00088 cout << endl;
00089 PrintUtilization(final_deadspace, final_blkArea);
00090 cout << endl;
00091
00092 ofstream outfile;
00093 outfile.open(outfilename.c_str());
00094 Save_bbb(outfile, BTreeOrientedPacking(compactor));
00095 if (outfile.good())
00096 cout << "Output successfully written to " << outfilename << endl;
00097 else
00098 cout << "Something wrong with the file " << outfilename << endl;
00099 outfile.close();
00100
00101 return (compactor.totalArea() - compactor.blockArea());
00102 }
00103