Skip to content

Commit ae2ae08

Browse files
committed
add settings as input of cleanup results method + rename Qp as qp in tests and examples
1 parent c199a3e commit ae2ae08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+8459
-8482
lines changed

examples/cpp/init_dense_qp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -13,9 +13,9 @@ main()
1313
// generate a random qp
1414
T sparsity_factor(0.15);
1515
T strong_convexity_factor(1.e-2);
16-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
16+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1717
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1818

19-
dense::QP<T> Qp(dim, n_eq, n_in); // create the QP object
20-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l); // initialize the model
19+
dense::QP<T> qp(dim, n_eq, n_in); // create the QP object
20+
qp.init(qp_random.H, qp_random.g, qp_random.A, qp_random.b, qp_random.C, qp_random.u, qp_random.l); // initialize the model
2121
}

examples/cpp/init_dense_qp_with_other_options.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -12,13 +12,13 @@ main()
1212
// generate a random qp
1313
T sparsity_factor(0.15);
1414
T strong_convexity_factor(1.e-2);
15-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
15+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1616
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1717

18-
dense::QP<T> Qp(
18+
dense::QP<T> qp(
1919
dim, n_eq, n_in); // create the QP
2020
// initialize the model, along with another rho parameter
21-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l, true, /*rho*/ 1.e-7);
21+
qp.init(qp_random.H, qp_random.g, qp_random.A, qp_random.b, qp_random.C, qp_random.u, qp_random.l, true, /*rho*/ 1.e-7);
2222
// in c++ you must follow the order speficied in the API for the parameters
2323
// if you don't want to change one parameter (here compute_preconditioner),
2424
// just let it be std::nullopt
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -12,10 +12,10 @@ main()
1212
// generate a random qp
1313
T sparsity_factor(0.15);
1414
T strong_convexity_factor(1.e-2);
15-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
15+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1616
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1717

18-
dense::QP<T> Qp(dim, n_eq, n_in); // create the QP object
19-
Qp.settings.compute_timings = true; // compute all timings
20-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l); // initialize the model
18+
dense::QP<T> qp(dim, n_eq, n_in); // create the QP object
19+
qp.settings.compute_timings = true; // compute all timings
20+
qp.init(qp_random.H, qp_random.g, qp_random.A, qp_random.b, qp_random.C, qp_random.u, qp_random.l); // initialize the model
2121
}

examples/cpp/init_with_default_options.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -12,30 +12,30 @@ main()
1212
// generate a random qp
1313
T sparsity_factor(0.15);
1414
T strong_convexity_factor(1.e-2);
15-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
15+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1616
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1717

