Solver.hpp
Go to the documentation of this file.
1 // Copyright 2019, University of Maryland and the MANGO development team.
2 //
3 // This file is part of MANGO.
4 //
5 // MANGO is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // MANGO is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with MANGO. If not, see
17 // <https://www.gnu.org/licenses/>.
18 
19 #ifndef MANGO_SOLVER_H
20 #define MANGO_SOLVER_H
21 
22 #include <mpi.h>
23 #include <string>
24 #include <ctime>
25 #include "mango.hpp"
26 #include "Package.hpp"
27 #include "Recorder.hpp"
28 
29 namespace mango {
30 
31  class Solver {
32  // This class contains the ugly implementation details of the interface for Problem specified in mango.hpp.
33  // All methods are "virtual" so they can be over-ridden in subclasses of Solver that replace the solver in Problem.
34  protected:
35  Solver(); // This version of the constructor, with no arguments, is used only for unit testing.
36  virtual void group_leaders_loop();
37  virtual void set_package();
38 
39  public:
40  // All data in this class is public because this information must be used by the concrete Package.
41  // It would not work to make Package a friend of this class because friendship would not extend to the concrete subclasses of Package.
46  int argc;
47  char** argv;
54  double* lower_bounds;
55  double* upper_bounds;
58  double* state_vector;
61  std::string output_filename;
63  int verbose;
64  void* user_data;
69 
70  Solver(Problem*, int);
71  ~Solver();
72 
73  virtual double optimize(MPI_Partition*);
74  virtual void init_optimization();
75  virtual void objective_function_wrapper(const double*, double*, bool*);
76  virtual void finite_difference_gradient(const double*, double*, double*);
77  virtual bool record_function_evaluation(const double*, double, bool); // Called from objective_function_wrapper
78  virtual void record_function_evaluation_pointer(const double*, double*, bool); // Called from evaluate_set_in_parallel
79 
80  void finite_difference_Jacobian(vector_function_type, int, const double*, double*, double*);
81  void evaluate_set_in_parallel(vector_function_type, int, int, double*, double*, bool*);
82  static void objective_to_vector_function(int*, const double*, int*, double*, int*, mango::Problem*, void*);
83  };
84 
85 }
86 
87 #endif
mango::Solver::lower_bounds
double * lower_bounds
Definition: Solver.hpp:54
mango::Solver::package
Package * package
Definition: Solver.hpp:57
mango::Solver::finite_difference_gradient
virtual void finite_difference_gradient(const double *, double *, double *)
Definition: Solver.cpp:82
mango::Solver::start_time
clock_t start_time
Definition: Solver.hpp:56
mango::Package
Definition: Package.hpp:29
mango::Solver::Solver
Solver()
Definition: Solver.cpp:54
mango::Solver::record_function_evaluation_pointer
virtual void record_function_evaluation_pointer(const double *, double *, bool)
Definition: Solver.cpp:86
mango::Solver::problem
Problem * problem
Definition: Solver.hpp:66
mango::Solver::upper_bounds
double * upper_bounds
Definition: Solver.hpp:55
mango::Solver::objective_function
objective_function_type objective_function
Definition: Solver.hpp:44
mango::Solver::centered_differences
bool centered_differences
Definition: Solver.hpp:59
mango::Solver::verbose
int verbose
Definition: Solver.hpp:63
mango::Solver::argc
int argc
Definition: Solver.hpp:46
mango::Recorder
Definition: Recorder.hpp:27
mango::Solver::objective_function_wrapper
virtual void objective_function_wrapper(const double *, double *, bool *)
Definition: objective_function_wrapper.cpp:27
mango::Solver::~Solver
~Solver()
Definition: Solver.cpp:67
mango::Solver::user_data
void * user_data
Definition: Solver.hpp:64
mango::algorithm_type
algorithm_type
A list of the algorithms that MANGO can potentially use.
Definition: mango.hpp:75
mango::Solver::finite_difference_step_size
double finite_difference_step_size
Definition: Solver.hpp:60
mango::Solver::state_vector
double * state_vector
Definition: Solver.hpp:58
mango::Solver::best_state_vector
double * best_state_vector
Definition: Solver.hpp:50
mango::Solver::best_time
clock_t best_time
Definition: Solver.hpp:56
mango::Solver::finite_difference_Jacobian
void finite_difference_Jacobian(vector_function_type, int, const double *, double *, double *)
Definition: finite_difference_Jacobian.cpp:28
mango::Solver::init_optimization
virtual void init_optimization()
Definition: init_optimization.cpp:28
mango::Solver::recorder
Recorder * recorder
Definition: Solver.hpp:67
mango::Solver::N_line_search
int N_line_search
Definition: Solver.hpp:68
mango::Solver::best_objective_function
double best_objective_function
Definition: Solver.hpp:51
mango::Solver::bound_constraints_set
bool bound_constraints_set
Definition: Solver.hpp:53
mango::vector_function_type
void(* vector_function_type)(int *N_parameters, const double *state_vector, int *N_terms, double *residuals, int *failed, mango::Problem *problem, void *user_data)
Format for the user-supplied subroutine that computes the residuals for a least-squares optimization ...
Definition: mango.hpp:439
mango::Solver::mpi_partition
MPI_Partition * mpi_partition
Definition: Solver.hpp:65
mango::Solver::evaluate_set_in_parallel
void evaluate_set_in_parallel(vector_function_type, int, int, double *, double *, bool *)
Definition: evaluate_set_in_parallel.cpp:28
mango::Solver::argv
char ** argv
Definition: Solver.hpp:47
mango.hpp
mango::Solver::max_function_evaluations
int max_function_evaluations
Definition: Solver.hpp:62
mango::Solver::output_filename
std::string output_filename
Definition: Solver.hpp:61
mango::objective_function_type
void(* objective_function_type)(int *N_parameters, const double *state_vector, double *objective_value, int *failed, mango::Problem *problem, void *user_data)
Format for the user-supplied subroutine that computes the objective function for a general (non least...
Definition: mango.hpp:424
mango::Solver::N_parameters
int N_parameters
Definition: Solver.hpp:43
mango::Solver::optimize
virtual double optimize(MPI_Partition *)
Definition: optimize.cpp:28
mango
This C++ namespace contains everything related to MANGO.
Definition: Imfil.hpp:7
mango::Solver::objective_to_vector_function
static void objective_to_vector_function(int *, const double *, int *, double *, int *, mango::Problem *, void *)
Definition: Solver.cpp:71
mango::Solver::algorithm
algorithm_type algorithm
Definition: Solver.hpp:42
mango::Solver::record_function_evaluation
virtual bool record_function_evaluation(const double *, double, bool)
Definition: objective_function_wrapper.cpp:41
mango::Solver::at_least_one_success
bool at_least_one_success
Definition: Solver.hpp:49
mango::Solver
Definition: Solver.hpp:31
mango::Solver::max_function_and_gradient_evaluations
int max_function_and_gradient_evaluations
Definition: Solver.hpp:48
mango::Solver::function_evaluations
int function_evaluations
Definition: Solver.hpp:45
Recorder.hpp
Package.hpp
mango::MPI_Partition
A class for dividing the set of MPI processes into worker groups.
Definition: mango.hpp:195
mango::Solver::group_leaders_loop
virtual void group_leaders_loop()
Definition: group_leaders_loop.cpp:23
mango::Solver::set_package
virtual void set_package()
Definition: set_package.cpp:34
mango::Solver::best_function_evaluation
int best_function_evaluation
Definition: Solver.hpp:52
mango::Problem
Definition: mango.hpp:442