-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3235d5f
commit fba7422
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <suboptimal/LinearProblem.h> | ||
|
||
#include <Eigen/Core> | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
using namespace suboptimal; | ||
using namespace Eigen; | ||
|
||
TEST_CASE("LinearProblem - Problem initialization") { | ||
auto problem = LinearProblem::maximizationProblem(Vector2d{{3, 2}}); | ||
problem.addLessThanConstraint(Vector2d{{2, 1}}, 50); | ||
problem.addGreaterThanConstraint(Vector2d{{1, 3}}, 15); | ||
problem.addEqualityConstraint(Vector2d{{5, 6}}, 60); | ||
|
||
CHECK(problem.numConstraints() == 3); | ||
CHECK(problem.numDecisionVars() == 2); | ||
CHECK(problem.numSlackVars() == 2); | ||
CHECK(problem.numArtificialVars() == 2); | ||
|
||
const Matrix<double, 3, 6> expected_mat{{2, 1, 1, 0, 0, 0}, // | ||
{5, 6, 0, 0, 1, 0}, // | ||
{1, 3, 0, -1, 0, 1}}; // | ||
const Vector3d expected_rhs{{50, 60, 15}}; | ||
|
||
MatrixXd mat; | ||
VectorXd rhs; | ||
problem.buildConstraints(mat, rhs); | ||
|
||
REQUIRE(mat.rows() == expected_mat.rows()); | ||
REQUIRE(mat.cols() == expected_mat.cols()); | ||
REQUIRE(rhs.size() == expected_rhs.size()); | ||
|
||
CHECK(mat == expected_mat); | ||
CHECK(rhs == expected_rhs); | ||
} |