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

partsegm.h

Go to the documentation of this file.
00001 /// @addtogroup unifexp
00002 /// @{
00003 
00004 /////////////////////////////////////////////////////////////////////////////
00005 ///
00006 /// @file partsegm.h
00007 ///
00008 /// This file contains the definition of a segmented partition type in which
00009 /// each component of the complement of the critical neighborhood
00010 /// is divided into the same number of intervals.
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 March 8, 2007. Last revision: August 22, 2007.
00034 
00035 #ifndef _partsegm_h_
00036 #define _partsegm_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 segmented partition type.
00050 /// Each component of the complement of the critical neighborhood
00051 /// is divided into the same number of intervals.
00052 template <class numType>
00053 class partSegmented: 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 partSegmented */
00071 
00072 // --------------------------------------------------
00073 
00074 template <class numType>
00075 std::string partSegmented<numType>::name () const
00076 {
00077         return std::string ("segmented");
00078 } /* partSegmented::name */
00079 
00080 template <class numType>
00081 void partSegmented<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 } /* partSegmented::fillUniform */
00090 
00091 template <class numType>
00092 void partSegmented<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         int prev = 0;
00102         for (int i = 0; i < nCrit; ++ i)
00103         {
00104                 int n = partCount / (nCrit + 1) * (i + 1);
00105                 this -> addCritical (n);
00106                 const numType crit = theMap. criticalPoint (i);
00107                 const numType left = crit - delta;
00108                 const numType right = crit + delta;
00109                 if ((left <= (*this) [prev]) ||
00110                         ((*this) [partCount] <= right))
00111                 {
00112                         throw "Too large critical neighborhood requested.";
00113                 }
00114                 (*this) [n] = left;
00115                 fillUniform (prev, n);
00116                 (*this) [n + 1] = right;
00117                 prev = n + 1;
00118         }
00119         fillUniform (prev, partCount);
00120         return;
00121 } /* partSegmented::create */
00122 
00123 
00124 } // namespace unifexp
00125 
00126 #endif // _partsegm_h_
00127 
00128 /// @}
00129 

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