-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample_expcone.c
More file actions
67 lines (55 loc) · 1.7 KB
/
example_expcone.c
File metadata and controls
67 lines (55 loc) · 1.7 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
#include "utils.h"
#include <clarabel.h>
#include <math.h>
int main(void)
{
// 3 x 3 zero matrix
ClarabelCscMatrix P;
clarabel_CscMatrix_init(
&P,
3, // row
3, // col
(uintptr_t[]){ 0, 0, 0, 0 }, // colptr
NULL, // rowval
NULL // nzval
);
ClarabelFloat q[3] = { -1.0, 0.0, 0.0 };
/* From dense matrix:
* [-1.0, 0., 0.],
* [0., -1., 0.],
* [0., 0., -1.],
* [0., 1., 0.],
* [0., 0., 1.],
*/
ClarabelCscMatrix A;
clarabel_CscMatrix_init(
&A,
5, // row
3, // col
(uintptr_t[]){ 0, 1, 3, 5 }, // colptr
(uintptr_t[]){ 0, 1, 3, 2, 4 }, // rowval
(ClarabelFloat[]){ -1.0, -1.0, 1.0, -1.0, 1.0 } // nzval
);
ClarabelFloat b[5] = { 0., 0., 0., 1., exp(5.0) };
ClarabelSupportedConeT cones[2] = { ClarabelExponentialConeT(), ClarabelZeroConeT(2) };
// Settings
ClarabelDefaultSettings settings = clarabel_DefaultSettings_default();
settings.verbose = true;
// Build solver
ClarabelDefaultSolver *solver = clarabel_DefaultSolver_new(
&P, // P
q, // q
&A, // A
b, // b
2, // n_cones
cones, &settings
);
// Solve
clarabel_DefaultSolver_solve(solver);
// Get solution
ClarabelDefaultSolution solution = clarabel_DefaultSolver_solution(solver);
print_solution(&solution);
// Free the solver
clarabel_DefaultSolver_free(solver);
return 0;
}