ReFRACtor
iterative_solver.h
Go to the documentation of this file.
1 #ifndef ITERATIVE_SOLVER_H
2 #define ITERATIVE_SOLVER_H
3 #include <vector>
4 #include <printable.h>
5 #include <blitz/array.h>
6 #include <boost/shared_ptr.hpp>
7 #include <cost_func.h>
8 #include "observer.h"
9 
10 namespace FullPhysics {
11 
12 //-----------------------------------------------------------------------
37 //-----------------------------------------------------------------------
38 
40  public Observable<IterativeSolver>,
41  public Printable<IterativeSolver> {
42 
43 public:
44 
45 
46 //-----------------------------------------------------------------------
48 //-----------------------------------------------------------------------
49 
50  enum status_t {
56  };
57 
58 
59 //-----------------------------------------------------------------------
69 //-----------------------------------------------------------------------
70 
71  IterativeSolver(int max_cost_function_calls, bool vrbs)
72  : max_cost_f_calls(max_cost_function_calls),
73  verbose(vrbs), stat(UNTRIED)
74  {}
75 
76 
77  virtual ~IterativeSolver() {}
78 
79 //-----------------------------------------------------------------------
80 // Observers can be be registered to get notified for each accepted
81 // solver state.
82 //-----------------------------------------------------------------------
83 
85  { add_observer_do(Obs, *this);}
86 
88  { remove_observer_do(Obs, *this);}
89 
90 //-----------------------------------------------------------------------
94 //-----------------------------------------------------------------------
95 
96  virtual int num_accepted_steps() const
97  { return Accepted_points.size()-1; }
98 
99 
100 //-----------------------------------------------------------------------
131 //-----------------------------------------------------------------------
132 
133  virtual std::vector< blitz::Array<double, 1> > accepted_points() const
134  { return Accepted_points; }
135 
136 
137 //-----------------------------------------------------------------------
155 //-----------------------------------------------------------------------
156 
157  virtual std::vector<double> cost_at_accepted_points() const
158  { return Cost_at_accepted_points; }
159 
160 
161 //-----------------------------------------------------------------------
167 //-----------------------------------------------------------------------
168 
169  virtual void solve() = 0;
170 
171 
172 //-----------------------------------------------------------------------
188 //-----------------------------------------------------------------------
189 
190  virtual status_t status() const
191  { return stat; }
192 
193 
194 //-----------------------------------------------------------------------
214 //-----------------------------------------------------------------------
215 
216  virtual const char * const status_str() const;
217 
218 
219 //-----------------------------------------------------------------------
221 //-----------------------------------------------------------------------
222 
223  virtual void print(std::ostream& Os) const
224  { Os << "IterativeSolver"; }
225 
226 
227 protected:
228 
230 
231  bool verbose;
233 
234 //-----------------------------------------------------------------------
244 //-----------------------------------------------------------------------
245 
246  void record_accepted_point(const blitz::Array<double, 1>& point)
247  {
248  Accepted_points.push_back(point);
249 
250  // Notify observers, number of accepted points will be > 0 now
251  notify_update_do(*this);
252  }
253 
254 
255 //-----------------------------------------------------------------------
267 //-----------------------------------------------------------------------
268 
270  { Cost_at_accepted_points.push_back(cost); }
271 
272 
273 private:
274 
275  std::vector< blitz::Array<double, 1> > Accepted_points;
276  std::vector< double > Cost_at_accepted_points;
277 
278 };
279 }
280 #endif
virtual const char *const status_str() const
Returns the string version of the solver status.
solve method called but an error was encountered
void record_cost_at_accepted_point(double cost)
Called to record the cost function value at an accepted point.
solve method called and a solution found
solve method was called but stalled
status_t
Enum type for the status of the iterative solver.
void add_observer_do(Observer< IterativeSolver > &Obs, IterativeSolver &t)
Add an observer.
Definition: observer.h:148
virtual void solve()=0
The method that solves the optimization problem.
virtual int num_accepted_steps() const
Returns the number of the accepted steps.
void remove_observer_do(Observer< IterativeSolver > &Obs, IterativeSolver &t)
Remove an observer.
Definition: observer.h:173
This is a Mixin for classes that can be printed.
Definition: printable.h:24
void notify_update_do(const IterativeSolver &Self)
Function to call to notify Observers of a state change.
Definition: observer.h:121
virtual void remove_observer(Observer< IterativeSolver > &Obs)
Remove an observer.
solve method called but did not converge to a solution
solve method not called yet
Mixin for a class that allows other classes to observe it state.
Definition: observer.h:12
virtual status_t status() const
Returns a value of IterativeSolver::status_t type.
void record_accepted_point(const blitz::Array< double, 1 > &point)
Called to record an accepted point.
virtual std::vector< blitz::Array< double, 1 > > accepted_points() const
Returns a vector (std) of accepted points.
virtual std::vector< double > cost_at_accepted_points() const
Returns a vector (std) of cost function values at accepted points.
virtual void print(std::ostream &Os) const
Prints description of object.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
IterativeSolver(int max_cost_function_calls, bool vrbs)
Constructor.
The base class for all iterative optimizers.
virtual void add_observer(Observer< IterativeSolver > &Obs)
Add an observer.

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10