ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_queue.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
9// Slightly different than 'bump_variable' since the variable is not
10// enqueued at all.
11
12inline void Internal::init_enqueue (int idx) {
13 Link &l = links[idx];
14 if (opts.reverse) {
15 l.prev = 0;
16 if (queue.first) {
17 CADICAL_assert (!links[queue.first].prev);
18 links[queue.first].prev = idx;
19 btab[idx] = btab[queue.first] - 1;
20 } else {
21 CADICAL_assert (!queue.last);
22 queue.last = idx;
23 btab[idx] = 0;
24 }
25 CADICAL_assert (btab[idx] <= stats.bumped);
26 l.next = queue.first;
27 queue.first = idx;
28 if (!queue.unassigned)
30 } else {
31 l.next = 0;
32 if (queue.last) {
33 CADICAL_assert (!links[queue.last].next);
34 links[queue.last].next = idx;
35 } else {
36 CADICAL_assert (!queue.first);
37 queue.first = idx;
38 }
39 btab[idx] = ++stats.bumped;
40 l.prev = queue.last;
41 queue.last = idx;
43 }
44}
45
46// Initialize VMTF queue from current 'old_max_var + 1' to 'new_max_var'.
47// This incorporates an initial variable order. We currently simply assume
48// that variables with smaller index are more important. This is the same
49// as in MiniSAT (implicitly) and also matches the 'scores' initialization.
50//
51void Internal::init_queue (int old_max_var, int new_max_var) {
52 LOG ("initializing VMTF queue from %d to %d", old_max_var + 1,
53 new_max_var);
54 CADICAL_assert (old_max_var < new_max_var);
55 // New variables can be created that can invoke enlarge anytime (eg via
56 // calls during ipasir-up call-backs), thus assuming (!level) is not
57 // correct
58 for (int idx = old_max_var; idx < new_max_var; idx++)
59 init_enqueue (idx + 1);
60}
61
62// Shuffle the VMTF queue.
63
65 if (!opts.shuffle)
66 return;
67 if (!opts.shufflequeue)
68 return;
69 stats.shuffled++;
70 LOG ("shuffling queue");
71 vector<int> shuffle;
72 if (opts.shufflerandom) {
73 for (int idx = max_var; idx; idx--)
74 shuffle.push_back (idx);
75 Random random (opts.seed); // global seed
76 random += stats.shuffled; // different every time
77 for (int i = 0; i <= max_var - 2; i++) {
78 const int j = random.pick_int (i, max_var - 1);
79 swap (shuffle[i], shuffle[j]);
80 }
81 } else {
82 for (int idx = queue.last; idx; idx = links[idx].prev)
83 shuffle.push_back (idx);
84 }
85 queue.first = queue.last = 0;
86 for (const int idx : shuffle)
87 queue.enqueue (links, idx);
88 int64_t bumped = queue.bumped;
89 for (int idx = queue.last; idx; idx = links[idx].prev)
90 btab[idx] = bumped--;
91 queue.unassigned = queue.last;
92}
93
94} // namespace CaDiCaL
95
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
Definition global.h:14
#define LOG(...)
void update_queue_unassigned(int idx)
Definition internal.hpp:652
void init_queue(int old_max_var, int new_max_var)
vector< int64_t > btab
Definition internal.hpp:234
void init_enqueue(int idx)
int64_t & bumped(int lit)
Definition internal.hpp:455
long random()