• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

partunif.h

Go to the documentation of this file.
00001 /// @addtogroup unifexp
00002 /// @{
00003 
00004 /////////////////////////////////////////////////////////////////////////////
00005 ///
00006 /// @file partunif.h
00007 ///
00008 /// This file contains the definition of a uniform partition type in which
00009 /// the complement of the critical neighborhood is divided into intervals
00010 /// of approximately the same length.
00011 ///
00012 /// @author Pawel Pilarczyk
00013 ///
00014 /////////////////////////////////////////////////////////////////////////////
00015 
00016 // Copyright (C) 2007 by Pawel Pilarczyk.
00017 //
00018 // This file is part of my research program package.  This is free software;
00019 // you can redistribute it and/or modify it under the terms of the GNU
00020 // General Public License as published by the Free Software Foundation;
00021 // either version 2 of the License, or (at your option) any later version.
00022 //
00023 // This software is distributed in the hope that it will be useful,
00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026 // GNU General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License along
00029 // with this software; see the file "license.txt".  If not, write to the
00030 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00031 // MA 02111-1307, USA.
00032 
00033 // Started on August 21, 2007. Last revision: August 22, 2007.
00034 
00035 #ifndef _partunif_h_
00036 #define _partunif_h_
00037 
00038 #include <vector>
00039 #include <string>
00040 #include "parttype.h"
00041 
00042 
00043 namespace unifexp {
00044 
00045 // --------------------------------------------------
00046 // --------------- uniform partition ----------------
00047 // --------------------------------------------------
00048 
00049 /// A uniform partition type.
00050 /// The complement of the critical neighborhood is divided into intervals
00051 /// of approximately the same length.
00052 template <class numType>
00053 class partUniform: public partType<numType>
00054 {
00055 public:
00056         /// Returns the name of the object.
00057         std::string name () const;
00058 
00059         /// Creates a partition based on the given map, the requested
00060         /// number of elements in the partition, and the width of the
00061         /// critical neighborhood.
00062         void create (const mapType<numType> &theMap, int partCount,
00063                 const numType &delta);
00064 
00065 private:
00066         /// Fills part of the partition table between the given entries
00067         /// in a uniform way based on the values at these ends.
00068         void fillUniform (int first, int last);
00069         
00070 }; /* class partUniform */
00071 
00072 // --------------------------------------------------
00073 
00074 template <class numType>
00075 std::string partUniform<numType>::name () const
00076 {
00077         return std::string ("uniform");
00078 } /* partUniform::name */
00079 
00080 template <class numType>
00081 void partUniform<numType>::fillUniform (int first, int last)
00082 {
00083         const numType &numFirst = (*this) [first];
00084         const numType &numLast = (*this) [last];
00085         const numType numDiff = (numLast - numFirst) / (last - first);
00086         for (int i = first + 1; i < last; ++ i)
00087                 (*this) [i] = numFirst + (i - first) * numDiff;
00088         return;
00089 } /* partUniform::fillUniform */
00090 
00091 template <class numType>
00092 void partUniform<numType>::create (const mapType<numType> &theMap,
00093         int partCount, const numType &delta)
00094 {
00095         int nCrit = theMap. countCritical ();
00096         if (partCount < 2 * nCrit + 2)
00097                 throw "Too small partition requested.";
00098         this -> allocate (partCount);
00099         (*this) [0] = theMap. leftBound ();
00100         (*this) [partCount] = theMap. rightBound ();
00101         numType width = (*this) [partCount] - (*this) [0] -
00102                 2 * delta * nCrit;
00103         if (width <= 0)
00104                 throw "Too wide critical neighborhood requested.";
00105         int prev = 0;
00106         for (int i = 0; i < nCrit; ++ i)
00107         {
00108                 const numType crit = theMap. criticalPoint (i);
00109                 const numType left = crit - delta;
00110                 const numType right = crit + delta;
00111                 if ((left <= (*this) [prev]) ||
00112                         ((*this) [partCount] <= right))
00113                 {
00114                         throw "Too large critical neighborhood requested.";
00115                 }
00116                 int n = prev + static_cast<int> (partCount / width *
00117                         (left - (*this) [prev]));
00118                 if (n <= prev)
00119                         n = prev + 1;
00120                 if (partCount <= n + 1)
00121                         throw "Too few partition intervals requested.";
00122                 this -> addCritical (n);
00123                 (*this) [n] = left;
00124                 fillUniform (prev, n);
00125                 (*this) [n + 1] = right;
00126                 prev = n + 1;
00127         }
00128         fillUniform (prev, partCount);
00129         return;
00130 } /* partUniform::create */
00131 
00132 
00133 } // namespace unifexp
00134 
00135 #endif // _partunif_h_
00136 
00137 /// @}
00138 

Generated on Sun Feb 3 2013 12:40:32 for The Uniform Expansion Software by  doxygen 1.7.2