Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
set_cover_reader.h
Go to the documentation of this file.
1// Copyright 2010-2025 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_ALGORITHMS_SET_COVER_READER_H_
15#define OR_TOOLS_ALGORITHMS_SET_COVER_READER_H_
16
17#include "absl/strings/string_view.h"
19
20namespace operations_research {
21
22// Readers for set covering problems at
23// http://people.brunel.ac.uk/~mastjjb/jeb/orlib/scpinfo.html
24// All the instances have either the Beasley or the rail format.
25
26// There is currently NO error handling, as the files are in a limited number.
27// TODO(user): add proper error handling.
28
29// Also, note that the indices in the files, when mentioned, start from 1, while
30// SetCoverModel starts from 0, The translation is done at read time.
31
32// Reads a rail set cover problem create by Beasley and returns a SetCoverModel.
33// The format of all of these 80 data files is:
34// number of rows (m), number of columns (n)
35// for each column j, (j=1,...,n): the cost of the column c(j)
36// for each row i (i=1,...,m): the number of columns which cover
37// row i followed by a list of the columns which cover row i
38// The columns and rows are 1-indexed with this file format.
39// The translation to 0-indexing is done at read time.
40SetCoverModel ReadOrlibScp(absl::string_view filename);
41
42// Reads a rail set cover problem and returns a SetCoverModel.
43// The format of these test problems is:
44// number of rows (m), number of columns (n)
45// for each column j (j=1,...,n): the cost of the column, the
46// number of rows that it covers followed by a list of the rows
47// that it covers.
48// The columns and rows are 1-indexed with this file format.
49// The translation to 0-indexing is done at read time.
50SetCoverModel ReadOrlibRail(absl::string_view filename);
51
52// Reads a file in the FIMI / .dat file format. FIMI stands for "Frequent
53// Itemset Mining Implementations".
54// The file is given column-by-column, with each column containing a space-
55// separated list of elements terminating with a newline. The elements are
56// 0-indexed.
57// The cost of each subset is 1.
58SetCoverModel ReadFimiDat(absl::string_view filename);
59
60// Reads a set cover problem from a SetCoverProto.
61// The proto is either read from a binary (if binary is true) or a text file.
62SetCoverModel ReadSetCoverProto(absl::string_view filename, bool binary);
63
64// Writers for the Beasley and Rail formats.
65// The translation of indices from 0 to 1-indexing is done at write time.
66void WriteOrlibScp(const SetCoverModel& model, absl::string_view filename);
67void WriteOrlibRail(const SetCoverModel& model, absl::string_view filename);
68
69// Writes a set cover problem to a SetCoverProto.
70// The proto is either written to a binary (if binary is true) or a text file.
71// The model is modified (its columns are sorted) in-place when the proto is
72// generated.
73void WriteSetCoverProto(const SetCoverModel& model, absl::string_view filename,
74 bool binary);
75
76// Reads a set cover solution from a text file.
77// The format of the file is:
78// number of columns (n)
79// number of selected columns (k)
80// for each i (j=1,...,k): 1 if column[i] is selected, 0 otherwise.
81// The solution is 0-indexed.
82SubsetBoolVector ReadSetCoverSolutionText(absl::string_view filename);
83
84// Reads a set cover solution from a SetCoverSolutionResponse proto.
85// The proto is either read from a binary (if binary is true) or a text file.
86// The solution is 0-indexed.
87SubsetBoolVector ReadSetCoverSolutionProto(absl::string_view filename,
88 bool binary);
89
90// Writes a set cover solution to a text file.
91// The format of the file is:
92// number of columns (n)
93// number of selected columns (k)
94// for each i (j=1,...,k): 1 if column[i] is selected, 0 otherwise.
95// The solution is 0-indexed.
98 absl::string_view filename);
99
100// Writes a set cover solution to a SetCoverSolutionResponse proto.
101// The proto is either written to a binary (if binary is true) or a text file.
102// The solution is 0-indexed.
105 absl::string_view filename, bool binary);
106
107} // namespace operations_research
108
109#endif // OR_TOOLS_ALGORITHMS_SET_COVER_READER_H_
Main class for describing a weighted set-covering problem.
In SWIG mode, we don't want anything besides these top-level includes.
SetCoverModel ReadOrlibScp(absl::string_view filename)
This is a row-based format where the elements are 1-indexed.
void WriteSetCoverProto(const SetCoverModel &model, absl::string_view filename, bool binary)
SetCoverModel ReadSetCoverProto(absl::string_view filename, bool binary)
void WriteSetCoverSolutionProto(const SetCoverModel &model, const SubsetBoolVector &solution, absl::string_view filename, bool binary)
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid
SubsetBoolVector ReadSetCoverSolutionText(absl::string_view filename)
void WriteSetCoverSolutionText(const SetCoverModel &model, const SubsetBoolVector &solution, absl::string_view filename)
SetCoverModel ReadOrlibRail(absl::string_view filename)
This is a column-based format where the elements are 1-indexed.
util_intops::StrongVector< SubsetIndex, bool > SubsetBoolVector
void WriteOrlibScp(const SetCoverModel &model, absl::string_view filename)
void WriteOrlibRail(const SetCoverModel &model, absl::string_view filename)
Beware the fact that elements written are converted to 1-indexed.
SubsetBoolVector ReadSetCoverSolutionProto(absl::string_view filename, bool binary)
SetCoverModel ReadFimiDat(absl::string_view filename)