Skip to content

Commit

Permalink
fix: get rid of unnecessary extra row in tableau
Browse files Browse the repository at this point in the history
  • Loading branch information
mimizh2418 committed Oct 15, 2024
1 parent 9e46a78 commit 901ee0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ include(FetchContent)
find_package(Eigen3 3.4 CONFIG)
if (NOT Eigen3_FOUND)
message(STATUS "Eigen3 not found, fetching from gitlab")
fetchcontent_declare(
FetchContent_Declare(
Eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4
)
fetchcontent_makeavailable(Eigen3)
FetchContent_MakeAvailable(Eigen3)
endif()
target_link_libraries(suboptimal PUBLIC Eigen3::Eigen)
8 changes: 4 additions & 4 deletions src/solvers/linear/simplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ SolverExitStatus solveSimplex(const LinearProblem& problem, VectorXd& solution,
}

// Initialize tableau
MatrixXd tableau = MatrixXd::Zero(num_constraints + 1, num_decision_vars + num_constraints + 2);
MatrixXd tableau = MatrixXd::Zero(num_constraints + 1, num_decision_vars + num_constraints + 1);
tableau.topLeftCorner(num_constraints, num_decision_vars) = problem.getConstraintMatrix();
tableau.block(0, num_decision_vars, num_constraints + 1, num_constraints + 1) =
MatrixXd::Identity(num_constraints + 1, num_constraints + 1);
tableau.block(0, num_decision_vars, num_constraints, num_constraints) =
MatrixXd::Identity(num_constraints, num_constraints);
tableau.topRightCorner(num_constraints, 1) = problem.getConstraintRHS();
tableau.bottomLeftCorner(1, num_decision_vars) = -problem.getObjectiveCoeffs().transpose();

Expand Down Expand Up @@ -166,7 +166,7 @@ SolverExitStatus solveSimplex(const LinearProblem& problem, VectorXd& solution,
auto rhs = tableau.col(tableau.cols() - 1);
for (size_t i = 0; i < basic_vars.size(); i++) {
if (const Index var_index = basic_vars[i]; var_index < num_decision_vars) {
solution(var_index) = rhs(i);
solution(var_index) = rhs(static_cast<Index>(i));
}
}
objective_value = tableau(tableau.rows() - 1, tableau.cols() - 1);
Expand Down

0 comments on commit 901ee0c

Please sign in to comment.