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 "absl/types/span.h"
22#include "ortools/algorithms/set_cover.pb.h"
33 static_assert(
sizeof(
subset) ==
sizeof(decision_));
34 DCHECK_GE(
subset.value(), 0);
39 return SubsetIndex(decision_ >= 0 ? decision_ : ~decision_);
42 bool decision()
const {
return decision_ >= 0; }
114 return num_free_elements_;
120 return num_non_overcovered_elements_;
128 absl::Span<const SubsetIndex> focus)
const;
135 const std::vector<SetCoverDecision>&
trace()
const {
return trace_; }
142 newly_removable_subsets_.clear();
143 newly_non_removable_subsets_.clear();
148 return newly_removable_subsets_;
153 return newly_non_removable_subsets_;
210 std::tuple<Cost, ElementToIntVector> ComputeCostAndCoverage(
242 BaseInt num_uncovered_elements_;
251 std::vector<SetCoverDecision> trace_;
276 std::vector<SubsetIndex> newly_removable_subsets_;
280 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
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 Select(SubsetIndex subset, ConsistencyLevel consistency)
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.
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.
void Flip(SubsetIndex subset, ConsistencyLevel consistency)
const std::vector< SubsetIndex > & newly_removable_subsets() const
Returns the subsets that become removable after the last update.
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.
Cost cost() const
Returns the cost of current solution.
void Deselect(SubsetIndex subset, ConsistencyLevel consistency)
void SelectNoUpdate(SubsetIndex subset)
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%.