Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
mps_reader.h
Go to the documentation of this file.
1// Copyright 2010-2024 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// A reader for files in the MPS format.
15// see http://lpsolve.sourceforge.net/5.5/mps-format.htm
16// and http://www.ici.ro/camo/language/ml11.htm.
17//
18// MPS stands for Mathematical Programming System.
19//
20// The format was invented by IBM in the 60's, and has become the de facto
21// standard. We developed this reader to be able to read benchmark data files.
22// Using the MPS file format for new models is discouraged.
23
24#ifndef OR_TOOLS_LP_DATA_MPS_READER_H_
25#define OR_TOOLS_LP_DATA_MPS_READER_H_
26
27#include <string>
28
29#include "absl/base/attributes.h"
30#include "absl/status/status.h"
31#include "absl/status/statusor.h"
32#include "absl/strings/string_view.h"
33#include "ortools/linear_solver/linear_solver.pb.h"
35
36namespace operations_research {
37namespace glop {
38
39// Parses an MPS model from a string.
40absl::StatusOr<MPModelProto> MpsDataToMPModelProto(absl::string_view mps_data);
41
42// Parses an MPS model from a file.
43absl::StatusOr<MPModelProto> MpsFileToMPModelProto(absl::string_view mps_file);
44
45// Implementation class. Please use the 2 functions above.
46//
47// Reads a linear program in the mps format.
48//
49// All Parse() methods clear the previously parsed instance and store the result
50// in the given Data class.
51//
52// TODO(user): Remove the MPSReader class.
53class ABSL_DEPRECATED("Use the direct methods instead") MPSReader {
54 public:
55 enum Form { AUTO_DETECT, FREE, FIXED };
56
57 // Parses instance from a file.
58 absl::Status ParseFile(absl::string_view file_name, LinearProgram* data,
59 Form form = AUTO_DETECT);
60
61 absl::Status ParseFile(absl::string_view file_name, MPModelProto* data,
62 Form form = AUTO_DETECT);
63 // Loads instance from string. Useful with MapReduce. Automatically detects
64 // the file's format (free or fixed).
65 absl::Status ParseProblemFromString(absl::string_view source,
66 LinearProgram* data,
67 MPSReader::Form form = AUTO_DETECT);
68 absl::Status ParseProblemFromString(absl::string_view source,
69 MPModelProto* data,
70 MPSReader::Form form = AUTO_DETECT);
71};
72
73} // namespace glop
74} // namespace operations_research
75
76#endif // OR_TOOLS_LP_DATA_MPS_READER_H_
absl::StatusOr< MPModelProto > MpsFileToMPModelProto(absl::string_view mps_file)
Parses an MPS model from a file.
absl::StatusOr< MPModelProto > MpsDataToMPModelProto(absl::string_view mps_data)
Parses an MPS model from a string.
class ABSL_DEPRECATED("Use the direct methods instead") MPSReader
Definition mps_reader.h:53
In SWIG mode, we don't want anything besides these top-level includes.