GCC Code Coverage Report


Directory: ./
File: include/hpp/centroidal-dynamics/solver_LP_abstract.hh
Date: 2025-03-17 04:04:52
Exec Total Coverage
Lines: 10 12 83.3%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 * Copyright 2015, LAAS-CNRS
3 * Author: Andrea Del Prete
4 */
5
6 #ifndef HPP_CENTROIDAL_DYNAMICS_SOLVER_LP_ABSTRACT_HH
7 #define HPP_CENTROIDAL_DYNAMICS_SOLVER_LP_ABSTRACT_HH
8
9 #include <Eigen/Dense>
10 #include <hpp/centroidal-dynamics/local_config.hh>
11 #include <hpp/centroidal-dynamics/util.hh>
12
13 namespace centroidal_dynamics {
14
15 /**
16 * Available LP solvers.
17 */
18 enum CENTROIDAL_DYNAMICS_DLLAPI SolverLP {
19 SOLVER_LP_QPOASES = 0
20 #ifdef CLP_FOUND
21 ,
22 SOLVER_LP_CLP = 1
23 #endif
24 };
25
26 /**
27 * Possible states of an LP solver.
28 */
29 enum CENTROIDAL_DYNAMICS_DLLAPI LP_status {
30 LP_STATUS_UNKNOWN = -1,
31 LP_STATUS_OPTIMAL = 0,
32 LP_STATUS_INFEASIBLE = 1,
33 LP_STATUS_UNBOUNDED = 2,
34 LP_STATUS_MAX_ITER_REACHED = 3,
35 LP_STATUS_ERROR = 4
36 };
37
38 /**
39 * @brief Abstract interface for a Linear Program (LP) solver.
40 */
41 class CENTROIDAL_DYNAMICS_DLLAPI Solver_LP_abstract {
42 protected:
43 bool m_useWarmStart; // true if the solver is allowed to warm start
44 int m_maxIter; // max number of iterations
45 double m_maxTime; // max time to solve the LP [s]
46
47 public:
48 15 Solver_LP_abstract() {
49 15 m_maxIter = 1000;
50 15 m_maxTime = 100.0;
51 15 m_useWarmStart = true;
52 15 }
53
54 12 virtual ~Solver_LP_abstract() {}
55
56 /**
57 * @brief Create a new LP solver of the specified type.
58 * @param solverType Type of LP solver.
59 * @return A pointer to the new solver.
60 */
61 static Solver_LP_abstract *getNewSolver(SolverLP solverType);
62
63 /** Solve the linear program
64 * minimize c' x
65 * subject to Alb <= A x <= Aub
66 * lb <= x <= ub
67 */
68 virtual LP_status solve(Cref_vectorX c, Cref_vectorX lb, Cref_vectorX ub,
69 Cref_matrixXX A, Cref_vectorX Alb, Cref_vectorX Aub,
70 Ref_vectorX sol) = 0;
71
72 /**
73 * @brief Solve the linear program described in the specified file.
74 * @param filename Name of the file containing the LP description.
75 * @param sol Output solution of the LP.
76 * @return A flag describing the final status of the solver.
77 */
78 virtual LP_status solve(const std::string &filename, Ref_vectorX sol);
79
80 /**
81 * @brief Write the specified Linear Program to binary file.
82 * minimize c' x
83 * subject to Alb <= A x <= Aub
84 * lb <= x <= ub
85 * @param filename
86 * @param c
87 * @param lb
88 * @param ub
89 * @param A
90 * @param Alb
91 * @param Aub
92 * @return True if the operation succeeded, false otherwise.
93 */
94 virtual bool writeLpToFile(const std::string &filename, Cref_vectorX c,
95 Cref_vectorX lb, Cref_vectorX ub, Cref_matrixXX A,
96 Cref_vectorX Alb, Cref_vectorX Aub);
97
98 /**
99 * @brief Read the data describing a Linear Program from the specified binary
100 * file. The vectors and matrices are resized inside the method. minimize c' x
101 * subject to Alb <= A x <= Aub
102 * lb <= x <= ub
103 * @param filename
104 * @param c
105 * @param lb
106 * @param ub
107 * @param A
108 * @param Alb
109 * @param Aub
110 * @return True if the operation succeeded, false otherwise.
111 */
112 virtual bool readLpFromFile(const std::string &filename, VectorX &c,
113 VectorX &lb, VectorX &ub, MatrixXX &A,
114 VectorX &Alb, VectorX &Aub);
115
116 /** Get the status of the solver. */
117 virtual LP_status getStatus() = 0;
118
119 /** Get the objective value of the last solved problem. */
120 virtual double getObjectiveValue() = 0;
121
122 /** Get the value of the dual variables. */
123 virtual void getDualSolution(Ref_vectorX res) = 0;
124
125 /** Return true if the solver is allowed to warm start, false otherwise. */
126 2 virtual bool getUseWarmStart() { return m_useWarmStart; }
127 /** Specify whether the solver is allowed to use warm-start techniques. */
128 14 virtual void setUseWarmStart(bool useWarmStart) {
129 14 m_useWarmStart = useWarmStart;
130 14 }
131
132 /** Get the current maximum number of iterations performed by the solver. */
133 virtual unsigned int getMaximumIterations() { return m_maxIter; }
134 /** Set the current maximum number of iterations performed by the solver. */
135 virtual bool setMaximumIterations(unsigned int maxIter);
136
137 /** Get the maximum time allowed to solve a problem. */
138 virtual double getMaximumTime() { return m_maxTime; }
139 /** Set the maximum time allowed to solve a problem. */
140 virtual bool setMaximumTime(double seconds);
141 };
142
143 } // end namespace centroidal_dynamics
144
145 #endif // HPP_CENTROIDAL_DYNAMICS_SOLVER_LP_ABSTRACT_HH
146