Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
binpacking_2d_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#ifndef OR_TOOLS_PACKING_BINPACKING_2D_PARSER_H_
15#define OR_TOOLS_PACKING_BINPACKING_2D_PARSER_H_
16
17#include <string>
18#include <vector>
19
20#include "absl/strings/string_view.h"
21#include "ortools/base/types.h"
22#include "ortools/packing/multiple_dimensions_bin_packing.pb.h"
23
24namespace operations_research {
25namespace packing {
26
27// A BinPacking parser.
28// It supports the following file format:
29// - 2bp:
30// see http://or.dei.unibo.it/library/two-dimensional-bin-packing-problem
31// - Binpacking with conflicts:
32// see http://or.dei.unibo.it/library/bin-packing-problem-conflicts
33//
34// The generated problems have the following characteristics:
35//
36// You have one box with n dimensions. The size of the box is stored in the
37// field box_shape().
38// You need to fit items into this box. Each item has the same number of
39// dimensions and one or more possible shapes (this usually means that
40// you can rotate the item). Each item has a value, and a possible list of
41// conflicts (items you cannot put alongside this item).
42// The objective of the problem is to fit as many items as possible in the box
43// while maximizing the sum of values of selected items. For each item, you need
44// to select the shape and the position of the item in the box.
45// Each item must not overlap (in n dimensions) with any other item.
47 public:
49
50 // Loads the 'instance'th instance of the bin packing problem if the given
51 // file. The instance are 1 based (first is 1).
52 // Only one call to a Load*() function is supported. All the subsequent
53 // calls will do nothing and return false.
54 bool Load2BPFile(absl::string_view file_name, int instance);
55 MultipleDimensionsBinPackingProblem problem() const { return problem_; }
56
57 private:
58 enum LoadStatus { NOT_STARTED = 0, INSTANCE_FOUND = 1, PARSING_FINISHED = 2 };
59
60 void ProcessNew2BpLine(const std::string& line, int instance);
61
62 MultipleDimensionsBinPackingProblem problem_;
63 int num_dimensions_;
64
65 // Temporary.
66 LoadStatus load_status_;
67 int num_items_;
68 int instances_seen_;
69};
70
71} // namespace packing
72} // namespace operations_research
73
74#endif // OR_TOOLS_PACKING_BINPACKING_2D_PARSER_H_
MultipleDimensionsBinPackingProblem problem() const
bool Load2BPFile(absl::string_view file_name, int instance)
In SWIG mode, we don't want anything besides these top-level includes.
int line