OR-Tools
9.1
set_covering_parser.h
Go to the documentation of this file.
1
// Copyright 2010-2021 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_DATA_SET_COVERING_PARSER_H_
15
#define OR_TOOLS_DATA_SET_COVERING_PARSER_H_
16
17
#include <cstdint>
18
#include <string>
19
#include <vector>
20
21
#include "
ortools/base/integral_types.h
"
22
#include "
ortools/data/set_covering_data.h
"
23
24
namespace
operations_research
{
25
namespace
scp {
26
27
// Set covering problem.
28
//
29
// We have a list of subsets of a set. Each subset has a cost. The
30
// goal is to select of solution set of subsets such that (1) all elements
31
// of the set belongs to at least one subset of the solution set, and (2)
32
// the sum of the cost of each subset in the solution set is minimal.
33
//
34
// To follow the standard literature, each element is called a row, and each
35
// subset is called a column.
36
37
class
ScpParser
{
38
public
:
39
enum
Section
{
40
INIT
,
41
COSTS
,
42
COLUMN
,
43
NUM_COLUMNS_IN_ROW
,
44
ROW
,
45
NUM_NON_ZEROS
,
46
END
,
47
ERROR
,
48
};
49
50
enum
Format
{
51
// The original scp format of these problem is:
52
//
53
// number of rows (m), number of columns (n)
54
//
55
// the cost of each column c(j),j=1,...,n
56
//
57
// for each row i (i=1,...,m): the number of columns which cover row
58
// i followed by a list of the columns which cover row i.
59
//
60
// The original problems (scp*) from the OR-LIB follow this format.
61
SCP_FORMAT
,
62
// The railroad format is:
63
// number of rows (m), number of columns (n)
64
//
65
// for each column j (j=1,...,n): the cost of the column, the number
66
// of rows that it covers followed by a list of the rows that it
67
// covers.
68
//
69
// The railroad problems follow this format.
70
RAILROAD_FORMAT
,
71
// The triplet format is:
72
//
73
// number of rows (m), number of columns (n)
74
//
75
// for each column, the 3 rows it contains. Note that the cost of
76
// each column is 1.
77
//
78
// The Steiner triple covering problems follow this format.
79
TRIPLET_FORMAT
,
80
// The spp format is:
81
// number of rows (m), number of columns (n)
82
//
83
// for each column j (j=1,...,n): the cost of the column, the number
84
// of rows that it covers followed by a list of the rows that it
85
// covers.
86
//
87
// number of non_zeros
88
//
89
// The set partitioning problems follow this format.
90
SPP_FORMAT
91
};
92
93
ScpParser
();
94
95
// This will clear the data before importing the file.
96
bool
LoadProblem
(
const
std::string& filename,
Format
format,
ScpData
* data);
97
98
private
:
99
void
ProcessLine(
const
std::string& line,
Format
format,
ScpData
* data);
100
void
LogError(
const
std::string& line,
const
std::string& error_message);
101
int
strtoint32(
const
std::string& word);
102
int64_t strtoint64(
const
std::string& word);
103
104
Section
section_;
105
int
line_;
106
int
remaining_;
107
int
current_;
108
};
109
110
}
// namespace scp
111
}
// namespace operations_research
112
113
#endif // OR_TOOLS_DATA_SET_COVERING_PARSER_H_
operations_research::scp::ScpParser
Definition:
set_covering_parser.h:37
operations_research::scp::ScpParser::ScpParser
ScpParser()
Definition:
set_covering_parser.cc:25
set_covering_data.h
operations_research::scp::ScpParser::SCP_FORMAT
Definition:
set_covering_parser.h:61
operations_research::scp::ScpParser::NUM_COLUMNS_IN_ROW
Definition:
set_covering_parser.h:43
operations_research::scp::ScpParser::LoadProblem
bool LoadProblem(const std::string &filename, Format format, ScpData *data)
Definition:
set_covering_parser.cc:27
operations_research::scp::ScpParser::INIT
Definition:
set_covering_parser.h:40
operations_research::scp::ScpParser::Format
Format
Definition:
set_covering_parser.h:50
integral_types.h
operations_research::scp::ScpParser::TRIPLET_FORMAT
Definition:
set_covering_parser.h:79
operations_research::scp::ScpParser::SPP_FORMAT
Definition:
set_covering_parser.h:90
operations_research::scp::ScpParser::COLUMN
Definition:
set_covering_parser.h:42
operations_research::scp::ScpParser::END
Definition:
set_covering_parser.h:46
operations_research::scp::ScpParser::ROW
Definition:
set_covering_parser.h:44
operations_research::scp::ScpParser::NUM_NON_ZEROS
Definition:
set_covering_parser.h:45
operations_research::scp::ScpParser::RAILROAD_FORMAT
Definition:
set_covering_parser.h:70
operations_research::scp::ScpParser::COSTS
Definition:
set_covering_parser.h:41
operations_research
Collection of objects used to extend the Constraint Solver library.
Definition:
dense_doubly_linked_list.h:21
operations_research::scp::ScpParser::Section
Section
Definition:
set_covering_parser.h:39
operations_research::scp::ScpParser::ERROR
Definition:
set_covering_parser.h:47
operations_research::scp::ScpData
Definition:
set_covering_data.h:24
ortools
data
set_covering_parser.h
Generated by
1.8.15