DART 6.10.1
Loading...
Searching...
No Matches
Problem.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2021, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_OPTIMIZER_PROBLEM_HPP_
34#define DART_OPTIMIZER_PROBLEM_HPP_
35
36#include <cstddef>
37#include <vector>
38
39#include <Eigen/Dense>
40
42
43namespace dart {
44namespace optimizer {
45
48{
49public:
51 explicit Problem(std::size_t _dim = 0);
52
54 virtual ~Problem() = default;
55
56 //--------------------------- Problem Setting --------------------------------
59 void setDimension(std::size_t _dim);
60
62 std::size_t getDimension() const;
63
65 void setInitialGuess(const Eigen::VectorXd& _initGuess);
66
68 const Eigen::VectorXd& getInitialGuess() const;
69
72 void addSeed(const Eigen::VectorXd& _seed);
73
77 Eigen::VectorXd& getSeed(std::size_t _index);
78
80 const Eigen::VectorXd& getSeed(std::size_t _index) const;
81
84 std::vector<Eigen::VectorXd>& getSeeds();
85
87 const std::vector<Eigen::VectorXd>& getSeeds() const;
88
90 void clearAllSeeds();
91
93 void setLowerBounds(const Eigen::VectorXd& _lb);
94
96 const Eigen::VectorXd& getLowerBounds() const;
97
99 void setUpperBounds(const Eigen::VectorXd& _ub);
100
102 const Eigen::VectorXd& getUpperBounds() const;
103
105 void setObjective(FunctionPtr _obj);
106
109
111 void addEqConstraint(FunctionPtr _eqConst);
112
115 void addIneqConstraint(FunctionPtr _ineqConst);
116
118 std::size_t getNumEqConstraints() const;
119
121 std::size_t getNumIneqConstraints() const;
122
124 FunctionPtr getEqConstraint(std::size_t _idx) const;
125
127 FunctionPtr getIneqConstraint(std::size_t _idx) const;
128
130 void removeEqConstraint(FunctionPtr _eqConst);
131
133 void removeIneqConstraint(FunctionPtr _ineqConst);
134
137
140
141 //------------------------------ Result --------------------------------------
144 void setOptimumValue(double _val);
145
147 double getOptimumValue() const;
148
150 void setOptimalSolution(const Eigen::VectorXd& _optParam);
151
153 const Eigen::VectorXd& getOptimalSolution();
154
155protected:
157 std::size_t mDimension;
158
160 Eigen::VectorXd mInitialGuess;
161
163 std::vector<Eigen::VectorXd> mSeeds;
164
166 Eigen::VectorXd mLowerBounds;
167
169 Eigen::VectorXd mUpperBounds;
170
173
175 std::vector<FunctionPtr> mEqConstraints;
176
178 std::vector<FunctionPtr> mIneqConstraints;
179
182
184 Eigen::VectorXd mOptimalSolution;
185};
186
187} // namespace optimizer
188} // namespace dart
189
190#endif // #ifndef DART_OPTIMIZER_PROBLEM_HPP_
class Problem
Definition Problem.hpp:48
void addIneqConstraint(FunctionPtr _ineqConst)
Add inequality constraint.
Definition Problem.cpp:218
Eigen::VectorXd mInitialGuess
Initial guess for optimization parameters.
Definition Problem.hpp:160
void setLowerBounds(const Eigen::VectorXd &_lb)
Set lower bounds for optimization parameters.
Definition Problem.cpp:172
void setOptimalSolution(const Eigen::VectorXd &_optParam)
Set optimal solution. This function called by Solver.
Definition Problem.cpp:295
std::size_t getNumIneqConstraints() const
Get number of inequality constraints.
Definition Problem.cpp:231
FunctionPtr getObjective() const
Get objective function.
Definition Problem.cpp:205
void removeAllEqConstraints()
Remove all equality constraints.
Definition Problem.cpp:269
double mOptimumValue
Optimal objective value.
Definition Problem.hpp:181
double getOptimumValue() const
Get optimum value of the objective function.
Definition Problem.cpp:289
void setUpperBounds(const Eigen::VectorXd &_ub)
Set upper bounds for optimization parameters.
Definition Problem.cpp:185
virtual ~Problem()=default
Destructor.
FunctionPtr getEqConstraint(std::size_t _idx) const
Get equality constraint.
Definition Problem.cpp:237
std::size_t mDimension
Dimension of this problem.
Definition Problem.hpp:157
Eigen::VectorXd mOptimalSolution
Optimal solution.
Definition Problem.hpp:184
void setDimension(std::size_t _dim)
Set dimension.
Definition Problem.cpp:64
std::vector< FunctionPtr > mEqConstraints
Equality constraint functions.
Definition Problem.hpp:175
void addEqConstraint(FunctionPtr _eqConst)
Add equality constraint.
Definition Problem.cpp:211
void removeEqConstraint(FunctionPtr _eqConst)
Remove equality constraint.
Definition Problem.cpp:251
Eigen::VectorXd mLowerBounds
Lower bounds for optimization parameters.
Definition Problem.hpp:166
std::size_t getDimension() const
Get dimension.
Definition Problem.cpp:84
std::vector< Eigen::VectorXd > mSeeds
Additional guess hints for the Solver.
Definition Problem.hpp:163
Eigen::VectorXd mUpperBounds
Upper bounds for optimization parameters.
Definition Problem.hpp:169
Eigen::VectorXd & getSeed(std::size_t _index)
Get a mutable reference of the seed for the specified index.
Definition Problem.cpp:130
void removeAllIneqConstraints()
Remove all inequality constraints.
Definition Problem.cpp:276
const Eigen::VectorXd & getOptimalSolution()
Get optimal solution.
Definition Problem.cpp:304
void addSeed(const Eigen::VectorXd &_seed)
Add a seed for the Solver to use as a hint for the neighborhood of the solution.
Definition Problem.cpp:115
void clearAllSeeds()
Clear the seeds that this Problem currently contains.
Definition Problem.cpp:166
const Eigen::VectorXd & getInitialGuess() const
Set initial guess for opimization parameters.
Definition Problem.cpp:109
std::size_t getNumEqConstraints() const
Get number of equality constraints.
Definition Problem.cpp:225
const Eigen::VectorXd & getUpperBounds() const
Get upper bounds for optimization parameters.
Definition Problem.cpp:192
FunctionPtr getIneqConstraint(std::size_t _idx) const
Get inequality constraint.
Definition Problem.cpp:244
void setInitialGuess(const Eigen::VectorXd &_initGuess)
Set initial guess for opimization parameters.
Definition Problem.cpp:90
std::vector< Eigen::VectorXd > & getSeeds()
Get a mutable reference to the full vector of seeds that this Problem currently contains.
Definition Problem.cpp:154
void removeIneqConstraint(FunctionPtr _ineqConst)
Remove inequality constraint.
Definition Problem.cpp:260
std::vector< FunctionPtr > mIneqConstraints
Inequality constraint functions.
Definition Problem.hpp:178
const Eigen::VectorXd & getLowerBounds() const
Get lower bounds for optimization parameters.
Definition Problem.cpp:179
void setObjective(FunctionPtr _obj)
Set minimum objective function.
Definition Problem.cpp:198
void setOptimumValue(double _val)
Set optimum value of the objective function.
Definition Problem.cpp:283
FunctionPtr mObjective
Objective function.
Definition Problem.hpp:172
std::shared_ptr< Function > FunctionPtr
Definition Function.hpp:84
Definition BulletCollisionDetector.cpp:65