-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbasic_unconstrained.cpp
More file actions
61 lines (43 loc) · 1.59 KB
/
basic_unconstrained.cpp
File metadata and controls
61 lines (43 loc) · 1.59 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
#include <clarabel.hpp>
#include <Eigen/Eigen>
#include <cmath>
#include <gtest/gtest.h>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
using namespace clarabel;
using namespace Eigen;
TEST(BasicUnconstrainedTest, Feasible)
{
SparseMatrix<double> P = MatrixXd::Identity(3, 3).sparseView();
P.makeCompressed();
Vector<double, 3> c = { 1., 2., -3. };
SparseMatrix<double> A = MatrixXd::Zero(0, 3).sparseView();
A.makeCompressed();
Vector<double, 0> b = {};
vector<SupportedConeT<double>> cones = {};
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
DefaultSolver<double> solver(P, c, A, b, cones, settings);
solver.solve();
DefaultSolution<double> solution = solver.solution();
ASSERT_EQ(solution.status, SolverStatus::Solved);
// Compare the solution to the reference solution
Vector3d ref_solution{ -1., -2., 3. };
ASSERT_EQ(solution.x.size(), 3);
ASSERT_TRUE(solution.x.isApprox(ref_solution, 1e-6));
}
TEST(BasicUnconstrainedTest, Infeasible)
{
SparseMatrix<double> P = MatrixXd::Zero(3, 3).sparseView();
P.makeCompressed();
Vector<double, 3> c = { 1., 0., 0. };
SparseMatrix<double> A = MatrixXd::Zero(0, 3).sparseView();
A.makeCompressed();
Vector<double, 0> b = {};
vector<SupportedConeT<double>> cones = {};
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
DefaultSolver<double> solver(P, c, A, b, cones, settings);
solver.solve();
ASSERT_EQ(solver.solution().status, SolverStatus::DualInfeasible);
}