ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
CaDiCaL::External Struct Reference

#include <external.hpp>

Collaboration diagram for CaDiCaL::External:

Public Member Functions

void export_learned_empty_clause ()
 
void export_learned_unit_clause (int ilit)
 
void export_learned_large_clause (const vector< int > &)
 
void add_observed_var (int elit)
 
void remove_observed_var (int elit)
 
void reset_observed_vars ()
 
bool observed (int elit)
 
bool is_witness (int elit)
 
bool is_decision (int elit)
 
void force_backtrack (size_t new_level)
 
int vidx (int elit) const
 
int vlit (int elit) const
 
bool is_valid_input (int elit)
 
void push_zero_on_extension_stack ()
 
void push_clause_literal_on_extension_stack (int ilit)
 
void push_witness_literal_on_extension_stack (int ilit)
 
void push_clause_on_extension_stack (Clause *)
 
void push_clause_on_extension_stack (Clause *, int witness)
 
void push_binary_clause_on_extension_stack (int64_t id, int witness, int other)
 
void extend ()
 
void conclude_sat ()
 
unsigned elit2ulit (int elit) const
 
bool marked (const vector< bool > &map, int elit) const
 
void mark (vector< bool > &map, int elit)
 
void unmark (vector< bool > &map, int elit)
 
void push_external_clause_and_witness_on_extension_stack (const vector< int > &clause, const vector< int > &witness, int64_t id)
 
void push_id_on_extension_stack (int64_t id)
 
void restore_clause (const vector< int >::const_iterator &begin, const vector< int >::const_iterator &end, const int64_t id)
 
void restore_clauses ()
 
void freeze (int elit)
 
void melt (int elit)
 
bool frozen (int elit)
 
 External (Internal *)
 
 ~External ()
 
void enlarge (int new_max_var)
 
void init (int new_max_var, bool extension=false)
 
int internalize (int, bool extension=false)
 
void reset_assumptions ()
 
void reset_concluded ()
 
void reset_extended ()
 
void reset_limits ()
 
void add (int elit)
 
void assume (int elit)
 
int solve (bool preprocess_only)
 
int ival (int elit) const
 
bool flip (int elit)
 
bool flippable (int elit)
 
bool failed (int elit)
 
void terminate ()
 
void constrain (int elit)
 
bool failed_constraint ()
 
void reset_constraint ()
 
int propagate_assumptions ()
 
void implied (std::vector< int > &entrailed)
 
void conclude_unknown ()
 
int lookahead ()
 
CaDiCaL::CubesWithStatus generate_cubes (int, int)
 
int fixed (int elit) const
 
void phase (int elit)
 
void unphase (int elit)
 
bool traverse_all_frozen_units_as_clauses (ClauseIterator &)
 
bool traverse_all_non_frozen_units_as_witnesses (WitnessIterator &)
 
bool traverse_witnesses_backward (WitnessIterator &)
 
bool traverse_witnesses_forward (WitnessIterator &)
 
void copy_flags (External &other) const
 
void check_assumptions_satisfied ()
 
void check_constraint_satisfied ()
 
void check_failing ()
 
void check_solution_on_learned_clause ()
 
void check_solution_on_shrunken_clause (Clause *)
 
void check_solution_on_learned_unit_clause (int unit)
 
void check_no_solution_after_learning_empty_clause ()
 
void check_learned_empty_clause ()
 
void check_learned_unit_clause (int unit)
 
void check_learned_clause ()
 
void check_shrunken_clause (Clause *c)
 
void check_assignment (int(External::*assignment)(int) const)
 
void check_satisfiable ()
 
void check_unsatisfiable ()
 
void check_solve_result (int res)
 
void update_molten_literals ()
 
int sol (int elit) const
 

Public Attributes

Internalinternal
 
int max_var
 
size_t vsize
 
vector< boolvals
 
vector< int > e2i
 
vector< int > assumptions
 
vector< int > constraint
 
vector< int64_t > ext_units
 
vector< boolext_flags
 
vector< int > eclause
 
bool extended
 
bool concluded
 
vector< int > extension
 
vector< boolwitness
 
vector< booltainted
 
vector< boolervars
 
vector< unsigned > frozentab
 
Terminatorterminator
 
Learnerlearner
 
FixedAssignmentListenerfixed_listener
 
ExternalPropagatorpropagator
 
vector< boolis_observed
 
unordered_map< uint64_t, vector< int > > forgettable_original
 
signed char * solution
 
int solution_size
 
vector< int > original
 
vector< boolmoltentab
 
const Range vars
 

Detailed Description

Definition at line 57 of file external.hpp.

Constructor & Destructor Documentation

◆ External()

CaDiCaL::External::External ( Internal * i)

Definition at line 10 of file cadical_external.cpp.

11 : internal (i), max_var (0), vsize (0), extended (false),
12 concluded (false), terminator (0), learner (0), fixed_listener (0),
13 propagator (0), solution (0), vars (max_var) {
15 CADICAL_assert (!internal->external);
16 internal->external = this;
17}
#define CADICAL_assert(ignore)
Definition global.h:14
const Range vars
Definition external.hpp:149
signed char * solution
Definition external.hpp:135
Terminator * terminator
Definition external.hpp:97
Learner * learner
Definition external.hpp:101
Internal * internal
Definition external.hpp:61
FixedAssignmentListener * fixed_listener
Definition external.hpp:109
ExternalPropagator * propagator
Definition external.hpp:113
Here is the caller graph for this function:

◆ ~External()

CaDiCaL::External::~External ( )

Definition at line 19 of file cadical_external.cpp.

19 {
20 if (solution)
21 delete[] solution;
22}

Member Function Documentation

◆ add()

void CaDiCaL::External::add ( int elit)

Definition at line 171 of file cadical_external.cpp.

171 {
172 CADICAL_assert (elit != INT_MIN);
174
175 bool forgettable = false;
176
177 if (internal->opts.check &&
178 (internal->opts.checkwitness || internal->opts.checkfailed)) {
179
180 forgettable =
181 internal->from_propagator && internal->ext_clause_forgettable;
182
183 // Forgettable clauses (coming from the external propagator) are not
184 // saved into the external 'original' stack. They are stored separately
185 // in external 'forgettable_original', from where they are deleted when
186 // the corresponding clause is deleted (actually deleted, not just
187 // marked as garbage).
188 if (!forgettable)
189 original.push_back (elit);
190 }
191
192 const int ilit = internalize (elit);
193 CADICAL_assert (!elit == !ilit);
194
195 // The external literals of the new clause must be saved for later
196 // when the proof is printed during add_original_lit (0)
197 if (elit && (internal->proof || forgettable)) {
198 eclause.push_back (elit);
199 if (internal->lrat) {
200 // actually find unit of -elit (flips elit < 0)
201 unsigned eidx = (elit > 0) + 2u * (unsigned) abs (elit);
202 CADICAL_assert ((size_t) eidx < ext_units.size ());
203 const int64_t id = ext_units[eidx];
204 bool added = ext_flags[abs (elit)];
205 if (id && !added) {
206 ext_flags[abs (elit)] = true;
207 internal->lrat_chain.push_back (id);
208 }
209 }
210 }
211
212 if (!elit && internal->proof && internal->lrat) {
213 for (const auto &elit : eclause) {
214 ext_flags[abs (elit)] = false;
215 }
216 }
217
218 if (elit)
219 LOG ("adding external %d as internal %d", elit, ilit);
220 internal->add_original_lit (ilit);
221
222 // Clean-up saved external literals once proof line is printed
223 if (!elit && (internal->proof || forgettable))
224 eclause.clear ();
225}
#define LOG(...)
vector< bool > ext_flags
Definition external.hpp:74
vector< int64_t > ext_units
Definition external.hpp:73
vector< int > original
Definition external.hpp:137
vector< int > eclause
Definition external.hpp:75
int internalize(int, bool extension=false)
Here is the call graph for this function:

◆ add_observed_var()

void CaDiCaL::External::add_observed_var ( int elit)

Definition at line 341 of file cadical_external.cpp.

341 {
342 if (!propagator) {
343 LOG ("No connected propagator that could observe the variable, "
344 "observed flag is not set.");
345 return;
346 }
347
348 CADICAL_assert (elit);
349 CADICAL_assert (elit != INT_MIN);
350 reset_extended (); // tainting!
351
352 int eidx = abs (elit);
353 if (eidx <= max_var &&
354 (marked (witness, elit) || marked (witness, -elit))) {
355 LOG ("Error, only clean variables are allowed to become observed.");
356 CADICAL_assert (false);
357
358 // TODO: here needs to come the taint and restore of the newly
359 // observed variable. Restore_clauses must be called before continue.
360 // LOG ("marking tainted %d", elit);
361 // mark (tainted, elit);
362 // mark (tainted, -elit);
363 // restore_clauses ...
364 }
365
366 if (eidx >= (int64_t) is_observed.size ())
367 is_observed.resize (1 + (size_t) eidx, false);
368
369 if (is_observed[eidx])
370 return;
371
372 LOG ("marking %d as externally watched", eidx);
373
374 // Will do the necessary internalization
375 freeze (elit);
376 is_observed[eidx] = true;
377
378 int ilit = internalize (elit);
379 // internal add-observed-var backtracks to a lower decision level to
380 // unassign the variable in case it was already assigned previously (but
381 // not on the current level)
382 internal->add_observed_var (ilit);
383
384 if (propagator->is_lazy)
385 return;
386
387 // In case this variable was already assigned (e.g. via unit clause) and
388 // got compacted to map to another (not observed) variable, it can not be
389 // unnasigned so it must be notified explicitly now. (-> Can lead to
390 // repeated fixed assignment notifications, in case it was unobserved and
391 // observed again. But a repeated notification is less error-prone than
392 // never notifying an assignment.)
393 const int tmp = fixed (elit);
394 if (!tmp)
395 return;
396 int unit = tmp < 0 ? -elit : elit;
397
398 LOG ("notify propagator about fixed assignment upon observe for %d",
399 unit);
400
401 // internal add-observed-var had to backtrack to root-level already
402 CADICAL_assert (!internal->level);
403
404 std::vector<int> assigned = {unit};
405 propagator->notify_assignment (assigned);
406}
struct assigned assigned
Definition assign.h:15
vector< bool > is_observed
Definition external.hpp:115
bool marked(const vector< bool > &map, int elit) const
Definition external.hpp:216
vector< bool > witness
Definition external.hpp:87
int fixed(int elit) const
Here is the call graph for this function:

◆ assume()

void CaDiCaL::External::assume ( int elit)

Definition at line 227 of file cadical_external.cpp.

227 {
228 CADICAL_assert (elit);
230 if (internal->proof)
231 internal->proof->add_assumption (elit);
232 assumptions.push_back (elit);
233 const int ilit = internalize (elit);
234 CADICAL_assert (ilit);
235 LOG ("assuming external %d as internal %d", elit, ilit);
236 internal->assume (ilit);
237}
vector< int > assumptions
Definition external.hpp:69
Here is the call graph for this function:

◆ check_assignment()

void CaDiCaL::External::check_assignment ( int(External::* assignment )(int) const)

Definition at line 697 of file cadical_external.cpp.

697 {
698
699 // First check all assigned and consistent.
700 //
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)
707 CADICAL_assert (value_neg_idx == idx);
708 else {
709 CADICAL_assert (value_idx == -idx);
710 CADICAL_assert (value_neg_idx == -idx);
711 }
712 if (value_idx != value_neg_idx)
713 FATAL ("inconsistently assigned literals %d and %d", idx, -idx);
714 }
715
716 // Then check that all (saved) original clauses are satisfied.
717 //
718 bool satisfied = false;
719 const auto end = original.end ();
720 auto start = original.begin (), i = start;
721#ifndef CADICAL_QUIET
722 int64_t count = 0;
723#endif
724 for (; i != end; i++) {
725 int lit = *i;
726 if (!lit) {
727 if (!satisfied) {
729 fputs ("unsatisfied clause:\n", stderr);
730 for (auto j = start; j != i; j++)
731 fprintf (stderr, "%d ", *j);
732 fputc ('0', stderr);
734 }
735 satisfied = false;
736 start = i + 1;
737#ifndef CADICAL_QUIET
738 count++;
739#endif
740 } else if (!satisfied && (this->*a) (lit) == lit)
741 satisfied = true;
742 }
743
744 bool presence_flag;
745 // Check those forgettable external clauses that are still present, but
746 // only if the external propagator is still connected (otherwise solution
747 // reconstruction is allowed to touch the previously observed variables so
748 // there is no guarantee that the final model will satisfy these clauses.)
749 for (const auto &forgettables : forgettable_original) {
750 if (!propagator)
751 break;
752 presence_flag = true;
753 satisfied = false;
754#ifndef CADICAL_QUIET
755 count++;
756#endif
757 std::vector<int> literals;
758 for (const auto lit : forgettables.second) {
759 if (presence_flag) {
760 // First integer is a Boolean flag, not a literal
761 if (!lit) {
762 // Deleted clauses can be ignored, they count as satisfied
763 satisfied = true;
764 break;
765 }
766 presence_flag = false;
767 continue;
768 }
769
770 if ((this->*a) (lit) == lit) {
771 satisfied = true;
772 break;
773 }
774 }
775
776 if (!satisfied) {
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]);
781 fputc ('0', stderr);
783 }
784 }
785#ifndef CADICAL_QUIET
786 VERBOSE (1, "satisfying assignment checked on %" PRId64 " clauses",
787 count);
788#endif
789}
#define FATAL
Definition message.hpp:64
#define VERBOSE(...)
Definition message.hpp:58
void fatal_message_start()
void fatal_message_end()
int lit
Definition satVec.h:130
unordered_map< uint64_t, vector< int > > forgettable_original
Definition external.hpp:121
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_assumptions_satisfied()

void CaDiCaL::External::check_assumptions_satisfied ( )

Definition at line 793 of file cadical_external.cpp.

793 {
794 for (const auto &lit : assumptions) {
795 // Not 'signed char' !!!!
796 const int tmp = ival (lit);
797 if (tmp != lit)
798 FATAL ("assumption %d falsified", lit);
799 if (!tmp)
800 FATAL ("assumption %d unassigned", lit);
801 }
802 VERBOSE (1, "checked that %zd assumptions are satisfied",
803 assumptions.size ());
804}
int ival(int elit) const
Definition external.hpp:325
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_constraint_satisfied()

void CaDiCaL::External::check_constraint_satisfied ( )

Definition at line 806 of file cadical_external.cpp.

806 {
807 for (const auto lit : constraint) {
808 if (ival (lit) == lit) {
809 VERBOSE (1, "checked that constraint is satisfied");
810 return;
811 }
812 }
813 FATAL ("constraint not satisfied");
814}
vector< int > constraint
Definition external.hpp:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_failing()

void CaDiCaL::External::check_failing ( )

Definition at line 816 of file cadical_external.cpp.

816 {
817 Solver *checker = new Solver ();
818 DeferDeletePtr<Solver> delete_checker (checker);
819 checker->prefix ("checker ");
820#ifdef LOGGING
821 if (internal->opts.log)
822 checker->set ("log", true);
823#endif
824
825 for (const auto lit : assumptions) {
826 if (!failed (lit))
827 continue;
828 LOG ("checking failed literal %d in core", lit);
829 checker->add (lit);
830 checker->add (0);
831 }
832 if (failed_constraint ()) {
833 LOG (constraint, "checking failed constraint");
834 for (const auto lit : constraint)
835 checker->add (lit);
836 } else if (constraint.size ())
837 LOG (constraint, "constraint satisfied and ignored");
838
839 // Add original clauses as last step, failing () and failed_constraint ()
840 // might add more external clauses (due to lazy explanation)
841 for (const auto lit : original)
842 checker->add (lit);
843
844 // Add every forgettable external clauses
845 for (const auto &forgettables : forgettable_original) {
846 bool presence_flag = true;
847 for (const auto lit : forgettables.second) {
848 if (presence_flag) {
849 // First integer is a Boolean flag, not a literal, ignore it here
850 presence_flag = false;
851 continue;
852 }
853 checker->add (lit);
854 }
855 checker->add (0);
856 }
857
858 int res = checker->solve ();
859 if (res != 20)
860 FATAL ("failed assumptions do not form a core");
861 delete_checker.free ();
862 VERBOSE (1, "checked that %zd failing assumptions form a core",
863 assumptions.size ());
864}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_learned_clause()

void CaDiCaL::External::check_learned_clause ( )
inline

Definition at line 417 of file external.hpp.

417 {
418 if (solution)
420 }
void check_solution_on_learned_clause()
Here is the call graph for this function:

◆ check_learned_empty_clause()

void CaDiCaL::External::check_learned_empty_clause ( )
inline

Definition at line 407 of file external.hpp.

407 {
408 if (solution)
410 }
void check_no_solution_after_learning_empty_clause()
Here is the call graph for this function:

◆ check_learned_unit_clause()

void CaDiCaL::External::check_learned_unit_clause ( int unit)
inline

Definition at line 412 of file external.hpp.

412 {
413 if (solution)
415 }
void check_solution_on_learned_unit_clause(int unit)
Here is the call graph for this function:

◆ check_no_solution_after_learning_empty_clause()

void CaDiCaL::External::check_no_solution_after_learning_empty_clause ( )

Definition at line 42 of file cadical_solution.cpp.

42 {
44 FATAL ("learned empty clause but got solution");
45}
Here is the caller graph for this function:

◆ check_satisfiable()

void CaDiCaL::External::check_satisfiable ( )

Definition at line 544 of file cadical_external.cpp.

544 {
545 LOG ("checking satisfiable");
546 if (!extended)
547 extend ();
548 if (internal->opts.checkwitness)
550 if (internal->opts.checkassumptions && !assumptions.empty ())
552 if (internal->opts.checkconstraint && !constraint.empty ())
554}
void check_assignment(int(External::*assignment)(int) const)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_shrunken_clause()

void CaDiCaL::External::check_shrunken_clause ( Clause * c)
inline

Definition at line 422 of file external.hpp.

422 {
423 if (solution)
425 }
void check_solution_on_shrunken_clause(Clause *)
Here is the call graph for this function:

◆ check_solution_on_learned_clause()

void CaDiCaL::External::check_solution_on_learned_clause ( )

Definition at line 17 of file cadical_solution.cpp.

17 {
19 for (const auto &lit : internal->clause)
20 if (sol (internal->externalize (lit)) == lit)
21 return;
23 fputs ("learned clause unsatisfied by solution:\n", stderr);
24 for (const auto &lit : internal->clause)
25 fprintf (stderr, "%d ", lit);
26 fputc ('0', stderr);
28}
int sol(int elit) const
Definition external.hpp:446
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_solution_on_learned_unit_clause()

void CaDiCaL::External::check_solution_on_learned_unit_clause ( int unit)

Definition at line 47 of file cadical_solution.cpp.

47 {
49 if (sol (internal->externalize (unit)) == unit)
50 return;
51 FATAL ("learned unit %d contradicts solution", unit);
52}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_solution_on_shrunken_clause()

void CaDiCaL::External::check_solution_on_shrunken_clause ( Clause * c)

Definition at line 30 of file cadical_solution.cpp.

30 {
32 for (const auto &lit : *c)
33 if (sol (internal->externalize (lit)) == lit)
34 return;
36 for (const auto &lit : *c)
37 fprintf (stderr, "%d ", lit);
38 fputc ('0', stderr);
40}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_solve_result()

void CaDiCaL::External::check_solve_result ( int res)

Definition at line 568 of file cadical_external.cpp.

568 {
569 if (!internal->opts.check)
570 return;
571 if (res == 10)
573 if (res == 20)
575}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_unsatisfiable()

void CaDiCaL::External::check_unsatisfiable ( )

Definition at line 558 of file cadical_external.cpp.

558 {
559 LOG ("checking unsatisfiable");
560 if (!internal->opts.checkfailed)
561 return;
562 if (!assumptions.empty () || !constraint.empty ())
563 check_failing ();
564}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conclude_sat()

void CaDiCaL::External::conclude_sat ( )

Definition at line 269 of file cadical_extend.cpp.

269 {
270 if (!internal->proof || concluded)
271 return;
272 concluded = true;
273 if (!extended)
274 extend ();
275 vector<int> model;
276 for (int idx = 1; idx <= max_var; idx++) {
277 if (ervars[idx])
278 continue;
279 const int lit = ival (idx);
280 model.push_back (lit);
281 }
282 internal->proof->conclude_sat (model);
283}
vector< bool > ervars
Definition external.hpp:90
Here is the call graph for this function:

◆ conclude_unknown()

void CaDiCaL::External::conclude_unknown ( )

Definition at line 530 of file cadical_external.cpp.

530 {
531 if (!internal->proof || concluded)
532 return;
533 concluded = true;
534
535 vector<int> trail;
536 implied (trail);
537 internal->proof->conclude_unknown (trail);
538}
void implied(std::vector< int > &entrailed)
Here is the call graph for this function:

◆ constrain()

void CaDiCaL::External::constrain ( int elit)

Definition at line 288 of file cadical_external.cpp.

288 {
289 if (constraint.size () && !constraint.back ()) {
290 LOG (constraint, "replacing previous constraint");
292 }
293 CADICAL_assert (elit != INT_MIN);
295 const int ilit = internalize (elit);
296 CADICAL_assert (!elit == !ilit);
297 if (elit)
298 LOG ("adding external %d as internal %d to constraint", elit, ilit);
299 else if (!elit && internal->proof) {
300 internal->proof->add_constraint (constraint);
301 }
302 constraint.push_back (elit);
303 internal->constrain (ilit);
304}
Here is the call graph for this function:

◆ copy_flags()

void CaDiCaL::External::copy_flags ( External & other) const

Definition at line 964 of file cadical_external.cpp.

964 {
965 const vector<Flags> &this_ftab = internal->ftab;
966 vector<Flags> &other_ftab = other.internal->ftab;
967 const unsigned limit = min (max_var, other.max_var);
968 for (unsigned eidx = 1; eidx <= limit; eidx++) {
969 const int this_ilit = e2i[eidx];
970 if (!this_ilit)
971 continue;
972 const int other_ilit = other.e2i[eidx];
973 if (!other_ilit)
974 continue;
975 if (!internal->active (this_ilit))
976 continue;
977 if (!other.internal->active (other_ilit))
978 continue;
979 CADICAL_assert (this_ilit != INT_MIN);
980 CADICAL_assert (other_ilit != INT_MIN);
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);
984 }
985}
vector< int > e2i
Definition external.hpp:67
struct vector vector
Definition vector.h:24
Here is the call graph for this function:

◆ elit2ulit()

unsigned CaDiCaL::External::elit2ulit ( int elit) const
inline

Definition at line 208 of file external.hpp.

208 {
209 CADICAL_assert (elit);
210 CADICAL_assert (elit != INT_MIN);
211 const int idx = abs (elit) - 1;
212 CADICAL_assert (idx <= max_var);
213 return 2u * idx + (elit < 0);
214 }
Here is the caller graph for this function:

◆ enlarge()

void CaDiCaL::External::enlarge ( int new_max_var)

Definition at line 24 of file cadical_external.cpp.

24 {
25
27
28 size_t new_vsize = vsize ? 2 * vsize : 1 + (size_t) new_max_var;
29 while (new_vsize <= (size_t) new_max_var)
30 new_vsize *= 2;
31 LOG ("enlarge external size from %zd to new size %zd", vsize, new_vsize);
32 vsize = new_vsize;
33}
Here is the caller graph for this function:

◆ export_learned_empty_clause()

void CaDiCaL::External::export_learned_empty_clause ( )

Definition at line 989 of file cadical_external.cpp.

989 {
991 if (learner->learning (0)) {
992 LOG ("exporting learned empty clause");
993 learner->learn (0);
994 } else
995 LOG ("not exporting learned empty clause");
996}

◆ export_learned_large_clause()

void CaDiCaL::External::export_learned_large_clause ( const vector< int > & clause)

Definition at line 1010 of file cadical_external.cpp.

1010 {
1012 size_t size = clause.size ();
1013 CADICAL_assert (size <= (unsigned) INT_MAX);
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);
1018 CADICAL_assert (elit);
1019 learner->learn (elit);
1020 }
1021 learner->learn (0);
1022 } else
1023 LOG ("not exporting learned clause of size %zu", size);
1024}
unsigned long long size
Definition giaNewBdd.h:39
struct clause_t clause
STRUCTURE DEFINITIONS ///.
Definition satClause.h:48
unsigned size
Definition satClause.h:55

◆ export_learned_unit_clause()

void CaDiCaL::External::export_learned_unit_clause ( int ilit)

Definition at line 998 of file cadical_external.cpp.

998 {
1000 if (learner->learning (1)) {
1001 LOG ("exporting learned unit clause");
1002 const int elit = internal->externalize (ilit);
1003 CADICAL_assert (elit);
1004 learner->learn (elit);
1005 learner->learn (0);
1006 } else
1007 LOG ("not exporting learned unit clause");
1008}

◆ extend()

void CaDiCaL::External::extend ( )

Definition at line 117 of file cadical_extend.cpp.

