29 parameters_(*
model->GetOrCreate<SatParameters>()) {
31 pseudo_costs_.resize(num_vars);
34 void PseudoCosts::InitializeCosts(
double initial_value) {
35 if (pseudo_costs_initialized_)
return;
36 VLOG(1) <<
"Initializing pseudo costs";
37 for (
int i = 0; i < pseudo_costs_.size(); ++i) {
38 pseudo_costs_[IntegerVariable(i)].Reset(initial_value);
40 pseudo_costs_initialized_ =
true;
43 void PseudoCosts::UpdateCostForVar(IntegerVariable
var,
double new_cost) {
44 if (
var >= pseudo_costs_.size()) {
47 pseudo_costs_.resize(new_size, IncrementalAverage(0.0));
49 CHECK_LT(
var, pseudo_costs_.size());
50 pseudo_costs_[
var].AddData(new_cost);
54 const std::vector<VariableBoundChange>& bound_changes,
55 const IntegerValue obj_bound_improvement) {
56 DCHECK_GE(obj_bound_improvement, 0);
57 if (obj_bound_improvement == IntegerValue(0))
return;
62 if (decision.lower_bound_change > IntegerValue(0)) {
63 const double current_pseudo_cost =
ToDouble(obj_bound_improvement) /
64 ToDouble(decision.lower_bound_change);
73 if (!pseudo_costs_initialized_) {
76 UpdateCostForVar(decision.var, current_pseudo_cost);
84 const double epsilon = 1e-6;
86 double best_cost = -std::numeric_limits<double>::infinity();
89 for (IntegerVariable positive_var(0); positive_var < pseudo_costs_.size();
91 const IntegerVariable negative_var =
NegationOf(positive_var);
93 const IntegerValue lb = integer_trail_.
LowerBound(positive_var);
94 const IntegerValue ub = integer_trail_.
UpperBound(positive_var);
95 if (lb >= ub)
continue;
97 parameters_.pseudo_cost_reliability_threshold()) {
102 const double current_merged_cost =
106 if (current_merged_cost > best_cost) {
107 chosen_var = positive_var;
108 best_cost = current_merged_cost;
122 std::vector<PseudoCosts::VariableBoundChange> bound_changes;
128 encoder->GetAllIntegerLiterals(
Literal(decision))) {
130 if (integer_trail->IsCurrentlyIgnored(l.var))
continue;
132 var_bound_change.
var = l.var;
133 const IntegerValue current_lb = integer_trail->LowerBound(l.var);
135 bound_changes.push_back(var_bound_change);
138 return bound_changes;