Skip to content

setInitialTrajectory mutates the problem's initial state instead of validating the warm start #177

@astomodynamics

Description

@astomodynamics

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:

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:

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions