-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathStaticOptimization.h
More file actions
224 lines (203 loc) · 8.03 KB
/
StaticOptimization.h
File metadata and controls
224 lines (203 loc) · 8.03 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#ifndef BIORBD_MUSCLES_STATIC_OPTIMIZATION_H
#define BIORBD_MUSCLES_STATIC_OPTIMIZATION_H
#include "biorbdConfig.h"
#include <IpTNLP.hpp>
#include <memory>
#include <vector>
namespace BIORBD_NAMESPACE {
class Model;
namespace utils {
class Vector;
}
namespace rigidbody {
class GeneralizedCoordinates;
class GeneralizedVelocity;
class GeneralizedTorque;
} // namespace rigidbody
namespace internal_forces {
namespace muscles {
class StateDynamics;
///
/// \brief Base class for a Static Optimization algorithm
///
class BIORBD_API StaticOptimization {
public:
///
/// \brief Construct static optimization
/// \param model The musculoskeletal Model
/// \param Q The generalized coordinates
/// \param Qdot The generalized velocities
/// \param torqueTarget The generalized torque target to match during the
/// optimization
/// \param initialActivationGuess The initial activation guess
/// \param pNormFactor The p-norm to perform
/// \param useResidualTorque If use residual torque, if set to false, the
/// optimization will fail if the model is not strong enough
/// \param verbose Level of IPOPT verbose you want
///
StaticOptimization(
Model& model,
const rigidbody::GeneralizedCoordinates& Q,
const rigidbody::GeneralizedVelocity& Qdot,
const rigidbody::GeneralizedTorque& torqueTarget,
double initialActivationGuess = 0.01,
unsigned int pNormFactor = 2,
bool useResidualTorque = true,
int verbose = 0);
///
/// \brief Construct static optimization
/// \param model The musculoskeletal Model
/// \param Q The generalized coordinates
/// \param Qdot The generalized velocities
/// \param torqueTarget The generalized torque target to match during the
/// optimization
/// \param initialActivationGuess The initial activation guess
/// \param pNormFactor The p-norm to perform
/// \param useResidualTorque If use residual torque, if set to false, the
/// optimization will fail if the model is not strong enough
/// \param verbose Level of IPOPT verbose you want
///
StaticOptimization(
Model& model,
const rigidbody::GeneralizedCoordinates& Q,
const rigidbody::GeneralizedVelocity& Qdot,
const rigidbody::GeneralizedTorque& torqueTarget,
const utils::Vector& initialActivationGuess,
unsigned int pNormFactor = 2,
bool useResidualTorque = true,
int verbose = 0);
///
/// \brief Construct static optimization
/// \param model The musculoskeletal Model
/// \param Q The generalized coordinates
/// \param Qdot The generalized velocities
/// \param torqueTarget The generalized torque target to match during the
/// optimization
/// \param initialActivationGuess The initial activation guess
/// \param pNormFactor The p-norm to perform
/// \param useResidualTorque If use residual torque, if set to false, the
/// optimization will fail if the model is not strong enough
/// \param verbose Level of IPOPT verbose you want
///
StaticOptimization(
Model& model,
const rigidbody::GeneralizedCoordinates& Q,
const rigidbody::GeneralizedVelocity& Qdot,
const rigidbody::GeneralizedTorque& torqueTarget,
const std::vector<StateDynamics>& initialActivationGuess,
unsigned int pNormFactor = 2,
bool useResidualTorque = true,
int verbose = 0);
///
/// \brief Construct static optimization for multiple frames
/// \param model The musculoskeletal Model
/// \param allQ The generalized coordinates
/// \param allQdot The generalized velocities
/// \param allTorqueTarget The generalized torque target to match during the
/// optimization
/// \param initialActivationGuess The initial activation guess
/// \param pNormFactor The p-norm to perform
/// \param useResidualTorque If use residual torque, if set to false, the
/// optimization will fail if the model is not strong enough
/// \param verbose Level of IPOPT verbose you want
///
StaticOptimization(
Model& model,
const std::vector<rigidbody::GeneralizedCoordinates>& allQ,
const std::vector<rigidbody::GeneralizedVelocity>& allQdot,
const std::vector<rigidbody::GeneralizedTorque>& allTorqueTarget,
double initialActivationGuess = 0.01,
unsigned int pNormFactor = 2,
bool useResidualTorque = true,
int verbose = 0);
///
/// \brief Construct static optimization for multiple frames
/// \param model The musculoskeletal Model
/// \param allQ The generalized coordinates
/// \param allQdot The generalized velocities
/// \param allTorqueTarget The generalized torque target to match during the
/// optimization
/// \param initialActivationGuess The initial activation guess
/// \param pNormFactor The p-norm to perform
/// \param useResidualTorque If use residual torque, if set to false, the
/// optimization will fail if the model is not strong enough
/// \param verbose Level of IPOPT verbose you want
///
StaticOptimization(
Model& model,
const std::vector<rigidbody::GeneralizedCoordinates>& allQ,
const std::vector<rigidbody::GeneralizedVelocity>& allQdot,
const std::vector<rigidbody::GeneralizedTorque>& allTorqueTarget,
const utils::Vector& initialActivationGuess,
unsigned int pNormFactor = 2,
bool useResidualTorque = true,
int verbose = 0);
///
/// \brief Construct static optimization for multiple frames
/// \param model The musculoskeletal Model
/// \param allQ The generalized coordinates
/// \param allQdot The generalized velocities
/// \param allTorqueTarget The generalized torque target to match during the
/// optimization
/// \param initialActivationGuess The initial activation guess
/// \param pNormFactor The p-norm to perform
/// \param useResidualTorque If use residual torque, if set to false, the
/// optimization will fail if the model is not strong enough
/// \param verbose Level of IPOPT verbose you want
///
StaticOptimization(
Model& model,
const std::vector<rigidbody::GeneralizedCoordinates>& allQ,
const std::vector<rigidbody::GeneralizedVelocity>& allQdot,
const std::vector<rigidbody::GeneralizedTorque>& allTorqueTarget,
const std::vector<StateDynamics>& initialActivationGuess,
unsigned int pNormFactor = 2,
bool useResidualTorque = true,
int verbose = 0);
///
/// \brief Run the static optimization
/// \param useLinearizedState If use the algorithm should be run with the
/// linearized approach (faster but less precise)
///
void run(bool useLinearizedState = true);
///
/// \brief Return the final solution
/// \return The final solution
///
std::vector<utils::Vector> finalSolution();
///
/// \brief Return the final solution at a specific index
/// \return The final solution at a specific index
///
utils::Vector finalSolution(unsigned int index);
///
/// \brief Return the final residuals
/// \return The final residuals
///
std::vector<utils::Vector> finalResidual();
///
/// \brief Return the final residuals at a specific index
/// \return The final residuals at a specific index
///
utils::Vector finalResidual(unsigned int index);
protected:
Model& m_model; ///< A reference to the model
bool m_useResidualTorque; ///< To use residual torque
std::vector<rigidbody::GeneralizedCoordinates>
m_allQ; ///< All the generalized coordinates
std::vector<rigidbody::GeneralizedVelocity>
m_allQdot; ///< All the generalized velocities
std::vector<rigidbody::GeneralizedTorque>
m_allTorqueTarget; ///< All the torque targets
std::shared_ptr<utils::Vector>
m_initialActivationGuess; ///< Initial activation guess
unsigned int m_pNormFactor; ///< The p-norm factor
int m_verbose; ///< Verbose level
std::vector<Ipopt::SmartPtr<Ipopt::TNLP>>
m_staticOptimProblem; ///< The static optimization problem
bool m_alreadyRun; ///< If already ran the static optimization
};
} // namespace muscles
} // namespace internal_forces
} // namespace BIORBD_NAMESPACE
#endif // BIORBD_MUSCLES_STATIC_OPTIMIZATION_H