Skip to content

Commit b9743ff

Browse files
committed
Merge pull request #5741 from danston/Solvers-add_osqp-danston
[Small Feature] OSQP Support in Solver Interface
2 parents 249d0f3 + 5e17827 commit b9743ff

30 files changed

+795
-84
lines changed

Documentation/doc/Documentation/Third_party.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,24 +297,27 @@ If you experience such an issue, we recommand to compile \ceres without `glog` s
297297

298298
\glpk (GNU Linear Programming Kit) is a library for solving linear programming (LP), mixed integer programming (MIP), and other related problems.
299299

300-
In \cgal, \glpk provides an optional linear integer program solver
301-
in the \ref PkgPolygonalSurfaceReconstruction package. In order to use
302-
\glpk in \cgal programs, the executables should be linked with the
303-
CMake imported target `CGAL::GLPK_support` provided in
304-
`CGAL_GLPK_support.cmake`.
300+
In \cgal, \glpk provides an optional linear integer program solver in the \ref PkgPolygonalSurfaceReconstruction package.
301+
In order to use \glpk in \cgal programs, the executables should be linked with the CMake imported target `CGAL::GLPK_support` provided in `CGAL_GLPK_support.cmake`.
305302

306303
The \glpk web site is <A HREF="https://www.gnu.org/software/glpk/">`https://www.gnu.org/software/glpk/`</A>.
307304

308305
\subsection thirdpartySCIP SCIP
309306

310307
\scip (Solving Constraint Integer Programs) is currently one of the fastest open source solvers for mixed integer programming (MIP) and mixed integer nonlinear programming (MINLP).
311308

312-
In \cgal, \scip provides an optional linear integer program solver
313-
in the \ref PkgPolygonalSurfaceReconstruction package. In order to use
314-
\scip in \cgal programs, the executables should be linked with the
315-
CMake imported target `CGAL::SCIP_support` provided in
316-
`CGAL_SCIP_support.cmake`.
309+
In \cgal, \scip provides an optional linear integer program solver in the \ref PkgPolygonalSurfaceReconstruction package.
310+
In order to use \scip in \cgal programs, the executables should be linked with the CMake imported target `CGAL::SCIP_support` provided in `CGAL_SCIP_support.cmake`.
317311

318312
The \scip web site is <A HREF="http://scip.zib.de/">`http://scip.zib.de/`</A>.
319313

314+
\subsection thirdpartyOSQP OSQP
315+
316+
\osqp (Operator Splitting Quadratic Program) is currently one of the fastest open source solvers for convex Quadratic Programs (QP).
317+
318+
In \cgal, \osqp provides an optional solver for the QP problems often arising in various computational geometry algorithms.
319+
In order to use \osqp in \cgal programs, the executables should be linked with the CMake imported target `CGAL::OSQP_support` provided in `CGAL_OSQP_support.cmake`.
320+
321+
The \osqp web site is <A HREF="https://osqp.org">`https://osqp.org`</A>.
322+
320323
*/

Documentation/doc/resources/1.8.13/BaseDoxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ ALIASES = "cgal=%CGAL" \
267267
"ceres=Ceres" \
268268
"glpk=GLPK" \
269269
"scip=SCIP" \
270+
"osqp=OSQP" \
270271
"rs=RS" \
271272
"rs3=RS3" \
272273
"unix=Unix" \

Documentation/doc/resources/1.8.14/BaseDoxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ ALIASES = "cgal=%CGAL" \
268268
"ceres=Ceres" \
269269
"glpk=GLPK" \
270270
"scip=SCIP" \
271+
"osqp=OSQP" \
271272
"rs=RS" \
272273
"rs3=RS3" \
273274
"unix=Unix" \

Documentation/doc/resources/1.8.20/BaseDoxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ ALIASES = "cgal=%CGAL" \
290290
"ceres=Ceres" \
291291
"glpk=GLPK" \
292292
"scip=SCIP" \
293+
"osqp=OSQP" \
293294
"rs=RS" \
294295
"rs3=RS3" \
295296
"unix=Unix" \

Documentation/doc/resources/1.8.4/BaseDoxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ ALIASES += "zlib=zlib"
236236
ALIASES += "ceres=Ceres"
237237
ALIASES += "glpk=GLPK"
238238
ALIASES += "scip=SCIP"
239+
ALIASES += "osqp=OSQP"
239240
ALIASES += "rs=RS"
240241
ALIASES += "rs3=RS3"
241242
ALIASES += "unix=Unix"

Installation/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Release date: December 2021
99

1010
- Added the function `CGAL::Polygon_mesh_processing::match_faces()`, which, given two polygon meshes, identifies their common faces as well as as faces present in only either of them.
1111

