14#ifndef OR_TOOLS_ALGORITHMS_SET_COVER_MODEL_H_
15#define OR_TOOLS_ALGORITHMS_SET_COVER_MODEL_H_
21#include "absl/log/check.h"
22#include "absl/strings/str_cat.h"
23#include "ortools/algorithms/set_cover.pb.h"
111 row_view_is_valid_(false),
112 elements_in_subsets_are_sorted_(false),
144 bool IsEmpty()
const {
return rows_.empty() || columns_.empty(); }
169 DCHECK(row_view_is_valid_);
183 ElementIndex(num_elements_));
187 std::vector<SubsetIndex>
all_subsets()
const {
return all_subsets_; }
249 return absl::StrCat(
"min = ",
min,
", max = ",
max,
", mean = ",
mean,
280 void UpdateAllSubsetsList();
290 int64_t num_nonzeros_;
293 bool row_view_is_valid_;
296 bool elements_in_subsets_are_sorted_;
322 std::vector<SubsetIndex> all_subsets_;
336 SubsetIndex seed_subset)
337 : intersecting_subset_(-1),
340 seed_subset_(seed_subset),
342 subset_seen_(model_.columns().size(), false) {
343 CHECK(model_.row_view_is_valid());
344 subset_seen_[seed_subset] =
true;
350 return element_entry_.value() == model_.columns()[seed_subset_].size();
354 SubsetIndex
operator*()
const {
return intersecting_subset_; }
358 DCHECK(model_.row_view_is_valid());
361 const SparseColumn& column = model_.columns()[seed_subset_];
362 for (; element_entry_ < ColumnEntryIndex(column.size()); ++element_entry_) {
363 const ElementIndex current_element = column[element_entry_];
364 const SparseRow& current_row = rows[current_element];
365 for (; subset_entry_ < RowEntryIndex(current_row.size());
367 intersecting_subset_ = current_row[subset_entry_];
368 if (!subset_seen_[intersecting_subset_]) {
369 subset_seen_[intersecting_subset_] =
true;
373 subset_entry_ = RowEntryIndex(0);
380 SubsetIndex intersecting_subset_;
383 ColumnEntryIndex element_entry_;
386 RowEntryIndex subset_entry_;
389 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.
static SetCoverModel GenerateRandomModelFrom(const SetCoverModel &seed_model, BaseInt num_elements, BaseInt num_subsets, double row_scale, double column_scale, double cost_scale)
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.
std::vector< int64_t > ComputeRowDeciles() const
Computes deciles on rows and returns a vector of deciles.
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.
const SparseRowView & rows() const
Row view of the set covering problem.
void ReserveNumSubsets(BaseInt num_subsets)
Reserves num_subsets columns in the model.
int64_t num_nonzeros() const
Current number of nonzeros in the matrix.
BaseInt num_elements() const
void SortElementsInSubsets()
util_intops::StrongIntRange< SubsetIndex > SubsetRange() const
Access to the ranges of subsets and elements.
Stats ComputeColumnDeltaSizeStats() const
void AddElementToSubset(BaseInt element, BaseInt subset)
Stats ComputeRowDeltaSizeStats() const
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()
SetCoverProto ExportModelAsProto() const
SetCoverModel()
Constructs an empty weighted set-covering problem.
std::vector< int64_t > ComputeColumnDeciles() const
Computes deciles on columns and returns a vector of deciles.
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.
util_intops::StrongVector< RowEntryIndex, SubsetIndex > SparseRow
util_intops::StrongVector< SubsetIndex, Cost > SubsetCostVector
util_intops::StrongVector< SubsetIndex, BaseInt > SubsetToIntVector
util_intops::StrongIntRange< SubsetIndex > SubsetRange
util_intops::StrongVector< SubsetIndex, SubsetIndex > SubsetToSubsetVector
util_intops::StrongVector< ElementIndex, Cost > ElementCostVector
util_intops::StrongVector< ElementIndex, ElementIndex > ElementToElementVector
Useful for representing permutations,.
util_intops::StrongIntRange< ColumnEntryIndex > ColumnEntryRange
util_intops::StrongVector< ElementIndex, BaseInt > ElementToIntVector
util_intops::StrongVector< SubsetIndex, bool > SubsetBoolVector
util_intops::StrongVector< SubsetIndex, SparseColumn > SparseColumnView
util_intops::StrongVector< ElementIndex, bool > ElementBoolVector
double Cost
Basic non-strict type for cost. The speed penalty for using double is ~2%.
util_intops::StrongIntRange< ElementIndex > ElementRange
util_intops::StrongVector< ColumnEntryIndex, ElementIndex > SparseColumn
util_intops::StrongVector< ElementIndex, SparseRow > SparseRowView
#define DEFINE_STRONG_INT_TYPE(int_type_name, value_type)
std::string DebugString() const