Skip to content

Commit cc8268b

Browse files
IPDDP development (infeasible) (#81)
* Add control constraint class for IPDDP * Refactor IPDDP forward pass and update filter point structure for log cost handling * Infeasible IPDDP without regularization now completed
1 parent 4855c7a commit cc8268b

File tree

7 files changed

+883
-736
lines changed

7 files changed

+883
-736
lines changed

include/cddp-cpp/cddp_core/cddp_core.hpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ struct CDDPOptions {
4444

4545
// Line search method
4646
int max_line_search_iterations = 11; // Maximum iterations for line search
47-
double backtracking_coeff = 1.0; // Maximum step size for line search backtracking
48-
double backtracking_min = 0.5; // Coefficient for line search backtracking
49-
double backtracking_factor = std::pow(10, (-3.0/10.0)); // Factor for line search backtracking
47+
double backtracking_coeff = 1.0; // Coefficient for line search backtracking
48+
double backtracking_min = 1e-7; // Minimum step size for line search
49+
double backtracking_factor = 0.5; // Factor for line search backtracking
5050
double minimum_reduction_ratio = 1e-6; // Minimum reduction for line search
5151

5252
// interior-point method
@@ -121,6 +121,7 @@ struct ForwardPassResult {
121121
std::vector<Eigen::VectorXd> control_sequence;
122122
std::map<std::string, std::vector<Eigen::VectorXd>> dual_sequence;
123123
std::map<std::string, std::vector<Eigen::VectorXd>> slack_sequence;
124+
std::map<std::string, std::vector<Eigen::VectorXd>> constraint_sequence;
124125
double cost;
125126
double lagrangian;
126127
double alpha = 1.0;
@@ -129,10 +130,17 @@ struct ForwardPassResult {
129130
};
130131

131132
struct FilterPoint {
132-
double cost;
133+
double log_cost;
133134
double violation;
135+
136+
// Default constructor
137+
FilterPoint() : log_cost(0.0), violation(0.0) {}
138+
139+
// Constructor with parameters
140+
FilterPoint(double lc, double v) : log_cost(lc), violation(v) {}
141+
134142
bool dominates(const FilterPoint& other) const {
135-
return cost <= other.cost && violation <= other.violation;
143+
return log_cost <= other.log_cost && violation <= other.violation;
136144
}
137145
};
138146

@@ -304,6 +312,9 @@ class CDDP {
304312
CDDPSolution solveFeasibleIPDDP();
305313
ForwardPassResult solveFeasibleIPDDPForwardPass(double alpha);
306314
bool solveFeasibleIPDDPBackwardPass();
315+
void resetIPDDPFilter();
316+
void initialIPDDPRollout();
317+
void resetIPDDPRegularization();
307318

308319
// Helper methods
309320
double computeConstraintViolation(const std::vector<Eigen::VectorXd>& X, const std::vector<Eigen::VectorXd>& U) const;
@@ -343,6 +354,7 @@ class CDDP {
343354
// Intermediate trajectories
344355
std::vector<Eigen::VectorXd> X_; // State trajectory
345356
std::vector<Eigen::VectorXd> U_; // Control trajectory
357+
std::map<std::string, std::vector<Eigen::VectorXd>> G_; // Constraint trajectory
346358
std::map<std::string, std::vector<Eigen::VectorXd>> Y_; // Dual trajectory
347359
std::map<std::string, std::vector<Eigen::VectorXd>> S_; // Slack trajectory
348360

@@ -359,6 +371,8 @@ class CDDP {
359371

360372
// Log-barrier
361373
double mu_; // Barrier coefficient
374+
std::vector<FilterPoint> filter_; // [logcost, error measure
375+
int ipddp_regularization_counter_ = 0; // Regularization counter for IPDDP
362376
double constraint_violation_; // Current constraint violation measure
363377
double gamma_; // Small value for filter acceptance
364378

include/cddp-cpp/cddp_core/constraint.hpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,71 @@ class LinearConstraint : public Constraint {
257257
double scale_factor_;
258258
};
259259

260+
class ControlConstraint : public Constraint {
261+
public:
262+
ControlConstraint(const Eigen::VectorXd& upper_bound,
263+
double scale_factor = 1.0)
264+
: Constraint("ControlConstraint"),
265+
scale_factor_(scale_factor) {
266+
// Rescale the upper bound for this constraint class
267+
upper_bound_.resize(2*upper_bound.size());
268+
upper_bound_.head(upper_bound.size()) = upper_bound * scale_factor_;
269+
upper_bound_.tail(upper_bound.size()) = upper_bound * scale_factor_;
270+
dim_ = 2*upper_bound.size();
271+
}
272+
273+
int getDualDim() const override {
274+
return dim_;
275+
}
276+
277+
Eigen::VectorXd evaluate(const Eigen::VectorXd& /**/,
278+
const Eigen::VectorXd& control) const override
279+
{
280+
// return [-control; control];
281+
Eigen::VectorXd g(2*control.size());
282+
g.head(control.size()) = -control;
283+
g.tail(control.size()) = control;
284+
return g * scale_factor_;
285+
}
286+
287+
Eigen::VectorXd getLowerBound() const override {
288+
return Eigen::VectorXd::Constant(upper_bound_.size(), -std::numeric_limits<double>::infinity());
289+
}
290+
291+
Eigen::VectorXd getUpperBound() const override {
292+
return upper_bound_;
293+
}
294+
295+
Eigen::MatrixXd getStateJacobian(const Eigen::VectorXd& state,
296+
const Eigen::VectorXd& control) const override
297+
{
298+
return Eigen::MatrixXd::Zero(dim_, state.size());
299+
}
300+
301+
Eigen::MatrixXd getControlJacobian(const Eigen::VectorXd& state,
302+
const Eigen::VectorXd& control) const override
303+
{
304+
Eigen::MatrixXd jac(2*control.size(), control.size());
305+
jac.topLeftCorner(control.size(), control.size()) = -Eigen::MatrixXd::Identity(control.size(), control.size());
306+
jac.bottomRightCorner(control.size(), control.size()) = Eigen::MatrixXd::Identity(control.size(), control.size());
307+
return jac;
308+
}
309+
310+
double computeViolation(const Eigen::VectorXd& state,
311+
const Eigen::VectorXd& control) const override
312+
{
313+
Eigen::VectorXd g = evaluate(state, control) - upper_bound_;
314+
return computeViolationFromValue(g);
315+
}
316+
317+
double computeViolationFromValue(const Eigen::VectorXd& g) const override {
318+
return (g - upper_bound_).cwiseMax(0.0).sum();
319+
}
320+
private:
321+
int dim_;
322+
Eigen::VectorXd upper_bound_;
323+
double scale_factor_;
324+
};
260325

261326
class BallConstraint : public Constraint {
262327
public:
2.29 KB
Loading

src/cddp_core/asddp_core.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@ bool CDDP::solveASCDDPBackwardPass()
498498
optimality_gap_ = Qu_error;
499499
}
500500

501+
if (options_.debug) {
502+
std::cout << "Qu_error: " << Qu_error << std::endl;
503+
std::cout << "dV: " << dV_.transpose() << std::endl;
504+
}
505+
501506
return true;
502507
}
503508

0 commit comments

Comments
 (0)