From 0d841b9c277e4c3d9a30495a154672d29424e846 Mon Sep 17 00:00:00 2001 From: tbittar Date: Wed, 13 Dec 2023 11:09:11 +0100 Subject: [PATCH] Clean subproblem cut data structures (#731) * Clean subproblem cut data structures * Remove deleted file from CMakeLists --------- Co-authored-by: Thomas Bittar --- src/cpp/benders/benders_core/CMakeLists.txt | 1 - .../benders/benders_core/SubproblemCut.cpp | 123 ------------------ src/cpp/benders/benders_core/WorkerMaster.cpp | 3 +- .../benders_core/include/SubproblemCut.h | 62 +-------- 4 files changed, 3 insertions(+), 186 deletions(-) delete mode 100644 src/cpp/benders/benders_core/SubproblemCut.cpp diff --git a/src/cpp/benders/benders_core/CMakeLists.txt b/src/cpp/benders/benders_core/CMakeLists.txt index 05f6af399..6386208cf 100644 --- a/src/cpp/benders/benders_core/CMakeLists.txt +++ b/src/cpp/benders/benders_core/CMakeLists.txt @@ -19,7 +19,6 @@ add_library (benders_core STATIC ${CMAKE_CURRENT_SOURCE_DIR}/SimulationOptions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/BendersBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/WorkerMaster.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/SubproblemCut.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common.cpp ${CMAKE_CURRENT_SOURCE_DIR}/BendersStructsDatas.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Worker.cpp diff --git a/src/cpp/benders/benders_core/SubproblemCut.cpp b/src/cpp/benders/benders_core/SubproblemCut.cpp deleted file mode 100644 index 2cc77678f..000000000 --- a/src/cpp/benders/benders_core/SubproblemCut.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "SubproblemCut.h" - -/*! - * \brief Constructor of a slave cut handler from slave cut data - * - * \param data : pointer to a slave cut data - */ -SubproblemCutDataHandler::SubproblemCutDataHandler(SubproblemCutDataPtr& data) - : _data(data) { - // get_subgradient().clear(); - get_int().resize(MAXINTEGER); - get_dbl().resize(MAXDBL); - get_str().resize(SubproblemCutStr::MAXSTR); -} - -/*! - * \brief Get subgradient of a slave cut - */ -Point& SubproblemCutDataHandler::get_subgradient() { - return _data->first.first.first; -} - -/*! - * \brief Get int variable of a slave cut - */ -IntVector& SubproblemCutDataHandler::get_int() { - return _data->first.first.second; -} - -/*! - * \brief Get double variable of a slave cut - */ -DblVector& SubproblemCutDataHandler::get_dbl() { return _data->first.second; } - -/*! - * \brief Get string variable of a slave cut - */ -StrVector& SubproblemCutDataHandler::get_str() { return _data->second; } - -/*! - * \brief Get int variable of a slave cut (SIMPLEXITE, LPSTATUS) - */ -int& SubproblemCutDataHandler::get_int(SubproblemCutInt key) { - return get_int()[key]; -} - -/*! - * \brief Get double variable of a slave cut (SLAVECOST, ALPHA_I, - * SUBPROBLEM_TIMER) - */ -double& SubproblemCutDataHandler::get_dbl(SubproblemCutDbl key) { - return get_dbl()[key]; -} - -/*! - * \brief Get string variable of a slave cut - */ -std::string& SubproblemCutDataHandler::get_str(SubproblemCutStr key) { - return get_str()[key]; -} - -/*! - * \brief Get subgradient of a slave cut - */ -Point const& SubproblemCutDataHandler::get_subgradient() const { - return _data->first.first.first; -} - -/*! - * \brief Get int variable of a slave cut - */ -IntVector const& SubproblemCutDataHandler::get_int() const { - return _data->first.first.second; -} - -/*! - * \brief Get double variable of a slave cut - */ -DblVector const& SubproblemCutDataHandler::get_dbl() const { - return _data->first.second; -} - -/*! - * \brief Get string variable of a slave cut - */ -StrVector const& SubproblemCutDataHandler::get_str() const { - return _data->second; -} - -/*! - * \brief Get int variable of a slave cut (SIMPLEXITE, LPSTATUS) - */ -int SubproblemCutDataHandler::get_int(SubproblemCutInt key) const { - return get_int()[key]; -} - -/*! - * \brief Get double variable of a slave cut (SLAVECOST, ALPHA_I, - * SUBPROBLEM_TIMER) - */ -double SubproblemCutDataHandler::get_dbl(SubproblemCutDbl key) const { - return get_dbl()[key]; -} - -/*! - * \brief Get string variable of a slave cut - */ -std::string const& SubproblemCutDataHandler::get_str( - SubproblemCutStr key) const { - return get_str()[key]; -} - -/*! - * \brief Function to print a slave cut handler - * - * \param stream : output stream - */ -void SubproblemCutDataHandler::print(std::ostream& stream) const { - std::stringstream buffer; - buffer << get_dbl(SUBPROBLEM_COST) << get_subgradient(); - stream << buffer.str(); - stream << " Simplexiter " << get_int(SIMPLEXITER) << " | "; -} diff --git a/src/cpp/benders/benders_core/WorkerMaster.cpp b/src/cpp/benders/benders_core/WorkerMaster.cpp index 1758511fd..92dcb1bd6 100644 --- a/src/cpp/benders/benders_core/WorkerMaster.cpp +++ b/src/cpp/benders/benders_core/WorkerMaster.cpp @@ -212,7 +212,8 @@ void WorkerMaster::define_matval_mclind_for_index( // TODO : Refactor this with add_cut and define_matval_mclind(_for_index) void WorkerMaster::addSubproblemCut(int i, Point const &s, Point const &x_cut, double const &rhs) const { - // cut is -rhs >= overall_subpb_cost_under_approx + s^(x-x_cut) + // cut is -theta_i + s.x <= -subproblem_cost + s.x_cut (in the solver) + // i.e. theta_i >= subproblem_cost + s.(x - x_cut) (human form) int ncoeffs(1 + (int)s.size()); std::vector rowtype(1, 'L'); std::vector rowrhs(1, 0); diff --git a/src/cpp/benders/benders_core/include/SubproblemCut.h b/src/cpp/benders/benders_core/include/SubproblemCut.h index e0bf88076..58fef4899 100644 --- a/src/cpp/benders/benders_core/include/SubproblemCut.h +++ b/src/cpp/benders/benders_core/include/SubproblemCut.h @@ -21,64 +21,4 @@ struct SubProblemData { ar &lpstatus; } }; -using SubProblemDataMap = std::map; - -typedef std::pair SubproblemCutData1; -typedef std::pair SubproblemCutData2; -typedef std::pair SubproblemCutData3; -typedef SubproblemCutData3 SubproblemCutData; - -typedef std::shared_ptr SubproblemCutDataPtr; - -typedef std::map SubproblemCutPackage; -typedef std::vector AllCutPackage; - -class SubproblemCutTrimmer; - -class SubproblemCutDataHandler; -typedef std::shared_ptr SubproblemCutDataHandlerPtr; - -typedef std::vector> DynamicAggregateCuts; - -typedef std::set - SubproblemCutDataHandlerPtrSet; - -void BuildSubproblemCutData(SubproblemCutData &); - -const int MAXINTEGER = 2; -enum SubproblemCutInt { SIMPLEXITER = 0, LPSTATUS }; - -const int MAXDBL = 2; -enum SubproblemCutDbl { SUBPROBLEM_COST = 0, ALPHA_I, SUBPROBLEM_TIMER }; -enum SubproblemCutStr { MAXSTR = 0 }; - -class SubproblemCutDataHandler { - public: - Point &get_subgradient(); - IntVector &get_int(); - DblVector &get_dbl(); - StrVector &get_str(); - - int &get_int(SubproblemCutInt); - double &get_dbl(SubproblemCutDbl); - std::string &get_str(SubproblemCutStr); - - int get_int(SubproblemCutInt) const; - double get_dbl(SubproblemCutDbl) const; - std::string const &get_str(SubproblemCutStr) const; - - Point const &get_subgradient() const; - IntVector const &get_int() const; - DblVector const &get_dbl() const; - StrVector const &get_str() const; - void print(std::ostream &stream) const; - - public: - explicit SubproblemCutDataHandler(SubproblemCutDataPtr const &data); - explicit SubproblemCutDataHandler(SubproblemCutDataPtr &data); - virtual ~SubproblemCutDataHandler() = default; - - SubproblemCutDataPtr _data; -}; - -std::ostream &operator<<(std::ostream &stream, SubproblemCutData const &rhs); +using SubProblemDataMap = std::map; \ No newline at end of file