14#ifndef OR_TOOLS_ALGORITHMS_SET_COVER_INVARIANT_H_
15#define OR_TOOLS_ALGORITHMS_SET_COVER_INVARIANT_H_
20#include "absl/log/check.h"
21#include "ortools/algorithms/set_cover.pb.h"
33 static_assert(
sizeof(
subset) ==
sizeof(decision_));
34 DCHECK_GE(
subset.value(), 0);
35 decision_ =
value ?
subset.value() : ~subset.value();
39 return SubsetIndex(decision_ >= 0 ? decision_ : ~decision_);
42 bool decision()
const {
return decision_ >= 0; }
102 return num_free_elements_;
108 return num_non_overcovered_elements_;
116 absl::Span<const SubsetIndex> focus)
const;
123 const std::vector<SetCoverDecision>&
trace()
const {
return trace_; }
130 new_removable_subsets_.clear();
131 new_non_removable_subsets_.clear();
136 return new_removable_subsets_;
141 return new_non_removable_subsets_;
177 void Flip(SubsetIndex subset) {
Flip(subset,
false); }
203 std::tuple<Cost, ElementToIntVector> ComputeCostAndCoverage(
220 ComputeNumNonOvercoveredElementsAndIsRedundant(
229 void Flip(SubsetIndex,
bool incremental_full_update);
233 void Select(SubsetIndex subset,
bool incremental_full_update);
237 void Deselect(SubsetIndex subset,
bool incremental_full_update);
240 void SelectAvx512(SubsetIndex subset);
243 void DeselectAvx512(SubsetIndex subset);
252 BaseInt num_uncovered_elements_;
261 std::vector<SetCoverDecision> trace_;
286 std::vector<SubsetIndex> new_removable_subsets_;
290 std::vector<SubsetIndex> new_non_removable_subsets_;
297 bool is_fully_updated_;
300 bool supports_avx512_;
A helper class used to store the decisions made during a search.
SetCoverDecision(SubsetIndex subset, bool value)
SubsetIndex subset() const
void Flip(SubsetIndex subset)
const SetCoverModel * const_model() const
bool ComputeIsRedundant(SubsetIndex subset) const
const SubsetBoolVector & is_redundant() const
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 has led to the current solution.
void SelectAndFullyUpdate(SubsetIndex subset)
void Select(SubsetIndex subset)
void RecomputeInvariant()
Recomputes all the invariants for the current solution.
void LoadSolution(const SubsetBoolVector &solution)
Loads the solution and recomputes the data in the invariant.
const std::vector< SubsetIndex > & new_non_removable_subsets() const
Returns the subsets that become non removable after the last update.
void ImportSolutionFromProto(const SetCoverSolutionResponse &message)
Imports the solution from a proto.
SetCoverInvariant(SetCoverModel *m)
void FlipAndFullyUpdate(SubsetIndex subset)
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.
bool CheckConsistency() const
void Deselect(SubsetIndex subset)
void DeselectAndFullyUpdate(SubsetIndex subset)
const ElementToIntVector & coverage() const
Returns vector containing number of subsets covering each element.
const std::vector< SubsetIndex > & new_removable_subsets() const
Returns the subsets that become removable after the last update.
void ClearTrace()
Clears the trace.
Cost cost() const
Returns the cost of current solution.
ElementToIntVector ComputeCoverageInFocus(absl::Span< const SubsetIndex > focus) const
void ClearRemovabilityInformation()
Clear the removability information.
BaseInt num_uncovered_elements() const
Returns the number of uncovered elements.
Main class for describing a weighted set-covering problem.
BaseInt num_subsets() const
void assign(size_type n, const value_type &val)
In SWIG mode, we don't want anything besides these top-level includes.
util_intops::StrongVector< SubsetIndex, BaseInt, IntAllocator > SubsetToIntVector
double Cost
Basic non-strict type for cost. The speed penalty for using double is ~2%.