18-
dense::QP<T> Qp(
18+
dense::QP<T> qp(
1919
dim, n_eq, n_in); // create the QP
2020
// initialize the model, along with another rho parameter
21-
Qp.settings.initial_guess = InitialGuessStatus::NO_INITIAL_GUESS;
22-
Qp.init(qp.H,
23-
qp.g,
24-
qp.A,
25-
qp.b,
26-
qp.C,
27-
qp.u,
28-
qp.l,
21+
qp.settings.initial_guess = InitialGuessStatus::NO_INITIAL_GUESS;
22+
qp.init(qp_random.H,
23+
qp_random.g,
24+
qp_random.A,
25+
qp_random.b,
26+
qp_random.C,
27+
qp_random.u,
28+
qp_random.l,
2929
true,
3030
/*rho*/ 1.e-7,
3131
/*mu_eq*/ 1.e-4);
32-
// Initializing rho sets in practive Qp.settings.default_rho value,
33-
// hence, after each solve or update method, the Qp.results.info.rho value
34-
// will be reset to Qp.settings.default_rho value.
35-
Qp.solve();
36-
// So if we redo a solve, Qp.settings.default_rho value = 1.e-7, hence
37-
// Qp.results.info.rho restarts at 1.e-7 The same occurs for mu_eq.
38-
Qp.solve();
32+
// Initializing rho sets in practive qp.settings.default_rho value,
33+
// hence, after each solve or update method, the qp.results.info.rho value
34+
// will be reset to qp.settings.default_rho value.
35+
qp.solve();
36+
// So if we redo a solve, qp.settings.default_rho value = 1.e-7, hence
37+
// qp.results.info.rho restarts at 1.e-7 The same occurs for mu_eq.
38+
qp.solve();
3939
// There might be a different result with WARM_START_WITH_PREVIOUS_RESULT
4040
// initial guess option, as by construction, it reuses the last proximal step
4141
// sizes of the last solving method.
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "proxsuite/proxqp/dense/dense.hpp"
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -9,27 +9,27 @@ main()
99
dense::isize dim = 10;
1010
dense::isize n_eq(0);
1111
dense::isize n_in(0);
12-
dense::QP<T> Qp(dim, n_eq, n_in);
12+
dense::QP<T> qp(dim, n_eq, n_in);
1313
T strong_convexity_factor(0.1);
1414
T sparsity_factor(0.15);
1515
// we generate a qp, so the function used from helpers.hpp is
1616
// in proxqp namespace. The qp is in dense eigen format and
1717
// you can control its sparsity ratio and strong convexity factor.
18-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
18+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1919
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
2020

21-
Qp.init(qp.H,
22-
qp.g,
23-
qp.A,
24-
qp.b,
25-
qp.C,
26-
qp.u,
27-
qp.l); // initialization with zero shape matrices
28-
// it is equivalent to do Qp.init(qp.H, qp.g,
21+
qp.init(qp_random.H,
22+
qp_random.g,
23+
qp_random.A,
24+
qp_random.b,
25+
qp_random.C,
26+
qp_random.u,
27+
qp_random.l); // initialization with zero shape matrices
28+
// it is equivalent to do qp.init(qp_random.H, qp_random.g,
2929
// std::nullopt,std::nullopt,std::nullopt,std::nullopt,std::nullopt);
30-
Qp.solve();
30+
qp.solve();
3131
// print an optimal solution x,y and z
32-
std::cout << "optimal x: " << Qp.results.x << std::endl;
33-
std::cout << "optimal y: " << Qp.results.y << std::endl;
34-
std::cout << "optimal z: " << Qp.results.z << std::endl;
32+
std::cout << "optimal x: " << qp.results.x << std::endl;
33+
std::cout << "optimal y: " << qp.results.y << std::endl;
34+
std::cout << "optimal z: " << qp.results.z << std::endl;
3535
}

examples/cpp/initializing_with_none_without_api.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "proxsuite/proxqp/dense/dense.hpp"
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -14,18 +14,18 @@ main()
1414
// we generate a qp, so the function used from helpers.hpp is
1515
// in proxqp namespace. The qp is in dense eigen format and
1616
// you can control its sparsity ratio and strong convexity factor.
17-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
17+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1818
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1919

2020
Results<T> results =
21-
dense::solve<T>(qp.H,
22-
qp.g,
23-
qp.A,
24-
qp.b,
25-
qp.C,
26-
qp.u,
27-
qp.l); // initialization with zero shape matrices
28-
// it is equivalent to do dense::solve<T>(qp.H, qp.g,
21+
dense::solve<T>(qp_random.H,
22+
qp_random.g,
23+
qp_random.A,
24+
qp_random.b,
25+
qp_random.C,
26+
qp_random.u,
27+
qp_random.l); // initialization with zero shape matrices
28+
// it is equivalent to do dense::solve<T>(qp_random.H, qp_random.g,
2929
// std::nullopt,std::nullopt,std::nullopt,std::nullopt,std::nullopt);
3030
// print an optimal solution x,y and z
3131
std::cout << "optimal x: " << results.x << std::endl;

examples/cpp/loading_dense_qp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ main()
88
dense::isize dim = 10;
99
dense::isize n_eq(dim / 4);
1010
dense::isize n_in(dim / 4);
11-
dense::QP<T> Qp(dim, n_eq, n_in);
11+
dense::QP<T> qp(dim, n_eq, n_in);
1212
}

