-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample_sdp.cpp
More file actions
71 lines (52 loc) · 1.55 KB
/
example_sdp.cpp
File metadata and controls
71 lines (52 loc) · 1.55 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
59
60
61
62
63
64
65
66
67
68
69
70
71
// #define FEATURE_SDP
#include "utils.h"
#include <clarabel.hpp>
#include <Eigen/Eigen>
#include <cmath>
#include <vector>
using namespace clarabel;
using namespace std;
using namespace Eigen;
int main(void)
{
#ifndef FEATURE_SDP
printf("This example requires SDP support.\n");
return 1;
#else
// SDP Example
int n = 3;
int nvec = (n * (n + 1)) >> 1;
// 6 x 6 zero matrix
SparseMatrix<double> P = MatrixXd::Zero(nvec, nvec).sparseView();
P.makeCompressed();
Vector<double, 6> c = { 1., 0., 1., 0., 0., 1. };
double sqrt2 = sqrt(2.0);
MatrixXd A_dense(7, 6);
A_dense <<
-1., 0., 0., 0., 0., 0.,
0., -sqrt2, 0., 0., 0., 0.,
0., 0., -1., 0., 0., 0.,
0., 0., 0., -sqrt2, 0., 0.,
0., 0., 0., 0., -sqrt2, 0.,
0., 0., 0., 0., 0., -1.,
1., 4., 3., 8., 10., 6.;
SparseMatrix<double> A = A_dense.sparseView();
A.makeCompressed();
Vector<double, 7> b = { 0., 0., 0., 0., 0., 0., 1. };
vector<SupportedConeT<double>> cones
{
PSDTriangleConeT<double>(n),
ZeroConeT<double>(1),
};
// Settings
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
// Build solver
DefaultSolver<double> solver(P, c, A, b, cones, settings);
// Solve
solver.solve();
// Get solution
DefaultSolution<double> solution = solver.solution();
utils::print_solution(solution);
return 0;
#endif // FEATURE_SDP
}