Skip to content

Commit

Permalink
Add WriteModelToMpsFile to MPSolver in Java/Python/.NET
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Oct 7, 2024
1 parent ae517c0 commit 5912937
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ortools/linear_solver/csharp/linear_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ CONVERT_VECTOR(operations_research::MPVariable, MPVariable)
// Extend code.
%unignore operations_research::MPSolver::ExportModelAsLpFormat(bool);
%unignore operations_research::MPSolver::ExportModelAsMpsFormat(bool, bool);
%unignore operations_research::MPSolver::WriteModelToMpsFile(
const std::string& filename, bool, bool);
%unignore operations_research::MPSolver::SetHint(
const std::vector<operations_research::MPVariable*>&,
const std::vector<double>&);
Expand All @@ -187,6 +189,15 @@ CONVERT_VECTOR(operations_research::MPVariable, MPVariable)
return ExportModelAsMpsFormat(model, options).value_or("");
}

bool WriteModelToMpsFile(const std::string& filename, bool fixed_format,
bool obfuscated) {
operations_research::MPModelExportOptions options;
options.obfuscate = obfuscated;
operations_research::MPModelProto model;
$self->ExportModelToProto(&model);
return WriteModelToMpsFile(filename, model, options).ok();
}

void SetHint(const std::vector<operations_research::MPVariable*>& variables,
const std::vector<double>& values) {
if (variables.size() != values.size()) {
Expand Down
12 changes: 12 additions & 0 deletions ortools/linear_solver/java/linear_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ PROTO2_RETURN(
return ExportModelAsMpsFormat(model, options).value_or("");
}

/**
* Write the model to file in MPS format.
*/
bool writeModelToMpsFile(const std::string& filename, bool fixed_format,
bool obfuscated) {
operations_research::MPModelExportOptions options;
options.obfuscate = obfuscated;
operations_research::MPModelProto model;
$self->ExportModelToProto(&model);
return WriteModelToMpsFile(filename, model, options).ok();
}

/**
* Sets a hint for solution.
*
Expand Down
9 changes: 9 additions & 0 deletions ortools/linear_solver/python/linear_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ from ortools.linear_solver.python.linear_solver_natural_api import VariableExpr
return ExportModelAsMpsFormat(model, options).value_or("");
}

bool WriteModelToMpsFile(const std::string& filename, bool fixed_format,
bool obfuscated) {
operations_research::MPModelExportOptions options;
options.obfuscate = obfuscated;
operations_research::MPModelProto model;
$self->ExportModelToProto(&model);
return WriteModelToMpsFile(filename, model, options).ok();
}

/// Set a hint for solution.
///
/// If a feasible or almost-feasible solution to the problem is already known,
Expand Down

0 comments on commit 5912937

Please sign in to comment.