ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rephase.c
Go to the documentation of this file.
1#include "rephase.h"
2#include "backtrack.h"
3#include "decide.h"
4#include "internal.h"
5#include "logging.h"
6#include "print.h"
7#include "report.h"
8#include "terminate.h"
9#include "walk.h"
10
11#include <inttypes.h>
12#include <string.h>
13
15
16static void kissat_reset_best_assigned (kissat *solver) {
17 if (!solver->best_assigned)
18 return;
20 "resetting best assigned trail height %u to 0",
21 solver->best_assigned);
22 solver->best_assigned = 0;
23}
24
25static void kissat_reset_target_assigned (kissat *solver) {
26 if (!solver->target_assigned)
27 return;
29 solver, "resetting target assigned trail height %u to 0",
30 solver->target_assigned);
31 solver->target_assigned = 0;
32}
33
35 if (!GET_OPTION (rephase))
36 return false;
37 if (!solver->stable)
38 return false;
39 return CONFLICTS > solver->limits.rephase.conflicts;
40}
41
42static char rephase_best (kissat *solver) {
43 const value *const best = solver->phases.best;
44 const value *const end_of_best = best + VARS;
45 value const *b;
46
47 value *const saved = solver->phases.saved;
48 value *s, tmp;
49
50 for (s = saved, b = best; b != end_of_best; s++, b++)
51 if ((tmp = *b))
52 *s = tmp;
53
54 INC (rephased_best);
55
56 return 'B';
57}
58
59static char rephase_original (kissat *solver) {
60 const value initial_phase = INITIAL_PHASE;
61 value *s = solver->phases.saved;
62 const value *const end = s + VARS;
63 while (s != end)
64 *s++ = initial_phase;
65 INC (rephased_original);
66 return 'O';
67}
68
69static char rephase_inverted (kissat *solver) {
70 const value inverted_initial_phase = -INITIAL_PHASE;
71 value *s = solver->phases.saved;
72 const value *const end = s + VARS;
73 while (s != end)
74 *s++ = inverted_initial_phase;
75 INC (rephased_inverted);
76 return 'I';
77}
78
79static char rephase_walking (kissat *solver) {
81 STOP (rephase);
83 START (rephase);
84 INC (rephased_walking);
85 return 'W';
86}
87
88static char (*rephase_schedule[]) (kissat *) = {
89 rephase_best, rephase_walking, rephase_inverted,
90 rephase_best, rephase_walking, rephase_original,
91};
92
93#define size_rephase_schedule \
94 (sizeof rephase_schedule / sizeof *rephase_schedule)
95
96#ifndef KISSAT_QUIET
97
98static const char *rephase_type_as_string (char type) {
99 if (type == 'B')
100 return "best";
101 if (type == 'I')
102 return "inverted";
103 if (type == 'O')
104 return "original";
105 KISSAT_assert (type == 'W');
106 return "walking";
107}
108
109#endif
110
111static char reset_phases (kissat *solver) {
112 const uint64_t count = GET (rephased);
113 KISSAT_assert (count > 0);
114 const uint64_t select = (count - 1) % (uint64_t) size_rephase_schedule;
115 const char type = rephase_schedule[select](solver);
117 solver, "rephase", GET (rephased), "%s phases in %s search mode",
118 rephase_type_as_string (type), solver->stable ? "stable" : "focused");
119 LOG ("copying saved phases as target phases");
120 memcpy (solver->phases.target, solver->phases.saved, VARS);
121 UPDATE_CONFLICT_LIMIT (rephase, rephased, NLOG3N, false);
122 kissat_reset_target_assigned (solver);
123 if (type == 'B')
124 kissat_reset_best_assigned (solver);
125 return type;
126}
127
130 KISSAT_assert (!solver->inconsistent);
131 START (rephase);
132 INC (rephased);
133#ifndef KISSAT_QUIET
134 const char type =
135#endif
136 reset_phases (solver);
137 REPORT (0, type);
138 STOP (rephase);
139}
140
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void kissat_backtrack_propagate_and_flush_trail(kissat *solver)
Definition backtrack.c:165
#define INC(NAME)
#define LOG(...)
ABC_NAMESPACE_IMPL_START typedef signed char value
#define INITIAL_PHASE
Definition decide.h:15
type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
#define VARS
Definition internal.h:250
#define NLOG3N(COUNT)
Definition kimits.h:111
#define UPDATE_CONFLICT_LIMIT(NAME, COUNT, SCALE_COUNT_FUNCTION, SCALE_DELTA)
Definition kimits.h:115
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define GET_OPTION(N)
Definition options.h:295
#define kissat_extremely_verbose(...)
Definition print.h:53
#define kissat_phase(...)
Definition print.h:48
#define STOP(P)
Definition profile.hpp:158
#define START(P)
Definition profile.hpp:150
void kissat_rephase(kissat *solver)
Definition rephase.c:128
bool kissat_rephasing(kissat *solver)
Definition rephase.c:34
#define size_rephase_schedule
Definition rephase.c:93
#define REPORT(...)
Definition report.h:10
#define CONFLICTS
Definition statistics.h:335
#define GET(NAME)
Definition statistics.h:416
char * memcpy()
void kissat_walk(kissat *solver)
Definition walk.c:938
bool kissat_walking(kissat *solver)
Definition walk.c:913