10 #include "../../testSystems/SpringLoadedMass.h" 13 TEST(LQOCSolverTest, compareHPIPMandRiccati)
18 const double dt = 0.5;
23 std::shared_ptr<LQOCSolver<state_dim, control_dim>> hpipmSolver(
new HPIPMInterface<state_dim, control_dim>);
27 std::vector<std::shared_ptr<LQOCSolver<state_dim, control_dim>>> lqocSolvers;
28 lqocSolvers.push_back(gnRiccatiSolver);
29 lqocSolvers.push_back(hpipmSolver);
30 std::vector<std::string> solverNames = {
"Riccati",
"HPIPM"};
33 std::vector<std::shared_ptr<LQOCProblem<state_dim, control_dim>>> problems;
37 problems.push_back(lqocProblem1);
38 problems.push_back(lqocProblem2);
62 problems[0]->setFromTimeInvariantLinearQuadraticProblem(discreteExampleSystem, *costFunction, b, dt);
63 problems[1]->setFromTimeInvariantLinearQuadraticProblem(discreteExampleSystem, *costFunction, b, dt);
66 lqocSolvers[0]->setProblem(problems[0]);
67 lqocSolvers[1]->setProblem(problems[1]);
70 lqocSolvers[0]->initializeAndAllocate();
71 lqocSolvers[1]->initializeAndAllocate();
74 lqocSolvers[0]->solve();
75 lqocSolvers[1]->solve();
78 lqocSolvers[0]->computeStatesAndControls();
79 lqocSolvers[0]->computeFeedbackMatrices();
80 lqocSolvers[0]->compute_lv();
81 lqocSolvers[1]->computeStatesAndControls();
82 lqocSolvers[1]->computeFeedbackMatrices();
83 lqocSolvers[1]->compute_lv();
86 auto xSol_riccati = lqocSolvers[0]->getSolutionState();
87 auto uSol_riccati = lqocSolvers[0]->getSolutionControl();
90 auto xSol_hpipm = lqocSolvers[1]->getSolutionState();
91 auto uSol_hpipm = lqocSolvers[1]->getSolutionControl();
96 for (
size_t j = 0; j < xSol_riccati.size(); j++)
100 std::cout <<
"x solution from riccati solver:" << std::endl;
101 std::cout << xSol_riccati[j].transpose() << std::endl;
102 std::cout <<
"x solution from hpipm solver:" << std::endl;
103 std::cout << xSol_hpipm[j].transpose() << std::endl;
106 ASSERT_NEAR((xSol_riccati[j] - xSol_hpipm[j]).array().abs().maxCoeff(), 0.0, 1e-6);
109 for (
size_t j = 0; j < uSol_riccati.size(); j++)
113 std::cout <<
"u solution from riccati solver:" << std::endl;
114 std::cout << uSol_riccati[j].transpose() << std::endl;
115 std::cout <<
"u solution from hpipm solver:" << std::endl;
116 std::cout << uSol_hpipm[j].transpose() << std::endl;
119 ASSERT_NEAR((uSol_riccati[j] - uSol_hpipm[j]).array().abs().maxCoeff(), 0.0, 1e-6);
122 for (
size_t j = 0; j < KSol_riccati.size(); j++)
126 std::cout <<
"K solution from riccati solver:" << std::endl;
127 std::cout << KSol_riccati[j] << std::endl << std::endl;
128 std::cout <<
"K solution from hpipm solver:" << std::endl;
129 std::cout << KSol_hpipm[j] << std::endl << std::endl;
132 ASSERT_NEAR((KSol_riccati[j] - KSol_hpipm[j]).array().abs().maxCoeff(), 0.0, 1e-6);
135 for (
size_t j = 0; j < lv_sol_riccati.size(); j++)
139 std::cout <<
"lv solution from riccati solver:" << std::endl;
140 std::cout << lv_sol_riccati[j] << std::endl << std::endl;
141 std::cout <<
"lv solution from hpipm solver:" << std::endl;
142 std::cout << lv_sol_hpipm[j] << std::endl << std::endl;
145 ASSERT_NEAR((lv_sol_riccati[j] - lv_sol_hpipm[j]).array().abs().maxCoeff(), 0.0, 1e-6);
std::shared_ptr< CostFunctionQuadratic< 2, 1 > > createSpringLoadedMassCostFunction(const core::StateVector< 2 > &x_final)
Definition: SpringLoadedMass.h:67
const size_t state_dim
Definition: ConstraintExampleOutput.cpp:17
const double dt
Definition: LQOCSolverTiming.cpp:18
Linear system class for the GNMS unit test.
Definition: SpringLoadedMass.h:35
Defines a Linear-Quadratic Optimal Control Problem, which is optionally constrained.
Definition: LQOCProblem.hpp:57
Definition: GNRiccatiSolver.hpp:22
TEST(LQOCSolverTest, compareHPIPMandRiccati)
Definition: LQOCSolverTest.h:13
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
const bool verbose
Definition: ConstraintComparison.h:18
Definition: exampleDir.h:9
const size_t control_dim
Definition: ConstraintExampleOutput.cpp:18