-
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-2299] Enable save/restore with xpress and enable by default (Ben…
…ders) (#987) Follow up #959 handle save/restore option inside Benders. Properly save master and last_iteration master. Note: Introduce new library fmt https://github.com/fmtlib/fmt
- Loading branch information
1 parent
c4683a8
commit d719d22
Showing
19 changed files
with
187 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "antares-xpansion/benders/benders_core/ProblemFormatStream.h" | ||
|
||
auto fmt::formatter<ProblemsFormat>::format(ProblemsFormat problems_format, | ||
format_context &ctx) const -> format_context::iterator | ||
{ | ||
string_view result = "Unknown"; | ||
switch (problems_format) { | ||
case ProblemsFormat::MPS_FILE: | ||
result = "MPS_FILE"; | ||
break; | ||
case ProblemsFormat::SAVED_FILE: | ||
result = "SAVED_FILE"; | ||
break; | ||
default: | ||
result = "Unknown"; | ||
} | ||
return formatter<string_view>::format(result, ctx); | ||
} |
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,37 @@ | ||
|
||
#include <antares-xpansion/benders/benders_core/SolverIO.h> | ||
#include <antares-xpansion/benders/benders_core/ProblemFormatStream.h> | ||
#include <fmt/format.h> | ||
|
||
void SolverIO::write(SolverAbstract* solver, | ||
const std::filesystem::path& path) const { | ||
switch (format_) { | ||
case ProblemsFormat::MPS_FILE: | ||
solver->write_prob_mps(path); | ||
break; | ||
case ProblemsFormat::SAVED_FILE: | ||
solver->save_prob(path); | ||
break; | ||
default: | ||
throw LogUtils::XpansionError<std::runtime_error>( | ||
fmt::format("Unknown file format {} for problem file: {}", format_, path.string()), LOGLOCATION); | ||
} | ||
} | ||
void SolverIO::read(SolverAbstract* solver, | ||
const std::filesystem::path& path) const { | ||
switch (format_) { | ||
case ProblemsFormat::MPS_FILE: | ||
solver->read_prob_mps(path); | ||
break; | ||
case ProblemsFormat::SAVED_FILE: | ||
solver->restore_prob(path); | ||
break; | ||
default: | ||
throw LogUtils::XpansionError<std::runtime_error>( | ||
fmt::format("Unknown file format {} for problem file: {}", format_, path.string()), LOGLOCATION); | ||
} | ||
} | ||
void SolverIO::configure(const std::string& solver_name, ProblemsFormat format) { | ||
solver_config_ = solver_name; | ||
format_ = format; | ||
} |
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
30 changes: 30 additions & 0 deletions
30
.../benders/benders_core/include/antares-xpansion/benders/benders_core/ProblemFormatStream.h
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,30 @@ | ||
#pragma once | ||
|
||
#include <fmt/format.h> | ||
|
||
#include <ostream> | ||
|
||
#include "ProblemFormat.h" | ||
|
||
inline std::ostream &operator<<(std::ostream &stream, | ||
ProblemsFormat const &rhs) { | ||
switch (rhs) { | ||
case ProblemsFormat::MPS_FILE: | ||
stream << "MPS_FILE"; | ||
break; | ||
case ProblemsFormat::SAVED_FILE: | ||
stream << "SAVED_FILE"; | ||
break; | ||
default: | ||
stream << "Unknown"; | ||
} | ||
return stream; | ||
} | ||
|
||
template <> | ||
struct fmt::formatter<ProblemsFormat> : formatter<string_view> { | ||
// parse is inherited from formatter<string_view>. | ||
|
||
auto format(ProblemsFormat problems_format, | ||
format_context &ctx) const -> format_context::iterator; | ||
}; |
14 changes: 14 additions & 0 deletions
14
src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/SolverIO.h
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,14 @@ | ||
#pragma once | ||
|
||
#include "ProblemFormat.h" | ||
#include "antares-xpansion/multisolver_interface/SolverAbstract.h" | ||
#include "antares-xpansion/multisolver_interface/SolverConfig.h" | ||
|
||
class SolverIO { | ||
SolverConfig solver_config_{"Coin"}; | ||
ProblemsFormat format_; | ||
public: | ||
void configure(const std::string& solver_name, ProblemsFormat format); | ||
void write(SolverAbstract* solver, const std::filesystem::path& path) const; | ||
void read(SolverAbstract* solver, const std::filesystem::path& path) const; | ||
}; |
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.