AbstractSingleObjectiveOptimizer.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief AbstractSingleObjectiveOptimizer
6  *
7  *
8  *
9  * \author T.Voss, T. Glasmachers, O.Krause
10  * \date 2010-2011
11  *
12  *
13  * \par Copyright 1995-2017 Shark Development Team
14  *
15  * <BR><HR>
16  * This file is part of Shark.
17  * <http://shark-ml.org/>
18  *
19  * Shark is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU Lesser General Public License as published
21  * by the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * Shark is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
33 //===========================================================================
34 #ifndef SHARK_OBJECTIVEFUNCTIONS_ABSTRACTSINGLEOBJECTIVEOPTIMIZER_H
35 #define SHARK_OBJECTIVEFUNCTIONS_ABSTRACTSINGLEOBJECTIVEOPTIMIZER_H
36 
38 #include <shark/Core/ResultSets.h>
39 
40 namespace shark {
41  ///\brief Base class for all single objective optimizer
42  ///
43  /// This class is a spezialization of the AbstractOptimizer itnerface for the class of single objective optimizers. A single objective optimizer is an optimizer
44  /// which can only optimize functions with a single objective. This is the default case for most optimisation problems.
45  /// the class requires the ObjectiveFunction to provide a feasible starting point. If this is not possible, a second version of init is provided where the starting point can be
46  /// explicitely defined.
47  /// The Return type of an SingleObjectiveOptimizer is the SingleObjectiveResultSet which is a struct returning the best value of the function and together with it's point.
48  template<class PointType>
49  class AbstractSingleObjectiveOptimizer: public AbstractOptimizer<PointType,double,SingleObjectiveResultSet<PointType> >{
50  private:
52  public:
57 
58  ///\brief By default most single objective optimizers only require a single point
59  std::size_t numInitPoints() const{
60  return 1;
61  }
62 
63  using base_type::init;
64 
65  /// \brief Initialize the optimizer for the supplied objective function using a set of initialisation points
66  ///
67  /// The default implementation picks either the first point in the set, or if it is enmpty, trys
68  /// to generate one from the function.
69  ///
70  /// Be aware that function.init() has to be called before calling this function!
71  ///
72  /// \param [in] function The objective function to initialize for.
73  /// \param [in] initPoints points used for initialisation. Should be at least numInitPoints().
74  virtual void init( ObjectiveFunctionType const& function, std::vector<SearchPointType> const& initPoints ){
75  if(initPoints.empty())
76  init(function);
77  else
78  init(function,initPoints[0]);
79  }
80 
81  ///initializes the optimizer using a predefined starting point
82  virtual void init(ObjectiveFunctionType const& function, SearchPointType const& startingPoint)=0;
83  ///returns the current solution of the optimizer
84  virtual const SolutionType& solution() const{
85  return m_best;
86  }
87 
88  protected:
89 
90  SolutionType m_best; ///<Current solution of the optimizer
91  };
92 
93 }
94 #endif