Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
vector_bin_packing_parser.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// 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
27#include "absl/strings/string_view.h"
28#include "ortools/base/types.h"
29#include "ortools/packing/vector_bin_packing.pb.h"
30
31namespace operations_research {
32namespace packing {
33namespace vbp {
34
35class VbpParser {
36 public:
37 // Return true iff there were no error, in which case problem() can be
38 // called to retrieve the parsed problem.
39 bool ParseFile(absl::string_view data_filename);
40
41 // We keep the fully qualified name for SWIG.
42 ::operations_research::packing::vbp::VectorBinPackingProblem problem() const {
43 return vbp_;
44 }
45
46 private:
47 enum LoadStatus {
48 NOT_STARTED,
49 DIMENSION_SECTION,
50 BIN_SECTION,
51 NUMBER_OF_ITEMS_SECTION,
52 ITEM_SECTION,
53 ERROR_FOUND
54 };
55
56 void ProcessLine(const std::string& line);
57 void ReportError(const std::string& line);
58 int strtoint32(absl::string_view word);
59 int64_t strtoint64(absl::string_view word);
60
61 LoadStatus load_status_ = NOT_STARTED;
62 int num_declared_items_ = -1;
63 int num_resources_ = -1;
64
65 VectorBinPackingProblem vbp_;
66};
67
68} // namespace vbp
69} // namespace packing
70} // namespace operations_research
71
72#endif // OR_TOOLS_PACKING_VECTOR_BIN_PACKING_PARSER_H_
::operations_research::packing::vbp::VectorBinPackingProblem problem() const
We keep the fully qualified name for SWIG.
bool ParseFile(absl::string_view data_filename)
In SWIG mode, we don't want anything besides these top-level includes.
int line