16#include "absl/log/check.h"
17#include "absl/log/log.h"
28 values_.assign(model_.subset_costs().size(),
false);
29 DCHECK_EQ(values_.size(), model_.subset_costs().size())
30 <<
"The cost vector (length: " << model_.subset_costs().size()
31 <<
") is inconsistent with the assignment (length: " << values_.size()
36 CHECK(constraint_ ==
nullptr);
41 CHECK(constraint_ !=
nullptr);
42 side_constraints_.push_back(i);
48 SubsetIndex subset,
bool is_selected,
50 DVLOG(1) <<
"[Assignment] Subset " << subset <<
" becoming " << is_selected
51 <<
"; used to be " << values_[subset];
54 if (values_[subset] == is_selected)
return;
56 values_[subset] = is_selected;
58 cost_ += model_.subset_costs()[subset];
60 constraint_->Select(subset, set_cover_consistency);
63 capacity_constraint->Select(subset);
66 cost_ -= model_.subset_costs()[subset];
68 constraint_->Deselect(subset, set_cover_consistency);
71 capacity_constraint->Deselect(subset);
78 SetCoverSolutionResponse message;
79 message.set_num_subsets(values_.size());
80 message.set_cost(cost_);
81 for (SubsetIndex subset(0);
82 subset < SubsetIndex(model_.subset_costs().size()); ++subset) {
83 if (values_[subset]) {
84 message.add_subset(subset.value());
91 DCHECK_EQ(
solution.size(), values_.size());
93 cost_ = ComputeCost(values_);
97 const SetCoverSolutionResponse& message) {
98 values_.resize(SubsetIndex(message.num_subsets()),
false);
100 for (
auto s : message.subset()) {
101 SubsetIndex subset(s);
102 values_[subset] =
true;
103 cost_ += model_.subset_costs()[subset];
110 Cost cst = ComputeCost(values_);
117 SubsetIndex subset(0);
118 for (
const bool b : choices) {
static bool AlmostEquals(const T x, const T y)
bool CheckConsistency() const
void LoadAssignment(const SubsetBoolVector &solution)
void ImportSolutionFromProto(const SetCoverSolutionResponse &message)
void Clear()
Clears the current assignment.
void SetValue(SubsetIndex subset, bool is_selected, SetCoverInvariant::ConsistencyLevel set_cover_consistency)
Sets the subset's assignment to the given bool.
SetCoverSolutionResponse ExportSolutionAsProto() const
Returns the current solution as a proto.
void AttachInvariant(SetCoverInvariant *i)
const SubsetCostVector & subset_costs() const
Vector of costs for each subset.
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, bool > SubsetBoolVector
double Cost
Basic non-strict type for cost. The speed penalty for using double is ~2%.