18#include "absl/log/check.h"
19#include "absl/log/log.h"
29 is_selected_.assign(set_cover_model_->num_subsets(),
false);
36 return sum > std::numeric_limits<CapacityWeight>::max() - q;
42 return sum < std::numeric_limits<CapacityWeight>::min() - q;
47 const SubsetIndex subset)
const {
49 for (CapacityTermIndex term : model_->TermRange()) {
50 if (model_->GetTermSubsetIndex(term) == subset) {
53 const CapacityWeight term_weight = model_->GetTermCapacityWeight(term);
55 CHECK(!PositiveAddOverflows(slack_change, term_weight));
56 slack_change += term_weight;
62bool CapacityInvariant::SlackChangeFitsConstraint(
66 return new_slack >= model_->GetMinimumCapacity() &&
67 new_slack <= model_->GetMaximumCapacity();
71 DVLOG(1) <<
"[Capacity constraint] Selecting subset " << subset;
72 DCHECK(!is_selected_[subset]);
75 if (!SlackChangeFitsConstraint(slack_change)) {
76 DVLOG(1) <<
"[Capacity constraint] Selecting subset " << subset
80 CHECK(!PositiveAddOverflows(current_slack_, slack_change));
81 is_selected_[subset] =
true;
82 current_slack_ += slack_change;
83 DVLOG(1) <<
"[Capacity constraint] New slack: " << current_slack_;
88 DVLOG(1) <<
"[Capacity constraint] Can select subset " << subset <<
"?";
89 DCHECK(!is_selected_[subset]);
92 DVLOG(1) <<
"[Capacity constraint] New slack if selecting: "
93 << current_slack_ + slack_change;
94 return SlackChangeFitsConstraint(slack_change);
98 DVLOG(1) <<
"[Capacity constraint] Deselecting subset " << subset;
99 DCHECK(is_selected_[subset]);
102 if (!SlackChangeFitsConstraint(slack_change)) {
103 DVLOG(1) <<
"[Capacity constraint] Deselecting subset " << subset
107 CHECK(!NegativeAddOverflows(current_slack_, slack_change));
108 is_selected_[subset] =
false;
109 current_slack_ += slack_change;
110 DVLOG(1) <<
"[Capacity constraint] New slack: " << current_slack_;
115 DVLOG(1) <<
"[Capacity constraint] Can deselect subset " << subset <<
"?";
116 DCHECK(is_selected_[subset]);
119 DVLOG(1) <<
"[Capacity constraint] New slack if deselecting: "
120 << current_slack_ + slack_change;
121 return SlackChangeFitsConstraint(slack_change);
void Clear()
Clears the invariant.
bool Select(SubsetIndex subset)
bool Deselect(SubsetIndex subset)
bool CanSelect(SubsetIndex subset) const
bool CanDeselect(SubsetIndex subset) const
In SWIG mode, we don't want anything besides these top-level includes.
bool AddOverflows(int64_t x, int64_t y)
int64_t CapacityWeight
Basic type for weights. For now, the same as Cost for the set covering.