117 {
118
120 START (extend);
121 internal->stats.extensions++;
122
123 PHASE ("extend", internal->stats.extensions,
124 "mapping internal %d assignments to %d assignments",
125 internal->max_var, max_var);
126
127#ifndef CADICAL_QUIET
128 int64_t updated = 0;
129#endif
130 for (unsigned i = 1; i <= (unsigned) max_var; i++) {
131 const int ilit = e2i[i];
132 if (!ilit)
133 continue;
134 if (i >= vals.size ())
135 vals.resize (i + 1, false);
136 vals[i] = (internal->val (ilit) > 0);
137#ifndef CADICAL_QUIET
138 updated++;
139#endif
140 }
141 PHASE ("extend", internal->stats.extensions,
142 "updated %" PRId64 " external assignments", updated);
143 PHASE ("extend", internal->stats.extensions,
144 "extending through extension stack of size %zd",
145 extension.size ());
146 const auto begin = extension.begin ();
147 auto i = extension.end ();
148#ifndef CADICAL_QUIET
149 int64_t flipped = 0;
150#endif
151 while (i != begin) {
152 bool satisfied = false;
153 int lit;
154 CADICAL_assert (i != begin);
155 while ((lit = *--i)) {
156 if (satisfied)
157 continue;
158 if (ival (lit) == lit)
159 satisfied = true;
160 CADICAL_assert (i != begin);
161 }
162 CADICAL_assert (i != begin);
163 LOG ("id=%" PRId64, ((int64_t) *i << 32) + *(i - 1));
164 CADICAL_assert (*i || *(i - 1));
165 --i;
166 CADICAL_assert (i != begin);
167 --i;
168 CADICAL_assert (i != begin);
169 CADICAL_assert (!*i);
170 --i;
171 CADICAL_assert (i != begin);
172 if (satisfied)
173 while (*--i)
174 CADICAL_assert (i != begin);
175 else {
176 while ((lit = *--i)) {
177 const int tmp = ival (lit); // not 'signed char'!!!
178 if (tmp != lit) {
179 LOG ("flipping blocking literal %d", lit);
181 CADICAL_assert (lit != INT_MIN);
182 size_t idx = abs (lit);
183 if (idx >= vals.size ())
184 vals.resize (idx + 1, false);
185 vals[idx] = !vals[idx];
186 internal->stats.extended++;
187#ifndef CADICAL_QUIET
188 flipped++;
189#endif
190 }
191 CADICAL_assert (i != begin);
192 }
193 }
194 }
195 PHASE ("extend", internal->stats.extensions,
196 "flipped %" PRId64 " literals during extension", flipped);
197 extended = true;
198 LOG ("extended");
199 STOP (extend);
200}
#define PHASE(...)
Definition message.hpp:52
#define STOP(P)
Definition profile.hpp:158
#define START(P)
Definition profile.hpp:150
vector< int > extension
Definition external.hpp:85
vector< bool > vals
Definition external.hpp:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ failed()

bool CaDiCaL::External::failed ( int elit)

Definition at line 274 of file cadical_external.cpp.

274 {
275 CADICAL_assert (elit);
276 CADICAL_assert (elit != INT_MIN);
277 int eidx = abs (elit);
278 if (eidx > max_var)
279 return 0;
280 int ilit = e2i[eidx];
281 if (!ilit)
282 return 0;
283 if (elit < 0)
284 ilit = -ilit;
285 return internal->failed (ilit);
286}
Here is the caller graph for this function:

◆ failed_constraint()

bool CaDiCaL::External::failed_constraint ( )

Definition at line 306 of file cadical_external.cpp.

306 {
307 return internal->failed_constraint ();
308}
Here is the caller graph for this function:

◆ fixed()

int CaDiCaL::External::fixed ( int elit) const
inline

Definition at line 1768 of file internal.hpp.

1768 {
1769 CADICAL_assert (elit);
1770 CADICAL_assert (elit != INT_MIN);
1771 int eidx = abs (elit);
1772 if (eidx > max_var)
1773 return 0;
1774 int ilit = e2i[eidx];
1775 if (!ilit)
1776 return 0;
1777 if (elit < 0)
1778 ilit = -ilit;
1779 return internal->fixed (ilit);
1780}
Here is the caller graph for this function:

◆ flip()

bool CaDiCaL::External::flip ( int elit)

Definition at line 239 of file cadical_external.cpp.

239 {
240 CADICAL_assert (elit);
241 CADICAL_assert (elit != INT_MIN);
243
244 int eidx = abs (elit);
245 if (eidx > max_var)
246 return false;
247 if (marked (witness, elit))
248 return false;
249 int ilit = e2i[eidx];
250 if (!ilit)
251 return false;
252 bool res = internal->flip (ilit);
253 if (res && extended)
255 return res;
256}
Here is the call graph for this function:

◆ flippable()

bool CaDiCaL::External::flippable ( int elit)

Definition at line 258 of file cadical_external.cpp.

258 {
259 CADICAL_assert (elit);
260 CADICAL_assert (elit != INT_MIN);
262
263 int eidx = abs (elit);
264 if (eidx > max_var)
265 return false;
266 if (marked (witness, elit))
267 return false;
268 int ilit = e2i[eidx];
269 if (!ilit)
270 return false;
271 return internal->flippable (ilit);
272}
Here is the call graph for this function:

◆ force_backtrack()

void CaDiCaL::External::force_backtrack ( size_t new_level)

Definition at line 488 of file cadical_external.cpp.

488 {
489 if (!propagator) {
490 LOG ("No connected propagator that could force backtracking");
491 return;
492 }
493 LOG ("force backtrack to level %zd", new_level);
494 internal->force_backtrack (new_level);
495}

◆ freeze()

void CaDiCaL::External::freeze ( int elit)

Definition at line 654 of file cadical_external.cpp.

654 {
656 int ilit = internalize (elit);
657 unsigned eidx = vidx (elit);
658 if (eidx >= frozentab.size ())
659 frozentab.resize (eidx + 1, 0);
660 unsigned &ref = frozentab[eidx];
661 if (ref < UINT_MAX) {
662 ref++;
663 LOG ("external variable %d frozen once and now frozen %u times", eidx,
664 ref);
665 } else
666 LOG ("external variable %d frozen but remains frozen forever", eidx);
667 internal->freeze (ilit);
668}
unsigned short ref
Definition giaNewBdd.h:38
vector< unsigned > frozentab
Definition external.hpp:92
int vidx(int elit) const
Definition external.hpp:155
Here is the call graph for this function:
Here is the caller graph for this function:

◆ frozen()

bool CaDiCaL::External::frozen ( int elit)
inline

Definition at line 257 of file external.hpp.

257 {
258 CADICAL_assert (elit);
259 CADICAL_assert (elit != INT_MIN);
260 int eidx = abs (elit);
261 if (eidx > max_var)
262 return false;
263 if (eidx >= (int) frozentab.size ())
264 return false;
265 return frozentab[eidx] > 0;
266 }
Here is the caller graph for this function:

◆ generate_cubes()

CaDiCaL::CubesWithStatus CaDiCaL::External::generate_cubes ( int depth,
int min_depth = 0 )

Definition at line 631 of file cadical_external.cpp.

632 {
635 reset_limits ();
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);
640 return elit;
641 };
642 auto externalize_map = [this, externalize] (std::vector<int> cube) {
643 (void) this;
644 MSG ("Cube : ");
645 std::for_each (begin (cube), end (cube), externalize);
646 };
647 std::for_each (begin (cubes.cubes), end (cubes.cubes), externalize_map);
648
649 return cubes;
650}
#define MSG(...)
Definition message.hpp:49
Here is the call graph for this function:

◆ implied()

void CaDiCaL::External::implied ( std::vector< int > & entrailed)

Definition at line 508 of file cadical_external.cpp.

508 {
509 std::vector<int> ilit_implicants;
510 internal->implied (ilit_implicants);
511
512 // Those implied literals must be filtered out that are witnesses
513 // on the reconstruction stack -> no inplace externalize is possible.
514 // (Internal does not see these marks, so no earlier filter is
515 // possible.)
516
517 trailed.clear();
518
519 for (const auto &ilit : ilit_implicants) {
520 CADICAL_assert (ilit);
521 const int elit = internal->externalize (ilit);
522 const int eidx = abs (elit);
523 const bool is_extension_var = ervars[eidx];
524 if (!marked (tainted, elit) && !is_extension_var) {
525 trailed.push_back (elit);
526 }
527 }
528}
vector< bool > tainted
Definition external.hpp:88
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void CaDiCaL::External::init ( int new_max_var,
bool extension = false )

Definition at line 35 of file cadical_external.cpp.

