-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ant-2380] improving maintainability (#965)
This pull request includes several changes to the `BendersBase` class and related components to improve the handling of criterion computations and refactor the codebase. The most important changes include the renaming of `OuterLoopInputData` to `CriterionInputData`, the addition of the `CouplingMapGenerator` class, and the refactoring of methods related to criterion computations. ### Refactoring and Renaming: * Renamed `OuterLoopInputData` to `CriterionInputData` and updated all related references in `CriterionComputation.cpp` and `CriterionInputDataReader.cpp` [[1]](diffhunk://#diff-d0e3218aceff8618ccc9bf1b8ee0ed104175f6db50b089e0e2fd46c4372daf88L32-R44) [[2]](diffhunk://#diff-68cda14d5a160cbb0d388b11de54f391a6bf6aa2a2b46ee4f97dba03c963fedcL1-R1) [[3]](diffhunk://#diff-68cda14d5a160cbb0d388b11de54f391a6bf6aa2a2b46ee4f97dba03c963fedcL13-R83). * Removed the `OuterloopOptionsFile` method from `BendersBase` and updated the `setCriterionsComputation` method to `setCriterionComputationInputs` [[1]](diffhunk://#diff-debcbcbc301c4e3ac700146a75db0a05d686e1d30f20ce42019e1e77acf903a5L25-L29) [[2]](diffhunk://#diff-36a63705b7409199b9d45a79b1f80f656b02e9f5a4d1a2c41703742ad41a76c2L98-R103) [[3]](diffhunk://#diff-36a63705b7409199b9d45a79b1f80f656b02e9f5a4d1a2c41703742ad41a76c2L226-R225). ### Addition of CouplingMapGenerator: * Added a new `CouplingMapGenerator` class to handle the building of input maps from structure files, encapsulating this functionality [[1]](diffhunk://#diff-e5c5805ed18be849a2bcfcaf5f3a459394022162fe8c0b168ad0164688aac93eR1-R52) [[2]](diffhunk://#diff-2a07bb398e3d2d00e5899c2b0c02ae4da892bdcf20158651d1a4ce4c1a7b49c3R1-R9). ### Updates to Criterion Computation: * Refactored `CriterionComputation` to use `CriterionInputData` instead of `OuterLoopInputData`, updating methods and member variables accordingly [[1]](diffhunk://#diff-d0e3218aceff8618ccc9bf1b8ee0ed104175f6db50b089e0e2fd46c4372daf88L32-R44) [[2]](diffhunk://#diff-debcbcbc301c4e3ac700146a75db0a05d686e1d30f20ce42019e1e77acf903a5L420-R415) [[3]](diffhunk://#diff-debcbcbc301c4e3ac700146a75db0a05d686e1d30f20ce42019e1e77acf903a5R1045-R1054). ### CMakeLists and File Updates: * Updated `CMakeLists.txt` to reflect the renaming of files and the addition of new source files (`CouplingMapGenerator.cpp`) [[1]](diffhunk://#diff-89a10ccfdde5ce80ade12658a06704594fe58b1f86f162a55bc68252f382ff09L26-R28) [[2]](diffhunk://#diff-89a10ccfdde5ce80ade12658a06704594fe58b1f86f162a55bc68252f382ff09L44-L50). ### Removal of Unused Methods: * Removed the `build_input` method from `common.cpp` as its functionality is now encapsulated in `CouplingMapGenerator`.
- Loading branch information
Showing
33 changed files
with
530 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <antares-xpansion/benders/benders_core/CouplingMapGenerator.h> | ||
#include <antares-xpansion/xpansion_interfaces/LoggerUtils.h> | ||
|
||
struct InvalidStructureFile : LogUtils::XpansionError<std::runtime_error> { | ||
using LogUtils::XpansionError<std::runtime_error>::XpansionError; | ||
}; | ||
|
||
/*! | ||
* \brief Build the input from the structure file | ||
* | ||
* Function to build the map linking each problem name to its variables and | ||
*their id | ||
* | ||
* \param root : root of the structure file | ||
* | ||
* \param summary_name : name of the structure file | ||
* | ||
* \param coupling_map : empty map to increment | ||
* | ||
* \note The id in the coupling_map is that of the variable in the solver | ||
*responsible for the creation of the structure file. | ||
*/ | ||
CouplingMap CouplingMapGenerator::BuildInput( | ||
const std::filesystem::path& structure_path, | ||
std::shared_ptr<ILoggerXpansion> logger, const std::string& context) { | ||
CouplingMap coupling_map; | ||
std::ifstream summary(structure_path, std::ios::in); | ||
if (!summary) { | ||
auto log_location = LOGLOCATION; | ||
std::ostringstream msg; | ||
msg << "Cannot open structure file " << structure_path << std::endl; | ||
logger->display_message(msg.str(), LogUtils::LOGLEVEL::FATAL, log_location); | ||
throw InvalidStructureFile( | ||
PrefixMessage(LogUtils::LOGLEVEL::FATAL, context), msg.str(), | ||
log_location); | ||
} | ||
std::string line; | ||
|
||
while (std::getline(summary, line)) { | ||
std::stringstream buffer(line); | ||
std::string problem_name; | ||
std::string variable_name; | ||
int variable_id; | ||
buffer >> problem_name; | ||
buffer >> variable_name; | ||
buffer >> variable_id; | ||
coupling_map[problem_name][variable_name] = variable_id; | ||
} | ||
|
||
summary.close(); | ||
return coupling_map; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.