Skip to content

Commit

Permalink
Fix mps/svf
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 committed Jan 10, 2025
1 parent d5a86f1 commit 2f99513
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/cpp/lpnamer/problem_modifier/FileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
#include "antares-xpansion/lpnamer/problem_modifier/LinkProblemsGenerator.h"

void FileWriter::Write_problem(Problem *in_prblm, const std::filesystem::path &output_file) {
if (output_file.extension() == ".mps") {
in_prblm->write_prob_mps(output_file);
} else {
in_prblm->save_prob(output_file);
}
in_prblm->save_prob(output_file);
}

FileWriter::FileWriter(std::filesystem::path lp_dir)
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/lpnamer/problem_modifier/MasterGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ void MasterGeneration::write_master_mps(
master_problem._name = "master";
switch (save_mode_) {
case SaveMode::MPS:
master_problem.write_prob_mps(rootPath / "lp" / "master");
master_problem.write_prob_mps(rootPath / "lp" / "master.mps");
break;
case SaveMode::SAVE:
master_problem.save_prob(rootPath / "lp" / "master");
master_problem.save_prob(rootPath / "lp" / "master.svf");
break;
default:
throw std::runtime_error("Unknown save mode " + std::to_string(static_cast<int>(save_mode_)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ XpansionProblemsFromAntaresProvider::provideProblems(
AntaresProblemToXpansionProblemTranslator::translateToXpansionProblem(
antares_hebdo_problems, problem_id.year, problem_id.week,
solver_name, solver_log_manager);
problem->_name = std::filesystem::path(problem->_name).replace_extension(".svf");
xpansion_problems.push_back(problem);
}
return xpansion_problems;
Expand Down
14 changes: 10 additions & 4 deletions src/cpp/multisolver_interface/SolverCbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ void SolverCbc::write_prob_mps(const std::filesystem::path &filename) {
if (filename_to_use.extension() != ".mps") {
filename_to_use.replace_extension(".mps");
}
writer.writeMps(filename_to_use.string().c_str(), 0 /*gzip it*/, 1, 1, nullptr, 0,
nullptr);
writer.writeMps(filename_to_use.string().c_str(), 0 /*gzip it*/, 1, 1,
nullptr, 0, nullptr);
}

void SolverCbc::write_prob_lp(const std::filesystem::path &filename) {
Expand Down Expand Up @@ -186,8 +186,14 @@ void SolverCbc::setClpSimplexRowNamesFromInnerSolver(ClpSimplex *clps) const {
}

void SolverCbc::read_prob_mps(const std::filesystem::path &prob_name) {
int status = _clp_inner_solver.readMps(prob_name.string().c_str());
zero_status_check(status, " read problem "s + prob_name.string(),
auto filename_to_use = prob_name;
if (filename_to_use.extension() != ".mps") {
filename_to_use.replace_extension(".mps");
}
int status = _clp_inner_solver.readMps(filename_to_use.string().c_str());
zero_status_check(status,
" read problem "s + prob_name.string() + " , filename : "s +
filename_to_use.string(),
LOGLOCATION);
defineCbcModelFromInnerSolver();
}
Expand Down
8 changes: 6 additions & 2 deletions src/cpp/multisolver_interface/SolverClp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ void SolverClp::write_basis(const std::filesystem::path &filename) {
}

void SolverClp::read_prob_mps(const std::filesystem::path &filename) {
int status = _clp.readMps(filename.string().c_str(), true, false);
zero_status_check(status, " Clp readMps "s + filename.string(), LOGLOCATION);
auto filename_to_use = filename;
if (filename_to_use.extension() != ".mps") {
filename_to_use.replace_extension(".mps");
}
int status = _clp.readMps(filename_to_use.string().c_str(), true, false);
zero_status_check(status, " Clp readMps "s + filename_to_use.string(), LOGLOCATION);
}

void SolverClp::read_prob_lp(const std::filesystem::path &filename) {
Expand Down

0 comments on commit 2f99513

Please sign in to comment.