35 {
37 if (new_max_var <= max_var)
38 return;
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)
44 enlarge (new_max_var);
45 LOG ("initialized %d external variables", new_vars);
46 if (!max_var) {
47 CADICAL_assert (e2i.empty ());
48 e2i.push_back (0);
49 ext_units.push_back (0);
50 ext_units.push_back (0);
51 ext_flags.push_back (0);
52 ervars.push_back (0);
53 CADICAL_assert (internal->i2e.empty ());
54 internal->i2e.push_back (0);
55 } else {
56 CADICAL_assert (e2i.size () == (size_t) max_var + 1);
57 CADICAL_assert (internal->i2e.size () == (size_t) old_internal_max_var + 1);
58 }
59 unsigned iidx = old_internal_max_var + 1, eidx;
60 for (eidx = max_var + 1u; eidx <= (unsigned) new_max_var;
61 eidx++, iidx++) {
62 LOG ("mapping external %u to internal %u", eidx, iidx);
63 CADICAL_assert (e2i.size () == eidx);
64 e2i.push_back (iidx);
65 ext_units.push_back (0);
66 ext_units.push_back (0);
67 ext_flags.push_back (0);
68 ervars.push_back (0);
69 internal->i2e.push_back (eidx);
70 CADICAL_assert (internal->i2e[iidx] == (int) eidx);
71 CADICAL_assert (e2i[eidx] == (int) iidx);
72 }
73 if (extension)
74 internal->stats.variables_extension += new_vars;
75 else
76 internal->stats.variables_original += new_vars;
77 if (new_max_var >= (int64_t) is_observed.size ())
78 is_observed.resize (1 + (size_t) new_max_var, false);
79 if (internal->opts.checkfrozen)
80 if (new_max_var >= (int64_t) moltentab.size ())
81 moltentab.resize (1 + (size_t) new_max_var, false);
82 CADICAL_assert (iidx == (size_t) new_internal_max_var + 1);
83 CADICAL_assert (eidx == (size_t) new_max_var + 1);
84 CADICAL_assert (ext_units.size () == (size_t) new_max_var * 2 + 2);
85 max_var = new_max_var;
86}
void enlarge(int new_max_var)
vector< bool > moltentab
Definition external.hpp:145
Here is the call graph for this function:
Here is the caller graph for this function:

◆ internalize()

int CaDiCaL::External::internalize ( int elit,
bool extension = false )

Definition at line 120 of file cadical_external.cpp.

120 {
121 int ilit;
122 if (elit) {
123 CADICAL_assert (elit != INT_MIN);
124 const int eidx = abs (elit);
125 if (extension && eidx <= max_var)
126 FATAL ("can not add a definition for an already used variable %d",
127 eidx);
128 if (eidx > max_var) {
129 init (eidx, extension);
130 }
131 if (extension) {
132 CADICAL_assert (ervars.size () > (size_t) eidx);
133 ervars[eidx] = true;
134 }
135 ilit = e2i[eidx];
136 if (elit < 0)
137 ilit = -ilit;
138 if (!ilit) {
139 CADICAL_assert (internal->max_var < INT_MAX);
140 ilit = internal->max_var + 1u;
141 internal->init_vars (ilit);
142 e2i[eidx] = ilit;
143 LOG ("mapping external %d to internal %d", eidx, ilit);
144 e2i[eidx] = ilit;
145 internal->i2e.push_back (eidx);
146 CADICAL_assert (internal->i2e[ilit] == eidx);
147 CADICAL_assert (e2i[eidx] == ilit);
148 if (elit < 0)
149 ilit = -ilit;
150 }
151 if (internal->opts.checkfrozen) {
152 CADICAL_assert (eidx < (int64_t) moltentab.size ());
153 if (moltentab[eidx])
154 FATAL ("can not reuse molten literal %d", eidx);
155 }
156 Flags &f = internal->flags (ilit);
157 if (f.status == Flags::UNUSED)
158 internal->mark_active (ilit);
159 else if (f.status != Flags::ACTIVE && f.status != Flags::FIXED)
160 internal->reactivate (ilit);
161 if (!marked (tainted, elit) && marked (witness, -elit)) {
162 CADICAL_assert (!internal->opts.checkfrozen);
163 LOG ("marking tainted %d", elit);
164 mark (tainted, elit);
165 }
166 } else
167 ilit = 0;
168 return ilit;
169}
void init(int new_max_var, bool extension=false)
signed char mark
Definition value.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_decision()

bool CaDiCaL::External::is_decision ( int elit)

Definition at line 477 of file cadical_external.cpp.

477 {
478 CADICAL_assert (elit);
479 CADICAL_assert (elit != INT_MIN);
480 int eidx = abs (elit);
481 if (eidx > max_var)
482 return false;
483
484 int ilit = internalize (elit);
485 return internal->is_decision (ilit);
486}
Here is the call graph for this function:

◆ is_valid_input()

bool CaDiCaL::External::is_valid_input ( int elit)
inline

Definition at line 170 of file external.hpp.

170 {
171 CADICAL_assert (elit);
172 CADICAL_assert (elit != INT_MIN);
173 int eidx = abs (elit);
174 return eidx > max_var || !ervars[eidx];
175 }

◆ is_witness()

bool CaDiCaL::External::is_witness ( int elit)

Definition at line 468 of file cadical_external.cpp.

468 {
469 CADICAL_assert (elit);
470 CADICAL_assert (elit != INT_MIN);
471 int eidx = abs (elit);
472 if (eidx > max_var)
473 return false;
474 return (marked (witness, elit) || marked (witness, -elit));
475}
Here is the call graph for this function:

◆ ival()

int CaDiCaL::External::ival ( int elit) const
inline

Definition at line 325 of file external.hpp.

325 {
326 CADICAL_assert (elit != INT_MIN);
327 int eidx = abs (elit);
328 bool val = false;
329 if (eidx <= max_var && (size_t) eidx < vals.size ())
330 val = vals[eidx];
331 if (elit < 0)
332 val = !val;
333 return val ? elit : -elit;
334 }
Here is the caller graph for this function:

◆ lookahead()

int CaDiCaL::External::lookahead ( )

Definition at line 621 of file cadical_external.cpp.

621 {
624 int ilit = internal->lookahead ();
625 const int elit =
626 (ilit && ilit != INT_MIN) ? internal->externalize (ilit) : 0;
627 LOG ("lookahead internal %d external %d", ilit, elit);
628 return elit;
629}
Here is the call graph for this function:

◆ mark()

void CaDiCaL::External::mark ( vector< bool > & map,
int elit )
inline

Definition at line 221 of file external.hpp.

221 {
222 const unsigned ulit = elit2ulit (elit);
223 if (ulit >= map.size ())
224 map.resize (ulit + 1, false);
225 map[ulit] = true;
226 }
void map()
unsigned elit2ulit(int elit) const
Definition external.hpp:208
Here is the call graph for this function:

◆ marked()

bool CaDiCaL::External::marked ( const vector< bool > & map,
int elit ) const
inline

Definition at line 216 of file external.hpp.

