30 const int size_limit =
opts.factorsize;
33 const unsigned max_lit = 2 * (
max_var + 1);
34 enlarge_zero (bincount, max_lit);
36 enlarge_zero (largecount, max_lit);
39 int64_t &ticks =
stats.ticks.factor;
47 if (c->redundant && c->size > 2)
49 if (c->size > size_limit)
52 const int lit = c->literals[0];
53 const int other = c->literals[1];
55 bincount[
vlit (other)]++;
57 occs (other).push_back (c);
60 candidates.push_back (c);
61 for (
const auto &
lit : *c) {
69 const unsigned rounds =
opts.factorcandrounds;
70 unsigned candidates_before = 0;
71 for (
unsigned round = 1; round <= rounds; round++) {
72 LOG (
"factor round %d", round);
73 if (candidates.
size () == candidates_before)
76 candidates_before = candidates.
size ();
78 enlarge_zero (newlargecount, max_lit);
79 const auto begin = candidates.begin ();
80 auto p = candidates.begin ();
82 const auto end = candidates.end ();
86 for (
const auto &
lit : *c) {
88 if (bincount[idx] + largecount[idx] < 2) {
90 goto CONTINUE_WITH_NEXT_CLAUSE;
93 for (
const auto &
lit : *c) {
97 CONTINUE_WITH_NEXT_CLAUSE:
100 candidates.resize (q - begin);
101 largecount.swap (newlargecount);
105 for (
const auto &c : candidates)
106 for (
const auto &
lit : *c)
119 const unsigned max_var =
internal->max_var;
120 const unsigned max_lit = 2 * (max_var + 1);
123 enlarge_zero (
count, max_lit);
131 internal->release_quotients (*
this);
137 LOG (
"watches score %g of %d", res,
lit);
169 LOG (
"new quotient[%zu] with factor %d", res->
id,
factor);
190 qlauses.push_back (c);
193 size_t res = qlauses.
size ();
194 LOG (
"quotient[0] factor %d size %zu",
factor, res);
197 stats.ticks.factor += ticks;
202 for (
const auto &
lit : nounted) {
210 for (
auto c : flauses) {
218 size_t *best_reduction_ptr) {
219 size_t factors = 1, best_reduction = 0;
222 size_t quotients = q->qlauses.size ();
223 size_t before_factorization = quotients * factors;
224 size_t after_factorization = quotients + factors;
225 if (before_factorization == after_factorization)
226 LOG (
"quotient[%zu] factors %zu clauses into %zu thus no change",
227 factors - 1, before_factorization, after_factorization);
228 else if (before_factorization < after_factorization)
229 LOG (
"quotient[%zu] factors %zu clauses into %zu thus %zu more",
230 factors - 1, before_factorization, after_factorization,
231 after_factorization - before_factorization);
233 size_t delta = before_factorization - after_factorization;
234 LOG (
"quotient[%zu] factors %zu clauses into %zu thus %zu less",
235 factors - 1, before_factorization, after_factorization, delta);
236 if (!best || best_reduction < delta) {
237 best_reduction = delta;
244 LOG (
"no decreasing quotient found");
247 LOG (
"best decreasing quotient[%zu] with reduction %zu", best->
id,
249 *best_reduction_ptr = best_reduction;
264 for (
auto c : last_clauses) {
267 unsigned factors = 0;
270 for (
const auto &other : *c) {
277 const size_t other_size =
occs (other).
size ();
278 if (!min_lit || other_size < min_size) {
280 min_size = other_size;
287 const int c_size = c->size;
291 for (
auto d :
occs (min_lit)) {
297 if (d->size != c_size)
300 for (
const auto &other : *d) {
304 goto CONTINUE_WITH_NEXT_MIN_WATCH;
306 goto CONTINUE_WITH_NEXT_MIN_WATCH;
308 goto CONTINUE_WITH_NEXT_MIN_WATCH;
312 if (abs (next) > abs (initial))
319 nounted.push_back (next);
321 flauses.push_back (d);
322 if (!count[
vlit (next)])
323 counted.push_back (next);
324 count[
vlit (next)]++;
325 CONTINUE_WITH_NEXT_MIN_WATCH:;
329 for (
const auto &other : *c)
332 stats.ticks.factor += ticks;
338 unsigned next_count = 0;
342 for (
const auto &
lit : counted) {
343 const unsigned lit_count = count[
vlit (
lit)];
344 if (lit_count < next_count)
346 if (lit_count == next_count) {
351 next_count = lit_count;
356 if (next_count < 2) {
357 LOG (
"next factor count %u smaller than 2", next_count);
359 }
else if (ties > 1) {
360 LOG (
"found %u tied next factor candidate literals with count %u",
362 double next_score = -1;
363 for (
const auto &
lit : counted) {
364 const unsigned lit_count = count[
vlit (
lit)];
365 if (lit_count != next_count)
369 LOG (
"score %g of next factor candidate %d", lit_score,
lit);
370 if (lit_score <= next_score)
372 next_score = lit_score;
377 LOG (
"best score %g of next factor %d", next_score, next);
380 LOG (
"single next factor %d with count %u", next, next_count);
383 for (
const auto &
lit : counted)
387 *next_count_ptr = next_count;
392 unsigned expected_next_count) {
407 for (
auto c : last_clauses) {
410 unsigned factors = 0;
413 for (
const auto &other : *c) {
420 const size_t other_size =
occs (other).
size ();
421 if (!min_lit || other_size < min_size) {
423 min_size = other_size;
430 const int c_size = c->size;
432 for (
auto d :
occs (min_lit)) {
438 if (d->size != c_size)
440 for (
const auto &other : *d) {
444 goto CONTINUE_WITH_NEXT_MIN_WATCH;
449 next_clauses.push_back (d);
450 matches.push_back (i);
451 flauses.push_back (d);
455 CONTINUE_WITH_NEXT_MIN_WATCH:;
458 for (
const auto &other : *c)
464 stats.ticks.factor += ticks;
467 (void) expected_next_count;
474 size_t new_var_size =
lit + 1;
475 size_t new_lit_size = 2 * new_var_size;
483 const size_t n = q_clauses.
size ();
485 bool prev_is_first = !prev->
id;
487 while (i < q_matches.
size ()) {
488 size_t j = q_matches[i];
491 if (!prev_is_first) {
492 size_t matches = prev_matches[j];
493 prev_matches[i] = matches;
495 Clause *c = prev_clauses[j];
499 LOG (
"flushing %zu clauses of quotient[%zu]", prev_clauses.size () - n,
502 prev_matches.resize (n);
503 prev_clauses.resize (n);
512 const int not_factor =
p->factor;
515 "adding self subsuming factor because blocked clause is a tautology");
517 for (
const auto &
lit : *c) {
523 for (
auto d :
p->qlauses) {
525 for (
const auto &
lit : *d) {
526 if (
lit == not_factor)
545 const int unit =
clause[0];
546 const signed char tmp =
val (unit);
601 LOG (
"factored %d divider %d",
factor, fresh);
621 clause.push_back (not_fresh);
632 LOG (
"adding factored quotient[%zu] clauses", q->
id);
636 for (
unsigned idx = 0; idx < qlauses.size (); idx++) {
637 const auto c = qlauses[idx];
639 for (
const auto &other : *c) {
648 unsigned idxtoo = idx;
652 idxtoo =
p->matches[idx];
656 clause.push_back (not_fresh);
665 clause.push_back (not_fresh);
673 for (
const auto &
lit : *c) {
675 auto p = occ.begin ();
676 auto q = occ.begin ();
677 auto begin = occ.begin ();
678 auto end = occ.end ();
685 occ.resize (q - begin);
691 LOG (
"deleting unfactored quotient[%zu] clauses", q->
id);
695 stats.literals_unfactored += c->size;
696 stats.clauses_unfactored++;
706 LOG (c,
"deleting unfactored");
707 for (
const auto &
lit : *c)
730 const int not_fresh = -fresh;
745 const unsigned idx =
vlit (
lit);
754 for (
const auto &idx :
vars) {
758 const int not_lit = -
lit;
767 VERBOSE (2,
"scheduled %zu factorization candidate literals %.0f %%",
777 unsigned factored = 0;
779 int64_t *ticks = &
stats.ticks.factor;
780 VERBOSE (3,
"factorization limit of %" PRIu64
" ticks",
limit - *ticks);
784 LOG (
"next factor candidate %d", ufirst);
785 const int first =
u2i (ufirst);
786 const int first_idx =
vidx (first);
789 if (!
occs (first).size ()) {
793 if (*ticks >
limit) {
794 VERBOSE (2,
"factorization ticks limit hit");
800 const unsigned bit = 1u << (first < 0);
805 if (first_count > 1) {
835 completed =
occs (
u2i (idx)).empty ();
846 const int current_max_external =
external->max_var;
847 const int new_external = current_max_external + 1;
848 const int new_internal =
external->internalize (new_external,
true);
869 if (
last.factor.marked >=
stats.mark.factor) {
871 "factorization skipped as no literals have been"
872 "marked to be added (%" PRIu64
" < %" PRIu64
")",
887 int64_t variables,
clauses, ticks;
888 } before, after, delta;
889 before.variables =
stats.variables_extension +
stats.variables_original;
890 before.ticks =
stats.ticks.factor;
891 before.clauses =
stats.current.irredundant;
904 after.variables =
stats.variables_extension +
stats.variables_original;
905 after.clauses =
stats.current.irredundant;
906 after.ticks =
stats.ticks.factor;
907 delta.variables = after.variables - before.variables;
908 delta.clauses = before.clauses - after.clauses;
909 delta.ticks = after.ticks - before.ticks;
910 VERBOSE (2,
"used %f million factorization ticks", delta.ticks * 1e-6);
912 "introduced %" PRId64
" extension variables %.0f%%",
913 delta.variables,
percent (delta.variables, before.variables));
915 "removed %" PRId64
" irredundant clauses %.0f%%", delta.clauses,
916 percent (delta.clauses, before.clauses));
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
bool contains(unsigned e) const
void push_back(unsigned e)
#define SET_EFFORT_LIMIT(LIMIT, NAME, THRESHHOLD)
heap< factor_occs_size > FactorSchedule
double percent(double a, double b)
#define START_SIMPLIFIER(S, M)
#define STOP_SIMPLIFIER(S, M)
struct CaDiCaL::Factoring::@045300102074365064333035263007161374160235131045 quotients
Factoring(Internal *, int64_t)
vector< Clause * > flauses
Clause * new_factor_clause()
int64_t cache_lines(size_t bytes)
int get_new_extension_variable()
size_t first_factor(Factoring &, int)
Quotient * best_quotient(Factoring &, size_t *)
void mark_garbage(Clause *)
vector< int64_t > lrat_chain
void report(char type, int verbose_level=0)
bool run_factorization(int64_t limit)
void factorize_next(Factoring &, int, unsigned)
bool terminated_asynchronously(int factor=1)
void update_factored(Factoring &factoring, Quotient *q)
void eagerly_remove_from_occurences(Clause *c)
bool self_subsuming_factor(Quotient *)
void learn_empty_clause()
void assign_unit(int lit)
void clear_flauses(vector< Clause * > &)
void resize_factoring(Factoring &factoring, int lit)
bool apply_factoring(Factoring &factoring, Quotient *q)
void add_factored_quotient(Quotient *, int not_fresh)
signed char val(int lit) const
bool limit(const char *name, int)
void flush_unmatched_clauses(Quotient *)
int64_t unit_id(int lit) const
void schedule_factorization(Factoring &)
Quotient * new_quotient(Factoring &, int)
int next_factor(Factoring &, unsigned *)
void release_quotients(Factoring &)
unsigned vlit(int lit) const
vector< Clause * > clauses
void clear_analyzed_literals()
void update_factor_candidate(Factoring &, int)
void blocked_clause(Quotient *q, int)
void add_factored_divider(Quotient *, int)
void unmarkfact(int lit, int fact)
double tied_next_factor_score(int)
void markfact(int lit, int fact)
void add_self_subsuming_factor(Quotient *, Quotient *)
vector< int64_t > mini_chain
void clear_nounted(vector< int > &)
void delete_unfactored(Quotient *q)
bool getfact(int lit, int fact) const
void connect_watches(bool irredundant_only=false)
vector< Clause * > qlauses
bool operator()(unsigned a, unsigned b)
struct factoring::@160277325255143145147274163211332332056211107037 quotients