-
Notifications
You must be signed in to change notification settings - Fork 10
/
LSSOLSolver.h
121 lines (104 loc) · 3.91 KB
/
LSSOLSolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//This file is part of ModelPreviewController.
//ModelPreviewController is free software: you can redistribute it and/or modify
//it under the terms of the GNU Lesser General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//ModelPreviewController is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public License
//along with ModelPreviewController. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include "SolverInterface.h"
#include <Eigen/Core>
#include <eigen-lssol/LSSOL.h>
#include <memory>
namespace mpc
{
/**
* LSSOLSolver solver for both dense matrix.
*/
class LSSOLSolver : public SolverInterface // TODO: Enable sparse matrix
{
public:
/**
* LSSOLSolver default constructor
*/
LSSOLSolver();
/**
* Get information of eventual fail's solver output as define by the
* solver documentation.
* @return 0 The optimality conditions are satisfied.
* @return 1 The algorithm has been stopped after too many iterations.
* @return 2 Termination accuracy insufficient to satisfy convergence
* criterion.
* @return 3 Internal inconsistency of QL, division by zero.
* @return 4 Numerical instability prevents successful termination.
* @return 5 Length of a working array is too short.
* @return >100 Constraints are inconsistent and fail=100+ICON, where ICON
* denotes a constraint causing the conflict.
*/
int SI_fail() const override;
/**
* Print an information on the current solver status.
*/
void SI_inform() const override;
/**
* Get the number of needed iteration if available
* @return The number of iteration
*/
int SI_iter() const override;
/**
* Select the print level of the solver if available
* @param pl The print level.
* @param pl =0 : Nothing is printed
* @param pl =1 : The final solution is printed
* @param pl =5 : One line of output for each iteration
* @param pl =10 : One line of output for each iteration and the final solution is printed
* @param pl >20 : At each iteration, the Lagrangian multipliers, the variables x,
* the constraints values Cx and the constraints status.
* @param pl >30 : For an understanding of this, see the official documentation.
*/
void SI_printLevel(int pl) const override;
/**
* Set the maximum error tolerance of the solution if available
* @param tol The error tolerance
*/
void SI_tol(double tol) const override;
/**
* Get the warm start status of the solver if available
* @return True for warm start, False for cold start
*/
bool SI_warmStart() const override;
/**
* Set the warm start status of the solver if available
* @param w True for warm start, False for cold start
*/
void SI_warmStart(bool w) override;
/**
* Get the solver's solution.
* @return The qp solver result.
*/
const Eigen::VectorXd &SI_result() const override;
/**
* Initialize the variables of the problem to solve.
* @see SolverInterface::SI_problem()
* @return The qp solver result.
*/
void SI_problem(int nrVar, int nrEq, int nrInEq) override;
/**
* Solve the problem.
* @see SolverInterface::SI_solve()
* @return The qp solver result.
*/
bool SI_solve(const Eigen::MatrixXd &Q, const Eigen::VectorXd &C,
const Eigen::MatrixXd &Aeq, const Eigen::VectorXd &Beq,
const Eigen::MatrixXd &Aineq, const Eigen::VectorXd &Bineq,
const Eigen::VectorXd &XL, const Eigen::VectorXd &XU) override;
private:
std::unique_ptr<Eigen::StdLSSOL> solver_;
};
} // namespace pc