10 #include <gtest/gtest.h> 12 #include "../testSystems/LinearOscillator.h" 21 using std::shared_ptr;
34 TEST(LinearSystemsTest, NLOCSolverTest)
39 size_t testCounter = 0;
42 Eigen::Vector2d x_final;
55 nloc_settings.
dt = 0.01;
56 nloc_settings.
discretization = NLOptConSettings::APPROXIMATION::FORWARD_EULER;
57 nloc_settings.
lqocp_solver = NLOptConSettings::LQOCP_SOLVER::GNRICCATI_SOLVER;
61 for (
int algClass = 0; algClass < NLOptConSettings::NLOCP_ALGORITHM::NUM_TYPES; algClass++)
66 for (
int toggleLS = 0; toggleLS <= 1; toggleLS++)
71 for (
size_t nThreads = 1; nThreads < 5; nThreads = nThreads + 3)
76 for (
size_t kshot = 1; kshot < 11; kshot = kshot + 9)
78 nloc_settings.
K_shot = kshot;
80 if (kshot > 1 && nloc_settings.
nlocp_algorithm == NLOptConSettings::NLOCP_ALGORITHM::ILQR)
84 for (
size_t sensInt = 0; sensInt <= 1; sensInt++)
89 for (
size_t ksim = 1; ksim <= 5; ksim = ksim + 4)
91 nloc_settings.
K_sim = ksim;
98 for (
size_t integratortype = 0; integratortype <= 1; integratortype++)
100 if (integratortype == 0)
101 nloc_settings.
integrator = ct::core::IntegrationType::EULERCT;
105 nloc_settings.
integrator = ct::core::IntegrationType::RK4CT;
112 shared_ptr<ControlledSystem<state_dim, control_dim>> nonlinearSystem(
114 shared_ptr<LinearSystem<state_dim, control_dim>> analyticLinearSystem(
116 shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> costFunction =
117 tpl::createCostFunctionLinearOscillator<double>(x_final);
121 size_t nSteps = nloc_settings.
computeK(tf);
137 tf, x0[0], nonlinearSystem, costFunction, analyticLinearSystem);
150 ASSERT_GT(summary.
lx_norms.front(), 1e-9);
151 ASSERT_GT(summary.
lu_norms.front(), 1e-9);
154 ASSERT_LT(summary.
lx_norms.back(), 1e-10);
155 ASSERT_LT(summary.
lu_norms.back(), 1e-10);
169 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
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