10 #include <boost/property_tree/info_parser.hpp> 36 {
SIMPLE,
"Simple Backtracking with cost/merit"}, {
ARMIJO,
"ARMIJO-style Backtracking for single-shooting"},
37 {
GOLDSTEIN,
"GOLDSTEIN backtracking using Riccati matrices"}};
72 std::cout <<
"Line Search Settings: " << std::endl;
73 std::cout <<
"=====================" << std::endl;
74 std::cout <<
"type:\t" << lineSearchTypeToString.at(type) << std::endl;
75 std::cout <<
"adaptive:\t" << adaptive << std::endl;
76 std::cout <<
"maxIter:\t" << maxIterations << std::endl;
77 std::cout <<
"alpha_0:\t" << alpha_0 << std::endl;
78 std::cout <<
"alpha_max:\t" << alpha_max << std::endl;
79 std::cout <<
"n_alpha:\t" <<
n_alpha << std::endl;
80 std::cout <<
"armijo_parameter:\t" << armijo_parameter << std::endl;
81 std::cout <<
"debugPrint:\t" << debugPrint << std::endl;
82 std::cout <<
" =======" << std::endl;
83 std::cout << std::endl;
87 void load(
const std::string& filename,
bool verbose =
true,
const std::string& ns =
"line_search")
90 std::cout <<
"Trying to load line search settings from " << filename <<
": " << std::endl;
92 boost::property_tree::ptree pt;
93 boost::property_tree::read_info(filename, pt);
95 std::string ls_type = pt.get<std::string>(ns +
".type");
96 if (stringToLineSearchType.find(ls_type) != stringToLineSearchType.end())
98 type = stringToLineSearchType[ls_type];
102 std::cout <<
"Invalid line search type specified in config, should be one of the following:" << std::endl;
104 for (
auto it = stringToLineSearchType.begin(); it != stringToLineSearchType.end(); it++)
106 std::cout << it->first << std::endl;
113 maxIterations = pt.get<
size_t>(ns +
".maxIterations");
114 alpha_0 = pt.get<
double>(ns +
".alpha_0");
115 n_alpha = pt.get<
double>(ns +
".n_alpha");
116 debugPrint = pt.get<
bool>(ns +
".debugPrint");
122 armijo_parameter = pt.get<
double>(ns +
".armijo_parameter");
129 adaptive = pt.get<
bool>(ns +
".adaptive");
136 alpha_max = pt.get<
double>(ns +
".alpha_max");
143 std::cout <<
"Loaded line search settings from " << filename <<
": " << std::endl;
164 std::cout <<
"======================= LQOCSolverSettings =====================" << std::endl;
165 std::cout <<
"num_lqoc_iterations: \t" << num_lqoc_iterations << std::endl;
166 std::cout <<
"lqoc_debug_print: \t" << lqoc_debug_print << std::endl;
169 void load(
const std::string& filename,
bool verbose =
true,
const std::string& ns =
"lqoc_solver_settings")
172 std::cout <<
"Trying to load LQOCSolverSettings config from " << filename <<
": " << std::endl;
174 boost::property_tree::ptree pt;
175 boost::property_tree::read_info(filename, pt);
179 num_lqoc_iterations = pt.get<
int>(ns +
".num_lqoc_iterations");
185 lqoc_debug_print = pt.get<
bool>(ns +
".lqoc_debug_print");
217 GNRICCATI_SOLVER = 0,
230 timeVaryingDiscretization(false),
231 nlocp_algorithm(GNMS),
232 lqocp_solver(GNRICCATI_SOLVER),
233 loggingPrefix(
"alg"),
238 min_cost_improvement(1e-5),
240 meritFunctionRho(0.0),
241 meritFunctionRhoConstraints(1.0),
243 fixedHessianCorrection(false),
244 recordSmallestEigenvalue(false),
247 lineSearchSettings(),
250 useSensitivityIntegrator(false),
292 if (timeHorizon < 0.0)
294 throw std::runtime_error(
"time Horizon is negative");
296 return std::max(1, (
int)std::lround(timeHorizon / dt));
306 bool isSingleShooting()
const {
return nlocAlgorithmToSingleShooting.at(nlocp_algorithm); }
311 std::cout <<
"======================= NLOptCon Settings =====================" << std::endl;
312 std::cout <<
"===============================================================" << std::endl;
313 std::cout <<
"integrator: " << integratorToString.at(integrator) << std::endl;
314 std::cout <<
"discretization: " << discretizationToString.at(discretization) << std::endl;
315 std::cout <<
"time varying discretization: " << timeVaryingDiscretization << std::endl;
316 std::cout <<
"nonlinear OCP algorithm: " << nlocAlgorithmToString.at(nlocp_algorithm) << std::endl;
317 std::cout <<
"linear-quadratic OCP solver: " << lqocSolverToString.at(lqocp_solver) << std::endl;
318 std::cout <<
"dt:\t" << dt << std::endl;
319 std::cout <<
"K_sim:\t" << K_sim << std::endl;
320 std::cout <<
"K_shot:\t" << K_shot << std::endl;
321 std::cout <<
"maxIter:\t" << max_iterations << std::endl;
322 std::cout <<
"min cost improvement:\t" << min_cost_improvement << std::endl;
323 std::cout <<
"max defect sum:\t" << maxDefectSum << std::endl;
324 std::cout <<
"merit function rho defects:\t" << meritFunctionRho << std::endl;
325 std::cout <<
"merit function rho constraints:\t" << meritFunctionRhoConstraints << std::endl;
326 std::cout <<
"fixedHessianCorrection:\t" << fixedHessianCorrection << std::endl;
327 std::cout <<
"recordSmallestEigenvalue:\t" << recordSmallestEigenvalue << std::endl;
328 std::cout <<
"epsilon:\t" << epsilon << std::endl;
329 std::cout <<
"nThreads:\t" << nThreads << std::endl;
330 std::cout <<
"nThreadsEigen:\t" << nThreadsEigen << std::endl;
331 std::cout <<
"loggingPrefix:\t" << loggingPrefix << std::endl;
332 std::cout <<
"debugPrint:\t" << debugPrint << std::endl;
333 std::cout <<
"printSummary:\t" << printSummary << std::endl;
334 std::cout <<
"useSensitivityIntegrator:\t" << useSensitivityIntegrator << std::endl;
335 std::cout <<
"logToMatlab:\t" << logToMatlab << std::endl;
336 std::cout << std::endl;
338 lineSearchSettings.
print();
340 lqoc_solver_settings.
print();
342 std::cout <<
"===============================================================" << std::endl;
353 std::cout <<
"Invalid parameter dt in NLOptConSettings, needs to be > 0. dt currently is " << dt
360 std::cout <<
"Invalid parameter K_sim in NLOptConSettings, needs to be >= 1. K_sim currently is " << K_sim
367 std::cout <<
"Invalid parameter K_shot in NLOptConSettings, needs to be >= 1. K_shot currently is " 368 << K_shot << std::endl;
373 if ((K_shot > 1) && (nlocp_algorithm == ILQR))
375 std::cout <<
"Invalid parameter: for iLQR K_shot needs to be 1. K_shot currently is " << K_shot
380 if (nThreads > 100 || nThreadsEigen > 100)
382 std::cout <<
"Number of threads should not exceed 100." << std::endl;
396 void load(
const std::string& filename,
bool verbose =
true,
const std::string& ns =
"alg")
399 std::cout <<
"Trying to load NLOptCon config from " << filename <<
": " << std::endl;
401 boost::property_tree::ptree pt;
402 boost::property_tree::read_info(filename, pt);
406 epsilon = pt.get<
double>(ns +
".epsilon");
412 timeVaryingDiscretization = pt.get<
bool>(ns +
".timeVaryingDiscretization");
418 min_cost_improvement = pt.get<
double>(ns +
".min_cost_improvement");
424 maxDefectSum = pt.get<
double>(ns +
".maxDefectSum");
430 meritFunctionRho = pt.get<
double>(ns +
".meritFunctionRho");
436 meritFunctionRhoConstraints = pt.get<
double>(ns +
".meritFunctionRhoConstraints");
442 max_iterations = pt.get<
int>(ns +
".max_iterations");
448 nThreads = pt.get<
int>(ns +
".nThreads");
454 loggingPrefix = pt.get<std::string>(ns +
".loggingPrefix");
460 debugPrint = pt.get<
bool>(ns +
".debugPrint");
466 printSummary = pt.get<
bool>(ns +
".printSummary");
472 useSensitivityIntegrator = pt.get<
bool>(ns +
".useSensitivityIntegrator");
478 logToMatlab = pt.get<
bool>(ns +
".logToMatlab");
484 dt = pt.get<
double>(ns +
".dt");
490 K_sim = pt.get<
int>(ns +
".K_sim");
496 K_shot = pt.get<
int>(ns +
".K_shot");
502 nThreadsEigen = pt.get<
size_t>(ns +
".nThreadsEigen");
508 recordSmallestEigenvalue = pt.get<
bool>(ns +
".recordSmallestEigenvalue");
514 fixedHessianCorrection = pt.get<
bool>(ns +
".fixedHessianCorrection");
521 lineSearchSettings.
load(filename,
verbose, ns +
".line_search");
527 lqoc_solver_settings.
load(filename,
verbose, ns +
".lqoc_solver_settings");
535 std::string integratorStr = pt.get<std::string>(ns +
".integrator");
536 if (stringToIntegrator.find(integratorStr) != stringToIntegrator.end())
538 integrator = stringToIntegrator[integratorStr];
542 std::cout <<
"Invalid integrator specified in config, should be one of the following:" << std::endl;
544 for (
auto it = stringToIntegrator.begin(); it != stringToIntegrator.end(); it++)
546 std::cout << it->first << std::endl;
552 std::string discretizationStr = pt.get<std::string>(ns +
".discretization");
553 if (stringToDiscretization.find(discretizationStr) != stringToDiscretization.end())
555 discretization = stringToDiscretization[discretizationStr];
559 std::cout <<
"Invalid discretization specified in config, should be one of the following:" << std::endl;
561 for (
auto it = stringToDiscretization.begin(); it != stringToDiscretization.end(); it++)
563 std::cout << it->first << std::endl;
569 std::string nlocp_algorithmStr = pt.get<std::string>(ns +
".nlocp_algorithm");
570 if (stringToNlocAlgorithm.find(nlocp_algorithmStr) != stringToNlocAlgorithm.end())
572 nlocp_algorithm = stringToNlocAlgorithm[nlocp_algorithmStr];
576 std::cout <<
"Invalid nlocp_algorithm specified in config, should be one of the following:" 579 for (
auto it = stringToNlocAlgorithm.begin(); it != stringToNlocAlgorithm.end(); it++)
581 std::cout << it->first << std::endl;
588 std::string locp_solverStr = pt.get<std::string>(ns +
".locp_solver");
589 if (stringToLqocSolver.find(locp_solverStr) != stringToLqocSolver.end())
591 lqocp_solver = stringToLqocSolver[locp_solverStr];
595 std::cout <<
"Invalid locp_solver specified in config, should be one of the following:" << std::endl;
597 for (
auto it = stringToLqocSolver.begin(); it != stringToLqocSolver.end(); it++)
599 std::cout << it->first << std::endl;
611 std::cout <<
"Loaded NLOptCon config from " << filename <<
": " << std::endl;
626 const std::string& ns =
"alg")
629 settings.
load(filename,
true, ns);
635 std::map<ct::core::IntegrationType, std::string> integratorToString = {{ct::core::IntegrationType::EULER,
"Euler"},
636 {ct::core::IntegrationType::RK4,
"Runge-Kutta 4th Order"},
637 {ct::core::IntegrationType::MODIFIED_MIDPOINT,
"Modified midpoint"},
638 {ct::core::IntegrationType::ODE45,
"ode45"}, {ct::core::IntegrationType::RK5VARIABLE,
"RK5 variable step"},
639 {ct::core::IntegrationType::RK78,
"RK78"}, {ct::core::IntegrationType::BULIRSCHSTOER,
"Bulirsch-Stoer"},
640 {ct::core::IntegrationType::EULERCT,
"Euler (CT)"},
641 {ct::core::IntegrationType::RK4CT,
"Runge-Kutta 4th Order (CT"},
642 {ct::core::IntegrationType::EULER_SYM,
"Symplectic Euler"},
643 {ct::core::IntegrationType::RK_SYM,
"Symplectic Runge Kutta"}};
645 std::map<std::string, ct::core::IntegrationType> stringToIntegrator = {{
"Euler", ct::core::IntegrationType::EULER},
646 {
"RK4", ct::core::IntegrationType::RK4}, {
"MODIFIED_MIDPOINT", ct::core::IntegrationType::MODIFIED_MIDPOINT},
647 {
"ODE45", ct::core::IntegrationType::ODE45}, {
"RK5VARIABLE", ct::core::IntegrationType::RK5VARIABLE},
648 {
"RK78", ct::core::IntegrationType::RK78}, {
"BULIRSCHSTOER", ct::core::IntegrationType::BULIRSCHSTOER},
649 {
"EulerCT", ct::core::IntegrationType::EULERCT}, {
"RK4CT", ct::core::IntegrationType::RK4CT},
650 {
"Euler_Sym", ct::core::IntegrationType::EULER_SYM}, {
"Rk_Sym", ct::core::IntegrationType::RK_SYM}};
654 std::map<APPROXIMATION, std::string> discretizationToString = {{APPROXIMATION::FORWARD_EULER,
"Forward_euler"},
655 {APPROXIMATION::BACKWARD_EULER,
"Backward_euler"}, {APPROXIMATION::SYMPLECTIC_EULER,
"Symplectic_euler"},
656 {APPROXIMATION::TUSTIN,
"Tustin"}, {APPROXIMATION::MATRIX_EXPONENTIAL,
"Matrix_exponential"}};
658 std::map<std::string, APPROXIMATION> stringToDiscretization = {{
"Forward_euler", APPROXIMATION::FORWARD_EULER},
659 {
"Backward_euler", APPROXIMATION::BACKWARD_EULER}, {
"Symplectic_euler", APPROXIMATION::SYMPLECTIC_EULER},
660 {
"Tustin", APPROXIMATION::TUSTIN}, {
"Matrix_exponential", APPROXIMATION::MATRIX_EXPONENTIAL}};
664 std::map<NLOCP_ALGORITHM, std::string> nlocAlgorithmToString = {{GNMS,
"GNMS (Gauss-Newton Multiple Shooting)"},
665 {ILQR,
"ILQR (iterative linear-quadratic optimal control)"}, {MS_ILQR,
"MS_ILQR (multiple-shooting iLQR)"},
666 {SS_OL,
"SS_OL (open-loop Single Shooting)"}, {SS_CL,
"SS_CL (closed-loop Single Shooting)"},
667 {GNMS_M_OL,
"GNMS_M_OL (GNMS(M) with open-loop shooting)"},
668 {GNMS_M_CL,
"GNMS_M_CL (GNMS(M) with closed-loop shooting)"}};
670 std::map<std::string, NLOCP_ALGORITHM> stringToNlocAlgorithm = {{
"GNMS", GNMS}, {
"ILQR", ILQR},
671 {
"MS_ILQR", MS_ILQR}, {
"SS_OL", SS_OL}, {
"SS_CL", SS_CL}, {
"GNMS_M_OL", GNMS_M_OL}, {
"GNMS_M_CL", GNMS_M_CL}};
673 std::map<NLOCP_ALGORITHM, bool> nlocAlgorithmToClosedLoopShooting = {{GNMS,
false}, {ILQR,
true}, {MS_ILQR,
true},
674 {SS_OL,
false}, {SS_CL,
true}, {GNMS_M_OL,
false}, {GNMS_M_CL,
true}};
676 std::map<NLOCP_ALGORITHM, bool> nlocAlgorithmToSingleShooting = {{GNMS,
false}, {ILQR,
true}, {MS_ILQR,
false},
677 {SS_OL,
true}, {SS_CL,
true}, {GNMS_M_OL,
false}, {GNMS_M_CL,
false}};
680 std::map<LQOCP_SOLVER, std::string> lqocSolverToString = {
681 {GNRICCATI_SOLVER,
"GNRICCATI_SOLVER"}, {HPIPM_SOLVER,
"HPIPM_SOLVER"}};
683 std::map<std::string, LQOCP_SOLVER> stringToLqocSolver = {
684 {
"GNRICCATI_SOLVER", GNRICCATI_SOLVER}, {
"HPIPM_SOLVER", HPIPM_SOLVER}};
LineSearchSettings lineSearchSettings
number of threads for eigen parallelization (applies both to MP and ST) Note. in order to activate Ei...
Definition: NLOptConSettings.hpp:275
LQOCP_SOLVER lqocp_solver
which nonlinear optimal control algorithm is to be used
Definition: NLOptConSettings.hpp:259
double maxDefectSum
minimum cost improvement between two interations to assume convergence
Definition: NLOptConSettings.hpp:266
Classical (open-loop) Single Shooting.
Definition: NLOptConSettings.hpp:208
take full-step updates
Definition: NLOptConSettings.hpp:28
bool printSummary
Definition: NLOptConSettings.hpp:278
std::string loggingPrefix
the solver for the linear-quadratic optimal control problem
Definition: NLOptConSettings.hpp:260
size_t nThreadsEigen
number of threads, for MP version
Definition: NLOptConSettings.hpp:274
double armijo_parameter
Definition: NLOptConSettings.hpp:65
double dt
Eigenvalue correction factor for Hessian regularization.
Definition: NLOptConSettings.hpp:262
TYPE type
Definition: NLOptConSettings.hpp:58
bool closedLoopShooting() const
return if this is a closed-loop shooting algorithm (or not)
Definition: NLOptConSettings.hpp:303
int num_lqoc_iterations
Definition: NLOptConSettings.hpp:160
Classical iLQR (1 shooting interval equal to problem horizon)
Definition: NLOptConSettings.hpp:206
double alpha_0
Definition: NLOptConSettings.hpp:61
bool debugPrint
Definition: NLOptConSettings.hpp:66
bool debugPrint
Definition: NLOptConSettings.hpp:277
multiple-shooting iLQR
Definition: NLOptConSettings.hpp:207
Closed-loop single shooting.
Definition: NLOptConSettings.hpp:209
double meritFunctionRhoConstraints
trade off between internal (defect)constraint violation and cost
Definition: NLOptConSettings.hpp:268
double epsilon
the prefix to be stored before the matfile name for logging
Definition: NLOptConSettings.hpp:261
double getSimulationTimestep() const
compute the simulation timestep
Definition: NLOptConSettings.hpp:300
backtracking including riccati matrix measure
Definition: NLOptConSettings.hpp:30
void print() const
print the current line search settings to console
Definition: NLOptConSettings.hpp:70
LineSearchSettings()
default constructor for the NLOptCon line-search settings
Definition: NLOptConSettings.hpp:44
bool isSingleShooting() const
return if this is a single-shooting algorithm (or not)
Definition: NLOptConSettings.hpp:306
std::map< std::string, TYPE > stringToLineSearchType
Definition: NLOptConSettings.hpp:39
NLOCP_ALGORITHM
algorithm types for solving the NLOC problem
Definition: NLOptConSettings.hpp:202
void load(const std::string &filename, bool verbose=true, const std::string &ns="lqoc_solver_settings")
Definition: NLOptConSettings.hpp:169
std::map< TYPE, std::string > lineSearchTypeToString
mappings for line-search types
Definition: NLOptConSettings.hpp:35
double min_cost_improvement
duration of a shot as an integer multiple of dt
Definition: NLOptConSettings.hpp:265
const double dt
Definition: LQOCSolverTiming.cpp:18
NLOCP_ALGORITHM nlocp_algorithm
Definition: NLOptConSettings.hpp:258
LQOCP_SOLVER
the linear optimal control problem solver in the background
Definition: NLOptConSettings.hpp:215
bool useSensitivityIntegrator
Definition: NLOptConSettings.hpp:279
double meritFunctionRho
maximum sum of squared defects (assume covergence if lower than this number)
Definition: NLOptConSettings.hpp:267
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
bool logToMatlab
Definition: NLOptConSettings.hpp:280
ct::core::Time timeHorizon
Definition: ConstrainedNLOCTest.cpp:15
backtracking including riccati matrix measure and defects
Definition: NLOptConSettings.hpp:31
double alpha_max
Definition: NLOptConSettings.hpp:62
LQOCSolverSettings()
Definition: NLOptConSettings.hpp:157
APPROXIMATION discretization
which integrator to use during the NLOptCon forward rollout
Definition: NLOptConSettings.hpp:256
bool fixedHessianCorrection
the maximum admissible number of NLOptCon main iterations
Definition: NLOptConSettings.hpp:270
int K_sim
sampling time for the control input (seconds)
Definition: NLOptConSettings.hpp:263
bool timeVaryingDiscretization
Definition: NLOptConSettings.hpp:257
size_t maxIterations
Definition: NLOptConSettings.hpp:60
void print() const
number of allowed sub-iterations of LQOC solver per NLOC main iteration
Definition: NLOptConSettings.hpp:162
GNMS Line Search Settings.
Definition: NLOptConSettings.hpp:22
bool parametersOk() const
check if the currently set line-search parameters are meaningful
Definition: NLOptConSettings.hpp:57
int computeK(double timeHorizon) const
log to matlab (true/false)
Definition: NLOptConSettings.hpp:290
void load(const std::string &filename, bool verbose=true, const std::string &ns="line_search")
load line search settings from file
Definition: NLOptConSettings.hpp:87
void print() const
print the current NLOptCon settings to console
Definition: NLOptConSettings.hpp:309
GNMS(M) with open-loop shooting.
Definition: NLOptConSettings.hpp:210
static NLOptConSettings fromConfigFile(const std::string &filename, bool verbose=true, const std::string &ns="alg")
load settings from config file and return as settings struct
Definition: NLOptConSettings.hpp:624
simple backtracking using cost or merit function
Definition: NLOptConSettings.hpp:29
bool adaptive
Definition: NLOptConSettings.hpp:59
int max_iterations
trade off between external (general and path) constraint violation and cost
Definition: NLOptConSettings.hpp:269
bool recordSmallestEigenvalue
perform Hessian regularization by incrementing the eigenvalues by epsilon.
Definition: NLOptConSettings.hpp:271
LQOC Solver settings.
Definition: NLOptConSettings.hpp:154
LQOCSolverSettings lqoc_solver_settings
the line search settings
Definition: NLOptConSettings.hpp:276
ct::core::IntegrationType integrator
Definition: NLOptConSettings.hpp:255
const bool verbose
Definition: ConstraintComparison.h:18
int nThreads
save the smallest eigenvalue of the Hessian
Definition: NLOptConSettings.hpp:272
int K_shot
number of sub-integration-steps
Definition: NLOptConSettings.hpp:264
double n_alpha
Definition: NLOptConSettings.hpp:64
bool lqoc_debug_print
Definition: NLOptConSettings.hpp:159
Gauss-Newton Multiple Shooting (shooting interval = control interval)
Definition: NLOptConSettings.hpp:205
bool parametersOk() const
perform a quick check if the given NLOptCon settings fulfil minimum requirements
Definition: NLOptConSettings.hpp:349
TYPE
types of backtracking line-search
Definition: NLOptConSettings.hpp:25
typename core::SensitivityApproximationSettings::APPROXIMATION APPROXIMATION
Definition: NLOptConSettings.hpp:221
Definition: NLOptConSettings.hpp:27
NLOptConSettings()
NLOptCon Settings default constructor.
Definition: NLOptConSettings.hpp:227
void load(const std::string &filename, bool verbose=true, const std::string &ns="alg")
load NLOptCon Settings from file
Definition: NLOptConSettings.hpp:396