edoSampler.h
00001 /*
00002 The Evolving Distribution Objects framework (EDO) is a template-based,
00003 ANSI-C++ evolutionary computation library which helps you to write your
00004 own estimation of distribution algorithms.
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public
00017 License along with this library; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 Copyright (C) 2010 Thales group
00021 */
00022 /*
00023 Authors:
00024     Johann Dréo <johann.dreo@thalesgroup.com>
00025     Caner Candan <caner.candan@thalesgroup.com>
00026 */
00027 
00028 #ifndef _edoSampler_h
00029 #define _edoSampler_h
00030 
00031 #include <eoFunctor.h>
00032 
00033 #include "edoRepairer.h"
00034 #include "edoBounderNo.h"
00035 
00036 
00053 template < typename D >
00054 class edoSampler : public eoUF< D&, typename D::EOType >
00055 {
00056 public:
00057     typedef typename D::EOType EOType;
00058 
00059     edoSampler(edoRepairer< EOType > & repairer)
00060         : _dummy_repairer(), _repairer(repairer)
00061     {}
00062 
00063     
00064     edoSampler()
00065         : _dummy_repairer(), _repairer( _dummy_repairer )
00066     {}
00067     
00068 
00069     // virtual EOType operator()( D& ) = 0 (provided by eoUF< A1, R >)
00070 
00071     EOType operator()( D& distrib )
00072     {
00073         assert( distrib.size() > 0 );
00074 
00075         // Point we want to sample to get higher a set of points
00076         // (coordinates in n dimension)
00077         // x = {x1, x2, ..., xn}
00078         // the sample method is implemented in the derivated class
00079         EOType solution(sample(distrib));
00080 
00081         // Now we are bounding the distribution thanks to min and max
00082         // parameters.
00083         _repairer(solution);
00084 
00085         return solution;
00086     }
00087 
00088 protected:
00089 
00090     virtual EOType sample( D& ) = 0;
00091 
00092 private:
00093     edoBounderNo<EOType> _dummy_repairer;
00094 
00096     edoRepairer< EOType > & _repairer;
00097 
00098 };
00099 
00100 #endif // !_edoSampler_h
 All Classes Functions Variables Typedefs