ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
decide.c
Go to the documentation of this file.
1#include "decide.h"
2#include "inlineframes.h"
3#include "inlineheap.h"
4#include "inlinequeue.h"
5#include "print.h"
6
7#include <inttypes.h>
8
10
11static unsigned last_enqueued_unassigned_variable (kissat *solver) {
12 KISSAT_assert (solver->unassigned);
13 const links *const links = solver->links;
14 const value *const values = solver->values;
15 unsigned res = solver->queue.search.idx;
16 if (values[LIT (res)]) {
17 do {
18 res = links[res].prev;
20 } while (values[LIT (res)]);
21 kissat_update_queue (solver, links, res);
22 }
23#ifdef LOGGING
24 const unsigned stamp = links[res].stamp;
25 LOG ("last enqueued unassigned %s stamp %u", LOGVAR (res), stamp);
26#endif
27#ifdef CHECK_QUEUE
28 for (unsigned i = links[res].next; !DISCONNECTED (i); i = links[i].next)
29 KISSAT_assert (VALUE (LIT (i)));
30#endif
31 return res;
32}
33
34static unsigned largest_score_unassigned_variable (kissat *solver) {
36 unsigned res = kissat_max_heap (scores);
37 const value *const values = solver->values;
38 while (values[LIT (res)]) {
39 kissat_pop_max_heap (solver, scores);
40 res = kissat_max_heap (scores);
41 }
42#if defined(LOGGING) || defined(CHECK_HEAP)
43 const double score = kissat_get_heap_score (scores, res);
44#endif
45 LOG ("largest score unassigned %s score %g", LOGVAR (res), score);
46#ifdef CHECK_HEAP
47 for (all_variables (idx)) {
48 if (!ACTIVE (idx))
49 continue;
50 if (VALUE (LIT (idx)))
51 continue;
52 const double idx_score = kissat_get_heap_score (scores, idx);
53 KISSAT_assert (score >= idx_score);
54 }
55#endif
56 return res;
57}
58
60 if (!GET_OPTION (randec))
61 return;
62
63 if (solver->stable && !GET_OPTION (randecstable))
64 return;
65
66 if (!solver->stable && !GET_OPTION (randecfocused))
67 return;
68
69 if (solver->randec)
71 "continuing random decision sequence "
72 "at %s conflicts",
74 else {
75 INC (random_sequences);
76 const uint64_t count = solver->statistics_.random_sequences;
77 const unsigned length = GET_OPTION (randeclength) * LOGN (count);
79 "starting random decision sequence "
80 "at %s conflicts for %s conflicts",
82 solver->randec = length;
83
84 UPDATE_CONFLICT_LIMIT (randec, random_sequences, LOGN, false);
85 }
86}
87
88static unsigned next_random_decision (kissat *solver) {
89 if (!VARS)
90 return INVALID_IDX;
91
92 if (solver->warming)
93 return INVALID_IDX;
94
95 if (!GET_OPTION (randec))
96 return INVALID_IDX;
97
98 if (solver->stable && !GET_OPTION (randecstable))
99 return INVALID_IDX;
100
101 if (!solver->stable && !GET_OPTION (randecfocused))
102 return INVALID_IDX;
103
104 if (!solver->randec) {
105 KISSAT_assert (solver->level);
106 if (solver->level > 1)
107 return INVALID_IDX;
108
109 uint64_t conflicts = CONFLICTS;
110 limits *limits = &solver->limits;
111 if (conflicts < limits->randec.conflicts)
112 return INVALID_IDX;
113
115 }
116
117 for (;;) {
118 unsigned idx = kissat_next_random32 (&solver->random) % VARS;
119 if (!ACTIVE (idx))
120 continue;
121 unsigned lit = LIT (idx);
122 if (solver->values[lit])
123 continue;
124 return idx;
125 }
126}
127
129#ifdef LOGGING
130 const char *type = 0;
131#endif
132 unsigned res = next_random_decision (solver);
133 if (res == INVALID_IDX) {
134 if (solver->stable) {
135#ifdef LOGGING
136 type = "maximum score";
137#endif
138 res = largest_score_unassigned_variable (solver);
139 INC (score_decisions);
140 } else {
141#ifdef LOGGING
142 type = "dequeued";
143#endif
144 res = last_enqueued_unassigned_variable (solver);
145 INC (queue_decisions);
146 }
147 } else {
148#ifdef LOGGING
149 type = "random";
150#endif
151 INC (random_decisions);
152 }
153 LOG ("next %s decision %s", type, LOGVAR (res));
154 return res;
155}
156
157int kissat_decide_phase (kissat *solver, unsigned idx) {
158 bool force = GET_OPTION (forcephase);
159
160 value *target;
161 if (force)
162 target = 0;
163 else if (!GET_OPTION (target))
164 target = 0;
165 else if (solver->stable || GET_OPTION (target) > 1)
166 target = solver->phases.target + idx;
167 else
168 target = 0;
169
170 value *saved;
171 if (force)
172 saved = 0;
173 else if (GET_OPTION (phasesaving))
174 saved = solver->phases.saved + idx;
175 else
176 saved = 0;
177
178 value res = 0;
179
180 if (!solver->stable) {
181 switch ((solver->statistics_.switched >> 1) & 7) {
182 case 1:
183 res = INITIAL_PHASE;
184 break;
185 case 3:
186 res = -INITIAL_PHASE;
187 break;
188 }
189 }
190
191 if (!res && target && (res = *target)) {
192 LOG ("%s uses target decision phase %d", LOGVAR (idx), (int) res);
193 INC (target_decisions);
194 }
195
196 if (!res && saved && (res = *saved)) {
197 LOG ("%s uses saved decision phase %d", LOGVAR (idx), (int) res);
198 INC (saved_decisions);
199 }
200
201 if (!res) {
202 res = INITIAL_PHASE;
203 LOG ("%s uses initial decision phase %d", LOGVAR (idx), (int) res);
204 INC (initial_decisions);
205 }
206 KISSAT_assert (res);
207
208 return res < 0 ? -1 : 1;
209}
210
212 START (decide);
213 KISSAT_assert (solver->unassigned);
214 if (solver->warming)
215 INC (warming_decisions);
216 else {
217 INC (decisions);
218 if (solver->stable)
219 INC (stable_decisions);
220 else
221 INC (focused_decisions);
222 }
223 solver->level++;
225 const unsigned idx = kissat_next_decision_variable (solver);
226 const value value = kissat_decide_phase (solver, idx);
227 unsigned lit = LIT (idx);
228 if (value < 0)
229 lit = NOT (lit);
230 kissat_push_frame (solver, lit);
231 KISSAT_assert (solver->level < SIZE_STACK (solver->frames));
232 LOG ("decide literal %s", LOGLIT (lit));
234 STOP (decide);
235}
236
238 KISSAT_assert (solver->unassigned);
240 solver->level++;
242 kissat_push_frame (solver, lit);
243 KISSAT_assert (solver->level < SIZE_STACK (solver->frames));
244 LOG ("assuming literal %s", LOGLIT (lit));
246}
247
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void kissat_assign_decision(kissat *solver, unsigned lit)
Definition assign.c:28
#define INVALID_LEVEL
Definition assign.h:12
#define SIZE_STACK(S)
Definition stack.h:19
#define INC(NAME)
#define LOG(...)
ABC_NAMESPACE_IMPL_START typedef signed char value
int kissat_decide_phase(kissat *solver, unsigned idx)
Definition decide.c:157
void kissat_start_random_sequence(kissat *solver)
Definition decide.c:59
unsigned kissat_next_decision_variable(kissat *solver)
Definition decide.c:128
void kissat_internal_assume(kissat *solver, unsigned lit)
Definition decide.c:237
void kissat_decide(kissat *solver)
Definition decide.c:211
#define INITIAL_PHASE
Definition decide.h:15
#define ACTIVE
Definition espresso.h:129
type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
#define FORMAT_COUNT(WORD)
Definition format.h:33
#define VARS
Definition internal.h:250
#define all_variables(IDX)
Definition internal.h:269
#define SCORES
Definition internal.h:262
#define LOGN(COUNT)
Definition kimits.h:107
#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 LOGLIT(...)
Definition logging.hpp:99
#define GET_OPTION(N)
Definition options.h:295
#define kissat_very_verbose(...)
Definition print.h:52
#define STOP(P)
Definition profile.hpp:158
#define START(P)
Definition profile.hpp:150
#define DISCONNECTED(IDX)
Definition queue.h:8
int lit
Definition satVec.h:130
#define LIT(IDX)
Definition literal.h:31
#define INVALID_IDX
Definition literal.h:18
#define NOT(LIT)
Definition literal.h:33
#define CONFLICTS
Definition statistics.h:335
Definition heap.h:19
#define VALUE(LIT)
Definition value.h:10