Skip to content

Commit

Permalink
Use WriteLP
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes committed Jan 9, 2025
1 parent eb4dd66 commit 970297c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ILinearProblem
/// Solve the problem, returns a IMipSolution
virtual IMipSolution* solve(bool verboseSolver) = 0;

virtual void Write(const std::string& filename) = 0;
virtual void WriteLP(const std::string& filename) = 0;

// Definition of infinity
virtual double infinity() const = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/solver/modeler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ int main(int argc, const char** argv)

if (!parameters.noOutput)
{
logs.info() << "Writing problem.mps...";
auto mps_path = std::filesystem::current_path() / "problem.mps";
pb.Write(mps_path.c_str());
logs.info() << "Writing problem.lp...";
auto mps_path = std::filesystem::current_path() / "problem.lp";
pb.WriteLP(mps_path.c_str());
}

logs.info() << "Launching resolution...";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class OrtoolsLinearProblem: public Api::ILinearProblem
bool isMaximization() const override;

OrtoolsMipSolution* solve(bool verboseSolver) override;
void Write(const std::string& filename) override;
void WriteLP(const std::string& filename) override;

double infinity() const override;

Expand Down
8 changes: 6 additions & 2 deletions src/solver/modeler/ortoolsImpl/linearProblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include <exception>
#include <fstream>
#include <memory>
#include <ortools/linear_solver/linear_solver.h>

Expand Down Expand Up @@ -165,9 +166,12 @@ bool OrtoolsLinearProblem::isMaximization() const
return objective_->maximization();
}

void OrtoolsLinearProblem::Write(const std::string& filename)
void OrtoolsLinearProblem::WriteLP(const std::string& filename)
{
mpSolver_->Write(filename);
std::string out;
mpSolver_->ExportModelAsLpFormat(false, &out);
std::ofstream of(filename);
of << out;
}

MPSolver* OrtoolsLinearProblem::MpSolver() const
Expand Down

0 comments on commit 970297c

Please sign in to comment.