-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample_print_stream.cpp
More file actions
73 lines (57 loc) · 1.87 KB
/
example_print_stream.cpp
File metadata and controls
73 lines (57 loc) · 1.87 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
72
73
#include "utils.h"
#include <clarabel.hpp>
#include <Eigen/Eigen>
#include <vector>
#include <iostream>
using namespace clarabel;
using namespace std;
using namespace Eigen;
int main(void)
{
/* From dense matrix:
* [[6., 0.],
* [0., 4.]]
*/
MatrixXd P_dense(2, 2);
P_dense <<
6., 0.,
0., 4.;
SparseMatrix<double> P = P_dense.sparseView();
P.makeCompressed();
Vector<double, 2> q = { -1., -4. };
MatrixXd A_dense(5, 2);
A_dense <<
1., -2., // <-- LHS of equality constraint (lower bound)
1., 0., // <-- LHS of inequality constraint (upper bound)
0., 1., // <-- LHS of inequality constraint (upper bound)
-1., 0., // <-- LHS of inequality constraint (lower bound)
0., -1.; // <-- LHS of inequality constraint (lower bound)
SparseMatrix<double> A = A_dense.sparseView();
A.makeCompressed();
Vector<double, 5> b = { 0., 1., 1., 1., 1. };
vector<SupportedConeT<double>> cones
{
ZeroConeT<double>(1),
NonnegativeConeT<double>(4),
};
// Settings
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
// Build solver
DefaultSolver<double> solver(P, q, A, b, cones, settings);
// redirect progress output to a file
std::cout << "Printing to file ...." << std::endl;
solver.print_to_file("clarabel_example_print_stream.txt");
solver.solve();
// redirect progress output to a buffer
std::cout << "Printing to buffer ...." << std::endl;
solver.print_to_buffer();
solver.solve();
std::cout << "Recovering from buffer ...." << std::endl;
std::string bufstr = solver.get_print_buffer();
std::cout << bufstr << std::endl;
// restore the buffer to stdout
std::cout << "Printing to stdout ...." << std::endl;
solver.print_to_stdout();
solver.solve();
return 0;
}