Google OR-Tools
v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
vivification.h
Go to the documentation of this file.
1
// Copyright 2010-2025 Google LLC
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13
14
#ifndef ORTOOLS_SAT_VIVIFICATION_H_
15
#define ORTOOLS_SAT_VIVIFICATION_H_
16
17
#include <cstdint>
18
19
#include "absl/base/attributes.h"
20
#include "
ortools/sat/clause.h
"
21
#include "
ortools/sat/lrat_proof_handler.h
"
22
#include "
ortools/sat/model.h
"
23
#include "
ortools/sat/sat_base.h
"
24
#include "
ortools/sat/sat_solver.h
"
25
#include "
ortools/util/logging.h
"
26
#include "
ortools/util/time_limit.h
"
27
28
namespace
operations_research::sat
{
29
30
// Helper class responsible for "vivifying" clauses.
31
//
32
// See for instance "Clause Vivification by Unit Propagation in CDCL SAT
33
// Solvers" Chu-Min Li, Fan Xiao, Mao Luo, Felip Manyà, Zhipeng Lü, Yu Li.
34
//
35
// This is basically trying to minimize clauses using propagation by taking as
36
// decisions the negation of some literals of that clause.
37
class
Vivifier
{
38
public
:
39
explicit
Vivifier
(
Model
* model)
40
: assignment_(model->GetOrCreate<
Trail
>()->
Assignment
()),
41
parameters_(*model->GetOrCreate<
SatParameters
>()),
42
time_limit_(model->GetOrCreate<
TimeLimit
>()),
43
logger_(model->GetOrCreate<
SolverLogger
>()),
44
sat_solver_(model->GetOrCreate<
SatSolver
>()),
45
trail_(model->GetOrCreate<
Trail
>()),
46
binary_clauses_(model->GetOrCreate<
BinaryImplicationGraph
>()),
47
clause_manager_(model->GetOrCreate<
ClauseManager
>()),
48
clause_id_generator_(model->GetOrCreate<
ClauseIdGenerator
>()),
49
lrat_proof_handler_(model->Mutable<
LratProofHandler
>()) {}
50
51
// Minimize a batch of clauses using propagation.
52
// Returns false on UNSAT.
53
ABSL_MUST_USE_RESULT
bool
MinimizeByPropagation
(
54
bool
log_info,
double
dtime_budget,
55
bool
minimize_new_clauses_only =
false
);
56
57
// Values from the last MinimizeByPropagation() call.
58
int64_t
last_num_vivified
()
const
{
return
last_num_vivified_; }
59
int64_t
last_num_literals_removed
()
const
{
60
return
last_num_literals_removed_;
61
}
62
63
// Sum of everything ever done by this class.
64
struct
Counters
{
65
int64_t
num_clauses_vivified
= 0;
66
int64_t
num_decisions
= 0;
67
int64_t
num_true
= 0;
68
int64_t
num_subsumed
= 0;
69
int64_t
num_removed_literals
= 0;
70
int64_t
num_reused
= 0;
71
int64_t
num_conflicts
= 0;
72
};
73
Counters
counters
()
const
{
return
counters_; }
74
75
private
:
76
// Use propagation to try to minimize the given clause. This is really similar
77
// to MinimizeCoreWithPropagation(). Note that because this does a small tree
78
// search, it will impact the variable/clause activities and may add new
79
// conflicts.
80
ABSL_MUST_USE_RESULT
bool
TryToMinimizeClause(
SatClause
* clause);
81
82
// Returns true if variable is fixed in the current assignment due to
83
// non-removable clauses, plus at most one removable clause with size <=
84
// max_size.
85
bool
SubsumptionIsInteresting(BooleanVariable variable,
int
max_size);
86
void
KeepAllClausesUsedToInfer(BooleanVariable variable);
87
88
const
VariablesAssignment
& assignment_;
89
const
SatParameters
& parameters_;
90
91
TimeLimit
* time_limit_;
92
SolverLogger
* logger_;
93
SatSolver
* sat_solver_;
94
Trail
* trail_;
95
BinaryImplicationGraph
* binary_clauses_;
96
ClauseManager
* clause_manager_;
97
ClauseIdGenerator
* clause_id_generator_;
98
LratProofHandler
* lrat_proof_handler_ =
nullptr
;
99
100
Counters counters_;
101
102
int64_t last_num_vivified_ = 0;
103
int64_t last_num_literals_removed_ = 0;
104
};
105
106
}
// namespace operations_research::sat
107
#endif
// ORTOOLS_SAT_VIVIFICATION_H_
operations_research::Assignment
Definition
constraint_solver.h:5559
operations_research::SolverLogger
Definition
logging.h:43
operations_research::TimeLimit
Definition
time_limit.h:97
operations_research::sat::BinaryImplicationGraph
Definition
clause.h:619
operations_research::sat::ClauseIdGenerator
Definition
sat_base.h:264
operations_research::sat::ClauseManager
Definition
clause.h:180
operations_research::sat::LratProofHandler
Definition
lrat_proof_handler.h:140
operations_research::sat::Model
Definition
model.h:38
operations_research::sat::SatClause
Definition
clause.h:55
operations_research::sat::SatParameters
Definition
sat_parameters.pb.h:508
operations_research::sat::SatSolver
Definition
sat_solver.h:64
operations_research::sat::Trail
Definition
sat_base.h:331
operations_research::sat::VariablesAssignment
Definition
sat_base.h:174
operations_research::sat::Vivifier::last_num_vivified
int64_t last_num_vivified() const
Definition
vivification.h:58
operations_research::sat::Vivifier::last_num_literals_removed
int64_t last_num_literals_removed() const
Definition
vivification.h:59
operations_research::sat::Vivifier::Vivifier
Vivifier(Model *model)
Definition
vivification.h:39
operations_research::sat::Vivifier::counters
Counters counters() const
Definition
vivification.h:73
operations_research::sat::Vivifier::MinimizeByPropagation
ABSL_MUST_USE_RESULT bool MinimizeByPropagation(bool log_info, double dtime_budget, bool minimize_new_clauses_only=false)
Definition
vivification.cc:33
clause.h
lrat_proof_handler.h
operations_research::sat
Definition
routing_sat.cc:45
model.h
sat_base.h
sat_solver.h
operations_research::sat::Vivifier::Counters
Definition
vivification.h:64
operations_research::sat::Vivifier::Counters::num_decisions
int64_t num_decisions
Definition
vivification.h:66
operations_research::sat::Vivifier::Counters::num_true
int64_t num_true
Definition
vivification.h:67
operations_research::sat::Vivifier::Counters::num_subsumed
int64_t num_subsumed
Definition
vivification.h:68
operations_research::sat::Vivifier::Counters::num_reused
int64_t num_reused
Definition
vivification.h:70
operations_research::sat::Vivifier::Counters::num_clauses_vivified
int64_t num_clauses_vivified
Definition
vivification.h:65
operations_research::sat::Vivifier::Counters::num_removed_literals
int64_t num_removed_literals
Definition
vivification.h:69
operations_research::sat::Vivifier::Counters::num_conflicts
int64_t num_conflicts
Definition
vivification.h:71
time_limit.h
logging.h
ortools
sat
vivification.h
Generated by
1.15.0