Summary
CDDP::setInitialTrajectory() silently overwrites initial_state_ with X[0] from the provided trajectory.
Why this is a bug
A warm-start trajectory should seed the solver state, not change the optimization problem definition. With the current behavior, passing a mismatched X[0] changes the problem being solved instead of rejecting or repairing the input.
Code paths
src/cddp_core/cddp_core.cpp:126-140
src/cddp_core/cddp_core.cpp:272-305
setInitialTrajectory() assigns:
X_ = X;
U_ = U;
if (!X_.empty()) {
initial_state_ = X_[0];
}
Later, initialization forces:
So a caller-provided warm start can silently replace the original initial condition.
Expected behavior
One of these should happen instead:
- reject trajectories whose first state does not match
initial_state_ within a tolerance, or
- keep
initial_state_ authoritative and only use the rest of the trajectory as a warm start.
Impact
This can make solver results incorrect while looking superficially valid, because the library solves a different problem than the caller configured.
Suggested fix
- Stop mutating
initial_state_ in setInitialTrajectory().
- Add validation for
X[0] against the configured initial state.
- Add a regression test that passes a mismatched
X[0] and verifies the solver either throws or preserves the original initial condition.
Summary
CDDP::setInitialTrajectory()silently overwritesinitial_state_withX[0]from the provided trajectory.Why this is a bug
A warm-start trajectory should seed the solver state, not change the optimization problem definition. With the current behavior, passing a mismatched
X[0]changes the problem being solved instead of rejecting or repairing the input.Code paths
src/cddp_core/cddp_core.cpp:126-140src/cddp_core/cddp_core.cpp:272-305setInitialTrajectory()assigns:Later, initialization forces:
X_[0] = initial_state_;So a caller-provided warm start can silently replace the original initial condition.
Expected behavior
One of these should happen instead:
initial_state_within a tolerance, orinitial_state_authoritative and only use the rest of the trajectory as a warm start.Impact
This can make solver results incorrect while looking superficially valid, because the library solves a different problem than the caller configured.
Suggested fix
initial_state_insetInitialTrajectory().X[0]against the configured initial state.X[0]and verifies the solver either throws or preserves the original initial condition.