10 #include <gtest/gtest.h> 12 #include "../testSystems/LinearOscillator.h" 21 using std::shared_ptr;
28 TEST(LinearSystemsSolverComparison, LinearSystemsSolverComparison)
33 size_t testCounter = 0;
36 Eigen::Vector2d x_final;
49 nloc_settings.
dt = 0.01;
50 nloc_settings.
discretization = NLOptConSettings::APPROXIMATION::FORWARD_EULER;
54 for (
int algClass = 0; algClass < NLOptConSettings::NLOCP_ALGORITHM::NUM_TYPES; algClass++)
59 for (
int toggleLS = 0; toggleLS <= 1; toggleLS++)
64 for (
size_t nThreads = 1; nThreads < 5; nThreads = nThreads + 3)
69 for (
size_t kshot = 1; kshot < 11; kshot = kshot + 9)
71 nloc_settings.
K_shot = kshot;
73 if (kshot > 1 && nloc_settings.
nlocp_algorithm == NLOptConSettings::NLOCP_ALGORITHM::ILQR)
77 for (
size_t sensInt = 0; sensInt <= 1; sensInt++)
82 for (
size_t ksim = 1; ksim <= 5; ksim = ksim + 4)
84 nloc_settings.
K_sim = ksim;
91 for (
size_t integratortype = 0; integratortype <= 1; integratortype++)
93 if (integratortype == 0)
94 nloc_settings.
integrator = ct::core::IntegrationType::EULERCT;
98 nloc_settings.
integrator = ct::core::IntegrationType::RK4CT;
103 shared_ptr<ControlledSystem<state_dim, control_dim>> nonlinearSystem(
105 shared_ptr<LinearSystem<state_dim, control_dim>> analyticLinearSystem(
107 shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> costFunction =
108 tpl::createCostFunctionLinearOscillator<double>(x_final);
112 size_t nSteps = nloc_settings.
computeK(tf);
128 tf, x0[0], nonlinearSystem, costFunction, analyticLinearSystem);
131 nloc_settings.
lqocp_solver = NLOptConSettings::LQOCP_SOLVER::GNRICCATI_SOLVER;
133 solver_gnriccati.
configure(nloc_settings);
141 nloc_settings.
lqocp_solver = NLOptConSettings::LQOCP_SOLVER::HPIPM_SOLVER;
159 ASSERT_NEAR(sumGn.
merits.back(), sumHpipm.
merits.back(), 1e-6);
166 ASSERT_NEAR(sumGn.
merits.front(), sumHpipm.
merits.front(), 1e-6);
178 std::cout <<
"Performed " << testCounter <<
" successful NLOC tests with linear systems" << std::endl;
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
bool printSummary
Definition: NLOptConSettings.hpp:278
double dt
Eigenvalue correction factor for Hessian regularization.
Definition: NLOptConSettings.hpp:262
TYPE type
Definition: NLOptConSettings.hpp:58
const std::shared_ptr< Backend_t > & getBackend()
get a reference to the backend (
Definition: NLOptConSolver-impl.hpp:237
std::vector< SCALAR > merits
Definition: NLOCResults.hpp:37
const size_t state_dim
Definition: ConstraintComparison.h:20
double epsilon
the prefix to be stored before the matfile name for logging
Definition: NLOptConSettings.hpp:261
NLOCAlgorithm_t::Policy_t Policy_t
Definition: NLOptConSolver.hpp:62
void configure(const Settings_t &settings) override
Definition: NLOptConSolver-impl.hpp:62
NLOCP_ALGORITHM
algorithm types for solving the NLOC problem
Definition: NLOptConSettings.hpp:202
std::vector< SCALAR > defect_l2_norms
Definition: NLOCResults.hpp:25
void setInitialGuess(const Policy_t &initialGuess) override
Definition: NLOptConSolver-impl.hpp:118
Definition: NLOCResults.hpp:18
NLOCP_ALGORITHM nlocp_algorithm
Definition: NLOptConSettings.hpp:258
bool useSensitivityIntegrator
Definition: NLOptConSettings.hpp:279
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
TEST(ConstraintComparison, comparisonAnalyticAD)
Definition: ConstraintComparison.h:158
const double kStiffness
Definition: SymplecticTest.h:34
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
std::vector< SCALAR > lx_norms
step update norms
Definition: NLOCResults.hpp:30
virtual bool runIteration() override
Definition: NLOptConSolver-impl.hpp:102
int computeK(double timeHorizon) const
log to matlab (true/false)
Definition: NLOptConSettings.hpp:290
tpl::LinearOscillator< double > LinearOscillator
Definition: LinearOscillator.h:105
std::vector< SCALAR > defect_l1_norms
different overall defect norms
Definition: NLOCResults.hpp:24
bool recordSmallestEigenvalue
perform Hessian regularization by incrementing the eigenvalues by epsilon.
Definition: NLOptConSettings.hpp:271
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
tpl::LinearOscillatorLinear< double > LinearOscillatorLinear
Definition: LinearOscillator.h:106
ct::core::IntegrationType integrator
Definition: NLOptConSettings.hpp:255
std::vector< SCALAR > lu_norms
Definition: NLOCResults.hpp:31
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
Definition: NLOptConSolver.hpp:29
TYPE
types of backtracking line-search
Definition: NLOptConSettings.hpp:25
Definition: OptConProblemBase.h:40
const size_t control_dim
Definition: ConstraintComparison.h:21
Definition: exampleDir.h:9