9 #include <gtest/gtest.h> 12 #include "nloc_test_dir.h" 29 using std::shared_ptr;
32 TEST(NLOCTest, NonlinearSystemAlgorithmComparison)
36 std::cout <<
"setting up problem " << std::endl;
38 std::string configFile = std::string(NLOC_TEST_DIR) +
"/nonlinear/solver.info";
39 std::string
costFunctionFile = std::string(NLOC_TEST_DIR) +
"/nonlinear/cost.info";
41 Eigen::Matrix<double, 1, 1> x_0;
44 Eigen::Matrix<double, 1, 1> x_f;
48 gnms_settings.
load(configFile,
true,
"gnms");
51 ilqr_settings.
load(configFile,
true,
"ilqr");
53 std::shared_ptr<ControlledSystem<state_dim, control_dim>> nonlinearSystem(
new Dynamics);
54 std::shared_ptr<LinearSystem<state_dim, control_dim>> analyticLinearSystem(
new LinearizedSystem);
55 std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> costFunction(
62 size_t nSteps = gnms_settings.
computeK(tf);
66 uff_init_guess << -(x_0(0) + 1) * x_0(0);
77 tf, x0[0], nonlinearSystem, costFunction, analyticLinearSystem);
79 tf, x0[0], nonlinearSystem, costFunction, analyticLinearSystem);
82 std::cout <<
"initializing solvers" << std::endl;
83 NLOptConSolver gnms(optConProblem1, gnms_settings);
84 NLOptConSolver ilqr(optConProblem2, ilqr_settings);
94 std::cout <<
"============ running solvers ==============" << std::endl;
109 for (
size_t i = 0;
i < xRollout_gnms.
size();
i++)
111 ASSERT_NEAR(xRollout_gnms[
i](0), xRollout_ilqr[
i](0), 1e-4);
114 for (
size_t i = 0;
i < uRollout_ilqr.
size();
i++)
116 ASSERT_NEAR(uRollout_gnms[
i](0), uRollout_ilqr[
i](0), 1e-4);
virtual const core::StateTrajectory< STATE_DIM, SCALAR > getStateTrajectory() const override
Definition: NLOptConSolver-impl.hpp:152
Dynamics class for the GNMS unit test, slightly nonlinear dynamics.
Definition: DiehlSystem.h:20
void loadMatrix(const std::string &filename, const std::string &matrixName, Eigen::Matrix< SCALAR, ROW, COL > &matrix, const std::string &ns="")
double dt
Eigenvalue correction factor for Hessian regularization.
Definition: NLOptConSettings.hpp:262
virtual const core::ControlTrajectory< CONTROL_DIM, SCALAR > getControlTrajectory() const override
Definition: NLOptConSolver-impl.hpp:160
void loadScalar(const std::string &filename, const std::string &scalarName, SCALAR &scalar, const std::string &ns="")
NLOCAlgorithm_t::Policy_t Policy_t
Definition: NLOptConSolver.hpp:62
std::string costFunctionFile
Definition: LoadFromFileTest.cpp:13
void configure(const Settings_t &settings) override
Definition: NLOptConSolver-impl.hpp:62
A cost function which contains only terms that have analytical derivatives.
Definition: CostFunctionAnalytical.hpp:31
void setInitialGuess(const Policy_t &initialGuess) override
Definition: NLOptConSolver-impl.hpp:118
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
virtual bool solve() override
Definition: NLOptConSolver-impl.hpp:126
TEST(ConstraintComparison, comparisonAnalyticAD)
Definition: ConstraintComparison.h:158
for i
Definition: mpc_unittest_plotting.m:14
int computeK(double timeHorizon) const
log to matlab (true/false)
Definition: NLOptConSettings.hpp:290
Linear system class for the GNMS unit test.
Definition: DiehlSystem.h:37
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
Definition: NLOptConSolver.hpp:29
Definition: OptConProblemBase.h:40
Definition: exampleDir.h:9
void load(const std::string &filename, bool verbose=true, const std::string &ns="alg")
load NLOptCon Settings from file
Definition: NLOptConSettings.hpp:396