OR-Tools  9.6
vector_bin_packing_parser.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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 // Parses vector packing data files, and creates a VectorBinPackingProblem
15 //
16 // The supported file formats are:
17 // - vector packing solver: (.vbp files)
18 // http://www.dcc.fc.up.pt/~fdabrandao/Vector_Packing_Solver
19 
20 #ifndef OR_TOOLS_PACKING_VECTOR_BIN_PACKING_PARSER_H_
21 #define OR_TOOLS_PACKING_VECTOR_BIN_PACKING_PARSER_H_
22 
23 #include <cstdint>
24 #include <string>
25 #include <vector>
26 
28 #include "ortools/packing/vector_bin_packing.pb.h"
29 
30 namespace operations_research {
31 namespace packing {
32 namespace vbp {
33 
34 class VbpParser {
35  public:
36  // Return true iff there were no error, in which case problem() can be
37  // called to retrieve the parsed problem.
38  bool ParseFile(const std::string& data_filename);
39 
40  // We keep the fully qualified name for SWIG.
41  ::operations_research::packing::vbp::VectorBinPackingProblem problem() const {
42  return vbp_;
43  }
44 
45  private:
46  enum LoadStatus {
47  NOT_STARTED,
48  DIMENSION_SECTION,
49  BIN_SECTION,
50  NUMBER_OF_ITEMS_SECTION,
51  ITEM_SECTION,
52  ERROR_FOUND
53  };
54 
55  void ProcessLine(const std::string& line);
56  void ReportError(const std::string& line);
57  int strtoint32(const std::string& word);
58  int64_t strtoint64(const std::string& word);
59 
60  LoadStatus load_status_ = NOT_STARTED;
61  int num_declared_items_ = -1;
62  int num_resources_ = -1;
63 
64  VectorBinPackingProblem vbp_;
65 };
66 
67 } // namespace vbp
68 } // namespace packing
69 } // namespace operations_research
70 
71 #endif // OR_TOOLS_PACKING_VECTOR_BIN_PACKING_PARSER_H_
bool ParseFile(const std::string &data_filename)
::operations_research::packing::vbp::VectorBinPackingProblem problem() const
Collection of objects used to extend the Constraint Solver library.
int line
Definition: parse_proto.cc:31