cadical 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +26 -0
- data/README.md +101 -0
- data/ext/cadical/cadical/LICENSE +28 -0
- data/ext/cadical/cadical/README.md +65 -0
- data/ext/cadical/cadical/VERSION +1 -0
- data/ext/cadical/cadical/src/analyze.cpp +1360 -0
- data/ext/cadical/cadical/src/arena.cpp +30 -0
- data/ext/cadical/cadical/src/arena.hpp +105 -0
- data/ext/cadical/cadical/src/assume.cpp +616 -0
- data/ext/cadical/cadical/src/averages.cpp +34 -0
- data/ext/cadical/cadical/src/averages.hpp +37 -0
- data/ext/cadical/cadical/src/backbone.cpp +631 -0
- data/ext/cadical/cadical/src/backtrack.cpp +177 -0
- data/ext/cadical/cadical/src/backward.cpp +231 -0
- data/ext/cadical/cadical/src/bins.cpp +22 -0
- data/ext/cadical/cadical/src/bins.hpp +22 -0
- data/ext/cadical/cadical/src/block.cpp +824 -0
- data/ext/cadical/cadical/src/block.hpp +37 -0
- data/ext/cadical/cadical/src/cadical.cpp +1026 -0
- data/ext/cadical/cadical/src/cadical.hpp +1419 -0
- data/ext/cadical/cadical/src/ccadical.cpp +208 -0
- data/ext/cadical/cadical/src/ccadical.h +74 -0
- data/ext/cadical/cadical/src/checker.cpp +649 -0
- data/ext/cadical/cadical/src/checker.hpp +173 -0
- data/ext/cadical/cadical/src/clause.cpp +689 -0
- data/ext/cadical/cadical/src/clause.hpp +190 -0
- data/ext/cadical/cadical/src/collect.cpp +545 -0
- data/ext/cadical/cadical/src/compact.cpp +550 -0
- data/ext/cadical/cadical/src/condition.cpp +940 -0
- data/ext/cadical/cadical/src/config.cpp +101 -0
- data/ext/cadical/cadical/src/config.hpp +20 -0
- data/ext/cadical/cadical/src/congruence.cpp +7880 -0
- data/ext/cadical/cadical/src/congruence.hpp +757 -0
- data/ext/cadical/cadical/src/constrain.cpp +64 -0
- data/ext/cadical/cadical/src/contract.cpp +27 -0
- data/ext/cadical/cadical/src/contract.hpp +139 -0
- data/ext/cadical/cadical/src/cover.cpp +704 -0
- data/ext/cadical/cadical/src/cover.hpp +34 -0
- data/ext/cadical/cadical/src/decide.cpp +347 -0
- data/ext/cadical/cadical/src/decompose.cpp +738 -0
- data/ext/cadical/cadical/src/decompose.hpp +23 -0
- data/ext/cadical/cadical/src/deduplicate.cpp +275 -0
- data/ext/cadical/cadical/src/definition.cpp +283 -0
- data/ext/cadical/cadical/src/delay.hpp +38 -0
- data/ext/cadical/cadical/src/drattracer.cpp +153 -0
- data/ext/cadical/cadical/src/drattracer.hpp +55 -0
- data/ext/cadical/cadical/src/elim.cpp +1171 -0
- data/ext/cadical/cadical/src/elim.hpp +53 -0
- data/ext/cadical/cadical/src/elimfast.cpp +570 -0
- data/ext/cadical/cadical/src/ema.cpp +95 -0
- data/ext/cadical/cadical/src/ema.hpp +68 -0
- data/ext/cadical/cadical/src/extend.cpp +289 -0
- data/ext/cadical/cadical/src/external.cpp +1034 -0
- data/ext/cadical/cadical/src/external.hpp +487 -0
- data/ext/cadical/cadical/src/external_propagate.cpp +1316 -0
- data/ext/cadical/cadical/src/factor.cpp +1011 -0
- data/ext/cadical/cadical/src/factor.hpp +54 -0
- data/ext/cadical/cadical/src/file.cpp +506 -0
- data/ext/cadical/cadical/src/file.hpp +210 -0
- data/ext/cadical/cadical/src/flags.cpp +135 -0
- data/ext/cadical/cadical/src/flags.hpp +93 -0
- data/ext/cadical/cadical/src/flip.cpp +269 -0
- data/ext/cadical/cadical/src/format.cpp +89 -0
- data/ext/cadical/cadical/src/format.hpp +36 -0
- data/ext/cadical/cadical/src/frattracer.cpp +277 -0
- data/ext/cadical/cadical/src/frattracer.hpp +67 -0
- data/ext/cadical/cadical/src/gates.cpp +766 -0
- data/ext/cadical/cadical/src/heap.hpp +212 -0
- data/ext/cadical/cadical/src/idruptracer.cpp +566 -0
- data/ext/cadical/cadical/src/idruptracer.hpp +112 -0
- data/ext/cadical/cadical/src/instantiate.cpp +365 -0
- data/ext/cadical/cadical/src/instantiate.hpp +45 -0
- data/ext/cadical/cadical/src/internal.cpp +1265 -0
- data/ext/cadical/cadical/src/internal.hpp +1941 -0
- data/ext/cadical/cadical/src/inttypes.hpp +34 -0
- data/ext/cadical/cadical/src/ipasir.cpp +47 -0
- data/ext/cadical/cadical/src/ipasir.h +37 -0
- data/ext/cadical/cadical/src/kitten.c +2599 -0
- data/ext/cadical/cadical/src/kitten.h +97 -0
- data/ext/cadical/cadical/src/level.hpp +33 -0
- data/ext/cadical/cadical/src/lidruptracer.cpp +657 -0
- data/ext/cadical/cadical/src/lidruptracer.hpp +122 -0
- data/ext/cadical/cadical/src/limit.cpp +146 -0
- data/ext/cadical/cadical/src/limit.hpp +168 -0
- data/ext/cadical/cadical/src/logging.cpp +214 -0
- data/ext/cadical/cadical/src/logging.hpp +98 -0
- data/ext/cadical/cadical/src/lookahead.cpp +520 -0
- data/ext/cadical/cadical/src/lratchecker.cpp +833 -0
- data/ext/cadical/cadical/src/lratchecker.hpp +168 -0
- data/ext/cadical/cadical/src/lrattracer.cpp +200 -0
- data/ext/cadical/cadical/src/lrattracer.hpp +61 -0
- data/ext/cadical/cadical/src/lucky.cpp +506 -0
- data/ext/cadical/cadical/src/message.cpp +218 -0
- data/ext/cadical/cadical/src/message.hpp +65 -0
- data/ext/cadical/cadical/src/minimize.cpp +224 -0
- data/ext/cadical/cadical/src/mobical.cpp +5588 -0
- data/ext/cadical/cadical/src/occs.cpp +52 -0
- data/ext/cadical/cadical/src/occs.hpp +36 -0
- data/ext/cadical/cadical/src/options.cpp +359 -0
- data/ext/cadical/cadical/src/options.hpp +442 -0
- data/ext/cadical/cadical/src/parse.cpp +471 -0
- data/ext/cadical/cadical/src/parse.hpp +75 -0
- data/ext/cadical/cadical/src/phases.cpp +56 -0
- data/ext/cadical/cadical/src/phases.hpp +19 -0
- data/ext/cadical/cadical/src/probe.cpp +990 -0
- data/ext/cadical/cadical/src/profile.cpp +107 -0
- data/ext/cadical/cadical/src/profile.hpp +283 -0
- data/ext/cadical/cadical/src/proof.cpp +691 -0
- data/ext/cadical/cadical/src/proof.hpp +125 -0
- data/ext/cadical/cadical/src/propagate.cpp +584 -0
- data/ext/cadical/cadical/src/queue.cpp +90 -0
- data/ext/cadical/cadical/src/queue.hpp +74 -0
- data/ext/cadical/cadical/src/radix.hpp +180 -0
- data/ext/cadical/cadical/src/random.cpp +207 -0
- data/ext/cadical/cadical/src/random.h +44 -0
- data/ext/cadical/cadical/src/random.hpp +98 -0
- data/ext/cadical/cadical/src/range.hpp +125 -0
- data/ext/cadical/cadical/src/reap.cpp +127 -0
- data/ext/cadical/cadical/src/reap.hpp +28 -0
- data/ext/cadical/cadical/src/reduce.cpp +278 -0
- data/ext/cadical/cadical/src/reluctant.hpp +82 -0
- data/ext/cadical/cadical/src/rephase.cpp +402 -0
- data/ext/cadical/cadical/src/report.cpp +313 -0
- data/ext/cadical/cadical/src/resources.cpp +160 -0
- data/ext/cadical/cadical/src/resources.hpp +16 -0
- data/ext/cadical/cadical/src/restart.cpp +178 -0
- data/ext/cadical/cadical/src/restore.cpp +267 -0
- data/ext/cadical/cadical/src/score.cpp +51 -0
- data/ext/cadical/cadical/src/score.hpp +16 -0
- data/ext/cadical/cadical/src/shrink.cpp +507 -0
- data/ext/cadical/cadical/src/signal.cpp +136 -0
- data/ext/cadical/cadical/src/signal.hpp +33 -0
- data/ext/cadical/cadical/src/solution.cpp +50 -0
- data/ext/cadical/cadical/src/solver.cpp +1871 -0
- data/ext/cadical/cadical/src/stable.cpp +31 -0
- data/ext/cadical/cadical/src/stack.h +110 -0
- data/ext/cadical/cadical/src/stats.cpp +920 -0
- data/ext/cadical/cadical/src/stats.hpp +418 -0
- data/ext/cadical/cadical/src/subsume.cpp +645 -0
- data/ext/cadical/cadical/src/sweep.cpp +1960 -0
- data/ext/cadical/cadical/src/sweep.hpp +61 -0
- data/ext/cadical/cadical/src/terminal.cpp +38 -0
- data/ext/cadical/cadical/src/terminal.hpp +96 -0
- data/ext/cadical/cadical/src/ternary.cpp +450 -0
- data/ext/cadical/cadical/src/testing.hpp +24 -0
- data/ext/cadical/cadical/src/tier.cpp +189 -0
- data/ext/cadical/cadical/src/tracer.hpp +186 -0
- data/ext/cadical/cadical/src/transred.cpp +253 -0
- data/ext/cadical/cadical/src/unstable.cpp +29 -0
- data/ext/cadical/cadical/src/util.cpp +129 -0
- data/ext/cadical/cadical/src/util.hpp +181 -0
- data/ext/cadical/cadical/src/var.cpp +39 -0
- data/ext/cadical/cadical/src/var.hpp +22 -0
- data/ext/cadical/cadical/src/veripbtracer.cpp +427 -0
- data/ext/cadical/cadical/src/veripbtracer.hpp +106 -0
- data/ext/cadical/cadical/src/version.cpp +107 -0
- data/ext/cadical/cadical/src/version.hpp +13 -0
- data/ext/cadical/cadical/src/vivify.cpp +1893 -0
- data/ext/cadical/cadical/src/vivify.hpp +50 -0
- data/ext/cadical/cadical/src/walk.cpp +1088 -0
- data/ext/cadical/cadical/src/walk.hpp +91 -0
- data/ext/cadical/cadical/src/walk_full_occs.cpp +966 -0
- data/ext/cadical/cadical/src/warmup.cpp +403 -0
- data/ext/cadical/cadical/src/watch.cpp +126 -0
- data/ext/cadical/cadical/src/watch.hpp +77 -0
- data/ext/cadical/cadical_ext.c +778 -0
- data/ext/cadical/extconf.rb +26 -0
- data/lib/cadical/version.rb +3 -0
- data/lib/cadical.rb +12 -0
- metadata +218 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#ifndef _logging_hpp_INCLUDED
|
|
2
|
+
#define _logging_hpp_INCLUDED
|
|
3
|
+
|
|
4
|
+
/*------------------------------------------------------------------------*/
|
|
5
|
+
#ifdef LOGGING
|
|
6
|
+
/*------------------------------------------------------------------------*/
|
|
7
|
+
|
|
8
|
+
#include <cstdint>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
namespace CaDiCaL {
|
|
12
|
+
|
|
13
|
+
// For debugging purposes and to help understanding what the solver is doing
|
|
14
|
+
// there is a logging facility which is compiled in by './configure -l'. It
|
|
15
|
+
// still has to be enabled at run-time though (again using the '-l' option
|
|
16
|
+
// in the stand-alone solver). It produces quite a bit of information.
|
|
17
|
+
|
|
18
|
+
using namespace std;
|
|
19
|
+
|
|
20
|
+
struct Clause;
|
|
21
|
+
struct Gate;
|
|
22
|
+
struct Internal;
|
|
23
|
+
|
|
24
|
+
struct Logger {
|
|
25
|
+
|
|
26
|
+
static void print_log_prefix (Internal *);
|
|
27
|
+
|
|
28
|
+
// Simple logging of a C-style format string.
|
|
29
|
+
//
|
|
30
|
+
static void log (Internal *, const char *fmt, ...)
|
|
31
|
+
CADICAL_ATTRIBUTE_FORMAT (2, 3);
|
|
32
|
+
|
|
33
|
+
// Prints the format string (with its argument) and then the clause. The
|
|
34
|
+
// clause can also be a zero pointer and then is interpreted as a decision
|
|
35
|
+
// (current decision level > 0) or unit clause (zero decision level) and
|
|
36
|
+
// printed accordingly.
|
|
37
|
+
//
|
|
38
|
+
static void log (Internal *, const Clause *, const char *fmt, ...)
|
|
39
|
+
CADICAL_ATTRIBUTE_FORMAT (3, 4);
|
|
40
|
+
|
|
41
|
+
// Same as before, except that this is meant for the global 'clause' stack
|
|
42
|
+
// used for new clauses (and not for reasons).
|
|
43
|
+
//
|
|
44
|
+
static void log (Internal *, const vector<int> &, const char *fmt, ...)
|
|
45
|
+
CADICAL_ATTRIBUTE_FORMAT (3, 4);
|
|
46
|
+
|
|
47
|
+
// Another variant, to avoid copying (without logging).
|
|
48
|
+
//
|
|
49
|
+
static void log (Internal *, const vector<int>::const_iterator &begin,
|
|
50
|
+
const vector<int>::const_iterator &end, const char *fmt,
|
|
51
|
+
...) CADICAL_ATTRIBUTE_FORMAT (4, 5);
|
|
52
|
+
|
|
53
|
+
// used for logging LRAT proof chains
|
|
54
|
+
//
|
|
55
|
+
static void log (Internal *, const vector<int64_t> &, const char *fmt,
|
|
56
|
+
...) CADICAL_ATTRIBUTE_FORMAT (3, 4);
|
|
57
|
+
|
|
58
|
+
static void log (Internal *, const int *, const unsigned, const char *fmt,
|
|
59
|
+
...) CADICAL_ATTRIBUTE_FORMAT (4, 5);
|
|
60
|
+
|
|
61
|
+
static void log_empty_line (Internal *);
|
|
62
|
+
|
|
63
|
+
static void log (Internal *, const Gate *, const char *fmt, ...)
|
|
64
|
+
CADICAL_ATTRIBUTE_FORMAT (3, 4);
|
|
65
|
+
|
|
66
|
+
static string loglit (Internal *, int lit);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace CaDiCaL
|
|
70
|
+
|
|
71
|
+
/*------------------------------------------------------------------------*/
|
|
72
|
+
|
|
73
|
+
// Make sure that 'logging' code is really not included (second case of the
|
|
74
|
+
// '#ifdef') if logging code is not included.
|
|
75
|
+
|
|
76
|
+
#define LOG(...) \
|
|
77
|
+
do { \
|
|
78
|
+
if (!internal->opts.log) \
|
|
79
|
+
break; \
|
|
80
|
+
Logger::log (internal, __VA_ARGS__); \
|
|
81
|
+
} while (0)
|
|
82
|
+
|
|
83
|
+
#define LOGLIT(lit) Logger::loglit (internal, lit).c_str ()
|
|
84
|
+
|
|
85
|
+
/*------------------------------------------------------------------------*/
|
|
86
|
+
#else // end of 'then' part of 'ifdef LOGGING'
|
|
87
|
+
/*------------------------------------------------------------------------*/
|
|
88
|
+
|
|
89
|
+
#define LOG(...) \
|
|
90
|
+
do { \
|
|
91
|
+
} while (0)
|
|
92
|
+
|
|
93
|
+
#define LOGLIT(...)
|
|
94
|
+
|
|
95
|
+
/*------------------------------------------------------------------------*/
|
|
96
|
+
#endif // end of 'else' part of 'ifdef LOGGING'
|
|
97
|
+
/*------------------------------------------------------------------------*/
|
|
98
|
+
#endif
|
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
#include "internal.hpp"
|
|
2
|
+
|
|
3
|
+
namespace CaDiCaL {
|
|
4
|
+
|
|
5
|
+
struct literal_occ {
|
|
6
|
+
int lit;
|
|
7
|
+
int count;
|
|
8
|
+
bool operator< (const literal_occ &locc) const {
|
|
9
|
+
return (count > locc.count) || (count == locc.count && lit < locc.lit);
|
|
10
|
+
}
|
|
11
|
+
literal_occ operator++ () {
|
|
12
|
+
++count;
|
|
13
|
+
return *this;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
std::vector<int> Internal::lookahead_populate_locc () {
|
|
18
|
+
std::vector<literal_occ> loccs ((std::size_t) max_var + 1);
|
|
19
|
+
for (std::size_t lit = 0; lit < loccs.size (); ++lit) {
|
|
20
|
+
loccs[lit].lit = lit;
|
|
21
|
+
}
|
|
22
|
+
for (const auto &c : clauses)
|
|
23
|
+
if (!c->redundant)
|
|
24
|
+
for (const auto &lit : *c)
|
|
25
|
+
if (active (lit))
|
|
26
|
+
++loccs[std::abs (lit)];
|
|
27
|
+
std::sort (begin (loccs), end (loccs));
|
|
28
|
+
std::vector<int> locc_map;
|
|
29
|
+
locc_map.reserve (max_var);
|
|
30
|
+
for (const auto &locc : loccs)
|
|
31
|
+
locc_map.push_back (locc.lit);
|
|
32
|
+
return locc_map;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
int Internal::lookahead_locc (const std::vector<int> &loccs) {
|
|
36
|
+
for (auto lit : loccs)
|
|
37
|
+
if (active (abs (lit)) && !assumed (lit) && !assumed (-lit) &&
|
|
38
|
+
!val (lit))
|
|
39
|
+
return lit;
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// This calculates the literal that appears the most often reusing the
|
|
44
|
+
// available datastructures and iterating over the clause set. This is too
|
|
45
|
+
// slow to be called iteratively. A faster (but inexact) version is
|
|
46
|
+
// lookahead_populate_loc and lookahead_loc.
|
|
47
|
+
int Internal::most_occurring_literal () {
|
|
48
|
+
init_noccs ();
|
|
49
|
+
for (const auto &c : clauses)
|
|
50
|
+
if (!c->redundant)
|
|
51
|
+
for (const auto &lit : *c)
|
|
52
|
+
if (active (lit))
|
|
53
|
+
noccs (lit)++;
|
|
54
|
+
int64_t max_noccs = 0;
|
|
55
|
+
int res = 0;
|
|
56
|
+
|
|
57
|
+
if (unsat)
|
|
58
|
+
return INT_MIN;
|
|
59
|
+
|
|
60
|
+
propagate ();
|
|
61
|
+
for (int idx = 1; idx <= max_var; idx++) {
|
|
62
|
+
if (!active (idx) || assumed (idx) || assumed (-idx) || val (idx))
|
|
63
|
+
continue;
|
|
64
|
+
for (int sign = -1; sign <= 1; sign += 2) {
|
|
65
|
+
const int lit = sign * idx;
|
|
66
|
+
if (!active (lit))
|
|
67
|
+
continue;
|
|
68
|
+
int64_t tmp = noccs (lit);
|
|
69
|
+
if (tmp <= max_noccs)
|
|
70
|
+
continue;
|
|
71
|
+
max_noccs = tmp;
|
|
72
|
+
res = lit;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
MSG ("maximum occurrence %" PRId64 " of literal %d", max_noccs, res);
|
|
76
|
+
reset_noccs ();
|
|
77
|
+
return res;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// We probe on literals first, which occur more often negated and thus we
|
|
81
|
+
// sort the 'probes' stack in such a way that literals which occur negated
|
|
82
|
+
// less frequently come first. Probes are taken from the back of the stack.
|
|
83
|
+
|
|
84
|
+
struct probe_negated_noccs_rank {
|
|
85
|
+
Internal *internal;
|
|
86
|
+
probe_negated_noccs_rank (Internal *i) : internal (i) {}
|
|
87
|
+
typedef size_t Type;
|
|
88
|
+
Type operator() (int a) const { return internal->noccs (-a); }
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Follow the ideas in 'generate_probes' but flush non root probes and
|
|
92
|
+
// reorder remaining probes.
|
|
93
|
+
|
|
94
|
+
void Internal::lookahead_flush_probes () {
|
|
95
|
+
|
|
96
|
+
assert (!probes.empty ());
|
|
97
|
+
|
|
98
|
+
init_noccs ();
|
|
99
|
+
for (const auto &c : clauses) {
|
|
100
|
+
int a, b;
|
|
101
|
+
if (!is_binary_clause (c, a, b))
|
|
102
|
+
continue;
|
|
103
|
+
noccs (a)++;
|
|
104
|
+
noccs (b)++;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const auto eop = probes.end ();
|
|
108
|
+
auto j = probes.begin ();
|
|
109
|
+
for (auto i = j; i != eop; i++) {
|
|
110
|
+
int lit = *i;
|
|
111
|
+
if (!active (lit))
|
|
112
|
+
continue;
|
|
113
|
+
const bool have_pos_bin_occs = noccs (lit) > 0;
|
|
114
|
+
const bool have_neg_bin_occs = noccs (-lit) > 0;
|
|
115
|
+
if (have_pos_bin_occs == have_neg_bin_occs)
|
|
116
|
+
continue;
|
|
117
|
+
if (have_pos_bin_occs)
|
|
118
|
+
lit = -lit;
|
|
119
|
+
assert (!noccs (lit)), assert (noccs (-lit) > 0);
|
|
120
|
+
if (propfixed (lit) >= stats.all.fixed)
|
|
121
|
+
continue;
|
|
122
|
+
MSG ("keeping probe %d negated occs %" PRId64 "", lit, noccs (-lit));
|
|
123
|
+
*j++ = lit;
|
|
124
|
+
}
|
|
125
|
+
size_t remain = j - probes.begin ();
|
|
126
|
+
#ifndef QUIET
|
|
127
|
+
size_t flushed = probes.size () - remain;
|
|
128
|
+
#endif
|
|
129
|
+
probes.resize (remain);
|
|
130
|
+
|
|
131
|
+
rsort (probes.begin (), probes.end (), probe_negated_noccs_rank (this));
|
|
132
|
+
|
|
133
|
+
reset_noccs ();
|
|
134
|
+
shrink_vector (probes);
|
|
135
|
+
|
|
136
|
+
PHASE ("probe-round", stats.probingrounds,
|
|
137
|
+
"flushed %zd literals %.0f%% remaining %zd", flushed,
|
|
138
|
+
percent (flushed, remain + flushed), remain);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void Internal::lookahead_generate_probes () {
|
|
142
|
+
|
|
143
|
+
assert (probes.empty ());
|
|
144
|
+
|
|
145
|
+
// First determine all the literals which occur in binary clauses. It is
|
|
146
|
+
// way faster to go over the clauses once, instead of walking the watch
|
|
147
|
+
// lists for each literal.
|
|
148
|
+
//
|
|
149
|
+
init_noccs ();
|
|
150
|
+
for (const auto &c : clauses) {
|
|
151
|
+
int a, b;
|
|
152
|
+
if (!is_binary_clause (c, a, b))
|
|
153
|
+
continue;
|
|
154
|
+
noccs (a)++;
|
|
155
|
+
noccs (b)++;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for (int idx = 1; idx <= max_var; idx++) {
|
|
159
|
+
|
|
160
|
+
// Then focus on roots of the binary implication graph, which are
|
|
161
|
+
// literals occurring negatively in a binary clause, but not positively.
|
|
162
|
+
// If neither 'idx' nor '-idx' is a root it makes less sense to probe
|
|
163
|
+
// this variable.
|
|
164
|
+
|
|
165
|
+
// This argument requires that equivalent literal substitution through
|
|
166
|
+
// 'decompose' is performed, because otherwise there might be 'cyclic
|
|
167
|
+
// roots' which are not tried, i.e., -1 2 0, 1 -2 0, 1 2 3 0, 1 2 -3 0.
|
|
168
|
+
|
|
169
|
+
const bool have_pos_bin_occs = noccs (idx) > 0;
|
|
170
|
+
const bool have_neg_bin_occs = noccs (-idx) > 0;
|
|
171
|
+
|
|
172
|
+
// if (have_pos_bin_occs == have_neg_bin_occs) continue;
|
|
173
|
+
|
|
174
|
+
if (have_pos_bin_occs) {
|
|
175
|
+
int probe = -idx;
|
|
176
|
+
|
|
177
|
+
// See the discussion where 'propfixed' is used below.
|
|
178
|
+
//
|
|
179
|
+
if (propfixed (probe) >= stats.all.fixed)
|
|
180
|
+
continue;
|
|
181
|
+
|
|
182
|
+
MSG ("scheduling probe %d negated occs %" PRId64 "", probe,
|
|
183
|
+
noccs (-probe));
|
|
184
|
+
probes.push_back (probe);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (have_neg_bin_occs) {
|
|
188
|
+
int probe = idx;
|
|
189
|
+
|
|
190
|
+
// See the discussion where 'propfixed' is used below.
|
|
191
|
+
//
|
|
192
|
+
if (propfixed (probe) >= stats.all.fixed)
|
|
193
|
+
continue;
|
|
194
|
+
|
|
195
|
+
MSG ("scheduling probe %d negated occs %" PRId64 "", probe,
|
|
196
|
+
noccs (-probe));
|
|
197
|
+
probes.push_back (probe);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
rsort (probes.begin (), probes.end (), probe_negated_noccs_rank (this));
|
|
202
|
+
|
|
203
|
+
reset_noccs ();
|
|
204
|
+
shrink_vector (probes);
|
|
205
|
+
|
|
206
|
+
PHASE ("probe-round", stats.probingrounds,
|
|
207
|
+
"scheduled %zd literals %.0f%%", probes.size (),
|
|
208
|
+
percent (probes.size (), 2 * max_var));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
int Internal::lookahead_next_probe () {
|
|
212
|
+
|
|
213
|
+
int generated = 0;
|
|
214
|
+
|
|
215
|
+
for (;;) {
|
|
216
|
+
|
|
217
|
+
if (probes.empty ()) {
|
|
218
|
+
if (generated++)
|
|
219
|
+
return 0;
|
|
220
|
+
lookahead_generate_probes ();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
while (!probes.empty ()) {
|
|
224
|
+
|
|
225
|
+
int probe = probes.back ();
|
|
226
|
+
probes.pop_back ();
|
|
227
|
+
|
|
228
|
+
// Eliminated or assigned.
|
|
229
|
+
//
|
|
230
|
+
if (!active (probe) || assumed (probe) || assumed (-probe))
|
|
231
|
+
continue;
|
|
232
|
+
|
|
233
|
+
// There is now new unit since the last time we propagated this probe,
|
|
234
|
+
// thus we propagated it before without obtaining a conflict and
|
|
235
|
+
// nothing changed since then. Thus there is no need to propagate it
|
|
236
|
+
// again. This observation was independently made by Partik Simons
|
|
237
|
+
// et.al. in the context of implementing 'smodels' (see for instance
|
|
238
|
+
// Alg. 4 in his JAIR article from 2002) and it has also been
|
|
239
|
+
// contributed to the thesis work of Yacine Boufkhad.
|
|
240
|
+
//
|
|
241
|
+
if (propfixed (probe) >= stats.all.fixed)
|
|
242
|
+
continue;
|
|
243
|
+
|
|
244
|
+
return probe;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
bool non_tautological_cube (std::vector<int> cube) {
|
|
250
|
+
std::sort (begin (cube), end (cube), clause_lit_less_than ());
|
|
251
|
+
|
|
252
|
+
for (size_t i = 0, j = 1; j < cube.size (); ++i, ++j)
|
|
253
|
+
if (cube[i] == cube[j])
|
|
254
|
+
return false;
|
|
255
|
+
else if (cube[i] == -cube[j])
|
|
256
|
+
return false;
|
|
257
|
+
else if (cube[i] == 0)
|
|
258
|
+
return false;
|
|
259
|
+
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
bool Internal::terminating_asked () {
|
|
264
|
+
|
|
265
|
+
if (external->terminator && external->terminator->terminate ()) {
|
|
266
|
+
MSG ("connected terminator forces termination");
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (termination_forced) {
|
|
271
|
+
MSG ("termination forced");
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// We run probing on all literals with some differences:
|
|
278
|
+
//
|
|
279
|
+
// * no limit on the number of propagations. We rely on terminating to
|
|
280
|
+
// stop()
|
|
281
|
+
// * we run only one round
|
|
282
|
+
//
|
|
283
|
+
// The run can be expensive, so we actually first run the cheaper
|
|
284
|
+
// occurrence version and only then run lookahead.
|
|
285
|
+
//
|
|
286
|
+
int Internal::lookahead_probing () {
|
|
287
|
+
|
|
288
|
+
if (!active ())
|
|
289
|
+
return 0;
|
|
290
|
+
|
|
291
|
+
MSG ("lookahead-probe-round %" PRId64
|
|
292
|
+
" without propagations limit and %zu assumptions",
|
|
293
|
+
stats.probingrounds, assumptions.size ());
|
|
294
|
+
|
|
295
|
+
termination_forced = false;
|
|
296
|
+
|
|
297
|
+
#ifndef QUIET
|
|
298
|
+
int old_failed = stats.failed;
|
|
299
|
+
int64_t old_probed = stats.probed;
|
|
300
|
+
#endif
|
|
301
|
+
int64_t old_hbrs = stats.hbrs;
|
|
302
|
+
|
|
303
|
+
if (unsat)
|
|
304
|
+
return INT_MIN;
|
|
305
|
+
if (level)
|
|
306
|
+
backtrack ();
|
|
307
|
+
if (!propagate ()) {
|
|
308
|
+
MSG ("empty clause before probing");
|
|
309
|
+
learn_empty_clause ();
|
|
310
|
+
return INT_MIN;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (terminating_asked ())
|
|
314
|
+
return most_occurring_literal ();
|
|
315
|
+
|
|
316
|
+
decompose ();
|
|
317
|
+
|
|
318
|
+
if (ternary ()) // If we derived a binary clause
|
|
319
|
+
decompose (); // then start another round of ELS.
|
|
320
|
+
|
|
321
|
+
// Remove duplicated binary clauses and perform in essence hyper unary
|
|
322
|
+
// resolution, i.e., derive the unit '2' from '1 2' and '-1 2'.
|
|
323
|
+
//
|
|
324
|
+
mark_duplicated_binary_clauses_as_garbage ();
|
|
325
|
+
|
|
326
|
+
lim.conflicts = -1;
|
|
327
|
+
|
|
328
|
+
if (!probes.empty ())
|
|
329
|
+
lookahead_flush_probes ();
|
|
330
|
+
|
|
331
|
+
// We reset 'propfixed' since there was at least another conflict thus
|
|
332
|
+
// a new learned clause, which might produce new propagations (and hyper
|
|
333
|
+
// binary resolvents). During 'generate_probes' we keep the old value.
|
|
334
|
+
//
|
|
335
|
+
for (int idx = 1; idx <= max_var; idx++)
|
|
336
|
+
propfixed (idx) = propfixed (-idx) = -1;
|
|
337
|
+
|
|
338
|
+
assert (unsat || propagated == trail.size ());
|
|
339
|
+
propagated = propagated2 = trail.size ();
|
|
340
|
+
|
|
341
|
+
int probe;
|
|
342
|
+
int res = most_occurring_literal ();
|
|
343
|
+
int max_hbrs = -1;
|
|
344
|
+
|
|
345
|
+
set_mode (PROBE);
|
|
346
|
+
|
|
347
|
+
MSG ("unsat = %d, terminating_asked () = %d ", unsat,
|
|
348
|
+
terminating_asked ());
|
|
349
|
+
init_probehbr_lrat ();
|
|
350
|
+
while (!unsat && !terminating_asked () &&
|
|
351
|
+
(probe = lookahead_next_probe ())) {
|
|
352
|
+
stats.probed++;
|
|
353
|
+
int hbrs;
|
|
354
|
+
|
|
355
|
+
probe_assign_decision (probe);
|
|
356
|
+
if (probe_propagate ())
|
|
357
|
+
hbrs = trail.size (), backtrack ();
|
|
358
|
+
else
|
|
359
|
+
hbrs = 0, failed_literal (probe);
|
|
360
|
+
clean_probehbr_lrat ();
|
|
361
|
+
if (max_hbrs < hbrs ||
|
|
362
|
+
(max_hbrs == hbrs &&
|
|
363
|
+
internal->bumped (probe) > internal->bumped (res))) {
|
|
364
|
+
res = probe;
|
|
365
|
+
max_hbrs = hbrs;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
reset_mode (PROBE);
|
|
370
|
+
|
|
371
|
+
if (unsat) {
|
|
372
|
+
MSG ("probing derived empty clause");
|
|
373
|
+
res = INT_MIN;
|
|
374
|
+
} else if (propagated < trail.size ()) {
|
|
375
|
+
MSG ("probing produced %zd units",
|
|
376
|
+
(size_t) (trail.size () - propagated));
|
|
377
|
+
if (!propagate ()) {
|
|
378
|
+
MSG ("propagating units after probing results in empty clause");
|
|
379
|
+
learn_empty_clause ();
|
|
380
|
+
res = INT_MIN;
|
|
381
|
+
} else
|
|
382
|
+
sort_watches ();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
#ifndef QUIET
|
|
386
|
+
int failed = stats.failed - old_failed;
|
|
387
|
+
int64_t probed = stats.probed - old_probed;
|
|
388
|
+
#endif
|
|
389
|
+
int64_t hbrs = stats.hbrs - old_hbrs;
|
|
390
|
+
|
|
391
|
+
MSG ("lookahead-probe-round %" PRId64 " probed %" PRId64
|
|
392
|
+
" and found %d failed literals",
|
|
393
|
+
stats.probingrounds, probed, failed);
|
|
394
|
+
|
|
395
|
+
if (hbrs)
|
|
396
|
+
PHASE ("lookahead-probe-round", stats.probingrounds,
|
|
397
|
+
"found %" PRId64 " hyper binary resolvents", hbrs);
|
|
398
|
+
|
|
399
|
+
MSG ("lookahead literal %d with %d\n", res, max_hbrs);
|
|
400
|
+
|
|
401
|
+
return res;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
CubesWithStatus Internal::generate_cubes (int depth, int min_depth) {
|
|
405
|
+
if (!active () || depth == 0) {
|
|
406
|
+
CubesWithStatus cubes;
|
|
407
|
+
cubes.status = 0;
|
|
408
|
+
cubes.cubes.push_back (std::vector<int> ());
|
|
409
|
+
return cubes;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
lookingahead = true;
|
|
413
|
+
START (lookahead);
|
|
414
|
+
MSG ("Generating cubes of depth %i", depth);
|
|
415
|
+
|
|
416
|
+
// presimplify required due to assumptions
|
|
417
|
+
|
|
418
|
+
termination_forced = false;
|
|
419
|
+
int res = already_solved ();
|
|
420
|
+
if (res == 0)
|
|
421
|
+
res = restore_clauses ();
|
|
422
|
+
if (unsat)
|
|
423
|
+
res = 10;
|
|
424
|
+
if (res != 0)
|
|
425
|
+
res = solve (true);
|
|
426
|
+
if (res != 0) {
|
|
427
|
+
MSG ("Solved during preprocessing");
|
|
428
|
+
CubesWithStatus cubes;
|
|
429
|
+
cubes.status = res;
|
|
430
|
+
lookingahead = false;
|
|
431
|
+
STOP (lookahead);
|
|
432
|
+
return cubes;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
reset_limits ();
|
|
436
|
+
MSG ("generate cubes with %zu assumptions\n", assumptions.size ());
|
|
437
|
+
|
|
438
|
+
assert (ntab.empty ());
|
|
439
|
+
std::vector<int> current_assumptions{assumptions};
|
|
440
|
+
std::vector<std::vector<int>> cubes{{assumptions}};
|
|
441
|
+
auto loccs{lookahead_populate_locc ()};
|
|
442
|
+
LOG ("loccs populated\n");
|
|
443
|
+
assert (ntab.empty ());
|
|
444
|
+
|
|
445
|
+
for (int i = 0; i < depth; ++i) {
|
|
446
|
+
LOG ("Probing at depth %i, currently %zu have been generated", i,
|
|
447
|
+
cubes.size ());
|
|
448
|
+
std::vector<std::vector<int>> cubes2{std::move (cubes)};
|
|
449
|
+
cubes.clear ();
|
|
450
|
+
|
|
451
|
+
for (size_t j = 0; j < cubes2.size (); ++j) {
|
|
452
|
+
assert (ntab.empty ());
|
|
453
|
+
assert (!unsat);
|
|
454
|
+
reset_assumptions ();
|
|
455
|
+
for (auto lit : cubes2[j])
|
|
456
|
+
assume (lit);
|
|
457
|
+
restore_clauses ();
|
|
458
|
+
propagate ();
|
|
459
|
+
// preprocess_round(0); //uncomment maybe
|
|
460
|
+
|
|
461
|
+
if (unsat) {
|
|
462
|
+
LOG ("current cube is unsat; skipping");
|
|
463
|
+
unsat = false;
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
int res = terminating_asked () ? lookahead_locc (loccs)
|
|
468
|
+
: lookahead_probing ();
|
|
469
|
+
if (unsat) {
|
|
470
|
+
LOG ("current cube is unsat; skipping");
|
|
471
|
+
unsat = false;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (res == 0) {
|
|
476
|
+
LOG ("no lit to split %i", res);
|
|
477
|
+
cubes.push_back (cubes2[j]);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
assert (res != 0);
|
|
482
|
+
LOG ("splitting on lit %i", res);
|
|
483
|
+
std::vector<int> cube1{cubes2[j]};
|
|
484
|
+
cube1.push_back (res);
|
|
485
|
+
std::vector<int> cube2{std::move (cubes2[j])};
|
|
486
|
+
cube2.push_back (-res);
|
|
487
|
+
cubes.push_back (cube1);
|
|
488
|
+
cubes.push_back (cube2);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (terminating_asked () && i >= min_depth)
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
assert (std::for_each (
|
|
496
|
+
std::begin (cubes), std::end (cubes),
|
|
497
|
+
[] (std::vector<int> cube) { return non_tautological_cube (cube); }));
|
|
498
|
+
reset_assumptions ();
|
|
499
|
+
|
|
500
|
+
for (auto lit : current_assumptions)
|
|
501
|
+
assume (lit);
|
|
502
|
+
|
|
503
|
+
STOP (lookahead);
|
|
504
|
+
lookingahead = false;
|
|
505
|
+
|
|
506
|
+
if (unsat) {
|
|
507
|
+
LOG ("Solved during preprocessing");
|
|
508
|
+
CubesWithStatus cubes;
|
|
509
|
+
cubes.status = 20;
|
|
510
|
+
return cubes;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
CubesWithStatus rcubes;
|
|
514
|
+
rcubes.status = 0;
|
|
515
|
+
rcubes.cubes = cubes;
|
|
516
|
+
|
|
517
|
+
return rcubes;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
} // namespace CaDiCaL
|