ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_watch.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
10 CADICAL_assert (wtab.empty ());
11 if (wtab.size () < 2 * vsize)
12 wtab.resize (2 * vsize, Watches ());
13 LOG ("initialized watcher tables");
14}
15
17 for (auto lit : lits)
18 watches (lit).clear ();
19}
20
22 CADICAL_assert (!wtab.empty ());
24 LOG ("reset watcher tables");
25}
26
27// This can be quite costly since lots of memory is accessed in a rather
28// random fashion, and thus we optionally profile it.
29
30void Internal::connect_watches (bool irredundant_only) {
31 START (connect);
33
34 LOG ("watching all %sclauses", irredundant_only ? "irredundant " : "");
35
36 // First connect binary clauses.
37 //
38 for (const auto &c : clauses) {
39 if (irredundant_only && c->redundant)
40 continue;
41 if (c->garbage || c->size > 2)
42 continue;
43 watch_clause (c);
44 }
45
46 // Then connect non-binary clauses.
47 //
48 for (const auto &c : clauses) {
49 if (irredundant_only && c->redundant)
50 continue;
51 if (c->garbage || c->size == 2)
52 continue;
53 watch_clause (c);
54 if (!level) {
55 const int lit0 = c->literals[0];
56 const int lit1 = c->literals[1];
57 const signed char tmp0 = val (lit0);
58 const signed char tmp1 = val (lit1);
59 if (tmp0 > 0)
60 continue;
61 if (tmp1 > 0)
62 continue;
63 if (tmp0 < 0) {
64 const size_t pos0 = var (lit0).trail;
65 if (pos0 < propagated) {
66 propagated = pos0;
67 LOG ("literal %d resets propagated to %zd", lit0, pos0);
68 }
69 }
70 if (tmp1 < 0) {
71 const size_t pos1 = var (lit1).trail;
72 if (pos1 < propagated) {
73 propagated = pos1;
74 LOG ("literal %d resets propagated to %zd", lit1, pos1);
75 }
76 }
77 }
78 }
79
80 STOP (connect);
81}
82
83// This can be quite costly since lots of memory is accessed in a rather
84// random fashion, and thus we optionally profile it.
85
87 START (connect);
89
90 LOG ("watching binary clauses");
91
92 // First connect binary clauses.
93 //
94 for (const auto &c : clauses) {
95 if (c->garbage || c->size > 2)
96 continue;
97 watch_clause (c);
98 }
99
100 STOP (connect);
101}
102
105 LOG ("sorting watches");
106 Watches saved;
107 for (auto lit : lits) {
108 Watches &ws = watches (lit);
109
110 const const_watch_iterator end = ws.end ();
111 watch_iterator j = ws.begin ();
113
114 CADICAL_assert (saved.empty ());
115
116 for (i = j; i != end; i++) {
117 const Watch w = *i;
118 if (w.binary ())
119 *j++ = w;
120 else
121 saved.push_back (w);
122 }
123
124 std::copy (saved.cbegin (), saved.cend (), j);
125
126 saved.clear ();
127 }
128}
129
130} // namespace CaDiCaL
131
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
Definition global.h:14
#define LOG(...)
Watches::const_iterator const_watch_iterator
Definition watch.hpp:48
vector< Watch > Watches
Definition watch.hpp:45
void erase_vector(std::vector< T > &v)
Definition util.hpp:90
Watches::iterator watch_iterator
Definition watch.hpp:47
#define STOP(P)
Definition profile.hpp:158
#define START(P)
Definition profile.hpp:150
int lit
Definition satVec.h:130
Var & var(int lit)
Definition internal.hpp:452
const Sange lits
Definition internal.hpp:325
void watch_clause(Clause *c)
Definition internal.hpp:633
bool watching() const
Definition internal.hpp:462
signed char val(int lit) const
vector< Clause * > clauses
Definition internal.hpp:283
vector< Watches > wtab
Definition internal.hpp:241
void connect_watches(bool irredundant_only=false)
int trail
Definition var.hpp:20
bool binary() const
Definition watch.hpp:42
vector watches
Definition watch.h:49