/usr/include/roboptim/core/generic-solver.hh is in libroboptim-core-dev 2.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA.
//
// This file is part of the roboptim.
//
// roboptim is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// roboptim is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with roboptim. If not, see <http://www.gnu.org/licenses/>.
#ifndef ROBOPTIM_CORE_GENERIC_SOLVER_HH
# define ROBOPTIM_CORE_GENERIC_SOLVER_HH
# include <roboptim/core/sys.hh>
# include <roboptim/core/debug.hh>
# include <stdexcept>
# include <boost/variant/get.hpp>
# include <boost/variant/variant.hpp>
# include <boost/utility.hpp>
# include <log4cxx/logger.h>
# include <roboptim/core/fwd.hh>
# include <roboptim/core/problem.hh>
# include <roboptim/core/result.hh>
# include <roboptim/core/result-with-warnings.hh>
# include <roboptim/core/solver-error.hh>
# include <roboptim/core/solver-warning.hh>
namespace roboptim
{
/// \addtogroup roboptim_solver
/// @{
/// \brief Abstract interface satisfied by all solvers.
class ROBOPTIM_DLLAPI GenericSolver : public boost::noncopyable
{
public:
/// \brief Define the kind of solution which has been found.
enum solutions {
/// Solution has yet to be found.
SOLVER_NO_SOLUTION,
/// Solution has been found.
SOLVER_VALUE,
/// Solution has been found but some problems happened.
SOLVER_VALUE_WARNINGS,
/// The solver failed to found a solution.
SOLVER_ERROR
};
/// \brief Vector type imported from function class.
typedef Function::vector_t vector_t;
/// \brief Result type.
///
/// Uses a Boost.Variant to represent the different possible results:
/// - no solution (problem not yet solved),
/// - result (problem has been solved successfully),
/// - result and warnings (problem solved but some errors happened),
/// - solver error (optimization has failed).
typedef boost::variant<NoSolution,
Result,
ResultWithWarnings,
SolverError> result_t;
/// \name Constructors and destructors.
/// \{
explicit GenericSolver () throw ();
explicit GenericSolver (const GenericSolver&) throw ();
virtual ~GenericSolver () throw ();
/// \}
/// \brief Force to restart the optimization.
/// Reset the internal mechanism to force the solution to be
/// re-computed next time getMinimum is called.
void reset () throw ();
/// \brief Solve the problem.
/// Called automatically by getMinimum if required.
virtual void solve () throw () = 0;
/// \brief Returns the function minimum
/// This solves the problem automatically, if it has not yet been solved.
/// \see minimumType()
/// \see getMinimum()
const result_t& minimum () throw ();
/// \brief Display the solver on the specified output stream.
///
/// \param o output stream used for display
/// \return output stream
virtual std::ostream& print (std::ostream&) const throw ();
/// \brief Determine real minimum type.
///
/// \return value representing result type
solutions minimumType () throw ()
{
switch (minimum ().which ())
{
case 0:
return SOLVER_NO_SOLUTION;
case 1:
return SOLVER_VALUE;
case 2:
return SOLVER_VALUE_WARNINGS;
case 3:
return SOLVER_ERROR;
default:
break;
}
assert (0);
return SOLVER_ERROR;
}
/// \brief Get real result.
///
/// Optimization results is wrapped in a Boost.Variant
/// class, this method has to be used to retrieve the
/// real result type.
/// \return real result
template <typename T>
const T& getMinimum () throw (boost::bad_get)
{
return boost::get<T> (minimum ());
}
protected:
/// /brief Optimization result.
result_t result_;
/// \brief Pointer to function logger (see log4cxx documentation).
static log4cxx::LoggerPtr logger;
};
/// @}
/// \brief Override operator<< to handle solver display.
///
/// \param o output stream used for display
/// \param gs solver to be displayed
/// \return output stream
ROBOPTIM_DLLAPI std::ostream& operator<< (std::ostream& o,
const GenericSolver& gs);
/// \brief Override operator<< to display ``no solution'' objects.
///
/// \param o output stream used for display
/// \param ns NoSolution object, ignored
/// \return output stream
ROBOPTIM_DLLAPI std::ostream& operator<< (std::ostream& o,
const NoSolution& ns);
} // end of namespace roboptim
#endif //! ROBOPTIM_CORE_GENERIC_SOLVER_HH
|