-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample_socp.cpp
More file actions
58 lines (44 loc) · 1.09 KB
/
example_socp.cpp
File metadata and controls
58 lines (44 loc) · 1.09 KB
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
#include "utils.h"
#include <clarabel.hpp>
#include <Eigen/Eigen>
#include <vector>
using namespace clarabel;
using namespace std;
using namespace Eigen;
int main()
{
MatrixXd P_dense(2, 2);
P_dense <<
0., 0.,
0., 2.;
SparseMatrix<double> P = P_dense.sparseView();
P.makeCompressed();
Vector<double, 2> q = { 0., 0. };
/* From dense matrix:
* [[ 0., 0.],
* [-2., 0.],
* [ 0., -1.]]
*/
MatrixXd A_dense(3, 2);
A_dense <<
0., 0.,
-2., 0.,
0., -1.;
SparseMatrix<double> A = A_dense.sparseView();
A.makeCompressed();
Vector<double, 3> b = { 1., -2., -2. };
vector<SupportedConeT<double>> cones
{
SecondOrderConeT<double>(3),
};
// Settings
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
// Build solver
DefaultSolver<double> solver(P, q, A, b, cones, settings);
// Solve
solver.solve();
// Get solution
DefaultSolution<double> solution = solver.solution();
utils::print_solution(solution);
return 0;
}