@@ -49,9 +49,15 @@ struct CDDPOptions {
49
49
double backtracking_factor = std::pow(10 , (-3.0 /10.0 )); // Factor for line search backtracking
50
50
double minimum_reduction_ratio = 1e-6 ; // Minimum reduction for line search
51
51
52
+ // interior-point method
53
+ double mu_initial = 1e-2 ; // Initial barrier coefficient
54
+ double mu_min = 1e-8 ; // Minimum barrier coefficient
55
+ double mu_max = 1e1 ; // Maximum barrier coefficient
56
+ double mu_reduction_ratio = 0.1 ; // Factor for barrier coefficient
57
+
52
58
// log-barrier method
53
59
double barrier_coeff = 1e-2 ; // Coefficient for log-barrier method
54
- double barrier_factor = 0.90 ; // Factor for log-barrier method
60
+ double barrier_factor = 0.10 ; // Factor for log-barrier method
55
61
double barrier_tolerance = 1e-8 ; // Tolerance for log-barrier method
56
62
double relaxation_coeff = 1.0 ; // Relaxation for log-barrier method
57
63
int barrier_order = 2 ; // Order for log-barrier method
@@ -76,6 +82,7 @@ struct CDDPOptions {
76
82
// Other options
77
83
bool verbose = true ; // Option for debug printing
78
84
bool debug = false ; // Option for debug mode
85
+ bool header_and_footer = true ; // Option for header and footer
79
86
bool is_ilqr = true ; // Option for iLQR
80
87
bool use_parallel = true ; // Option for parallel computation
81
88
int num_threads = max_line_search_iterations; // Number of threads to use
@@ -96,9 +103,13 @@ struct CDDPSolution {
96
103
std::vector<double > time_sequence;
97
104
std::vector<Eigen::VectorXd> control_sequence;
98
105
std::vector<Eigen::VectorXd> state_sequence;
106
+ std::vector<Eigen::VectorXd> dual_sequence;
107
+ std::vector<Eigen::VectorXd> slack_sequence;
99
108
std::vector<double > cost_sequence;
100
109
std::vector<double > lagrangian_sequence;
101
- std::vector<Eigen::MatrixXd> feedback_gain;
110
+ std::vector<Eigen::MatrixXd> control_gain;
111
+ std::vector<Eigen::MatrixXd> dual_gain;
112
+ std::vector<Eigen::MatrixXd> slack_gain;
102
113
int iterations;
103
114
double alpha;
104
115
bool converged;
@@ -108,6 +119,8 @@ struct CDDPSolution {
108
119
struct ForwardPassResult {
109
120
std::vector<Eigen::VectorXd> state_sequence;
110
121
std::vector<Eigen::VectorXd> control_sequence;
122
+ std::map<std::string, std::vector<Eigen::VectorXd>> dual_sequence;
123
+ std::map<std::string, std::vector<Eigen::VectorXd>> slack_sequence;
111
124
double cost;
112
125
double lagrangian;
113
126
double alpha = 1.0 ;
@@ -143,6 +156,9 @@ class CDDP {
143
156
const Eigen::VectorXd& getReferenceState () const { return reference_state_; }
144
157
int getHorizon () const { return horizon_; }
145
158
double getTimestep () const { return timestep_; }
159
+ int getStateDim () const { return system_->getStateDim (); }
160
+ int getControlDim () const { return system_->getControlDim (); }
161
+ int getTotalDualDim () const { return total_dual_dim_; }
146
162
const CDDPOptions& getOptions () const { return options_; }
147
163
148
164
// Setters
@@ -212,7 +228,14 @@ class CDDP {
212
228
* @param constraint constraint object
213
229
*/
214
230
void addConstraint (std::string constraint_name, std::unique_ptr<Constraint> constraint) {
231
+ // Insert into the map
215
232
constraint_set_[constraint_name] = std::move (constraint);
233
+
234
+ // Increment total_dual_dim_
235
+ int dim = constraint_set_[constraint_name]->getDualDim ();
236
+ total_dual_dim_ += dim;
237
+
238
+ initialized_ = false ; // Reset the initialization flag
216
239
}
217
240
218
241
/* *
@@ -255,31 +278,49 @@ class CDDP {
255
278
256
279
private:
257
280
// Solver methods
281
+ // CLCDDP methods
258
282
CDDPSolution solveCLCDDP ();
259
283
ForwardPassResult solveCLCDDPForwardPass (double alpha);
260
284
bool solveCLCDDPBackwardPass ();
261
285
286
+ // LogCDDP methods
262
287
CDDPSolution solveLogCDDP ();
263
288
ForwardPassResult solveLogCDDPForwardPass (double alpha);
264
289
bool solveLogCDDPBackwardPass ();
265
290
291
+ // ASCDDP methods
266
292
CDDPSolution solveASCDDP ();
267
293
ForwardPassResult solveASCDDPForwardPass (double alpha);
268
294
bool solveASCDDPBackwardPass ();
295
+
296
+ // IPDDP methods
297
+ void initializeIPDDP ();
298
+ CDDPSolution solveIPDDP ();
299
+ ForwardPassResult solveIPDDPForwardPass (double alpha);
300
+ bool solveIPDDPBackwardPass ();
301
+
302
+ // Feasible IPDDP methods
303
+ void initializeFeasibleIPDDP ();
304
+ CDDPSolution solveFeasibleIPDDP ();
305
+ ForwardPassResult solveFeasibleIPDDPForwardPass (double alpha);
306
+ bool solveFeasibleIPDDPBackwardPass ();
269
307
270
308
// Helper methods
271
309
double computeConstraintViolation (const std::vector<Eigen::VectorXd>& X, const std::vector<Eigen::VectorXd>& U) const ;
272
310
273
311
bool checkConvergence (double J_new, double J_old, double dJ, double expected_dV, double gradient_norm);
274
312
275
- void printSolverInfo ();
313
+ // Regularization methods
314
+ void increaseRegularization ();
315
+ void decreaseRegularization ();
316
+ bool isRegularizationLimitReached () const ;
276
317
318
+ // Print methods
319
+ void printSolverInfo ();
277
320
void printOptions (const CDDPOptions& options);
278
-
279
321
void printIteration (int iter, double cost, double lagrangian,
280
322
double grad_norm, double lambda_state,
281
323
double lambda_control, double alpha, double mu, double constraint_violation);
282
-
283
324
void printSolution (const CDDPSolution& solution);
284
325
285
326
private:
@@ -297,9 +338,13 @@ class CDDP {
297
338
double timestep_; // Time step for the problem
298
339
CDDPOptions options_; // Options for the solver
299
340
341
+ int total_dual_dim_ = 0 ; // Number of total dual variables across constraints
342
+
300
343
// Intermediate trajectories
301
- std::vector<Eigen::VectorXd> X_; // State trajectory
302
- std::vector<Eigen::VectorXd> U_; // Control trajectory
344
+ std::vector<Eigen::VectorXd> X_; // State trajectory
345
+ std::vector<Eigen::VectorXd> U_; // Control trajectory
346
+ std::map<std::string, std::vector<Eigen::VectorXd>> Y_; // Dual trajectory
347
+ std::map<std::string, std::vector<Eigen::VectorXd>> S_; // Slack trajectory
303
348
304
349
// Cost and Lagrangian
305
350
double J_; // Cost
@@ -316,10 +361,14 @@ class CDDP {
316
361
double mu_; // Barrier coefficient
317
362
double constraint_violation_; // Current constraint violation measure
318
363
double gamma_; // Small value for filter acceptance
319
-
364
+
320
365
// Feedforward and feedback gains
321
- std::vector<Eigen::VectorXd> k_;
322
- std::vector<Eigen::MatrixXd> K_;
366
+ std::vector<Eigen::VectorXd> k_u_;
367
+ std::vector<Eigen::MatrixXd> K_u_;
368
+ std::map<std::string, std::vector<Eigen::VectorXd>> k_y_;
369
+ std::map<std::string, std::vector<Eigen::MatrixXd>> K_y_;
370
+ std::map<std::string, std::vector<Eigen::VectorXd>> k_s_;
371
+ std::map<std::string, std::vector<Eigen::MatrixXd>> K_s_;
323
372
324
373
// Q-function matrices
325
374
std::vector<Eigen::MatrixXd> Q_UU_;
0 commit comments