14#ifndef OR_TOOLS_SET_COVER_SET_COVER_SUBMODEL_H
15#define OR_TOOLS_SET_COVER_SET_COVER_SUBMODEL_H
94 const std::vector<FullSubsetIndex>& columns_focus);
105 return fixed_columns_;
111 void SetFocus(
const std::vector<FullSubsetIndex>& columns_focus);
119 const std::vector<FullSubsetIndex>& columns_to_fix,
128 const Solution& best_solution,
bool force) {
137 void ResetToIdentitySubModel();
140 const Model* full_model_;
147 std::vector<SubsetIndex> cols_focus_;
148 std::vector<ElementIndex> rows_focus_;
151 std::vector<FullSubsetIndex> fixed_columns_;
152 Cost fixed_cost_ = .0;
172 const std::vector<FullSubsetIndex>& columns_focus);
182 DCHECK(SubsetIndex() <= j && j < SubsetIndex(
num_subsets()));
186 DCHECK(ElementIndex() <= i && i < ElementIndex(
num_elements()));
187 return rows()[i].size();
191 DCHECK(ElementIndex() <= core_i && core_i < ElementIndex(
num_elements()));
192 return core2full_row_map_[core_i];
195 DCHECK(FullElementIndex() <= full_i &&
197 return full2core_row_map_[full_i];
200 DCHECK(SubsetIndex() <= core_j && core_j < SubsetIndex(
num_subsets()));
201 return core2full_col_map_[core_j];
216 return fixed_columns_;
222 void SetFocus(
const std::vector<FullSubsetIndex>& columns_focus);
230 const std::vector<FullSubsetIndex>& columns_to_fix,
239 const Solution& best_solution,
bool force) {
246 void MarkNewFixingInMaps(
const std::vector<SubsetIndex>& columns_to_fix);
249 void ResetToIdentitySubModel();
259 Cost fixed_cost_ = .0;
260 std::vector<FullSubsetIndex> fixed_columns_;
262 static constexpr SubsetIndex null_subset_index =
263 std::numeric_limits<SubsetIndex>::max();
264 static constexpr ElementIndex null_element_index =
265 std::numeric_limits<ElementIndex>::max();
266 static constexpr FullSubsetIndex null_full_subset_index =
267 std::numeric_limits<FullSubsetIndex>::max();
268 static constexpr FullElementIndex null_full_element_index =
269 std::numeric_limits<FullElementIndex>::max();
272template <
typename SubModelT>
274 if (model.num_elements() <= 0) {
275 std::cerr <<
"Sub-Model has no elements.\n";
278 if (model.num_subsets() <= 0) {
279 std::cerr <<
"Sub-Model has no subsets.\n";
283 for (SubsetIndex j : model.SubsetRange()) {
284 const auto& column = model.columns()[j];
285 if (model.column_size(j) == 0) {
286 std::cerr <<
"Column " << j <<
" is empty.\n";
289 BaseInt j_size = std::distance(column.begin(), column.end());
290 if (j_size != model.column_size(j)) {
291 std::cerr <<
"Sub-Model size mismatch on column " << j <<
", " << j_size
292 <<
" != " << model.column_size(j) <<
"\n";
297 for (ElementIndex i : model.ElementRange()) {
298 const auto& row = model.rows()[i];
299 if (model.row_size(i) == 0) {
300 std::cerr <<
"Row " << i <<
" is empty.\n";
303 BaseInt i_size = std::distance(row.begin(), row.end());
304 if (i_size != model.row_size(i)) {
305 std::cerr <<
"Sub-Model size mismatch on row " << i <<
", " << i_size
306 <<
" != " << model.row_size(i) <<
"\n";
IndexListModelView()=default
Main class for describing a weighted set-covering problem.
util_intops::StrongIntRange< ElementIndex > ElementRange() const
const SparseRowView & rows() const
Row view of the set covering problem.
BaseInt num_elements() const
util_intops::StrongIntRange< SubsetIndex > SubsetRange() const
Access to the ranges of subsets and elements.
const SubsetCostVector & subset_costs() const
Vector of costs for each subset.
const SparseColumnView & columns() const
Column view of the set covering problem.
BaseInt num_subsets() const
virtual void ResetColumnFixing(const std::vector< FullSubsetIndex > &columns_to_fix, const DualState &state)
BaseInt num_focus_subsets() const
void SetFocus(const std::vector< FullSubsetIndex > &columns_focus)
BaseInt num_focus_elements() const
const std::vector< FullSubsetIndex > & fixed_columns() const
List of fixed columns.
const SparseRowView & rows() const
Row view of the set covering problem.
CoreModel()=default
Empty initialization to facilitate delayed construction.
FullElementIndex MapCoreToFullElementIndex(ElementIndex core_i) const
StrongModelView StrongTypedFullModelView() const
ElementIndex MapFullToCoreElementIndex(FullElementIndex full_i) const
virtual ~CoreModel()=default
FullSubsetIndex MapCoreToFullSubsetIndex(SubsetIndex core_j) const
BaseInt column_size(SubsetIndex j) const
virtual bool UpdateCore(Cost best_lower_bound, const ElementCostVector &best_multipliers, const Solution &best_solution, bool force)
Cost fixed_cost() const
Current fixed cost: sum of the cost of the fixed columns.
BaseInt row_size(ElementIndex i) const
BaseInt num_elements() const
const SparseColumnView & columns() const
Member function relevant for the CFT inherited from Model.
virtual Cost FixMoreColumns(const std::vector< SubsetIndex > &columns_to_fix)
BaseInt num_subsets() const
Cost fixed_cost() const
Current fixed cost: sum of the cost of the fixed columns.
virtual bool UpdateCore(Cost best_lower_bound, const ElementCostVector &best_multipliers, const Solution &best_solution, bool force)
virtual ~SubModelView()=default
StrongModelView StrongTypedFullModelView() const
void SetFocus(const std::vector< FullSubsetIndex > &columns_focus)
const std::vector< FullSubsetIndex > & fixed_columns() const
List of fixed columns.
SubModelView()=default
Empty initialization to facilitate delayed construction.
virtual void ResetColumnFixing(const std::vector< FullSubsetIndex > &columns_to_fix, const DualState &state)
virtual Cost FixMoreColumns(const std::vector< SubsetIndex > &columns_to_fix)
bool ValidateSubModel(const SubModelT &model)
util_intops::StrongVector< SubsetIndex, FullSubsetIndex > CoreToFullSubsetMapVector
util_intops::StrongVector< FullElementIndex, ElementIndex > FullToCoreElementMapVector
util_intops::StrongVector< ElementIndex, FullElementIndex > CoreToFullElementMapVector
util_intops::StrongVector< SubsetIndex, BaseInt > SubsetToIntVector
util_intops::StrongVector< ElementIndex, Cost > ElementCostVector
util_intops::StrongVector< ElementIndex, BaseInt > ElementToIntVector
double Cost
Basic non-strict type for cost. The speed penalty for using double is ~2%.
Utility aggregate to store and pass around both primal and dual states.