Skip to content

Commit 9787a35

Browse files
committed
minor fix simple example
1 parent 8c2cfeb commit 9787a35

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

examples/cpp/first_example_dense.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//
22
// Copyright (c) 2022 INRIA
33
//
4-
#include <optional>
4+
#include <iostream>
55
#include <Eigen/Core>
6+
#include <proxsuite/helpers/optional.hpp> // for c++14
67
#include <proxsuite/proxqp/dense/dense.hpp>
78

89
using namespace proxsuite::proxqp;
10+
using proxsuite::nullopt; // c++17 simply use std::nullopt
911

1012
int
1113
main()
@@ -26,13 +28,13 @@ main()
2628
g << -22.0, -14.5, 13.0;
2729

2830
// inequality constraints C
29-
Eigen::MatrixXd C = Eigen::MatrixXd(dim, dim);
31+
Eigen::MatrixXd C = Eigen::MatrixXd(n_in, dim);
3032
C << 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0;
3133

32-
Eigen::VectorXd l = Eigen::VectorXd(dim);
34+
Eigen::VectorXd l = Eigen::VectorXd(n_in);
3335
l << -1.0, -1.0, -1.0;
3436

35-
Eigen::VectorXd u = Eigen::VectorXd(dim);
37+
Eigen::VectorXd u = Eigen::VectorXd(n_in);
3638
u << 1.0, 1.0, 1.0;
3739

3840
std::cout << "H:\n" << H << std::endl;
@@ -50,7 +52,7 @@ main()
5052

5153
// initialize qp with matrices describing the problem
5254
// note: it is also possible to use update here
53-
qp.init(H, g, std::nullopt, std::nullopt, C, l, u);
55+
qp.init(H, g, nullopt, nullopt, C, l, u);
5456

5557
qp.solve();
5658

examples/cpp/first_example_sparse.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//
22
// Copyright (c) 2022 INRIA
33
//
4-
#include <optional>
54
#include <random>
5+
#include <iostream>
66
#include <Eigen/Core>
7+
#include <proxsuite/helpers/optional.hpp> // for c++14
78
#include <proxsuite/proxqp/sparse/sparse.hpp>
89

910
using namespace proxsuite::proxqp;
11+
using proxsuite::nullopt; // c++17 simply use std::nullopt
1012

1113
int
1214
main()
@@ -44,15 +46,15 @@ main()
4446

4547
// inequality constraints C: other way to define sparse matrix from dense
4648
// matrix using sparseView
47-
Eigen::MatrixXd C = Eigen::MatrixXd(n_in, n_in);
49+
Eigen::MatrixXd C = Eigen::MatrixXd(n_in, dim);
4850
C << 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0;
4951
Eigen::SparseMatrix<double> C_spa(n_in, dim);
5052
C_spa = C.sparseView();
5153

52-
Eigen::VectorXd l = Eigen::VectorXd(dim);
54+
Eigen::VectorXd l = Eigen::VectorXd(n_in);
5355
l << -1.0, -1.0, -1.0;
5456

55-
Eigen::VectorXd u = Eigen::VectorXd(dim);
57+
Eigen::VectorXd u = Eigen::VectorXd(n_in);
5658
u << 1.0, 1.0, 1.0;
5759

5860
std::cout << "H:\n" << H_spa << std::endl;
@@ -70,7 +72,7 @@ main()
7072

7173
// initialize qp with matrices describing the problem
7274
// note: it is also possible to use update here
73-
qp.init(H_spa, g, std::nullopt, std::nullopt, C_spa, l, u);
75+
qp.init(H_spa, g, nullopt, nullopt, C_spa, l, u);
7476

7577
qp.solve();
7678

0 commit comments

Comments
 (0)