revamp non C++ MPSolver export methods

This commit is contained in:
Laurent Perron
2024-10-08 16:03:18 +02:00
parent 12ce2c7820
commit 5384913c34
5 changed files with 28 additions and 33 deletions

View File

@@ -520,15 +520,9 @@ public final class LinearSolverTest {
final MPConstraint c0 = solver.makeConstraint(-infinity, 100.0);
c0.setCoefficient(x1, 5);
final MPModelExportOptions obfuscate = new MPModelExportOptions();
obfuscate.setObfuscate(true);
String out = solver.exportModelAsLpFormat();
String out = solver.exportModelAsLpFormat(/* obfuscate= */ true);
assertThat(out).isNotEmpty();
out = solver.exportModelAsLpFormat(obfuscate);
assertThat(out).isNotEmpty();
out = solver.exportModelAsMpsFormat();
assertThat(out).isNotEmpty();
out = solver.exportModelAsMpsFormat(obfuscate);
out = solver.exportModelAsMpsFormat(/* fixed_format= */ true, /* obfuscate= */ true);
assertThat(out).isNotEmpty();
}
@@ -543,9 +537,9 @@ public final class LinearSolverTest {
assertNotNull(solver);
// Test that forbidden names are renamed.
solver.makeBoolVar("<-%$#!&~-+ ⌂"); // Some illegal name.
String out = solver.exportModelAsLpFormat();
String out = solver.exportModelAsLpFormat(/* obfuscate= */ false);
assertThat(out).isNotEmpty();
out = solver.exportModelAsMpsFormat();
out = solver.exportModelAsMpsFormat(/* fixed_format= */ true, /* obfuscate= */ true);
assertThat(out).isNotEmpty();
}
@@ -611,7 +605,7 @@ public final class LinearSolverTest {
System.out.println("Number of constraints = " + solver.numConstraints());
solver.enableOutput();
System.out.println(solver.exportModelAsLpFormat());
System.out.println(solver.exportModelAsLpFormat(/* obfuscate= */ false));
System.out.println(solver.solve());
}

View File

@@ -188,9 +188,9 @@ PROTO2_RETURN(
/**
* Export the loaded model in LP format.
*/
std::string exportModelAsLpFormat(
const operations_research::MPModelExportOptions& options =
operations_research::MPModelExportOptions()) {
std::string exportModelAsLpFormat(bool obfuscate) {
operations_research::MPModelExportOptions options;
options.obfuscate = obfuscate;
operations_research::MPModelProto model;
$self->ExportModelToProto(&model);
return ExportModelAsLpFormat(model, options).value_or("");
@@ -199,21 +199,21 @@ PROTO2_RETURN(
/**
* Export the loaded model in MPS format.
*/
std::string exportModelAsMpsFormat(
const operations_research::MPModelExportOptions& options =
operations_research::MPModelExportOptions()) {
std::string exportModelAsMpsFormat(bool fixed_format, bool obfuscate) {
operations_research::MPModelExportOptions options;
options.obfuscate = obfuscate;
operations_research::MPModelProto model;
$self->ExportModelToProto(&model);
return ExportModelAsMpsFormat(model, options).value_or("");
}
/**
* Write the model to file in MPS format.
* Write the loaded model to file in MPS format.
*/
bool writeModelToMpsFile(const std::string& filename, bool fixed_format,
bool obfuscated) {
bool obfuscate) {
operations_research::MPModelExportOptions options;
options.obfuscate = obfuscated;
options.obfuscate = obfuscate;
operations_research::MPModelProto model;
$self->ExportModelToProto(&model);
return WriteModelToMpsFile(filename, model, options).ok();