model_exporter.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
15 #define OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
16 
17 #include <string>
18 #include <vector>
19 
20 #include "absl/strings/str_format.h"
21 #include "ortools/base/hash.h"
22 #include "ortools/base/macros.h"
23 #include "ortools/base/statusor.h"
25 
27 
30 
31  // Obfuscates variable and constraint names.
32  bool obfuscate = false;
33  // Whether to log invalid variable and constraint names.
34  bool log_invalid_names = false;
35 
36  // For .lp files only. Decides whether variables unused in the objective and
37  // constraints are shown when exported to a file.
38  bool show_unused_variables = false;
39  // For .lp files only. Maximum line length in exported files. The default
40  // was chosen so that SCIP can read the files.
41  int max_line_length = 10000;
42 };
43 
44 // Outputs the current model (variables, constraints, objective) as a
45 // std::string encoded in the so-called "CPLEX LP file format" as generated by
46 // SCIP. The LP file format is easily readable by a human.
47 //
48 // Returns false if some error has occurred during execution.
49 // The validity of names is automatically checked. If a variable name or a
50 // constraint name is invalid or non-existent, a new valid name is
51 // automatically generated.
52 //
53 // If 'obfuscated' is true, the variable and constraint names of proto_
54 // are not used. Variable and constraint names of the form "V12345"
55 // and "C12345" are used instead.
56 //
57 // For more information about the different LP file formats:
58 // http://lpsolve.sourceforge.net/5.5/lp-format.htm
59 // The following give a reasonable idea of the CPLEX LP file format:
60 // http://lpsolve.sourceforge.net/5.5/CPLEX-format.htm
61 // http://tinyurl.com/cplex-lp-format
62 // http://www.gurobi.com/documentation/5.1/reference-manual/node871
63 util::StatusOr<std::string> ExportModelAsLpFormat(
64  const MPModelProto& model,
65  const MPModelExportOptions& options = MPModelExportOptions());
66 
67 // Outputs the current model (variables, constraints, objective) as a
68 // std::string encoded in MPS file format, using the "free" MPS format.
69 //
70 // Returns false if some error has occurred during execution. Models with
71 // maximization objectives trigger an error, because MPS can encode only
72 // minimization problems.
73 //
74 // The validity of names is automatically checked. If a variable name or a
75 // constraint name is invalid or non-existent, a new valid name is
76 // automatically generated.
77 //
78 // Name validity and obfuscation works exactly as in ExportModelAsLpFormat().
79 //
80 // For more information about the MPS format:
81 // http://en.wikipedia.org/wiki/MPS_(format)
82 // A close-to-original description coming from OSL:
83 // http://tinyurl.com/mps-format-by-osl
84 // A recent description from CPLEX:
85 // http://tinyurl.com/mps-format-by-cplex
86 // CPLEX extensions:
87 // http://tinyurl.com/mps-extensions-by-cplex
88 // Gurobi's description:
89 // http://www.gurobi.com/documentation/5.1/reference-manual/node869
90 util::StatusOr<std::string> ExportModelAsMpsFormat(
91  const MPModelProto& model,
92  const MPModelExportOptions& options = MPModelExportOptions());
93 
94 } // namespace operations_research
95 
96 #endif // OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_
bool log_invalid_names
Whether to log invalid variable and constraint names.
bool show_unused_variables
For .lp files only.
util::StatusOr< std::string > ExportModelAsMpsFormat(const MPModelProto &model, const MPModelExportOptions &options=MPModelExportOptions())
Outputs the current model (variables, constraints, objective) as a std::string encoded in MPS file fo...
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
bool obfuscate
Obfuscates variable and constraint names.
util::StatusOr< std::string > ExportModelAsLpFormat(const MPModelProto &model, const MPModelExportOptions &options=MPModelExportOptions())
Outputs the current model (variables, constraints, objective) as a std::string encoded in the so-call...