Line data Source code
1 : #pragma once 2 : 3 : #include "elsaDefines.h" 4 : #include "Cloneable.h" 5 : #include "Problem.h" 6 : 7 : namespace elsa 8 : { 9 : /** 10 : * @brief Base class representing a solver for an optimization problem. 11 : * 12 : * @author Matthias Wieczorek - initial code 13 : * @author Maximilian Hornung - modularization 14 : * @author Tobias Lasser - rewrite, modernization 15 : * 16 : * @tparam data_t data type for the domain and range of the problem, defaulting to real_t 17 : * 18 : * This class represents abstract (typically iterative) solvers acting on optimization problems. 19 : */ 20 : template <typename data_t = real_t> 21 : class Solver : public Cloneable<Solver<data_t>> 22 : { 23 : public: 24 : /// Scalar alias 25 : using Scalar = data_t; 26 : 27 : /** 28 : * @brief Constructor for the solver, accepting an optimization problem 29 : * 30 : * @param[in] problem the problem that is supposed to be solved 31 : */ 32 : explicit Solver(const Problem<data_t>& problem); 33 : 34 : /// default destructor 35 0 : ~Solver() override = default; 36 : 37 : /// return the current estimated solution (const version) 38 : const DataContainer<data_t>& getCurrentSolution() const; 39 : 40 : /// return the current estimated solution 41 : DataContainer<data_t>& getCurrentSolution(); 42 : 43 : /** 44 : * @brief Solve the optimization problem (most likely iteratively) 45 : * 46 : * @param[in] iterations number of iterations to execute (optional argument, the default 0 47 : * value lets the solve choose how many iterations to execute) 48 : * 49 : * @returns a reference to the current solution (after solving) 50 : * 51 : * Please note: this method calls solveImpl, which has to be overridden in derived classes. 52 : */ 53 : DataContainer<data_t>& solve(index_t iterations = 0); 54 : 55 : protected: 56 : /// the optimization problem 57 : std::unique_ptr<Problem<data_t>> _problem; 58 : 59 : /// the solve method to be overridden in derived classes 60 : virtual DataContainer<data_t>& solveImpl(index_t iterations) = 0; 61 : 62 : /// implement the polymorphic comparison operation 63 : bool isEqual(const Solver<data_t>& other) const override; 64 : }; 65 : } // namespace elsa