15 int idx =
vidx (ilit);
21 LOG (
"variable %d is observed %u times", idx, ref);
23 LOG (
"variable %d remains observed forever", idx);
52 const int idx =
vidx (ilit);
58 else if (ref < UINT_MAX) {
60 LOG (
"variable %d is not observed anymore", idx);
62 LOG (
"variable %d is unobserved once but remains observed %u times",
65 LOG (
"variable %d remains observed forever", idx);
85 for (
auto idx :
vars) {
106 LOG (
"notify external propagator about new assignments (after ilb)");
107#ifndef CADICAL_NDEBUG
108 LOG (
"(decision level: %d, trail size: %zd, notified %zd)",
level,
118 LOG (
"notify external propagator about new assignments (after local "
120#ifndef CADICAL_NDEBUG
121 LOG (
"(decision level: %d, trail size: %zd, notified %zd)",
level,
131 const size_t end_of_trail =
trail.size ();
139 int prev_max_level = 0;
140 int current_level = 0;
141 int propagator_level = 0;
147 current_level = prev_max_level + 1;
151 if (current_level > propagator_level) {
154 while (current_level > propagator_level) {
155 external->propagator->notify_new_decision_level ();
161 if (current_level > prev_max_level)
162 prev_max_level = current_level;
184 while (
level > propagator_level) {
185 external->propagator->notify_new_decision_level ();
200 const int idx =
vidx (ilit);
202#ifndef CADICAL_NDEBUG
204 "is_decision: i%d (current level: %d, is_fixed: %d, v.level: %d, "
205 "is_external_reason: %d, v.reason: )",
218#ifndef CADICAL_NDEBUG
219 LOG (
"external propagator forces backtrack to decision level"
220 "%zd (from level %d)",
241 bool cb_repropagate_needed =
true;
244#ifndef CADICAL_NDEBUG
245 LOG (
"external propagation starts (decision level: %d, trail size: "
246 "%zd, notified %zd)",
249 cb_repropagate_needed =
false;
254 int elit =
external->propagator->cb_propagate ();
255 stats.ext_prop.ext_cb++;
256 stats.ext_prop.eprop_call++;
259 int ilit =
external->e2i[abs (elit)];
262 int tmp =
val (ilit);
263#ifndef CADICAL_NDEBUG
265 LOG (
"External propagation of e%d (i%d val: %d)", elit, ilit, tmp);
272 LOG (res,
"reason clause of external propagation of %d:", elit);
277 stats.ext_prop.eprop_prop++;
285 }
else if (tmp < 0) {
286 LOG (
"External propgation of %d is falsified under current trail",
288 stats.ext_prop.eprop_conf++;
289 int level_before =
level;
293 LOG (res,
"reason clause of external propagation of %d:", elit);
310 elit =
external->propagator->cb_propagate ();
311 stats.ext_prop.ext_cb++;
312 stats.ext_prop.eprop_call++;
315#ifndef CADICAL_NDEBUG
316 LOG (
"External propagation ends (decision level: %d, trail size: %zd, "
321 int level_before =
level;
326 stats.ext_prop.ext_cb++;
327 stats.ext_prop.elearn_call++;
338#ifndef CADICAL_NDEBUG
339 if (has_external_clause)
340 LOG (
"New external clauses are to be added.");
342 LOG (
"No external clauses to be added.");
345 while (has_external_clause) {
346 level_before =
level;
353 cb_repropagate_needed =
true;
356 cb_repropagate_needed =
false;
363 cb_repropagate_needed =
false;
370 stats.ext_prop.ext_cb++;
371 stats.ext_prop.elearn_call++;
374#ifndef CADICAL_NDEBUG
375 LOG (
"External clause addition ends on decision level %d at trail "
377 "%zd (notified %zd)",
410 for (
int i = 0; i < 2; i++) {
411 int highest_position = i;
412 int highest_literal =
clause[i];
414 int highest_level =
var (highest_literal).
level;
415 int highest_value =
val (highest_literal);
417 for (
size_t j = i + 1; j <
clause.size (); j++) {
418 const int other =
clause[j];
419 const int other_level =
var (other).
level;
420 const int other_value =
val (other);
422 if (other_value < 0) {
423 if (highest_value >= 0)
425 if (other_level <= highest_level)
427 }
else if (other_value > 0) {
428 if (highest_value > 0 && other_level >= highest_level)
431 if (highest_value >= 0)
435 highest_position = j;
436 highest_literal = other;
437 highest_level = other_level;
438 highest_value = other_value;
440#ifndef CADICAL_NDEBUG
441 LOG (
"highest position: %d highest level: %d highest value: %d",
442 highest_position, highest_level, highest_value);
445 if (highest_position == i)
447 if (highest_position > i) {
483 if (propagated_elit) {
489#ifndef CADICAL_NDEBUG
490 LOG (
"add external reason of propagated lit: %d", propagated_elit);
492 elit =
external->propagator->cb_add_reason_clause_lit (propagated_elit);
494 elit =
external->propagator->cb_add_external_clause_lit ();
499 std::vector<int64_t> lrat_chain_ext = std::move (
lrat_chain);
516 external->propagator->cb_add_reason_clause_lit (propagated_elit);
518 elit =
external->propagator->cb_add_external_clause_lit ();
535 if (!
opts.exteagerreasons)
537#ifndef CADICAL_NDEBUG
538 LOG (reason,
"explain_reason of %d (open: %d)", ilit, open);
542 for (
const auto &other : *reason) {
588 std::vector<int> seen_lits;
592 int i =
trail.size ();
597 seen_lits.push_back (
lit);
610 if (!
opts.exteagerrecalc) {
611 for (
auto lit : seen_lits) {
615#ifndef CADICAL_NDEBUG
616 for (
auto idx :
vars) {
624 for (
auto it = seen_lits.rbegin (); it != seen_lits.rend (); ++it) {
630 for (
const auto &other : *v.
reason) {
634 if (tmp > real_level)
637 if (v.
level && !real_level) {
644 if (v.
level > real_level) {
645 v.
level = real_level;
652 for (
auto idx :
vars) {
673 auto clause_tmp = std::move (
clause);
678 stats.ext_prop.eprop_expl++;
681 if (!falsified_elit) {
685 elit = falsified_elit;
687 LOG (
"ilit: %d, elit: %d", ilit, elit);
690#ifndef CADICAL_NDEBUG
696 const int propagated_ilit = ilit;
703 clause = std::move (clause_tmp);
717 std::vector<int64_t> chain_tmp{std::move (
lrat_chain)};
722 std::vector<int> clause_tmp{std::move (
clause)};
730 clause = std::move (clause_tmp);
746 stats.ext_prop.elearned++;
752 stats.ext_prop.elearn_prop++;
762 stats.ext_prop.elearned++;
773 if (
val (pos0) < 0) {
778 if (
val (pos0) < 0) {
790 stats.ext_prop.elearn_conf++;
793 if (
val (pos1) < 0 && !
val (pos0)) {
799 stats.ext_prop.elearn_conf++;
834 bool trail_changed =
true;
835 bool added_new_clauses =
false;
836 while (trail_changed || added_new_clauses) {
840 trail_changed =
false;
841 added_new_clauses =
false;
842 LOG (
"Final check by external propagator is invoked.");
843 stats.ext_prop.echeck_call++;
847 std::vector<int> etrail;
852 for (
int idx = 1; idx <=
external->max_var; idx++) {
856 etrail.push_back (
lit);
857#ifndef CADICAL_NDEBUG
860 LOG (
"evals[%d]: %d ival(%d): %d", idx,
p, idx,
lit);
866 external->propagator->cb_check_found_model (etrail);
867 stats.ext_prop.ext_cb++;
869 LOG (
"Found solution is approved by external propagator.");
875 stats.ext_prop.ext_cb++;
876 stats.ext_prop.elearn_call++;
878 if (has_external_clause)
880 "Found solution triggered new clauses from external propagator.");
882 while (has_external_clause) {
883 int level_before =
level;
889 added_new_clauses =
true;
910 stats.ext_prop.ext_cb++;
911 stats.ext_prop.elearn_call++;
913 LOG (
"No more external clause to add.");
920 if (conflict_level !=
level) {
936 const size_t end_of_trail =
trail.size ();
941 LOG (
"notify external propagator about new assignments");
980 external->propagator->notify_new_decision_level ();
990 external->propagator->notify_backtrack (new_level);
1005 int level_before =
level;
1007 int elit =
external->propagator->cb_decide ();
1009 stats.ext_prop.ext_cb++;
1011 if (level_before !=
level) {
1029 LOG (
"external propagator proposes decision: %d", elit);
1031 if (!
external->is_observed[abs (elit)])
1034 int ilit =
external->e2i[abs (elit)];
1040 LOG (
"Asking external propagator for decision returned: %d (internal: "
1041 "%d, fixed: %d, val: %d)",
1042 elit, ilit,
fixed (ilit),
val (ilit));
1045 LOG (
"Proposed decision variable is already assigned, falling back to "
1046 "internal decision.");
1060 return (
external->forgettable_original.find (
id) !=
1061 external->forgettable_original.end ());
1075 "forgettable external lemma is deleted:");
1077 external->forgettable_original[id][0] = 0;
1086#ifndef CADICAL_NDEBUG
1110 for (
size_t i = 2; i <
clause.size (); i++)
1120 for (
size_t i = 2; i <
clause.size (); i++)
1127 for (
size_t i = 2; i <
clause.size (); i++)
1137 for (
size_t i = 2; i <
clause.size (); i++)
1143 for (
size_t i = 2; i <
clause.size (); i++)
1155 for (
size_t i = 2; i <
clause.size (); i++)
1161#ifndef CADICAL_NDEBUG
1175bool Internal::get_merged_literals (std::vector<int> &eq_class) {
1181 int ilit =
trail[0];
1182 size_t lit_level =
var (ilit).
level;
1187 int ivar = abs (ilit);
1188 for (
size_t i = 0; i < e2i_size; i++) {
1190 if (other == ivar) {
1192 eq_class.push_back (i);
1194 eq_class.push_back (-1 * i);
1211void Internal::get_all_fixed_literals (std::vector<int> &fixed_lits) {
1212 fixed_lits.clear ();
1216 int e2i_size =
external->e2i.size ();
1218 for (
int eidx = 1; eidx < e2i_size; eidx++) {
1220 if (ilit && !
external->ervars[eidx]) {
1221 Flags &f =
flags (ilit);
1223 fixed_lits.push_back (
vals[abs (ilit)] * eidx);
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
void notify_assignments()
vector< unsigned > relevanttab
bool ext_clause_forgettable
vector< int64_t > lrat_chain
Clause * wrapped_learn_external_reason_clause(int lit)
bool external_check_solution()
void force_backtrack(size_t new_level)
void add_observed_var(int ilit)
void renotify_trail_after_ilb()
void add_external_clause(int propagated_lit=0, bool no_backtrack=false)
void renotify_full_trail()
void move_literals_to_watch()
void handle_external_clause(Clause *)
void mark_garbage_external_forgettable(int64_t id)
Clause * learn_external_reason_clause(int lit, int falsified_elit=0, bool no_backtrack=false)
signed char val(int lit) const
bool ask_external_clause()
vector< int > assumptions
void explain_reason(int lit, Clause *, int &open)
void backtrack(int target_level=0)
bool is_external_forgettable(int64_t id)
bool forced_backt_allowed
bool is_decision(int ilit)
void renotify_trail_after_local_search()
void connect_propagator()
bool external_propagate()
int assignment_level(int lit, Clause *)
void search_assign_external(int lit)
void require_mode(Mode m) const
void set_tainted_literal()
void remove_observed_var(int ilit)
void explain_external_propagations()
void notify_backtrack(size_t new_level)
void learn_unit_clause(int lit)
bool external_prop_is_lazy
bool observed(int ilit) const
void search_assign_driving(int lit, Clause *reason)
void build_chain_for_units(int lit, Clause *reason, bool forced)
void check_watched_literal_invariants()