examples/cpp/loading_sparse_qp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#include <iostream>
22
#include <proxsuite/proxqp/sparse/sparse.hpp> // get the sparse API of ProxQP
3-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
3+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
44

55
using namespace proxsuite::proxqp;
66
using T = double;
77

88
int
99
main()
1010
{
11-
// design a Qp object using QP problem dimensions
11+
// design a qp object using QP problem dimensions
1212
isize n = 10;
1313
isize n_eq(n / 4);
1414
isize n_in(n / 4);
15-
sparse::QP<T, isize> Qp(n, n_eq, n_in);
15+
sparse::QP<T, isize> qp(n, n_eq, n_in);
1616

1717
// assume you generate these matrices H, A and C for your QP problem
1818

@@ -24,7 +24,7 @@ main()
2424
auto A = ::proxsuite::proxqp::utils::rand::sparse_matrix_rand<T>(n_eq, n, p);
2525
auto C = ::proxsuite::proxqp::utils::rand::sparse_matrix_rand<T>(n_in, n, p);
2626

27-
// design a Qp2 object using sparsity masks of H, A and C
28-
proxsuite::proxqp::sparse::QP<T, isize> Qp2(
27+
// design a qp2 object using sparsity masks of H, A and C
28+
proxsuite::proxqp::sparse::QP<T, isize> qp2(
2929
H.cast<bool>(), A.cast<bool>(), C.cast<bool>());
3030
}

examples/cpp/overview-simple.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp>
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -16,15 +16,15 @@ main()
1616
// we generate a qp, so the function used from helpers.hpp is
1717
// in proxqp namespace. The qp is in dense eigen format and
1818
// you can control its sparsity ratio and strong convexity factor.
19-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
19+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
2020
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
2121

2222
// load PROXQP solver with dense backend and solve the problem
23-
dense::QP<T> Qp(dim, n_eq, n_in);
24-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l);
25-
Qp.solve();
23+
dense::QP<T> qp(dim, n_eq, n_in);
24+
qp.init(qp_random.H, qp_random.g, qp_random.A, qp_random.b, qp_random.C, qp_random.u, qp_random.l);
25+
qp.solve();
2626
// print an optimal solution x,y and z
27-
std::cout << "optimal x: " << Qp.results.x << std::endl;
28-
std::cout << "optimal y: " << Qp.results.y << std::endl;
29-
std::cout << "optimal z: " << Qp.results.z << std::endl;
27+
std::cout << "optimal x: " << qp.results.x << std::endl;
28+
std::cout << "optimal y: " << qp.results.y << std::endl;
29+
std::cout << "optimal z: " << qp.results.z << std::endl;
3030
}

examples/cpp/solve_dense_qp.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -14,19 +14,19 @@ main()
1414
T sparsity_factor(0.15);
1515
T strong_convexity_factor(1.e-2);
1616

17-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
17+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1818
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1919

