This example shows how to use classical Direct Multiple Shooting with an oscillator system, using IPOPT as NLP solver.
int main(
int argc,
char** argv)
{
const size_t state_dim = SecondOrderSystem::STATE_DIM;
const size_t control_dim = SecondOrderSystem::CONTROL_DIM;
x_0 << 0.0, 0.0;
x_final << 2.0, -1.0;
std::shared_ptr<ct::optcon::TermQuadratic<state_dim, control_dim>> intermediateCost(
intermediateCost->loadConfigFile(ct::optcon::exampleDir + "/dmsCost.info", "intermediateCost", true);
std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> costFunction(
costFunction->addIntermediateTerm(intermediateCost);
std::shared_ptr<ct::optcon::ConstraintContainerAnalytical<state_dim, control_dim>> finalConstraints(
std::shared_ptr<TerminalConstraint<state_dim, control_dim>> terminalConstraint(
terminalConstraint->setName("TerminalConstraint");
finalConstraints->addTerminalConstraint(terminalConstraint, true);
finalConstraints->initialize();
for (
size_t i = 0;
i < settings.
N_ + 1; ++
i)
{
x_initguess[
i] = x_0 + (x_final - x_0) * (
i / settings.
N_);
}
std::shared_ptr<DmsSolver<state_dim, control_dim>> dmsSolver(
dmsSolver->setInitialGuess(initialPolicy);
dmsSolver->solve();
}