14#ifndef OR_TOOLS_ALGORITHMS_SET_COVER_MODEL_H_
15#define OR_TOOLS_ALGORITHMS_SET_COVER_MODEL_H_
19typedef SSIZE_T ssize_t;
27#include "absl/log/check.h"
28#include "absl/strings/str_cat.h"
29#include "ortools/algorithms/set_cover.pb.h"
129 row_view_is_valid_(false),
158 DCHECK(row_view_is_valid_);
172 ElementIndex(num_elements_));
176 std::vector<SubsetIndex>
all_subsets()
const {
return all_subsets_; }
231 return absl::StrCat(
"min = ",
min,
", max = ",
max,
", mean = ",
mean,
254 void UpdateAllSubsetsList();
263 ssize_t num_nonzeros_;
266 bool row_view_is_valid_;
293 std::vector<SubsetIndex> all_subsets_;
307 SubsetIndex seed_subset)
308 : intersecting_subset_(-1),
311 seed_subset_(seed_subset),
313 subset_seen_(model_.columns().
size(), false) {
315 subset_seen_[seed_subset] =
true;
321 return element_entry_.value() == model_.
columns()[seed_subset_].size();
325 SubsetIndex
operator*()
const {
return intersecting_subset_; }
333 for (; element_entry_ < ColumnEntryIndex(
column.size()); ++element_entry_) {
334 const ElementIndex current_element =
column[element_entry_];
335 const SparseRow& current_row = rows[current_element];
336 for (; subset_entry_ < RowEntryIndex(current_row.size());
338 intersecting_subset_ = current_row[subset_entry_];
339 if (!subset_seen_[intersecting_subset_]) {
340 subset_seen_[intersecting_subset_] =
true;
344 subset_entry_ = RowEntryIndex(0);
351 SubsetIndex intersecting_subset_;
354 ColumnEntryIndex element_entry_;
357 RowEntryIndex subset_entry_;
360 SubsetIndex seed_subset_;
bool at_end() const
Returns (true) whether the iterator is at the end.
SubsetIndex operator*() const
Returns the intersecting subset.
IntersectingSubsetsIterator & operator++()
Move the iterator to the next intersecting subset.
IntersectingSubsetsIterator(const SetCoverModel &model, SubsetIndex seed_subset)
Main class for describing a weighted set-covering problem.
void ImportModelFromProto(const SetCoverProto &message)
Imports the model from a SetCoverProto.
void ReserveNumElementsInSubset(BaseInt num_elements, BaseInt subset)
Reserves num_elements rows in the column indexed by subset.
Stats ComputeColumnStats()
Computes basic statistics on columns and returns a Stats structure.
util_intops::StrongIntRange< ElementIndex > ElementRange() const
void AddElementToLastSubset(BaseInt element)
Stats ComputeCostStats()
Computes basic statistics on costs and returns a Stats structure.
void AddEmptySubset(Cost cost)
Stats ComputeRowStats()
Computes basic statistics on rows and returns a Stats structure.
std::vector< ssize_t > ComputeColumnDeciles() const
Computes deciles on columns and returns a vector of deciles.
const SparseRowView & rows() const
Row view of the set covering problem.
void ReserveNumSubsets(BaseInt num_subsets)
Reserves num_subsets columns in the model.
SetCoverProto ExportModelAsProto()
ssize_t num_nonzeros() const
Current number of nonzeros in the matrix.
BaseInt num_elements() const
util_intops::StrongIntRange< SubsetIndex > SubsetRange() const
Access to the ranges of subsets and elements.
void AddElementToSubset(BaseInt element, BaseInt subset)
std::vector< ssize_t > ComputeRowDeciles() const
Computes deciles on rows and returns a vector of deciles.
void SetSubsetCost(BaseInt subset, Cost cost)
bool ComputeFeasibility() const
bool row_view_is_valid() const
Returns true if rows_ and columns_ represent the same problem.
const SubsetCostVector & subset_costs() const
Vector of costs for each subset.
void CreateSparseRowView()
Creates the sparse ("dual") representation of the problem.
SetCoverModel()
Constructs an empty weighted set-covering problem.
const SparseColumnView & columns() const
Column view of the set covering problem.
BaseInt num_subsets() const
std::vector< SubsetIndex > all_subsets() const
Returns the list of indices for all the subsets in the model.
In SWIG mode, we don't want anything besides these top-level includes.
constexpr int kSetCoverAlignmentInBytes
double Cost
Basic non-strict type for cost. The speed penalty for using double is ~2%.
#define DEFINE_STRONG_INT_TYPE(int_type_name, value_type)
std::string DebugString() const