12+
### [CGAL and Solvers](https://doc.cgal.org/5.4/Manual/packages.html#PkgSolverInterface)
13+
14+
- Added the [OSQP solver](https://osqp.org/) support. This solver enables to efficiently compute the convex Quadratic Programming (QP) problems arising in the context of several packages.
15+
16+
1217
[Release 5.3](https://github.com/CGAL/cgal/releases/tag/v5.3)
1318
-----------
1419

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if(OSQP_FOUND AND NOT TARGET CGAL::OSQP_support)
2+
add_library(CGAL::OSQP_support INTERFACE IMPORTED)
3+
set_target_properties(CGAL::OSQP_support PROPERTIES
4+
INTERFACE_COMPILE_DEFINITIONS "CGAL_USE_OSQP"
5+
INTERFACE_INCLUDE_DIRECTORIES "${OSQP_INCLUDE_DIR}"
6+
INTERFACE_LINK_LIBRARIES "${OSQP_LIBRARIES}")
7+
endif()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file sets up OSQP for CMake. Once done this will define
2+
# OSQP_FOUND - system has OSQP lib
3+
# OSQP_INCLUDE_DIR - the OSQP include directory
4+
# OSQP_LIBRARIES - link these to use OSQP
5+
6+
if(NOT OSQP_FOUND)
7+
find_path(OSQP_INCLUDE_DIR
8+
NAMES osqp.h
9+
PATHS /usr/local/include/osqp/
10+
ENV OSQP_INC_DIR)
11+
12+
find_library(OSQP_LIBRARIES
13+
NAMES libosqp osqp
14+
PATHS ENV LD_LIBRARY_PATH
15+
ENV LIBRARY_PATH
16+
/usr/local/lib
17+
${OSQP_INCLUDE_DIR}/../lib
18+
ENV OSQP_LIB_DIR)
19+
20+
if(OSQP_LIBRARIES AND OSQP_INCLUDE_DIR)
21+
set(OSQP_FOUND TRUE)
22+
endif()
23+
endif()
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*!
2+
\ingroup PkgSolverInterfaceConcepts
3+
\cgalConcept
4+
5+
A concept that describes the set of methods used to define and solve a
6+
linear programming (`lp`) problem of the general form:
7+
<center>
8+
\f{eqnarray*}{
9+
& \mbox{minimize} & \mathbf{q}^{T}\mathbf{x} + r \\
10+
& \mbox{subject to} & \mathbf{l} \leq A\mathbf{x} \leq \mathbf{u}
11+
\f}
12+
</center>
13+
in \f$ n \f$ real variables \f$ \mathbf{x} = (x_0, \ldots, x_{n-1}) \f$ and \f$ m \f$ constraints.
14+
15+
Here,
16+
<UL>
17+
<LI>\f$ \mathbf{q} \f$ is an \f$ n \f$-dimensional vector (the linear objective function),
18+
<LI>\f$ r \f$ is a constant,
19+
<LI>\f$ A \f$ is an \f$ m\times n\f$ matrix (the constraint matrix),
20+
<LI>\f$ \mathbf{l} \f$ is an \f$ m \f$-dimensional vector of lower constraint bounds,
21+
where \f$ l_i \in \mathbb{R} \cup \{-\infty\} \f$ for all \f$ i \f$,
22+
<LI>\f$ \mathbf{u} \f$ is an \f$ m \f$-dimensional vector of upper constraint bounds,
23+
where \f$ u_i \in \mathbb{R} \cup \{+\infty\} \f$ for all \f$ i \f$.
24+
</UL>
25+
*/
26+
class LinearProgramTraits {
27+
28+
public:
29+
30+
/// \name Memory
31+
/// @{
32+
33+
/*!
34+
Allocates memory for `n` variables and `m` constraints in `lp`.
35+
*/
36+
void resize(const std::size_t n, const std::size_t m) { }
37+
38+
/// @}
39+
40+
/// \name Initialization
41+
/// @{
42+
43+
/*!
44+
Sets the entry `qi` of `lp` to `value`.
45+
*/
46+
void set_q(const std::size_t i, const FT value) { }
47+
48+
/*!
49+
Sets the entry `r` of `lp` to `value`.
50+
*/
51+
void set_r(const FT value) { }
52+
53+
/*!
54+
Sets the entry `Aij` in the row `i` and column `j` of
55+
the constraint matrix `A` of `lp` to `value`.
56+
*/
57+
void set_A(const std::size_t i, const std::size_t j, const FT value) { }
58+
59+
/*!
60+
Sets the entry `li` of `lp` to `value`.
61+
*/
62+
void set_l(const std::size_t i, const FT value) { }
63+
64+
/*!
65+
Sets the entry `ui` of `lp` to `value`.
66+
*/
67+
void set_u(const std::size_t i, const FT value) { }
68+
69+
/// @}
70+
71+
/// \name Solution
72+
/// @{
73+
74+
/*!
75+
\brief solves the linear program.
76+
77+
Number of values in `solution` equals to the number `n` of values in the vector `x`.
78+
79+
\tparam OutIterator
80+
a model of `OutputIterator` that accepts values of type `FieldNumberType`
81+
82+
\param solution
83+
an output iterator with the solution
84+
85+
\returns a status of the computation `success == true`
86+
*/
87+
template<typename OutIterator>
88+
bool solve(OutIterator solution) { }
89+
90+
/// @}
91+
};
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*!
2+
\ingroup PkgSolverInterfaceConcepts
3+
\cgalConcept
4+
5+
A concept that describes the set of methods used to define and solve a
6+
quadratic programming (`qp`) problem of the general form:
7+
<center>
8+
\f{eqnarray*}{
9+
& \mbox{minimize} & \frac{1}{2}\mathbf{x}^{T}P\mathbf{x} + \mathbf{q}^{T}\mathbf{x} + r \\
10+
& \mbox{subject to} & \mathbf{l} \leq A\mathbf{x} \leq \mathbf{u}
11+
\f}
12+
</center>
13+
in \f$ n \f$ real variables \f$ \mathbf{x} = (x_0, \ldots, x_{n-1}) \f$ and \f$ m \f$ constraints.
14+
15+
Here,
16+
<UL>
17+
<LI>\f$ P \f$ is a symmetric positive-semidefinite \f$ n \times n\f$ matrix (the quadratic objective function),
18+
<LI>\f$ \mathbf{q} \f$ is an \f$ n \f$-dimensional vector (the linear objective function),
19+
<LI>\f$ r \f$ is a constant,
20+
<LI>\f$ A \f$ is an \f$ m\times n\f$ matrix (the constraint matrix),
21+
<LI>\f$ \mathbf{l} \f$ is an \f$ m \f$-dimensional vector of lower constraint bounds,
22+
where \f$ l_i \in \mathbb{R} \cup \{-\infty\} \f$ for all \f$ i \f$,
23+
<LI>\f$ \mathbf{u} \f$ is an \f$ m \f$-dimensional vector of upper constraint bounds,
24+
where \f$ u_i \in \mathbb{R} \cup \{+\infty\} \f$ for all \f$ i \f$.
25+
</UL>
26+
27+
\cgalHasModel
28+
`CGAL::OSQP_quadratic_program_traits<T>`
29+
*/
30+
class QuadraticProgramTraits {
31+
32+
public:
33+
34+
/// \name Memory
35+
/// @{
36+
37+
/*!
38+
Allocates memory for `n` variables and `m` constraints in `qp`.
39+
*/
40+
void resize(const std::size_t n, const std::size_t m) { }
41+
42+
/// @}
43+
44+
/// \name Initialization
45+
/// @{
46+
47+
/*!
48+
Sets the entries `Pij` and `Pji` of `qp` to `value`.
49+
*/
50+
void set_P(const std::size_t i, const std::size_t j, const FT value) { }
51+
52+
/*!
53+
Sets the entry `qi` of `qp` to `value`.
54+
*/
55+
void set_q(const std::size_t i, const FT value) { }
56+
57+
/*!
58+
Sets the entry `r` of `qp` to `value`.
59+
*/
60+
void set_r(const FT value) { }
61+
62+
/*!
63+
Sets the entry `Aij` in the row `i` and column `j` of
64+
the constraint matrix `A` of `qp` to `value`.
65+
*/
66+
void set_A(const std::size_t i, const std::size_t j, const FT value) { }
67+
68+
/*!
69+
Sets the entry `li` of `qp` to `value`.
70+
*/
71+
void set_l(const std::size_t i, const FT value) { }
72+
73+
/*!
74+
Sets the entry `ui` of `qp` to `value`.
75+
*/
76+
void set_u(const std::size_t i, const FT value) { }
77+
78+
/// @}
79+
80+
/// \name Solution
81+
/// @{
82+
83+
/*!
84+
\brief solves the quadratic program.
85+
86+
Number of values in `solution` equals to the number `n` of values in the vector `x`.
87+
88+
\tparam OutIterator
89+
a model of `OutputIterator` that accepts values of type `FieldNumberType`
90+
91+
\param solution
92+
an output iterator with the solution
93+
94+
\returns a status of the computation `success == true`
95+
*/
96+
template<typename OutIterator>
97+
bool solve(OutIterator solution) { }
98+
99+
/// @}
100+
};

0 commit comments

Comments
 (0)