diff --git a/src/LinearProblem.cpp b/src/LinearProblem.cpp index 2932e4c..4251087 100644 --- a/src/LinearProblem.cpp +++ b/src/LinearProblem.cpp @@ -19,9 +19,7 @@ LinearProblem::LinearProblem(const Ref& objective_coeffs, const : is_minimization(is_minimization), objective_coeffs((is_minimization ? -1 : 1) * objective_coeffs), num_decision_vars(objective_coeffs.size()) { - if (objective_coeffs.size() < 1) { - throw std::invalid_argument("Objective function must have at least one coefficient"); - } + Expects(objective_coeffs.size() > 0); } LinearProblem LinearProblem::maximizationProblem(const Ref& objective_coeffs) { @@ -45,9 +43,7 @@ void LinearProblem::addEqualityConstraint(const Ref& constraint_ } void LinearProblem::addConstraintImpl(const Ref& constraint_coeffs, const double rhs, const int constraint_type) { - if (constraint_coeffs.size() != num_decision_vars) { - throw std::invalid_argument("Constraint coefficients must have same dimension as decision variables"); - } + Expects(constraint_coeffs.size() == num_decision_vars); VectorXd new_constraint(constraint_coeffs.size() + 1); new_constraint.head(num_decision_vars) = constraint_coeffs; diff --git a/src/solvers/linear/simplex.cpp b/src/solvers/linear/simplex.cpp index 7fa11a5..ef44ef2 100644 --- a/src/solvers/linear/simplex.cpp +++ b/src/solvers/linear/simplex.cpp @@ -146,6 +146,8 @@ SolverExitStatus solveTableau(MatrixXd& tableau, VectorX& basic_vars, Sol SolverExitStatus suboptimal::solveSimplex(const LinearProblem& problem, Ref solution, double& objective_value, const SimplexSolverConfig& config) { + Expects(solution.size() == problem.numDecisionVars()); + MatrixXd constraint_matrix; VectorXd constraint_rhs; problem.buildConstraints(constraint_matrix, constraint_rhs); diff --git a/test/solvers/linear/simplex_fail_test.cpp b/test/solvers/linear/simplex_fail_test.cpp index f32e9d3..29e2dea 100644 --- a/test/solvers/linear/simplex_fail_test.cpp +++ b/test/solvers/linear/simplex_fail_test.cpp @@ -43,7 +43,7 @@ TEST_CASE("Simplex failure mode - Degenerate cycling", "[simplex]") { } } -TEST_CASE("Simplex falure mode - Unbounded problem", "[simplex]") { +TEST_CASE("Simplex failure mode - Unbounded problem", "[simplex]") { const auto pivot_rule = GENERATE(SimplexPivotRule::kLexicographic, SimplexPivotRule::kDantzig, SimplexPivotRule::kBland);