2025-01-10 11:35:44 +01:00
|
|
|
// Copyright 2010-2025 Google LLC
|
2013-06-11 14:59:00 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
2014-07-09 15:18:27 +00:00
|
|
|
|
2025-11-05 11:34:49 +01:00
|
|
|
#ifndef ORTOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
|
|
|
|
|
#define ORTOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
|
2013-06-11 14:59:00 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
2018-01-10 13:21:06 +01:00
|
|
|
|
2024-07-12 17:45:41 +02:00
|
|
|
#include "absl/status/status.h"
|
2020-10-18 16:38:25 +02:00
|
|
|
#include "absl/status/statusor.h"
|
2024-07-12 17:45:41 +02:00
|
|
|
#include "absl/strings/string_view.h"
|
2019-04-18 19:18:48 +02:00
|
|
|
#include "ortools/linear_solver/linear_solver.pb.h"
|
2013-06-11 14:59:00 +00:00
|
|
|
|
|
|
|
|
namespace operations_research {
|
|
|
|
|
|
2019-07-17 07:08:02 -07:00
|
|
|
/// Export options.
|
2019-04-18 19:18:48 +02:00
|
|
|
struct MPModelExportOptions {
|
2019-07-17 07:08:02 -07:00
|
|
|
/// Obfuscates variable and constraint names.
|
2019-04-18 19:18:48 +02:00
|
|
|
bool obfuscate = false;
|
2019-07-17 07:08:02 -07:00
|
|
|
/// Whether to log invalid variable and constraint names.
|
2019-04-18 19:18:48 +02:00
|
|
|
bool log_invalid_names = false;
|
2013-12-20 10:44:30 +00:00
|
|
|
|
2019-07-17 07:08:02 -07:00
|
|
|
/**
|
|
|
|
|
* For .lp files only. Decides whether variables unused in the objective and
|
|
|
|
|
* constraints are shown when exported to a file.
|
|
|
|
|
*/
|
2019-04-18 19:18:48 +02:00
|
|
|
bool show_unused_variables = false;
|
2019-07-17 07:08:02 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For .lp files only. Maximum line length in exported files. The default
|
|
|
|
|
* was chosen so that SCIP can read the files.
|
|
|
|
|
*/
|
2019-04-18 19:18:48 +02:00
|
|
|
int max_line_length = 10000;
|
2013-06-11 14:59:00 +00:00
|
|
|
};
|
|
|
|
|
|
2019-07-17 07:08:02 -07:00
|
|
|
/**
|
2019-11-20 14:28:11 -08:00
|
|
|
* Outputs the current model (variables, constraints, objective) as a string
|
|
|
|
|
* encoded in the so-called "CPLEX LP file format" as generated by SCIP.
|
|
|
|
|
* The LP file format is easily readable by a human.
|
2019-07-17 07:08:02 -07:00
|
|
|
*
|
|
|
|
|
* Returns false if some error has occurred during execution.
|
|
|
|
|
* The validity of names is automatically checked. If a variable name or a
|
|
|
|
|
* constraint name is invalid or non-existent, a new valid name is
|
|
|
|
|
* automatically generated.
|
|
|
|
|
*
|
|
|
|
|
* If 'obfuscated' is true, the variable and constraint names of proto_
|
|
|
|
|
* are not used. Variable and constraint names of the form "V12345"
|
|
|
|
|
* and "C12345" are used instead.
|
|
|
|
|
*
|
|
|
|
|
* For more information about the different LP file formats:
|
|
|
|
|
* http://lpsolve.sourceforge.net/5.5/lp-format.htm
|
|
|
|
|
* The following give a reasonable idea of the CPLEX LP file format:
|
|
|
|
|
* http://lpsolve.sourceforge.net/5.5/CPLEX-format.htm
|
2022-09-27 18:00:48 +02:00
|
|
|
* https://www.ibm.com/docs/en/icos/12.8.0.0?topic=cplex-lp-file-format-algebraic-representation
|
2019-07-17 07:08:02 -07:00
|
|
|
* http://www.gurobi.com/documentation/5.1/reference-manual/node871
|
|
|
|
|
*/
|
2020-10-22 23:36:58 +02:00
|
|
|
absl::StatusOr<std::string> ExportModelAsLpFormat(
|
2020-10-29 14:25:39 +01:00
|
|
|
const MPModelProto& model,
|
|
|
|
|
const MPModelExportOptions& options = MPModelExportOptions());
|
2019-04-18 19:18:48 +02:00
|
|
|
|
2019-07-17 07:08:02 -07:00
|
|
|
/**
|
2019-11-20 14:28:11 -08:00
|
|
|
* Outputs the current model (variables, constraints, objective) as a string
|
|
|
|
|
* encoded in MPS file format, using the "free" MPS format.
|
2019-07-17 07:08:02 -07:00
|
|
|
*
|
|
|
|
|
* Returns false if some error has occurred during execution. Models with
|
|
|
|
|
* maximization objectives trigger an error, because MPS can encode only
|
|
|
|
|
* minimization problems.
|
|
|
|
|
*
|
|
|
|
|
* The validity of names is automatically checked. If a variable name or a
|
|
|
|
|
* constraint name is invalid or non-existent, a new valid name is
|
|
|
|
|
* automatically generated.
|
|
|
|
|
*
|
|
|
|
|
* Name validity and obfuscation works exactly as in ExportModelAsLpFormat().
|
|
|
|
|
*
|
|
|
|
|
* For more information about the MPS format:
|
|
|
|
|
* http://en.wikipedia.org/wiki/MPS_(format)
|
|
|
|
|
* A close-to-original description coming from OSL:
|
|
|
|
|
* http://tinyurl.com/mps-format-by-osl
|
|
|
|
|
* A recent description from CPLEX:
|
|
|
|
|
* http://tinyurl.com/mps-format-by-cplex
|
|
|
|
|
* CPLEX extensions:
|
|
|
|
|
* http://tinyurl.com/mps-extensions-by-cplex
|
|
|
|
|
* Gurobi's description:
|
|
|
|
|
* http://www.gurobi.com/documentation/5.1/reference-manual/node869
|
|
|
|
|
*/
|
2020-10-22 23:36:58 +02:00
|
|
|
absl::StatusOr<std::string> ExportModelAsMpsFormat(
|
2020-10-29 14:25:39 +01:00
|
|
|
const MPModelProto& model,
|
|
|
|
|
const MPModelExportOptions& options = MPModelExportOptions());
|
2019-04-18 19:18:48 +02:00
|
|
|
|
2024-07-12 17:45:41 +02:00
|
|
|
/**
|
|
|
|
|
* Write the current model (variables, constraints, objective) to a file in MPS
|
|
|
|
|
* file format, using the "free" MPS format.
|
|
|
|
|
*
|
2024-08-02 10:55:25 -07:00
|
|
|
* See ExportModelAsMpsFormat().
|
2024-07-12 17:45:41 +02:00
|
|
|
*/
|
|
|
|
|
absl::Status WriteModelToMpsFile(
|
|
|
|
|
absl::string_view filename, const MPModelProto& model,
|
|
|
|
|
const MPModelExportOptions& options = MPModelExportOptions());
|
|
|
|
|
|
2020-10-22 23:36:58 +02:00
|
|
|
} // namespace operations_research
|
2013-06-11 14:59:00 +00:00
|
|
|
|
2025-11-05 11:34:49 +01:00
|
|
|
#endif // ORTOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
|