ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
watch.hpp
Go to the documentation of this file.
1#ifndef _watch_hpp_INCLUDED
2#define _watch_hpp_INCLUDED
3
4#include "global.h"
5
6#include <cassert>
7#include <vector>
8
10
11namespace CaDiCaL {
12
13// Watch lists for CDCL search. The blocking literal (see also comments
14// related to 'propagate') is a must and thus combining that with a 64 bit
15// pointer will give a 16 byte (8 byte aligned) structure anyhow, which
16// means the additional 4 bytes for the size come for free. As alternative
17// one could use a 32-bit reference instead of the pointer which would
18// however limit the number of clauses to '2^32 - 1'. One would also need
19// to use at least one more bit (either taken away from the variable space
20// or the clauses) to denote whether the watch is binary.
21
22// in fashion of Intel Sat 10.4230/LIPIcs.SAT.2022.8 we try to
23// guarantee the following invariant:
24// For both watches:
25// if the watched literal is negatively assigned
26// either it will be propagated in the future
27// or the corresponding blocking literal is positively assigned
28// and its level is smaller than the level of the watched literal
29//
30
31struct Clause;
32
33struct Watch {
34
36 int blit;
37 int size;
38
39 Watch (int b, Clause *c) : clause (c), blit (b), size (c->size) {}
40 Watch () {}
41
42 bool binary () const { return size == 2; }
43};
44
45typedef vector<Watch> Watches; // of one literal
46
47typedef Watches::iterator watch_iterator;
48typedef Watches::const_iterator const_watch_iterator;
49
50inline void remove_watch (Watches &ws, Clause *clause) {
51 const auto end = ws.end ();
52 auto i = ws.begin ();
53 for (auto j = i; j != end; j++) {
54 const Watch &w = *i++ = *j;
55 if (w.clause == clause)
56 i--;
57 }
58 CADICAL_assert (i + 1 == end);
59 ws.resize (i - ws.begin ());
60}
61
62// search for the clause and updates the size marked in the watch lists
63inline void update_watch_size (Watches &ws, int blit, Clause *conflict) {
64 bool found = false;
65 const int size = conflict->size;
66 for (Watch &w : ws) {
67 if (w.clause == conflict)
68 w.size = size, w.blit = blit, found = true;
69 CADICAL_assert (w.clause->garbage || w.size == 2 || w.clause->size != 2);
70 }
71 CADICAL_assert (found), (void) found;
72}
73
74} // namespace CaDiCaL
75
77
78#endif
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
#define CADICAL_assert(ignore)
Definition global.h:14
void remove_watch(Watches &ws, Clause *clause)
Definition watch.hpp:50
Watches::const_iterator const_watch_iterator
Definition watch.hpp:48
void update_watch_size(Watches &ws, int blit, Clause *conflict)
Definition watch.hpp:63
vector< Watch > Watches
Definition watch.hpp:45
Watches::iterator watch_iterator
Definition watch.hpp:47
bool binary() const
Definition watch.hpp:42
Clause * clause
Definition watch.hpp:35
Watch(int b, Clause *c)
Definition watch.hpp:39