DART 6.7.3
Loading...
Searching...
No Matches
Problem.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2019, 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:
50
52 explicit Problem(std::size_t _dim = 0);
53
55 virtual ~Problem() = default;
56
57 //--------------------------- Problem Setting --------------------------------
60 void setDimension(std::size_t _dim);
61
63 std::size_t getDimension() const;
64
66 void setInitialGuess(const Eigen::VectorXd& _initGuess);
67
69 const Eigen::VectorXd& getInitialGuess() const;
70
73 void addSeed(const Eigen::VectorXd& _seed);
74
78 Eigen::VectorXd& getSeed(std::size_t _index);
79
81 const Eigen::VectorXd& getSeed(std::size_t _index) const;
82
85 std::vector<Eigen::VectorXd>& getSeeds();
86
88 const std::vector<Eigen::VectorXd>& getSeeds() const;
89
91 void clearAllSeeds();
92
94 void setLowerBounds(const Eigen::VectorXd& _lb);
95
97 const Eigen::VectorXd& getLowerBounds() const;
98
100 void setUpperBounds(const Eigen::VectorXd& _ub);
101
103 const Eigen::VectorXd& getUpperBounds() const;
104
106 void setObjective(FunctionPtr _obj);
107
110
112 void addEqConstraint(FunctionPtr _eqConst);
113
116 void addIneqConstraint(FunctionPtr _ineqConst);
117
119 std::size_t getNumEqConstraints() const;
120
122 std::size_t getNumIneqConstraints() const;
123
125 FunctionPtr getEqConstraint(std::size_t _idx) const;
126
128 FunctionPtr getIneqConstraint(std::size_t _idx) const;
129
131 void removeEqConstraint(FunctionPtr _eqConst);
132
134 void removeIneqConstraint(FunctionPtr _ineqConst);
135
138
141
142 //------------------------------ Result --------------------------------------
145 void setOptimumValue(double _val);
146
148 double getOptimumValue() const;
149
151 void setOptimalSolution(const Eigen::VectorXd& _optParam);
152
154 const Eigen::VectorXd& getOptimalSolution();
155
156protected:
158 std::size_t mDimension;
159
161 Eigen::VectorXd mInitialGuess;
162
164 std::vector<Eigen::VectorXd> mSeeds;
165
167 Eigen::VectorXd mLowerBounds;
168
170 Eigen::VectorXd mUpperBounds;
171
174
176 std::vector<FunctionPtr> mEqConstraints;
177
179 std::vector<FunctionPtr> mIneqConstraints;
180
183
185 Eigen::VectorXd mOptimalSolution;
186};
187
188} // namespace optimizer
189} // namespace dart
190
191#endif // #ifndef DART_OPTIMIZER_PROBLEM_HPP_
192
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:161
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:297
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:271
double mOptimumValue
Optimal objective value.
Definition Problem.hpp:182
double getOptimumValue() const
Get optimum value of the objective function.
Definition Problem.cpp:291
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:158
Eigen::VectorXd mOptimalSolution
Optimal solution.
Definition Problem.hpp:185
void setDimension(std::size_t _dim)
Set dimension.
Definition Problem.cpp:65
std::vector< FunctionPtr > mEqConstraints
Equality constraint functions.
Definition Problem.hpp:176
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:167
std::size_t getDimension() const
Get dimension.
Definition Problem.cpp:85
std::vector< Eigen::VectorXd > mSeeds
Additional guess hints for the Solver.
Definition Problem.hpp:164
Eigen::VectorXd mUpperBounds
Upper bounds for optimization parameters.
Definition Problem.hpp:170
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:278
const Eigen::VectorXd & getOptimalSolution()
Get optimal solution.
Definition Problem.cpp:305
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:91
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:261
std::vector< FunctionPtr > mIneqConstraints
Inequality constraint functions.
Definition Problem.hpp:179
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:285
FunctionPtr mObjective
Objective function.
Definition Problem.hpp:173
std::shared_ptr< Function > FunctionPtr
Definition Function.hpp:84
Definition BulletCollisionDetector.cpp:63