Skip to content

Commit

Permalink
Synchronise structures.txt with proper filename for save/restore
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 committed Jan 13, 2025
1 parent da8e7c6 commit 2e1f54c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
master transmission_line 0
problem-1-1--optim-nb-1.mps transmission_line 840
problem-1-1--optim-nb-1.svf transmission_line 840
6 changes: 4 additions & 2 deletions src/cpp/lpnamer/problem_modifier/MasterGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ MasterGeneration::MasterGeneration(
const std::string &master_formulation, const std::string &solver_name,
std::shared_ptr<ProblemGenerationLog::ProblemGenerationLogger> logger,
SolverLogManager &solver_log_manager)
: logger_(std::move(logger)) {
: logger_(std::move(logger))
, solver_name_(solver_name)
{
add_candidates(links);
write_master_mps(rootPath, master_formulation, solver_name,
additionalConstraints_p, solver_log_manager);
Expand Down Expand Up @@ -68,7 +70,7 @@ void MasterGeneration::write_structure_file(
std::ofstream coupling_file(rootPath / "lp" / STRUCTURE_FILE);
for (auto const &[mps_file_path, candidates_name_and_colId] : structure) {
for (auto const &[candidate_name, colId] : candidates_name_and_colId) {
coupling_file << std::setw(50) << mps_file_path;
coupling_file << std::setw(50) << SolverConfig::FileName(mps_file_path, solver_name_).string();
coupling_file << std::setw(50) << candidate_name;
coupling_file << std::setw(10) << colId;
coupling_file << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ class MasterGeneration {
private: /*members*/
std::vector<Candidate> candidates;
std::shared_ptr<ProblemGenerationLog::ProblemGenerationLogger> logger_;
const std::string solver_name_;
};
#endif //__MASTER_GENERATION__
15 changes: 15 additions & 0 deletions src/cpp/multisolver_interface/SolverConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <utility>
#include "antares-xpansion/xpansion_interfaces/LogUtils.h"

const std::string save_ext = ".svf";
const std::string default_ext = ".mps";

const std::map<std::string, bool> SolverConfig::save_restore_support = {
{"clp", false}, {"cbc", false}, {"coin", false}, {"xpress", true}};
SolverConfig::SolverConfig(std::string solver_name) {
Expand All @@ -26,4 +29,16 @@ void SolverConfig::init(std::string solver_name) {
"Invalid solver name", LOGLOCATION);
}
save_restore_supported = save_restore_support.at(name);
use_save_restore = save_restore_supported;
}
std::filesystem::path SolverConfig::FileName(const std::string& problemName, std::string solverName) {
if (problemName == "master") return {"master"};
SolverConfig solverConfig(std::move(solverName));
std::filesystem::path path{problemName};
if (solverConfig.use_save_restore) {
path.replace_extension(save_ext);
} else {
path.replace_extension(default_ext);
}
return path;
}
4 changes: 3 additions & 1 deletion src/cpp/multisolver_interface/SolverXpress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ void SolverXpress::set_simplex_iter(int iter) {
}

void SolverXpress::save_prob(const std::filesystem::path &filename) {
int status = XPRSsaveas(_xprs, filename.string().c_str());
std::filesystem::path filename_to_use{filename};
filename_to_use.replace_extension(".svf");
int status = XPRSsaveas(_xprs, filename_to_use.string().c_str());
char errmsg[512];
XPRSgetlasterror(_xprs,errmsg);
std::cerr << errmsg << std::endl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <filesystem>
#include <map>
#include <string>

Expand All @@ -8,10 +9,12 @@
* Invariant: name is lowercase
*/
class SolverConfig {
static const std::map<std::string, bool> save_restore_support;
void init(std::string solver_name);

public:

static const std::map<std::string, bool> save_restore_support;
static std::filesystem::path FileName(const std::string& problemName, std::string solverName);

explicit SolverConfig(std::string name);
SolverConfig(SolverConfig&&) = default;
SolverConfig(const SolverConfig&) = default;
Expand All @@ -21,6 +24,7 @@ class SolverConfig {

std::string name;
bool save_restore_supported{false};
bool use_save_restore{false};
bool operator==(const std::string& rhs) const;
SolverConfig& operator=(const std::string& rhs);
};

0 comments on commit 2e1f54c

Please sign in to comment.