EigenOpt 1.0.0
Loading...
Searching...
No Matches
qp_example.cpp
Go to the documentation of this file.
1
29#include <Eigen/Dense>
30#include <iostream>
31
32int main(int argc, char** argv) {
33 /* Solve: min (x1 + x2 - 5)^2
34 * Such that: x1 - x2 = 10
35 * and: x1 + 4*x2 <= 0
36 */
37 // Objective and constraints in matrix form.
38 Eigen::MatrixXd Q(1, 2); Q << 1, 1;
39 Eigen::VectorXd r(1); r << 5;
40 Eigen::MatrixXd A(1, 2); A << 1, -1;
41 Eigen::VectorXd b(1); b << 10;
42 Eigen::MatrixXd C(1, 2); C << 1, 4;
43 Eigen::VectorXd d(1); d << 0;
44 double tolerance = 1e-6;
45
46 // Create the solver and setup the problem.
48 qp::Solver<double> solver(Q, r, tolerance);
49 solver.setConstraints(A, b, C, d);
50
51 // Solve the problem.
52 Eigen::VectorXd x;
53 solver.solve(x);
54 std::cout << "Solution: " << x.transpose() << std::endl;
55 // Prints: "Solution: 7.5 -2.5"
56
57 return 0;
58}
Contains the solver used for linearly constrained quadratic optimization problems.
int main(int argc, char **argv)