2025-01-10 11:35:44 +01:00
|
|
|
// Copyright 2010-2025 Google LLC
|
2021-04-01 12:10:10 +02:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
// Parses vector packing data files, and creates a VectorBinPackingProblem
|
|
|
|
|
//
|
|
|
|
|
// The supported file formats are:
|
|
|
|
|
// - vector packing solver: (.vbp files)
|
|
|
|
|
// http://www.dcc.fc.up.pt/~fdabrandao/Vector_Packing_Solver
|
|
|
|
|
|
2025-11-05 11:34:49 +01:00
|
|
|
#ifndef ORTOOLS_PACKING_VECTOR_BIN_PACKING_PARSER_H_
|
|
|
|
|
#define ORTOOLS_PACKING_VECTOR_BIN_PACKING_PARSER_H_
|
2021-04-01 12:10:10 +02:00
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2023-05-24 15:34:42 +02:00
|
|
|
#include "absl/strings/string_view.h"
|
2023-08-03 11:44:09 -07:00
|
|
|
#include "ortools/base/types.h"
|
2021-09-28 15:58:37 +02:00
|
|
|
#include "ortools/packing/vector_bin_packing.pb.h"
|
2021-04-01 12:10:10 +02:00
|
|
|
|
|
|
|
|
namespace operations_research {
|
2021-09-28 15:58:37 +02:00
|
|
|
namespace packing {
|
2021-04-01 12:10:10 +02:00
|
|
|
namespace vbp {
|
|
|
|
|
|
|
|
|
|
class VbpParser {
|
|
|
|
|
public:
|
|
|
|
|
// Return true iff there were no error, in which case problem() can be
|
|
|
|
|
// called to retrieve the parsed problem.
|
2024-07-12 13:56:11 +02:00
|
|
|
bool ParseFile(absl::string_view data_filename);
|
2021-04-01 12:10:10 +02:00
|
|
|
|
|
|
|
|
// We keep the fully qualified name for SWIG.
|
2021-09-28 15:58:37 +02:00
|
|
|
::operations_research::packing::vbp::VectorBinPackingProblem problem() const {
|
2021-04-01 12:10:10 +02:00
|
|
|
return vbp_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
enum LoadStatus {
|
|
|
|
|
NOT_STARTED,
|
|
|
|
|
DIMENSION_SECTION,
|
|
|
|
|
BIN_SECTION,
|
|
|
|
|
NUMBER_OF_ITEMS_SECTION,
|
|
|
|
|
ITEM_SECTION,
|
|
|
|
|
ERROR_FOUND
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void ProcessLine(const std::string& line);
|
|
|
|
|
void ReportError(const std::string& line);
|
2023-05-24 15:34:42 +02:00
|
|
|
int strtoint32(absl::string_view word);
|
|
|
|
|
int64_t strtoint64(absl::string_view word);
|
2021-04-01 12:10:10 +02:00
|
|
|
|
|
|
|
|
LoadStatus load_status_ = NOT_STARTED;
|
|
|
|
|
int num_declared_items_ = -1;
|
|
|
|
|
int num_resources_ = -1;
|
|
|
|
|
|
|
|
|
|
VectorBinPackingProblem vbp_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace vbp
|
2021-09-28 15:58:37 +02:00
|
|
|
} // namespace packing
|
2021-04-01 12:10:10 +02:00
|
|
|
} // namespace operations_research
|
|
|
|
|
|
2025-11-05 11:34:49 +01:00
|
|
|
#endif // ORTOOLS_PACKING_VECTOR_BIN_PACKING_PARSER_H_
|