From 901ee0c77b45a52b6acd9e887a367f3709e9a012 Mon Sep 17 00:00:00 2001 From: Alvin Zhang <41vin2h4n9@gmail.com> Date: Tue, 15 Oct 2024 10:30:41 -0700 Subject: [PATCH] fix: get rid of unnecessary extra row in tableau --- CMakeLists.txt | 4 ++-- src/solvers/linear/simplex.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb6a802..234c641 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/solvers/linear/simplex.cpp b/src/solvers/linear/simplex.cpp index 0eee091..b434c71 100644 --- a/src/solvers/linear/simplex.cpp +++ b/src/solvers/linear/simplex.cpp @@ -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(); @@ -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(i)); } } objective_value = tableau(tableau.rows() - 1, tableau.cols() - 1);