EigenOpt 1.0.0
Loading...
Searching...
No Matches
simplex_example.cpp
Go to the documentation of this file.
1
25#include <EigenOpt/simplex.hpp>
26#include <Eigen/Dense>
27#include <iostream>
28
29int main(int argc, char** argv) {
30 /* Solve: min - x1 + x2
31 * Such that: -4 x1 - x2 <= -5
32 * x1 -4 x2 <= -3
33 * 2 x1 - x2 <= 8
34 * x1, x2 >= 0
35 */
36 // Objective and constraints in matrix form.
37 Eigen::VectorXd f(2); f << -1, 1;
38 Eigen::MatrixXd C(5, 2); C << -4,-1,
39 1,-4,
40 2,-1,
41 -1, 0,
42 0,-1;
43 Eigen::VectorXd d(5); d << -5, -3, 8, 0, 0;
44 double tolerance = 1e-6;
45
46 // Solve the problem.
47 Eigen::VectorXd x;
48 std::string message;
49 EigenOpt::simplex::minimize(f, C, d, x, message, tolerance);
50 std::cout << "Solution: " << x.transpose() << std::endl;
51 // Prints: "Solution: 5 2"
52
53 return 0;
54}
bool minimize(const Eigen::MatrixBase< D1 > &f, const Eigen::MatrixBase< D2 > &A, const Eigen::MatrixBase< D3 > &b, const Eigen::MatrixBase< D4 > &C, const Eigen::MatrixBase< D5 > &d, Eigen::DenseBase< D6 > &x, std::string &halt_reason, const Scalar &small_number, const Scalar &large_number=-1)
Solve a constrained linear optimization problem.
Definition simplex.hxx:152
int main(int argc, char **argv)