216 {
217 const unsigned ulit = elit2ulit (elit);
218 return ulit < map.size () ? map[ulit] : false;
219 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ melt()

void CaDiCaL::External::melt ( int elit)

Definition at line 670 of file cadical_external.cpp.

670 {
672 int ilit = internalize (elit);
673 unsigned eidx = vidx (elit);
674 CADICAL_assert (eidx < frozentab.size ());
675 unsigned &ref = frozentab[eidx];
676 CADICAL_assert (ref > 0);
677 if (ref < UINT_MAX) {
678 if (!--ref) {
679 if (observed (elit)) {
680 ref++;
681 LOG ("external variable %d is observed, can not be completely "
682 "molten",
683 eidx);
684 } else
685 LOG ("external variable %d melted once and now completely melted",
686 eidx);
687 } else
688 LOG ("external variable %d melted once but remains frozen %u times",
689 eidx, ref);
690 } else
691 LOG ("external variable %d melted but remains frozen forever", eidx);
692 internal->melt (ilit);
693}
bool observed(int elit)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ observed()

bool CaDiCaL::External::observed ( int elit)

Definition at line 456 of file cadical_external.cpp.

456 {
457 CADICAL_assert (elit);
458 CADICAL_assert (elit != INT_MIN);
459 int eidx = abs (elit);
460 if (eidx > max_var)
461 return false;
462 if (eidx >= (int) is_observed.size ())
463 return false;
464
465 return is_observed[eidx];
466}
Here is the caller graph for this function:

◆ phase()

void CaDiCaL::External::phase ( int elit)

Definition at line 310 of file cadical_external.cpp.

310 {
311 CADICAL_assert (elit);
312 CADICAL_assert (elit != INT_MIN);
313 const int ilit = internalize (elit);
314 internal->phase (ilit);
315}
Here is the call graph for this function:

◆ propagate_assumptions()

int CaDiCaL::External::propagate_assumptions ( )

Definition at line 499 of file cadical_external.cpp.

499 {
500 int res = internal->propagate_assumptions ();
501 if (res == 10 && !extended)
502 extend (); // Call solution reconstruction
503 check_solve_result (res);
504 reset_limits ();
505 return res;
506}
void check_solve_result(int res)
Here is the call graph for this function:

◆ push_binary_clause_on_extension_stack()

void CaDiCaL::External::push_binary_clause_on_extension_stack ( int64_t id,
int witness,
int other )

Definition at line 67 of file cadical_extend.cpp.

68 {
69 internal->stats.weakened++;
70 internal->stats.weakenedlen += 2;
78}
void push_witness_literal_on_extension_stack(int ilit)
void push_id_on_extension_stack(int64_t id)
void push_zero_on_extension_stack()
void push_clause_literal_on_extension_stack(int ilit)
Here is the call graph for this function:

◆ push_clause_literal_on_extension_stack()

void CaDiCaL::External::push_clause_literal_on_extension_stack ( int ilit)

Definition at line 22 of file cadical_extend.cpp.

22 {
23 CADICAL_assert (ilit);
24 const int elit = internal->externalize (ilit);
25 CADICAL_assert (elit);
26 extension.push_back (elit);
27 LOG ("pushing clause literal %d on extension stack (internal %d)", elit,
28 ilit);
29}
Here is the caller graph for this function:

◆ push_clause_on_extension_stack() [1/2]

void CaDiCaL::External::push_clause_on_extension_stack ( Clause * c)

Definition at line 51 of file cadical_extend.cpp.

51 {
52 internal->stats.weakened++;
53 internal->stats.weakenedlen += c->size;
57 for (const auto &lit : *c)
59}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_clause_on_extension_stack() [2/2]

void CaDiCaL::External::push_clause_on_extension_stack ( Clause * c,
int witness )

Definition at line 61 of file cadical_extend.cpp.

Here is the call graph for this function:

◆ push_external_clause_and_witness_on_extension_stack()

void CaDiCaL::External::push_external_clause_and_witness_on_extension_stack ( const vector< int > & clause,
const vector< int > & witness,
int64_t id )

Definition at line 82 of file cadical_extend.cpp.

83 {
84 CADICAL_assert (id);
85 extension.push_back (0);
86 for (const auto &elit : w) {
87 CADICAL_assert (elit != INT_MIN);
88 init (abs (elit));
89 extension.push_back (elit);
90 mark (witness, elit);
91 }
92 extension.push_back (0);
93 const uint32_t higher_bits = static_cast<int> (id << 32);
94 const uint32_t lower_bits = (id & (((int64_t) 1 << 32) - 1));
95 extension.push_back (higher_bits);
96 extension.push_back (lower_bits);
97 extension.push_back (0);
98 for (const auto &elit : c) {
99 CADICAL_assert (elit != INT_MIN);
100 init (abs (elit));
101 extension.push_back (elit);
102 }
103}
unsigned int uint32_t
Definition Fxch.h:32
Here is the call graph for this function:

◆ push_id_on_extension_stack()

void CaDiCaL::External::push_id_on_extension_stack ( int64_t id)

Definition at line 14 of file cadical_extend.cpp.

14 {
15 const uint32_t higher_bits = static_cast<int> (id << 32);
16 const uint32_t lower_bits = (id & (((int64_t) 1 << 32) - 1));
17 extension.push_back (higher_bits);
18 extension.push_back (lower_bits);
19 LOG ("pushing id %" PRIu64 " = %d + %d", id, higher_bits, lower_bits);
20}
Here is the caller graph for this function:

◆ push_witness_literal_on_extension_stack()

void CaDiCaL::External::push_witness_literal_on_extension_stack ( int ilit)

Definition at line 31 of file cadical_extend.cpp.

31 {
32 CADICAL_assert (ilit);
33 const int elit = internal->externalize (ilit);
34 CADICAL_assert (elit);
35 extension.push_back (elit);
36 LOG ("pushing witness literal %d on extension stack (internal %d)", elit,
37 ilit);
38 if (marked (witness, elit))
39 return;
40 LOG ("marking witness %d", elit);
41 mark (witness, elit);
42}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_zero_on_extension_stack()

void CaDiCaL::External::push_zero_on_extension_stack ( )

Definition at line 9 of file cadical_extend.cpp.

9 {
10 extension.push_back (0);
11 LOG ("pushing 0 on extension stack");
12}
Here is the caller graph for this function:

◆ remove_observed_var()

void CaDiCaL::External::remove_observed_var ( int elit)

Definition at line 408 of file cadical_external.cpp.

408 {
409 if (!propagator) {
410 LOG ("No connected propagator that could have watched the variable");
411 return;
412 }
413 int eidx = abs (elit);
414
415 if (eidx > max_var)
416 return;
417
418 if (is_observed[eidx]) {
419 // Follow opposite order of add_observed_var, first remove internal
420 // is_observed
421 int ilit = e2i[eidx]; // internalize (elit);
422 internal->remove_observed_var (ilit);
423
424 is_observed[eidx] = false;
425 melt (elit);
426 LOG ("unmarking %d as externally watched", eidx);
427 }
428}
Here is the call graph for this function:

◆ reset_assumptions()

void CaDiCaL::External::reset_assumptions ( )

Definition at line 90 of file cadical_external.cpp.

90 {
91 assumptions.clear ();
92 internal->reset_assumptions ();
93}

◆ reset_concluded()

void CaDiCaL::External::reset_concluded ( )

Definition at line 95 of file cadical_external.cpp.

95 {
96 concluded = false;
97 internal->reset_concluded ();
98}

◆ reset_constraint()

void CaDiCaL::External::reset_constraint ( )

Definition at line 100 of file cadical_external.cpp.

100 {
101 constraint.clear ();
102 internal->reset_constraint ();
103}
Here is the caller graph for this function:

◆ reset_extended()

void CaDiCaL::External::reset_extended ( )

Definition at line 105 of file cadical_external.cpp.

105 {
106 if (!extended)
107 return;
108 LOG ("reset extended");
109 extended = false;
110}
Here is the caller graph for this function:

◆ reset_limits()

void CaDiCaL::External::reset_limits ( )

Definition at line 112 of file cadical_external.cpp.

112{ internal->reset_limits (); }
Here is the caller graph for this function:

◆ reset_observed_vars()

void CaDiCaL::External::reset_observed_vars ( )

Definition at line 430 of file cadical_external.cpp.

430 {
431 // Shouldn't be called if there is no connected propagator
434
435 internal->notified = 0;
436 LOG ("reset notified counter to 0");
437
438 if (!is_observed.size ())
439 return;
440
441 CADICAL_assert (!max_var || (size_t) max_var + 1 == is_observed.size ());
442
443 for (auto elit : vars) {
444 int eidx = abs (elit);
445 CADICAL_assert (eidx <= max_var);
446 if (is_observed[eidx]) {
447 int ilit = internalize (elit);
448 internal->remove_observed_var (ilit);
449 LOG ("unmarking %d as externally watched", eidx);
450 is_observed[eidx] = false;
451 melt (elit);
452 }
453 }
454}
Here is the call graph for this function:

◆ restore_clause()

void CaDiCaL::External::restore_clause ( const vector< int >::const_iterator & begin,
const vector< int >::const_iterator & end,
const int64_t id )

Definition at line 54 of file cadical_restore.cpp.

56 {
57 LOG (begin, end, "restoring external clause[%" PRId64 "]", id);
58 CADICAL_assert (eclause.empty ());
59 CADICAL_assert (id);
60 for (auto p = begin; p != end; p++) {
61 eclause.push_back (*p);
62 if (internal->proof && internal->lrat) {
63 const auto &elit = *p;
64 unsigned eidx = (elit > 0) + 2u * (unsigned) abs (elit);
65 CADICAL_assert ((size_t) eidx < ext_units.size ());
66 const int64_t id = ext_units[eidx];
67 bool added = ext_flags[abs (elit)];
68 if (id && !added) {
69 ext_flags[abs (elit)] = true;
70 internal->lrat_chain.push_back (id);
71 }
72 }
73 int ilit = internalize (*p);
74 internal->add_original_lit (ilit), internal->stats.restoredlits++;
75 }
76 if (internal->proof && internal->lrat) {
77 for (const auto &elit : eclause) {
78 ext_flags[abs (elit)] = false;
79 }
80 }
81 internal->finish_added_clause_with_id (id, true);
82 eclause.clear ();
83 internal->stats.restored++;
84}
Cube * p
Definition exorList.c:222
Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_clauses()

void CaDiCaL::External::restore_clauses ( )

Definition at line 88 of file cadical_restore.cpp.

88 {
89
90 CADICAL_assert (internal->opts.restoreall == 2 || !tainted.empty ());
91
92 START (restore);
93 internal->stats.restorations++;
94
95 struct {
96 int64_t weakened, satisfied, restored, removed;
97 } clauses;
98 memset (&clauses, 0, sizeof clauses);
99
100 if (internal->opts.restoreall && tainted.empty ())
101 PHASE ("restore", internal->stats.restorations,
102 "forced to restore all clauses");
103
104#ifndef CADICAL_QUIET
105 {
106 unsigned numtainted = 0;
107 for (const auto b : tainted)
108 if (b)
109 numtainted++;
110
111 PHASE ("restore", internal->stats.restorations,
112 "starting with %u tainted literals %.0f%%", numtainted,
113 percent (numtainted, 2u * max_var));
114 }
115#endif
116
117 auto end_of_extension = extension.end ();
118 auto p = extension.begin (), q = p;
119
120 // Go over all witness labelled clauses on the extension stack, restore
121 // those necessary, remove restored and flush satisfied clauses.
122 //
123 while (p != end_of_extension) {
124
125 clauses.weakened++;
126
127 CADICAL_assert (!*p);
128 const auto saved = q; // Save old start.
129 *q++ = *p++; // Copy zero '0'.
130
131 // Copy witness part and try to find a tainted witness literal in it.
132 //
133 int tlit = 0; // Negation tainted.
134 int elit;
135 //
136 CADICAL_assert (p != end_of_extension);
137 //
138 while ((elit = *q++ = *p++)) {
139
140 if (marked (tainted, -elit)) {
141 tlit = elit;
142 LOG ("negation of witness literal %d tainted", tlit);
143 }
144
145 CADICAL_assert (p != end_of_extension);
146 }
147
148 // now copy the id of the clause
149 const int64_t id = ((int64_t) (*p) << 32) + (int64_t) * (p + 1);
150 LOG ("id is %" PRId64, id);
151 *q++ = *p++;
152 *q++ = *p++;
153 CADICAL_assert (id);
154 CADICAL_assert (!*p);
155 *q++ = *p++;
156
157 // Now find 'end_of_clause' (clause starts at 'p') and at the same time
158 // figure out whether the clause is actually root level satisfied.
159 //
160 int satisfied = 0;
161 auto end_of_clause = p;
162 while (end_of_clause != end_of_extension && (elit = *end_of_clause)) {
163 if (!satisfied && fixed (elit) > 0)
164 satisfied = elit;
165 end_of_clause++;
166 }
167 CADICAL_assert (id);
168
169 // Do not apply our 'FLUSH' rule to remove satisfied (implied) clauses
170 // if the corresponding option is set simply by resetting 'satisfied'.
171 //
172 if (satisfied && !internal->opts.restoreflush) {
173 LOG (p, end_of_clause, "forced to not remove %d satisfied",
174 satisfied);
175 satisfied = 0;
176 }
177
178 if (satisfied || tlit || internal->opts.restoreall) {
179
180 if (satisfied) {
181 LOG (p, end_of_clause,
182 "flushing implied clause satisfied by %d from extension stack",
183 satisfied);
184 clauses.satisfied++;
185 } else {
186 restore_clause (p, end_of_clause, id); // Might taint literals.
187 clauses.restored++;
188 }
189
190 clauses.removed++;
191 p = end_of_clause;
192 q = saved;
193
194 } else {
195
196 LOG (p, end_of_clause, "keeping clause on extension stack");
197
198 while (p != end_of_clause) // Copy clause too.
199 *q++ = *p++;
200 }
201 }
202
203 extension.resize (q - extension.begin ());
205
206#ifndef CADICAL_QUIET
207 if (clauses.satisfied)
208 PHASE ("restore", internal->stats.restorations,
209 "removed %" PRId64 " satisfied %.0f%% of %" PRId64
210 " weakened clauses",
211 clauses.satisfied, percent (clauses.satisfied, clauses.weakened),
212 clauses.weakened);
213 else
214 PHASE ("restore", internal->stats.restorations,
215 "no satisfied clause removed out of %" PRId64
216 " weakened clauses",
217 clauses.weakened);
218
219 if (clauses.restored)
220 PHASE ("restore", internal->stats.restorations,
221 "restored %" PRId64 " clauses %.0f%% out of %" PRId64
222 " weakened clauses",
223 clauses.restored, percent (clauses.restored, clauses.weakened),
224 clauses.weakened);
225 else
226 PHASE ("restore", internal->stats.restorations,
227 "no clause restored out of %" PRId64 " weakened clauses",
228 clauses.weakened);
229 {
230 unsigned numtainted = 0;
231 for (const auto &b : tainted)
232 if (b)
233 numtainted++;
234
235 PHASE ("restore", internal->stats.restorations,
236 "finishing with %u tainted literals %.0f%%", numtainted,
237 percent (numtainted, 2u * max_var));
238 }
239
240#endif
241 LOG ("extension stack clean");
242 tainted.clear ();
243
244 // Finally recompute the witness bits.
245 //
246 witness.clear ();
247 const auto begin_of_extension = extension.begin ();
248 p = extension.end ();
249 while (p != begin_of_extension) {
250 while (*--p)
251 CADICAL_assert (p != begin_of_extension);
252 int elit;
253 CADICAL_assert (p != begin_of_extension);
254 --p;
255 CADICAL_assert (p != begin_of_extension);
256 CADICAL_assert (*p || *(p - 1));
257 --p;
258 CADICAL_assert (p != begin_of_extension);
259 CADICAL_assert (!*p);
260 --p;
261 CADICAL_assert (p != begin_of_extension);
262 while ((elit = *--p)) {
263 mark (witness, elit);
264 CADICAL_assert (p != begin_of_extension);
265 }
266 }
267
268 STOP (restore);
269}
void shrink_vector(std::vector< T > &v)
Definition util.hpp:101
double percent(double a, double b)
Definition util.hpp:21
void restore_clause(const vector< int >::const_iterator &begin, const vector< int >::const_iterator &end, const int64_t id)
char * memset()
Here is the call graph for this function:

◆ sol()

int CaDiCaL::External::sol ( int elit) const
inline

Definition at line 446 of file external.hpp.

446 {
448 CADICAL_assert (elit != INT_MIN);
449 int eidx = abs (elit);
450 if (eidx > max_var)
451 return 0;
452 else if (eidx > solution_size)
453 return elit;
454 signed char value = solution[eidx];
455 if (!value)
456 return 0;
457 if (elit < 0)
458 value = -value;
459 return value > 0 ? elit : -elit;
460 }
ABC_NAMESPACE_IMPL_START typedef signed char value
Here is the caller graph for this function:

◆ solve()

int CaDiCaL::External::solve ( bool preprocess_only)

Definition at line 610 of file cadical_external.cpp.

610 {
613 int res = internal->solve (preprocess_only);
614 check_solve_result (res);
615 reset_limits ();
616 return res;
617}
Here is the call graph for this function:

◆ terminate()

void CaDiCaL::External::terminate ( )

Definition at line 619 of file cadical_external.cpp.

619{ internal->terminate (); }

◆ traverse_all_frozen_units_as_clauses()

bool CaDiCaL::External::traverse_all_frozen_units_as_clauses ( ClauseIterator & it)

Definition at line 914 of file cadical_external.cpp.

914 {
915 if (internal->unsat)
916 return true;
917
918 vector<int> clause;
919
920 for (auto idx : vars) {
921 if (!frozen (idx))
922 continue;
923 const int tmp = fixed (idx);
924 if (!tmp)
925 continue;
926 int unit = tmp < 0 ? -idx : idx;
927 clause.push_back (unit);
928 if (!it.clause (clause))
929 return false;
930 clause.clear ();
931 }
932
933 return true;
934}
bool frozen(int elit)
Definition external.hpp:257
Here is the call graph for this function:

◆ traverse_all_non_frozen_units_as_witnesses()

bool CaDiCaL::External::traverse_all_non_frozen_units_as_witnesses ( WitnessIterator & it)

Definition at line 936 of file cadical_external.cpp.

937 {
938 if (internal->unsat)
939 return true;
940
941 vector<int> clause_and_witness;
942 for (auto idx : vars) {
943 if (frozen (idx))
944 continue;
945 const int tmp = fixed (idx);
946 if (!tmp)
947 continue;
948 int unit = tmp < 0 ? -idx : idx;
949 const int ilit = e2i[idx] * (tmp < 0 ? -1 : 1);
950 // heurstically add + max_var to the id to avoid reusing ids
951 const int64_t id = internal->lrat ? internal->unit_id (ilit) : 1;
952 CADICAL_assert (id);
953 clause_and_witness.push_back (unit);
954 if (!it.witness (clause_and_witness, clause_and_witness, id + max_var))
955 return false;
956 clause_and_witness.clear ();
957 }
958
959 return true;
960}
Here is the call graph for this function:

◆ traverse_witnesses_backward()

bool CaDiCaL::External::traverse_witnesses_backward ( WitnessIterator & it)

Definition at line 204 of file cadical_extend.cpp.

204 {
205 if (internal->unsat)
206 return true;
207 vector<int> clause, witness;
208 const auto begin = extension.begin ();
209 auto i = extension.end ();
210 while (i != begin) {
211 int lit;
212 while ((lit = *--i))
213 clause.push_back (lit);
215 --i;
216 const int64_t id =
217 ((int64_t) * (i - 1) << 32) + static_cast<int64_t> (*i);
218 CADICAL_assert (id);
219 i -= 2;
220 CADICAL_assert (!*i);
221 CADICAL_assert (i != begin);
222 while ((lit = *--i))
223 witness.push_back (lit);
224 reverse (clause.begin (), clause.end ());
225 reverse (witness.begin (), witness.end ());
226 LOG (clause, "traversing clause");
227 if (!it.witness (clause, witness, id))
228 return false;
229 clause.clear ();
230 witness.clear ();
231 }
232 return true;
233}
Here is the call graph for this function:

◆ traverse_witnesses_forward()

bool CaDiCaL::External::traverse_witnesses_forward ( WitnessIterator & it)

Definition at line 235 of file cadical_extend.cpp.

235 {
236 if (internal->unsat)
237 return true;
238 vector<int> clause, witness;
239 const auto end = extension.end ();
240 auto i = extension.begin ();
241 if (i != end) {
242 int lit = *i++;
243 do {
244 CADICAL_assert (!lit), (void) lit;
245 while ((lit = *i++))
246 witness.push_back (lit);
248 CADICAL_assert (i != end);
249 CADICAL_assert (!*i);
250 const int64_t id =
251 ((int64_t) *i << 32) + static_cast<int64_t> (*(i + 1));
252 CADICAL_assert (id > 0);
253 i += 3;
254 CADICAL_assert (*i);
255 CADICAL_assert (i != end);
256 while (i != end && (lit = *i++))
257 clause.push_back (lit);
258 if (!it.witness (clause, witness, id))
259 return false;
260 clause.clear ();
261 witness.clear ();
262 } while (i != end);
263 }
264 return true;
265}
Here is the call graph for this function:

◆ unmark()

void CaDiCaL::External::unmark ( vector< bool > & map,
int elit )
inline

Definition at line 228 of file external.hpp.

228 {
229 const unsigned ulit = elit2ulit (elit);
230 if (ulit < map.size ())
231 map[ulit] = false;
232 }
Here is the call graph for this function:

◆ unphase()

void CaDiCaL::External::unphase ( int elit)

Definition at line 317 of file cadical_external.cpp.

317 {
318 CADICAL_assert (elit);
319 CADICAL_assert (elit != INT_MIN);
320 int eidx = abs (elit);
321 if (eidx > max_var) {
322 UNUSED:
323 LOG ("resetting forced phase of unused external %d ignored", elit);
324 return;
325 }
326 int ilit = e2i[eidx];
327 if (!ilit)
328 goto UNUSED;
329 if (elit < 0)
330 ilit = -ilit;
331 internal->unphase (ilit);
332}

◆ update_molten_literals()

void CaDiCaL::External::update_molten_literals ( )

Definition at line 582 of file cadical_external.cpp.

582 {
583 if (!internal->opts.checkfrozen)
584 return;
585 CADICAL_assert ((size_t) max_var + 1 == moltentab.size ());
586#ifdef LOGGING
587 int registered = 0, molten = 0;
588#endif
589 for (auto lit : vars) {
590 if (moltentab[lit]) {
591 LOG ("skipping already molten literal %d", lit);
592#ifdef LOGGING
593 molten++;
594#endif
595 } else if (frozen (lit))
596 LOG ("skipping currently frozen literal %d", lit);
597 else {
598 LOG ("new molten literal %d", lit);
599 moltentab[lit] = true;
600#ifdef LOGGING
601 registered++;
602 molten++;
603#endif
604 }
605 }
606 LOG ("registered %d new molten literals", registered);
607 LOG ("reached in total %d molten literals", molten);
608}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vidx()

int CaDiCaL::External::vidx ( int elit) const
inline

Definition at line 155 of file external.hpp.

155 {
156 CADICAL_assert (elit);
157 CADICAL_assert (elit != INT_MIN);
158 int res = abs (elit);
159 CADICAL_assert (res <= max_var);
160 return res;
161 }
Here is the caller graph for this function:

◆ vlit()

int CaDiCaL::External::vlit ( int elit) const
inline

Definition at line 163 of file external.hpp.

163 {
164 CADICAL_assert (elit);
165 CADICAL_assert (elit != INT_MIN);
166 CADICAL_assert (abs (elit) <= max_var);
167 return elit;
168 }

Member Data Documentation

◆ assumptions

vector<int> CaDiCaL::External::assumptions

Definition at line 69 of file external.hpp.

◆ concluded

bool CaDiCaL::External::concluded

Definition at line 84 of file external.hpp.

◆ constraint

vector<int> CaDiCaL::External::constraint

Definition at line 70 of file external.hpp.

◆ e2i

vector<int> CaDiCaL::External::e2i

Definition at line 67 of file external.hpp.

◆ eclause

vector<int> CaDiCaL::External::eclause

Definition at line 75 of file external.hpp.

◆ ervars

vector<bool> CaDiCaL::External::ervars

Definition at line 90 of file external.hpp.

◆ ext_flags

vector<bool> CaDiCaL::External::ext_flags

Definition at line 74 of file external.hpp.

◆ ext_units

vector<int64_t> CaDiCaL::External::ext_units

Definition at line 73 of file external.hpp.

◆ extended

bool CaDiCaL::External::extended

Definition at line 83 of file external.hpp.

◆ extension

vector<int> CaDiCaL::External::extension

Definition at line 85 of file external.hpp.

◆ fixed_listener

FixedAssignmentListener* CaDiCaL::External::fixed_listener

Definition at line 109 of file external.hpp.

◆ forgettable_original

unordered_map<uint64_t, vector<int> > CaDiCaL::External::forgettable_original

Definition at line 121 of file external.hpp.

◆ frozentab

vector<unsigned> CaDiCaL::External::frozentab

Definition at line 92 of file external.hpp.

◆ internal

Internal* CaDiCaL::External::internal

Definition at line 61 of file external.hpp.

◆ is_observed

vector<bool> CaDiCaL::External::is_observed

Definition at line 115 of file external.hpp.

◆ learner

Learner* CaDiCaL::External::learner

Definition at line 101 of file external.hpp.

◆ max_var

int CaDiCaL::External::max_var

Definition at line 63 of file external.hpp.

◆ moltentab

vector<bool> CaDiCaL::External::moltentab

Definition at line 145 of file external.hpp.

◆ original

vector<int> CaDiCaL::External::original

Definition at line 137 of file external.hpp.

◆ propagator

ExternalPropagator* CaDiCaL::External::propagator

Definition at line 113 of file external.hpp.

◆ solution

signed char* CaDiCaL::External::solution

Definition at line 135 of file external.hpp.

◆ solution_size

int CaDiCaL::External::solution_size

Definition at line 136 of file external.hpp.

◆ tainted

vector<bool> CaDiCaL::External::tainted

Definition at line 88 of file external.hpp.

◆ terminator

Terminator* CaDiCaL::External::terminator

Definition at line 97 of file external.hpp.

◆ vals

vector<bool> CaDiCaL::External::vals

Definition at line 66 of file external.hpp.

◆ vars

const Range CaDiCaL::External::vars

Definition at line 149 of file external.hpp.

◆ vsize

size_t CaDiCaL::External::vsize

Definition at line 64 of file external.hpp.

◆ witness

vector<bool> CaDiCaL::External::witness

Definition at line 87 of file external.hpp.


The documentation for this struct was generated from the following files: