ABC: A System for Sequential Synthesis and Verification
Loading...
Searching...
No Matches
reluctant.hpp
Go to the documentation of this file.
1
#ifndef _reluctant_hpp_INCLUDED
2
#define _reluctant_hpp_INCLUDED
3
4
#include "
global.h
"
5
6
#include <cassert>
7
#include <cstdint>
8
9
ABC_NAMESPACE_CXX_HEADER_START
10
11
namespace
CaDiCaL
{
12
13
// This is Donald Knuth's version of the Luby restart sequence which he
14
// called 'reluctant doubling'. His bit-twiddling formulation in line (DK)
15
// requires to keep two words around which are updated every time the
16
// reluctant doubling sequence is advanced. The original version in the
17
// literature uses a complex recursive function which computes the length of
18
// the next inactive sub-sequence every time (but is state-less).
19
//
20
// In our code we incorporate a base interval 'period' and only after period
21
// many calls to 'tick' times the current sequence value we update the
22
// reluctant doubling sequence value. The 'tick' call is decoupled from
23
// the activation signal of the sequence (the 'bool ()' operator) through
24
// 'trigger'. It is also possible to set an upper limit to the length of an
25
// inactive sub-sequence. If that limit is reached the whole reluctant
26
// doubling sequence starts over with the initial values.
27
28
class
Reluctant
{
29
30
uint64_t u, v, limit;
31
uint64_t period, countdown;
32
bool
trigger, limited;
33
34
public
:
35
Reluctant
() : period (0), trigger (
false
) {}
36
37
void
enable
(
int
p
, int64_t l) {
38
CADICAL_assert
(
p
> 0);
39
u = v = 1;
40
period = countdown =
p
;
41
trigger =
false
;
42
if
(l <= 0)
43
limited =
false
;
44
else
45
limited =
true
, limit = l;
46
};
47
48
void
disable
() { period = 0, trigger =
false
; }
49
50
// Increments the count until the 'period' is hit. Then it performs the
51
// actual increment of reluctant doubling. This gives the common 'Luby'
52
// sequence with the specified base interval period. As soon the limit is
53
// reached (countdown goes to zero) we remember this event and then
54
// disable updating the reluctant sequence until the signal is delivered.
55
56
void
tick
() {
57
58
if
(!period)
59
return
;
// disabled
60
if
(trigger)
61
return
;
// already triggered
62
if
(--countdown)
63
return
;
// not there yet
64
65
if
((u & -u) == v)
66
u = u + 1, v = 1;
67
else
68
v = 2 * v;
// (DK)
69
70
if
(limited && v >= limit)
71
u = v = 1;
72
countdown = v * period;
73
trigger =
true
;
74
}
75
76
operator
bool
() {
77
if
(!trigger)
78
return
false
;
79
trigger =
false
;
80
return
true
;
81
}
82
};
83
84
}
// namespace CaDiCaL
85
86
ABC_NAMESPACE_CXX_HEADER_END
87
88
#endif
ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_START
Definition
abc_namespaces.h:52
ABC_NAMESPACE_CXX_HEADER_END
#define ABC_NAMESPACE_CXX_HEADER_END
Definition
abc_namespaces.h:53
global.h
CADICAL_assert
#define CADICAL_assert(ignore)
Definition
global.h:14
CaDiCaL::Reluctant::tick
void tick()
Definition
reluctant.hpp:56
CaDiCaL::Reluctant::Reluctant
Reluctant()
Definition
reluctant.hpp:35
CaDiCaL::Reluctant::enable
void enable(int p, int64_t l)
Definition
reluctant.hpp:37
CaDiCaL::Reluctant::disable
void disable()
Definition
reluctant.hpp:48
bool
#define bool
Definition
espresso.h:254
p
Cube * p
Definition
exorList.c:222
CaDiCaL
Definition
arena.hpp:8
false
#define false
Definition
place_base.h:29
src
sat
cadical
reluctant.hpp
Generated by Doxygen 1.13.2 © 2025 EPTansuo. All rights reserved.
鲁ICP备2021046540号