20-
dense::QP<T> Qp(dim, n_eq, n_in); // create the QP object
21-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l); // initialize the model
22-
Qp.solve(); // solve the problem without warm start
20+
dense::QP<T> qp(dim, n_eq, n_in); // create the QP object
21+
qp.init(qp_random.H, qp_random.g, qp_random.A, qp_random.b, qp_random.C, qp_random.u, qp_random.l); // initialize the model
22+
qp.solve(); // solve the problem without warm start
2323
auto x_wm = utils::rand::vector_rand<T>(dim);
2424
auto y_wm = utils::rand::vector_rand<T>(n_eq);
2525
auto z_wm = utils::rand::vector_rand<T>(n_in);
26-
Qp.solve(x_wm, y_wm,
26+
qp.solve(x_wm, y_wm,
2727
z_wm); // if you have a warm start, put it here
2828
// print an optimal solution x,y and z
29-
std::cout << "optimal x: " << Qp.results.x << std::endl;
30-
std::cout << "optimal y: " << Qp.results.y << std::endl;
31-
std::cout << "optimal z: " << Qp.results.z << std::endl;
29+
std::cout << "optimal x: " << qp.results.x << std::endl;
30+
std::cout << "optimal y: " << qp.results.y << std::endl;
31+
std::cout << "optimal z: " << qp.results.z << std::endl;
3232
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -13,16 +13,16 @@ main()
1313
// generate a random qp
1414
T sparsity_factor(0.15);
1515
T strong_convexity_factor(1.e-2);
16-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
16+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1717
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1818

19-
dense::QP<T> Qp(dim, n_eq, n_in); // create the QP object
20-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l); // initialize the model
21-
Qp.settings.eps_abs = T(1.E-9); // set accuracy threshold to 1.e-9
22-
Qp.settings.verbose = true; // print some intermediary results
23-
Qp.solve(); // solve the problem with previous settings
19+
dense::QP<T> qp(dim, n_eq, n_in); // create the QP object
20+
qp.init(qp_random.H, qp_random.g, qp_random.A, qp_random.b, qp_random.C, qp_random.u, qp_random.l); // initialize the model
21+
qp.settings.eps_abs = T(1.E-9); // set accuracy threshold to 1.e-9
22+
qp.settings.verbose = true; // print some intermediary results
23+
qp.solve(); // solve the problem with previous settings
2424
// print an optimal solution x,y and z
25-
std::cout << "optimal x: " << Qp.results.x << std::endl;
26-
std::cout << "optimal y: " << Qp.results.y << std::endl;
27-
std::cout << "optimal z: " << Qp.results.z << std::endl;
25+
std::cout << "optimal x: " << qp.results.x << std::endl;
26+
std::cout << "optimal y: " << qp.results.y << std::endl;
27+
std::cout << "optimal z: " << qp.results.z << std::endl;
2828
}

examples/cpp/solve_without_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22
#include "proxsuite/proxqp/sparse/sparse.hpp" // get the sparse backend of ProxQP
33
#include "proxsuite/proxqp/dense/dense.hpp" // get the dense backend of ProxQP
4-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
4+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
55

66
using namespace proxsuite::proxqp;
77
using T = double;

examples/cpp/solve_without_api_and_option.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22
#include <proxsuite/proxqp/sparse/sparse.hpp> // get the sparse backend of ProxQP
33
#include <proxsuite/proxqp/dense/dense.hpp> // get the dense backend of ProxQP
4-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
4+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
55

66
using namespace proxsuite::proxqp;
77
using T = double;

examples/cpp/update_dense_qp.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -13,21 +13,21 @@ main()
1313
// generate a random qp
1414
T sparsity_factor(0.15);
1515
T strong_convexity_factor(1.e-2);
16-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
16+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1717
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1818

19-
dense::QP<T> Qp(dim, n_eq, n_in); // create the QP object
20-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l); // initialize the model
21-
Qp.solve(); // solve the problem
22-
// a new Qp problem
19+
dense::QP<T> qp(dim, n_eq, n_in); // create the QP object
20+
qp.init(qp_random.H, qp_random.g, qp_random.A, qp_random.b, qp_random.C, qp_random.u, qp_random.l); // initialize the model
21+
qp.solve(); // solve the problem
22+
// a new qp problem
2323
dense::Model<T> qp2 = utils::dense_strongly_convex_qp(
2424
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
2525
// re update the model
26-
Qp.update(qp2.H, qp2.g, qp2.A, qp2.b, qp2.C, qp2.u, qp2.l);
26+
qp.update(qp2.H, qp2.g, qp2.A, qp2.b, qp2.C, qp2.u, qp2.l);
2727
// solve it
28-
Qp.solve();
28+
qp.solve();
2929
// print an optimal solution x,y and z
30-
std::cout << "optimal x: " << Qp.results.x << std::endl;
31-
std::cout << "optimal y: " << Qp.results.y << std::endl;
32-
std::cout << "optimal z: " << Qp.results.z << std::endl;
30+
std::cout << "optimal x: " << qp.results.x << std::endl;
31+
std::cout << "optimal y: " << qp.results.y << std::endl;
32+
std::cout << "optimal z: " << qp.results.z << std::endl;
3333
}

0 commit comments

Comments
 (0)