Skip to content

Commit

Permalink
Fix numerically small rhs in cut, update tolerance for zero subgradient
Browse files Browse the repository at this point in the history
  • Loading branch information
tbittar committed Jan 29, 2025
1 parent 9611fdc commit fbf0ebe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/SubproblemWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void SubproblemWorker::fix_to(Point const &x0) const {
solver_chgbounds(_solver, indexes, bndtypes, values);
}

static double INTTOL = 1e-4;
static double INTTOL = 5e-3;
void SubproblemWorker::roundIfWithinTolerance(std::vector<double> &values,
double tolerance) const {
std::transform(values.begin(), values.end(), values.begin(),
Expand Down
17 changes: 14 additions & 3 deletions src/cpp/benders/benders_core/WorkerMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ WorkerMaster::WorkerMaster(VariableMap const &variable_map,
const std::string &solver_name, const int log_level,
int subproblems_count,
SolverLogManager &solver_log_manager,
const bool mps_has_alpha, Logger logger, ProblemsFormat format)
const bool mps_has_alpha, Logger logger,
ProblemsFormat format)
: Worker(variable_map, path_to_mps, std::move(logger)),
subproblems_count{subproblems_count},
_mps_has_alpha{mps_has_alpha}
{
_mps_has_alpha{mps_has_alpha} {
_is_master = true;

init(solver_name, log_level, solver_log_manager, format);
Expand Down Expand Up @@ -237,6 +237,15 @@ void WorkerMaster::define_matval_mclind_for_index(
matval.back() = -1;
}

static double ISZEROTOL = 5e-3;
void WorkerMaster::roundIfWithinTolerance(std::vector<double> &values,
double tolerance) const {
std::transform(values.begin(), values.end(), values.begin(),
[tolerance](double value) -> double {
return std::abs(value) < tolerance ? 0 : value;
});
}

/*!
* \brief Add one benders cut to a problem
*
Expand All @@ -260,6 +269,8 @@ void WorkerMaster::addSubproblemCut(int i, Point const &s, Point const &x_cut,
DefineRhsWithMasterVariable(s, x_cut, rhs, rowrhs);
define_matval_mclind_for_index(i, s, matval, mclind);

roundIfWithinTolerance(rowrhs, ISZEROTOL);

solver_addrows(*_solver, rowtype, rowrhs, {}, mstart, mclind, matval);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class WorkerMaster : public Worker {
WorkerMaster(VariableMap const &variable_map,
const std::filesystem::path &path_to_mps,
const std::string &solver_name, int log_level,
int subproblems_count,
SolverLogManager&solver_log_manager,
int subproblems_count, SolverLogManager &solver_log_manager,
bool mps_has_alpha, Logger logger, ProblemsFormat format);
~WorkerMaster() override = default;

Expand Down Expand Up @@ -63,4 +62,5 @@ class WorkerMaster : public Worker {
void _set_nb_units_var_ids();
void roundXVarIfWithinTolerance(std::vector<double> &values,
double tolerance);
void roundIfWithinTolerance(std::vector<double> &values, double tolerance) const;
};

0 comments on commit fbf0ebe

Please sign in to comment.