Unfit  3.1.1
Data fitting and optimization software
SimulatedAnnealing.hpp
1 // Unfit: Data fitting and optimization software
2 //
3 // Copyright (C) 2012- Dr Martin Buist & Dr Alberto Corrias
4 // Contacts: martin.buist _at_ nus.edu.sg; alberto _at_ nus.edu.sg
5 //
6 // See the 'Contributors' file for a list of those who have contributed
7 // to this work.
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 #ifndef UNFIT_INCLUDE_SIMULATEDANNEALING_HPP_
23 #define UNFIT_INCLUDE_SIMULATEDANNEALING_HPP_
24 
25 #include <vector>
26 #include "GenericCostFunction.hpp"
27 #include "GenericOptimizer.hpp"
28 
29 namespace Unfit
30 {
47 {
49  friend class TestSimulatedAnnealing;
50  public:
55 
61  virtual ~SimulatedAnnealing() = default;
62 
102  int FindMin(GenericCostFunction &CostFunction,
103  std::vector<double> &coordinates) override;
104 
109  void Reset() override;
110 
111  private:
124  int ProcessFindMin(GenericCostFunction &CostFunction,
125  std::vector<double> &coordinates);
126 
131  void InitialiseParameters();
132 
145  void GenerateTrialPoint(std::vector<double> &trial_point, int i);
146 
152  void UpdateStepSizes() noexcept;
153 
164  void ResetStepSizes(double step_size) noexcept;
165 
167  std::size_t cost_;
169  std::size_t dimensions_;
173  std::vector<double> step_sizes_;
175  std::vector<double> acceptance_ratios_;
177  std::mt19937 generator_;
179  std::uniform_real_distribution<double> uniform_dist_;
180 };
181 
182 } // namespace Unfit
183 
184 #endif
std::mt19937 generator_
Definition: SimulatedAnnealing.hpp:177
int ProcessFindMin(GenericCostFunction &CostFunction, std::vector< double > &coordinates)
Definition: SimulatedAnnealing.cpp:187
void UpdateStepSizes() noexcept
Definition: SimulatedAnnealing.cpp:117
void ResetStepSizes(double step_size) noexcept
Definition: SimulatedAnnealing.cpp:136
virtual ~SimulatedAnnealing()=default
STL namespace.
Definition: GenericOptimizer.hpp:41
Definition: Bounds.hpp:27
std::size_t cost_
Definition: SimulatedAnnealing.hpp:167
void InitialiseParameters()
Definition: SimulatedAnnealing.cpp:57
Definition: TestSimulatedAnnealing.cpp:38
std::size_t dimensions_
Definition: SimulatedAnnealing.hpp:169
int FindMin(GenericCostFunction &CostFunction, std::vector< double > &coordinates) override
A method to find a minimum point of a function using a Simulated Annealing approach.
Definition: SimulatedAnnealing.cpp:145
Definition: GenericCostFunction.hpp:36
std::vector< double > step_sizes_
Definition: SimulatedAnnealing.hpp:173
double previous_best_cost_
Definition: SimulatedAnnealing.hpp:171
std::uniform_real_distribution< double > uniform_dist_
Definition: SimulatedAnnealing.hpp:179
void Reset() override
Definition: SimulatedAnnealing.cpp:44
SimulatedAnnealing()
Definition: SimulatedAnnealing.cpp:32
void GenerateTrialPoint(std::vector< double > &trial_point, int i)
Definition: SimulatedAnnealing.cpp:69
A class to implement the Simulated Annealing optimization method.
Definition: SimulatedAnnealing.hpp:46
std::vector< double > acceptance_ratios_
Definition: SimulatedAnnealing.hpp:175