14#ifndef OR_TOOLS_SET_COVER_SET_COVER_INVARIANT_H_
15#define OR_TOOLS_SET_COVER_SET_COVER_INVARIANT_H_
20#include "absl/log/check.h"
21#include "absl/types/span.h"
34 static_assert(
sizeof(
subset) ==
sizeof(decision_));
35 DCHECK_GE(
subset.value(), 0);
40 return SubsetIndex(decision_ >= 0 ? decision_ : ~decision_);
43 bool decision()
const {
return decision_ >= 0; }
107 lower_bound_ = lower_bound;
119 return is_cost_consistent_ ? cost_ : lower_bound_;
138 return num_free_elements_;
144 return num_non_overcovered_elements_;
152 absl::Span<const SubsetIndex> focus)
const;
159 const std::vector<SetCoverDecision>&
trace()
const {
return trace_; }
168 const SubsetIndex subset =
trace()[i].subset();
169 DCHECK_EQ(
trace()[i].decision(), is_selected_[subset]);
170 if (is_selected_[subset]) {
179 newly_removable_subsets_.clear();
180 newly_non_removable_subsets_.clear();
185 return newly_removable_subsets_;
190 return newly_non_removable_subsets_;
252 std::tuple<Cost, ElementToIntVector> ComputeCostAndCoverage(
287 bool is_cost_consistent_;
303 std::vector<SetCoverDecision> trace_;
328 std::vector<SubsetIndex> newly_removable_subsets_;
332 std::vector<SubsetIndex> newly_non_removable_subsets_;
SetCoverDecision(SubsetIndex subset, bool value)
SubsetIndex subset() const
const SetCoverModel * const_model() const
bool ComputeIsRedundant(SubsetIndex subset) const
void Recompute(ConsistencyLevel target_consistency)
Recomputes the invariant to the given consistency level.
const SubsetBoolVector & is_redundant() const
BaseInt ComputeCardinality() const
Returns the cardinality of the solution in the invariant.
const SubsetToIntVector & num_free_elements() const
SetCoverSolutionResponse ExportSolutionAsProto() const
Returns the current solution as a proto.
const std::vector< SetCoverDecision > & trace() const
Returns the vector of the decisions which have led to the current solution.
bool CheckConsistency(ConsistencyLevel consistency) const
Checks the consistency of the invariant at the given consistency level.
void LoadSolution(const SubsetBoolVector &solution)
Loads the solution and recomputes the data in the invariant.
void ImportSolutionFromProto(const SetCoverSolutionResponse &message)
Imports the solution from a proto.
bool Deselect(SubsetIndex subset, ConsistencyLevel consistency)
SetCoverInvariant(SetCoverModel *m)
const SubsetToIntVector & num_coverage_le_1_elements() const
const SubsetBoolVector & is_selected() const
Returns the subset assignment vector.
SetCoverModel * model() const
Returns the weighted set covering model to which the state applies.
Cost CostOrLowerBound() const
Cost LowerBound() const
Returns the lower bound of the problem.
void ReportLowerBound(Cost lower_bound, bool is_cost_consistent)
const std::vector< SubsetIndex > & newly_removable_subsets() const
Returns the subsets that become removable after the last update.
bool Select(SubsetIndex subset, ConsistencyLevel consistency)
const ElementToIntVector & coverage() const
Returns vector containing number of subsets covering each element.
void ClearTrace()
Clears the trace.
BaseInt ComputeNumFreeElements(SubsetIndex subset) const
Computes the number of free (uncovered) elements in the given subset.
void LoadTraceAndCoverage(const std::vector< SetCoverDecision > &trace, const ElementToIntVector &coverage)
Cost cost() const
Returns the cost of current solution.
bool is_cost_consistent() const
ElementToIntVector ComputeCoverageInFocus(absl::Span< const SubsetIndex > focus) const
void Clear()
Clears the invariant. Also called by Initialize.
void ClearRemovabilityInformation()
Clear the removability information.
BaseInt num_uncovered_elements() const
Returns the number of uncovered elements.
const std::vector< SubsetIndex > & newly_non_removable_subsets() const
Returns the subsets that become non removable after the last update.
Main class for describing a weighted set-covering problem.
In SWIG mode, we don't want anything besides these top-level includes.
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
util_intops::StrongVector< SubsetIndex, BaseInt > SubsetToIntVector
util_intops::StrongVector< ElementIndex, BaseInt > ElementToIntVector
util_intops::StrongVector< SubsetIndex, bool > SubsetBoolVector
double Cost
Basic non-strict type for cost. The speed penalty for using double is ~2%.
num_free_elements_[subset]