-
Notifications
You must be signed in to change notification settings - Fork 3
/
rephase.c
70 lines (62 loc) · 1.87 KB
/
rephase.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "rephase.h"
#include "backtrack.h"
#include "decide.h"
#include "message.h"
#include "report.h"
#include "ring.h"
#include "search.h"
#include "utilities.h"
#include "walk.h"
#include <inttypes.h>
static char rephase_walk (struct ring *ring) {
local_search (ring);
for (all_phases (p))
p->target = p->saved;
return 'W';
}
static char rephase_best (struct ring *ring) {
for (all_phases (p))
p->target = p->saved = p->best;
return 'B';
}
static char rephase_inverted (struct ring *ring) {
for (all_phases (p))
p->target = p->saved = -initial_phase (ring);
return 'I';
}
static char rephase_original (struct ring *ring) {
for (all_phases (p))
p->target = p->saved = initial_phase (ring);
return 'O';
}
bool rephasing (struct ring *ring) {
if (!ring->options.rephase)
return false;
return ring->stable && SEARCH_CONFLICTS > ring->limits.rephase;
}
static char (*schedule[]) (struct ring *) = {
rephase_original, rephase_best, rephase_walk,
rephase_inverted, rephase_best, rephase_walk,
};
void rephase (struct ring *ring) {
if (!backtrack_propagate_iterate (ring))
return;
struct ring_statistics *statistics = &ring->statistics;
struct ring_limits *limits = &ring->limits;
uint64_t rephased = ++statistics->rephased;
size_t size_schedule = sizeof schedule / sizeof *schedule;
char type = schedule[rephased % size_schedule](ring);
verbose (ring, "resetting number of target assigned %u", ring->target);
ring->target = 0;
if (type == 'B') {
verbose (ring, "resetting number of best assigned %u", ring->best);
ring->best = 0;
}
uint64_t base = ring->options.rephase_interval;
uint64_t interval = base * nlog3n (rephased);
limits->rephase = SEARCH_CONFLICTS + interval;
very_verbose (
ring, "new rephase limit of %" PRIu64 " after %" PRIu64 " conflicts",
limits->rephase, interval);
report (ring, type);
}