Files
ortools-clone/ortools/linear_solver/model_exporter.h

107 lines
3.8 KiB
C
Raw Normal View History

2022-06-17 08:40:20 +02:00
// Copyright 2010-2022 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.
2013-06-11 14:59:00 +00:00
#ifndef OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
#define OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
#include <string>
#include <vector>
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
#include "ortools/base/hash.h"
2018-06-08 16:40:43 +02:00
#include "ortools/base/macros.h"
#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.
struct MPModelExportOptions {
MPModelExportOptions() {}
2013-06-11 14:59:00 +00:00
2019-07-17 07:08:02 -07:00
/// Obfuscates variable and constraint names.
bool obfuscate = false;
2019-07-17 07:08:02 -07:00
/// Whether to log invalid variable and constraint names.
bool log_invalid_names = false;
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.
*/
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.
*/
int max_line_length = 10000;
2013-06-11 14:59:00 +00:00
};
2019-07-17 07:08:02 -07: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
* http://tinyurl.com/cplex-lp-format
* 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-07-17 07:08:02 -07: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());
2020-10-22 23:36:58 +02:00
} // namespace operations_research
2013-06-11 14:59:00 +00:00
2020-10-22 23:36:58 +02:00
#endif // OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_