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

btreecompactsstree.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // --------------------------------------------------------

Generated on Mon Apr 25 01:09:24 2005 for Parquete by doxygen 1.3.2