28 size_t new_vsize =
vsize ? 2 *
vsize : 1 + (size_t) new_max_var;
29 while (new_vsize <= (
size_t) new_max_var)
31 LOG (
"enlarge external size from %zd to new size %zd",
vsize, new_vsize);
39 int new_vars = new_max_var -
max_var;
40 int old_internal_max_var =
internal->max_var;
41 int new_internal_max_var = old_internal_max_var + new_vars;
42 internal->init_vars (new_internal_max_var);
43 if ((
size_t) new_max_var >=
vsize)
45 LOG (
"initialized %d external variables", new_vars);
59 unsigned iidx = old_internal_max_var + 1, eidx;
60 for (eidx =
max_var + 1u; eidx <= (unsigned) new_max_var;
62 LOG (
"mapping external %u to internal %u", eidx, iidx);
74 internal->stats.variables_extension += new_vars;
76 internal->stats.variables_original += new_vars;
78 is_observed.resize (1 + (
size_t) new_max_var,
false);
80 if (new_max_var >= (int64_t)
moltentab.size ())
81 moltentab.resize (1 + (
size_t) new_max_var,
false);
108 LOG (
"reset extended");
124 const int eidx = abs (elit);
126 FATAL (
"can not add a definition for an already used variable %d",
143 LOG (
"mapping external %d to internal %d", eidx, ilit);
154 FATAL (
"can not reuse molten literal %d", eidx);
163 LOG (
"marking tainted %d", elit);
175 bool forgettable =
false;
197 if (elit && (
internal->proof || forgettable)) {
201 unsigned eidx = (elit > 0) + 2u * (
unsigned) abs (elit);
207 internal->lrat_chain.push_back (
id);
213 for (
const auto &elit :
eclause) {
219 LOG (
"adding external %d as internal %d", elit, ilit);
223 if (!elit && (
internal->proof || forgettable))
231 internal->proof->add_assumption (elit);
235 LOG (
"assuming external %d as internal %d", elit, ilit);
244 int eidx = abs (elit);
249 int ilit =
e2i[eidx];
263 int eidx = abs (elit);
268 int ilit =
e2i[eidx];
277 int eidx = abs (elit);
280 int ilit =
e2i[eidx];
298 LOG (
"adding external %d as internal %d to constraint", elit, ilit);
299 else if (!elit &&
internal->proof) {
307 return internal->failed_constraint ();
320 int eidx = abs (elit);
323 LOG (
"resetting forced phase of unused external %d ignored", elit);
326 int ilit =
e2i[eidx];
343 LOG (
"No connected propagator that could observe the variable, "
344 "observed flag is not set.");
352 int eidx = abs (elit);
355 LOG (
"Error, only clean variables are allowed to become observed.");
372 LOG (
"marking %d as externally watched", eidx);
393 const int tmp =
fixed (elit);
396 int unit = tmp < 0 ? -elit : elit;
398 LOG (
"notify propagator about fixed assignment upon observe for %d",
410 LOG (
"No connected propagator that could have watched the variable");
413 int eidx = abs (elit);
421 int ilit =
e2i[eidx];
422 internal->remove_observed_var (ilit);
426 LOG (
"unmarking %d as externally watched", eidx);
436 LOG (
"reset notified counter to 0");
443 for (
auto elit :
vars) {
444 int eidx = abs (elit);
448 internal->remove_observed_var (ilit);
449 LOG (
"unmarking %d as externally watched", eidx);
459 int eidx = abs (elit);
471 int eidx = abs (elit);
480 int eidx = abs (elit);
485 return internal->is_decision (ilit);
490 LOG (
"No connected propagator that could force backtracking");
493 LOG (
"force backtrack to level %zd", new_level);
494 internal->force_backtrack (new_level);
500 int res =
internal->propagate_assumptions ();
509 std::vector<int> ilit_implicants;
510 internal->implied (ilit_implicants);
519 for (
const auto &ilit : ilit_implicants) {
521 const int elit =
internal->externalize (ilit);
522 const int eidx = abs (elit);
523 const bool is_extension_var =
ervars[eidx];
525 trailed.push_back (elit);
537 internal->proof->conclude_unknown (trail);
545 LOG (
"checking satisfiable");
559 LOG (
"checking unsatisfiable");
587 int registered = 0, molten = 0;
591 LOG (
"skipping already molten literal %d",
lit);
596 LOG (
"skipping currently frozen literal %d",
lit);
598 LOG (
"new molten literal %d",
lit);
606 LOG (
"registered %d new molten literals", registered);
607 LOG (
"reached in total %d molten literals", molten);
613 int res =
internal->solve (preprocess_only);
626 (ilit && ilit != INT_MIN) ?
internal->externalize (ilit) : 0;
627 LOG (
"lookahead internal %d external %d", ilit, elit);
636 auto cubes =
internal->generate_cubes (depth, min_depth);
637 auto externalize = [
this] (
int ilit) {
638 const int elit = ilit ?
internal->externalize (ilit) : 0;
639 MSG (
"lookahead internal %d external %d", ilit, elit);
642 auto externalize_map = [
this, externalize] (std::vector<int>
cube) {
645 std::for_each (begin (
cube), end (
cube), externalize);
647 std::for_each (begin (cubes.cubes), end (cubes.cubes), externalize_map);
657 unsigned eidx =
vidx (elit);
661 if (ref < UINT_MAX) {
663 LOG (
"external variable %d frozen once and now frozen %u times", eidx,
666 LOG (
"external variable %d frozen but remains frozen forever", eidx);
673 unsigned eidx =
vidx (elit);
677 if (ref < UINT_MAX) {
681 LOG (
"external variable %d is observed, can not be completely "
685 LOG (
"external variable %d melted once and now completely melted",
688 LOG (
"external variable %d melted once but remains frozen %u times",
691 LOG (
"external variable %d melted but remains frozen forever", eidx);
701 for (
auto idx :
vars) {
702 if (!(this->*a) (idx))
703 FATAL (
"unassigned variable: %d", idx);
704 int value_idx = (this->*a) (idx);
705 int value_neg_idx = (this->*a) (-idx);
706 if (value_idx == idx)
712 if (value_idx != value_neg_idx)
713 FATAL (
"inconsistently assigned literals %d and %d", idx, -idx);
718 bool satisfied =
false;
720 auto start =
original.begin (), i = start;
724 for (; i != end; i++) {
729 fputs (
"unsatisfied clause:\n", stderr);
730 for (
auto j = start; j != i; j++)
731 fprintf (stderr,
"%d ", *j);
740 }
else if (!satisfied && (this->*a) (
lit) ==
lit)
752 presence_flag =
true;
757 std::vector<int> literals;
758 for (
const auto lit : forgettables.second) {
766 presence_flag =
false;
770 if ((this->*a) (
lit) ==
lit) {
778 fputs (
"unsatisfied external forgettable clause:\n", stderr);
779 for (
size_t j = 1; j < forgettables.second.size (); j++)
780 fprintf (stderr,
"%d ", forgettables.second[j]);
786 VERBOSE (1,
"satisfying assignment checked on %" PRId64
" clauses",
798 FATAL (
"assumption %d falsified",
lit);
800 FATAL (
"assumption %d unassigned",
lit);
802 VERBOSE (1,
"checked that %zd assumptions are satisfied",
809 VERBOSE (1,
"checked that constraint is satisfied");
813 FATAL (
"constraint not satisfied");
819 checker->
prefix (
"checker ");
822 checker->
set (
"log",
true);
828 LOG (
"checking failed literal %d in core",
lit);
846 bool presence_flag =
true;
847 for (
const auto lit : forgettables.second) {
850 presence_flag =
false;
858 int res = checker->
solve ();
860 FATAL (
"failed assumptions do not form a core");
861 delete_checker.
free ();
862 VERBOSE (1,
"checked that %zd failing assumptions form a core",
920 for (
auto idx :
vars) {
923 const int tmp =
fixed (idx);
926 int unit = tmp < 0 ? -idx : idx;
942 for (
auto idx :
vars) {
945 const int tmp =
fixed (idx);
948 int unit = tmp < 0 ? -idx : idx;
949 const int ilit =
e2i[idx] * (tmp < 0 ? -1 : 1);
953 clause_and_witness.push_back (unit);
954 if (!it.
witness (clause_and_witness, clause_and_witness,
id +
max_var))
956 clause_and_witness.clear ();
968 for (
unsigned eidx = 1; eidx <= limit; eidx++) {
969 const int this_ilit =
e2i[eidx];
972 const int other_ilit = other.
e2i[eidx];
981 const Flags &this_flags = this_ftab[abs (this_ilit)];
982 Flags &other_flags = other_ftab[abs (other_ilit)];
983 this_flags.
copy (other_flags);
992 LOG (
"exporting learned empty clause");
995 LOG (
"not exporting learned empty clause");
1001 LOG (
"exporting learned unit clause");
1002 const int elit =
internal->externalize (ilit);
1007 LOG (
"not exporting learned unit clause");
1014 if (
learner->learning ((
int) size)) {
1015 LOG (
"exporting learned clause of size %zu", size);
1016 for (
auto ilit :
clause) {
1017 const int elit =
internal->externalize (ilit);
1023 LOG (
"not exporting learned clause of size %zu", size);
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
virtual bool clause(const std::vector< int > &)=0
void prefix(const char *verbose_message_prefix)
bool set(const char *name, int val)
virtual bool witness(const std::vector< int > &clause, const std::vector< int > &witness, int64_t id=0)=0
void fatal_message_start()
bool traverse_all_non_frozen_units_as_witnesses(WitnessIterator &)
void enlarge(int new_max_var)
int propagate_assumptions()
bool is_witness(int elit)
CaDiCaL::CubesWithStatus generate_cubes(int, int)
void update_molten_literals()
vector< bool > is_observed
void reset_observed_vars()
void export_learned_empty_clause()
bool marked(const vector< bool > &map, int elit) const
bool is_decision(int elit)
void export_learned_unit_clause(int ilit)
void implied(std::vector< int > &entrailed)
void check_unsatisfiable()
vector< int64_t > ext_units
void check_assignment(int(External::*assignment)(int) const)
unordered_map< uint64_t, vector< int > > forgettable_original
void remove_observed_var(int elit)
void add_observed_var(int elit)
void copy_flags(External &other) const
bool traverse_all_frozen_units_as_clauses(ClauseIterator &)
vector< unsigned > frozentab
void check_assumptions_satisfied()
int solve(bool preprocess_only)
FixedAssignmentListener * fixed_listener
void export_learned_large_clause(const vector< int > &)
void check_constraint_satisfied()
void force_backtrack(size_t new_level)
void init(int new_max_var, bool extension=false)
ExternalPropagator * propagator
int fixed(int elit) const
void check_solve_result(int res)
vector< int > assumptions
int internalize(int, bool extension=false)
void copy(Flags &dst) const