@@ -53,83 +53,96 @@ struct LagrangianMetricsConstRef {
53
53
};
54
54
55
55
/* *
56
- * The collection of cost, equality constraints, and LagrangianMetrics structure for all possible constraint terms (handled by
57
- * Lagrangian method) in a particular time point.
58
- * cost : The total cost in a particular time point.
59
- * stateEqConstraint : A vector of all active state equality constraints.
60
- * stateInputEqConstraint : A vector of all active state-input equality constraints.
61
- * stateEqLagrangian : An array of state equality constraint terms handled by Lagrangian method.
62
- * stateIneqLagrangian : An array of state inequality constraint terms handled by Lagrangian method.
63
- * stateInputEqLagrangian : An array of state-input equality constraint terms handled by Lagrangian method.
64
- * stateInputIneqLagrangian : An array of state-input inequality constraint terms handled by Lagrangian method.
56
+ * The collection of cost, dynamics violation, constraints, and LagrangianMetrics structure for all possible constraint
57
+ * terms (handled by Lagrangian method) in a point of time.
58
+ * cost : The total cost in a particular time point.
59
+ * dynamicsViolation : The vector of dynamics violation.
60
+ * stateEqConstraint : An array of all state equality constraints.
61
+ * stateInputEqConstraint : An array of all state-input equality constraints.
62
+ * stateIneqConstraint : An array of all state inequality constraints.
63
+ * stateInputIneqConstraint : An array of all state-input inequality constraints.
64
+ * stateEqLagrangian : An array of state equality constraint terms handled by Lagrangian method.
65
+ * stateIneqLagrangian : An array of state inequality constraint terms handled by Lagrangian method.
66
+ * stateInputEqLagrangian : An array of state-input equality constraint terms handled by Lagrangian method.
67
+ * stateInputIneqLagrangian : An array of state-input inequality constraint terms handled by Lagrangian method.
65
68
*/
66
- struct MetricsCollection {
69
+ struct Metrics {
67
70
// Cost
68
71
scalar_t cost;
69
72
73
+ // Dynamics violation
74
+ vector_t dynamicsViolation;
75
+
70
76
// Equality constraints
71
- vector_t stateEqConstraint;
72
- vector_t stateInputEqConstraint;
77
+ vector_array_t stateEqConstraint;
78
+ vector_array_t stateInputEqConstraint;
73
79
74
80
// Inequality constraints
75
- vector_t stateIneqConstraint;
76
- vector_t stateInputIneqConstraint;
81
+ vector_array_t stateIneqConstraint;
82
+ vector_array_t stateInputIneqConstraint;
77
83
78
84
// Lagrangians
79
85
std::vector<LagrangianMetrics> stateEqLagrangian;
80
86
std::vector<LagrangianMetrics> stateIneqLagrangian;
81
87
std::vector<LagrangianMetrics> stateInputEqLagrangian;
82
88
std::vector<LagrangianMetrics> stateInputIneqLagrangian;
83
89
84
- /* * Exchanges the values of MetricsCollection */
85
- void swap (MetricsCollection& other) {
86
- // Cost
87
- std::swap (cost, other.cost );
88
- // Equality constraints
89
- stateEqConstraint.swap (other.stateEqConstraint );
90
- stateInputEqConstraint.swap (other.stateInputEqConstraint );
91
- // Inequality constraints
92
- stateIneqConstraint.swap (other.stateIneqConstraint );
93
- stateInputIneqConstraint.swap (other.stateInputIneqConstraint );
94
- // Lagrangians
95
- stateEqLagrangian.swap (other.stateEqLagrangian );
96
- stateIneqLagrangian.swap (other.stateIneqLagrangian );
97
- stateInputEqLagrangian.swap (other.stateInputEqLagrangian );
98
- stateInputIneqLagrangian.swap (other.stateInputIneqLagrangian );
99
- }
90
+ /* * Exchanges the values of Metrics */
91
+ void swap (Metrics& other);
100
92
101
- /* * Clears the value of the MetricsCollection */
102
- void clear () {
103
- // Cost
104
- cost = 0.0 ;
105
- // Equality constraints
106
- stateEqConstraint = vector_t ();
107
- stateInputEqConstraint = vector_t ();
108
- // Inequality constraints
109
- stateIneqConstraint = vector_t ();
110
- stateInputIneqConstraint = vector_t ();
111
- // Lagrangians
112
- stateEqLagrangian.clear ();
113
- stateIneqLagrangian.clear ();
114
- stateInputEqLagrangian.clear ();
115
- stateInputIneqLagrangian.clear ();
116
- }
93
+ /* * Clears the value of the Metrics */
94
+ void clear ();
95
+
96
+ /* * Returns true if *this is approximately equal to other, within the precision determined by prec. */
97
+ bool isApprox (const Metrics& other, scalar_t prec = 1e-8 ) const ;
117
98
};
118
99
119
- /* * Sums penalties of an array of LagrangianMetrics */
100
+ /* * Sums penalties of an array of LagrangianMetrics. */
120
101
inline scalar_t sumPenalties (const std::vector<LagrangianMetrics>& metricsArray) {
121
102
scalar_t s = 0.0 ;
122
103
std::for_each (metricsArray.begin (), metricsArray.end (), [&s](const LagrangianMetrics& m) { s += m.penalty ; });
123
104
return s;
124
105
}
125
106
126
- /* * Computes the sum of squared norm of constraints of an array of LagrangianMetrics */
107
+ /* * Computes the sum of squared norm of constraints of an array of LagrangianMetrics. */
127
108
inline scalar_t constraintsSquaredNorm (const std::vector<LagrangianMetrics>& metricsArray) {
128
109
scalar_t s = 0.0 ;
129
110
std::for_each (metricsArray.begin (), metricsArray.end (), [&s](const LagrangianMetrics& m) { s += m.constraint .squaredNorm (); });
130
111
return s;
131
112
}
132
113
114
+ /* * Computes the sum of squared norm of a vector of equality constraints violation. */
115
+ inline scalar_t getEqConstraintsSSE (const vector_t & eqConstraint) {
116
+ if (eqConstraint.size () == 0 ) {
117
+ return 0.0 ;
118
+ } else {
119
+ return eqConstraint.squaredNorm ();
120
+ }
121
+ }
122
+
123
+ /* * Computes the sum of squared norm of a vector of inequality constraints violation. */
124
+ inline scalar_t getIneqConstraintsSSE (const vector_t & ineqConstraint) {
125
+ if (ineqConstraint.size () == 0 ) {
126
+ return 0.0 ;
127
+ } else {
128
+ return ineqConstraint.cwiseMin (0.0 ).squaredNorm ();
129
+ }
130
+ }
131
+
132
+ /* * Computes the sum of squared norm of an array of equality constraints violation. */
133
+ inline scalar_t getEqConstraintsSSE (const vector_array_t & eqConstraint) {
134
+ scalar_t s = 0.0 ;
135
+ std::for_each (eqConstraint.begin (), eqConstraint.end (), [&s](const vector_t & v) { s += getEqConstraintsSSE (v); });
136
+ return s;
137
+ }
138
+
139
+ /* * Computes the sum of squared norm of an array of inequality constraints violation. */
140
+ inline scalar_t getIneqConstraintsSSE (const vector_array_t & ineqConstraint) {
141
+ scalar_t s = 0.0 ;
142
+ std::for_each (ineqConstraint.begin (), ineqConstraint.end (), [&s](const vector_t & v) { s += getIneqConstraintsSSE (v); });
143
+ return s;
144
+ }
145
+
133
146
/* *
134
147
* Serializes an array of LagrangianMetrics structures associated to an array of constraint terms.
135
148
*
@@ -138,14 +151,40 @@ inline scalar_t constraintsSquaredNorm(const std::vector<LagrangianMetrics>& met
138
151
*/
139
152
vector_t toVector (const std::vector<LagrangianMetrics>& termsLagrangianMetrics);
140
153
154
+ /* *
155
+ * Serializes an array of constraint terms.
156
+ *
157
+ * @ param [in] constraintArray : An array of constraint terms.
158
+ * @return Serialized vector of the format : (..., constraintArray[i], ...).
159
+ */
160
+ vector_t toVector (const vector_array_t & constraintArray);
161
+
141
162
/* *
142
163
* Gets the size of constraint terms.
143
164
*
165
+ * @ param [in] constraintArray : An array of constraint terms.
166
+ * @return An array of constraint terms size. It has the same size as the input array.
167
+ */
168
+ size_array_t getSizes (const vector_array_t & constraintArray);
169
+
170
+ /* *
171
+ * Gets the size of constraint Lagrangian terms.
172
+ *
144
173
* @ param [in] termsLagrangianMetrics : LagrangianMetrics associated to an array of constraint terms.
145
174
* @return An array of constraint terms size. It has the same size as the input array.
146
175
*/
147
176
size_array_t getSizes (const std::vector<LagrangianMetrics>& termsLagrangianMetrics);
148
177
178
+ /* *
179
+ * Deserializes the vector to an array of constraint terms.
180
+ *
181
+ * @param [in] termsSize : An array of constraint terms size. It as the same size as the output array.
182
+ * @param [in] vec : Serialized array of constraint terms of the format :
183
+ * (..., constraintArray[i], ...)
184
+ * @return An array of constraint terms.
185
+ */
186
+ vector_array_t toConstraintArray (const size_array_t & termsSize, const vector_t & vec);
187
+
149
188
/* *
150
189
* Deserializes the vector to an array of LagrangianMetrics structures based on size of constraint terms.
151
190
*
@@ -171,13 +210,13 @@ namespace LinearInterpolation {
171
210
LagrangianMetrics interpolate (const index_alpha_t & indexAlpha, const std::vector<LagrangianMetricsConstRef>& dataArray);
172
211
173
212
/* *
174
- * Linearly interpolates a trajectory of MetricsCollection .
213
+ * Linearly interpolates a trajectory of Metrics .
175
214
*
176
215
* @param [in] indexAlpha : index and interpolation coefficient (alpha) pair.
177
- * @param [in] dataArray : A trajectory of MetricsCollection .
178
- * @return The interpolated MetricsCollection at indexAlpha.
216
+ * @param [in] dataArray : A trajectory of Metrics .
217
+ * @return The interpolated Metrics at indexAlpha.
179
218
*/
180
- MetricsCollection interpolate (const index_alpha_t & indexAlpha, const std::vector<MetricsCollection >& dataArray);
219
+ Metrics interpolate (const index_alpha_t & indexAlpha, const std::vector<Metrics >& dataArray);
181
220
182
221
} // namespace LinearInterpolation
183
222
} // namespace ocs2
0 commit comments