ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
satoko.h File Reference
#include "types.h"
#include "misc/util/abc_global.h"
Include dependency graph for satoko.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  satoko_opts
 
struct  satoko_stats
 

Typedefs

typedef struct solver_t_ satoko_t
 
typedef struct satoko_opts satoko_opts_t
 
typedef struct satoko_stats satoko_stats_t
 

Enumerations

enum  { SATOKO_ERR = 0 , SATOKO_OK = 1 }
 
enum  { SATOKO_UNDEC = 0 , SATOKO_SAT = 1 , SATOKO_UNSAT = -1 }
 
enum  { SATOKO_LIT_FALSE = 1 , SATOKO_LIT_TRUE = 0 , SATOKO_VAR_UNASSING = 3 }
 

Functions

satoko_tsatoko_create (void)
 
void satoko_destroy (satoko_t *)
 
void satoko_reset (satoko_t *)
 
void satoko_default_opts (satoko_opts_t *)
 
void satoko_configure (satoko_t *, satoko_opts_t *)
 
int satoko_parse_dimacs (char *, satoko_t **)
 
void satoko_setnvars (satoko_t *, int)
 
int satoko_add_variable (satoko_t *, char)
 
int satoko_add_clause (satoko_t *, int *, int)
 
void satoko_assump_push (satoko_t *s, int)
 
void satoko_assump_pop (satoko_t *s)
 
int satoko_simplify (satoko_t *)
 
int satoko_solve (satoko_t *)
 
int satoko_solve_assumptions (satoko_t *s, int *plits, int nlits)
 
int satoko_solve_assumptions_limit (satoko_t *s, int *plits, int nlits, int nconflim)
 
int satoko_minimize_assumptions (satoko_t *s, int *plits, int nlits, int nconflim)
 
void satoko_mark_cone (satoko_t *, int *, int)
 
void satoko_unmark_cone (satoko_t *, int *, int)
 
void satoko_rollback (satoko_t *)
 
void satoko_bookmark (satoko_t *)
 
void satoko_unbookmark (satoko_t *)
 
int satoko_final_conflict (satoko_t *, int **)
 
void satoko_write_dimacs (satoko_t *, char *, int, int)
 
satoko_stats_tsatoko_stats (satoko_t *)
 
satoko_opts_tsatoko_options (satoko_t *)
 
int satoko_varnum (satoko_t *)
 
int satoko_clausenum (satoko_t *)
 
int satoko_learntnum (satoko_t *)
 
int satoko_conflictnum (satoko_t *)
 
void satoko_set_stop (satoko_t *, int *)
 
void satoko_set_stop_func (satoko_t *s, int(*fnct)(int))
 
void satoko_set_runid (satoko_t *, int)
 
int satoko_read_cex_varvalue (satoko_t *, int)
 
abctime satoko_set_runtime_limit (satoko_t *, abctime)
 
char satoko_var_polarity (satoko_t *, unsigned)
 

Typedef Documentation

◆ satoko_opts_t

typedef struct satoko_opts satoko_opts_t

Definition at line 37 of file satoko.h.

◆ satoko_stats_t

typedef struct satoko_stats satoko_stats_t

Definition at line 72 of file satoko.h.

◆ satoko_t

typedef struct solver_t_ satoko_t

Definition at line 35 of file satoko.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Return valeus

Enumerator
SATOKO_ERR 
SATOKO_OK 

Definition at line 17 of file satoko.h.

17 {
18 SATOKO_ERR = 0,
19 SATOKO_OK = 1
20};
@ SATOKO_OK
Definition satoko.h:19
@ SATOKO_ERR
Definition satoko.h:18

◆ anonymous enum

anonymous enum
Enumerator
SATOKO_LIT_FALSE 
SATOKO_LIT_TRUE 
SATOKO_VAR_UNASSING 

Definition at line 28 of file satoko.h.

28 {
32};
@ SATOKO_LIT_FALSE
Definition satoko.h:29
@ SATOKO_LIT_TRUE
Definition satoko.h:30
@ SATOKO_VAR_UNASSING
Definition satoko.h:31

◆ anonymous enum

anonymous enum
Enumerator
SATOKO_UNDEC 
SATOKO_SAT 
SATOKO_UNSAT 

Definition at line 22 of file satoko.h.

22 {
23 SATOKO_UNDEC = 0, /* Undecided */
24 SATOKO_SAT = 1,
25 SATOKO_UNSAT = -1
26};
@ SATOKO_UNSAT
Definition satoko.h:25
@ SATOKO_SAT
Definition satoko.h:24
@ SATOKO_UNDEC
Definition satoko.h:23

Function Documentation

◆ satoko_add_clause()

int satoko_add_clause ( satoko_t * s,
int * lits,
int size )
extern

Definition at line 255 of file solver_api.c.

256{
257 unsigned i, j;
258 unsigned prev_lit;
259 unsigned max_var;
260 unsigned cref;
261
262 qsort((void *) lits, (size_t)size, sizeof(unsigned), stk_uint_compare);
263 max_var = lit2var(lits[size - 1]);
264 while (max_var >= vec_act_size(s->activity))
266
267 vec_uint_clear(s->temp_lits);
268 j = 0;
269 prev_lit = UNDEF;
270 for (i = 0; i < (unsigned)size; i++) {
271 if ((unsigned)lits[i] == lit_compl(prev_lit) || lit_value(s, lits[i]) == SATOKO_LIT_TRUE)
272 return SATOKO_OK;
273 else if ((unsigned)lits[i] != prev_lit && var_value(s, lit2var(lits[i])) == SATOKO_VAR_UNASSING) {
274 prev_lit = lits[i];
275 vec_uint_push_back(s->temp_lits, lits[i]);
276 }
277 }
278
279 if (vec_uint_size(s->temp_lits) == 0) {
280 s->status = SATOKO_ERR;
281 return SATOKO_ERR;
282 } if (vec_uint_size(s->temp_lits) == 1) {
283 solver_enqueue(s, vec_uint_at(s->temp_lits, 0), UNDEF);
284 return (s->status = (solver_propagate(s) == UNDEF));
285 }
286 if ( 0 ) {
287 for ( i = 0; i < vec_uint_size(s->temp_lits); i++ ) {
288 int lit = vec_uint_at(s->temp_lits, i);
289 printf( "%s%d ", lit&1 ? "!":"", lit>>1 );
290 }
291 printf( "\n" );
292 }
293 cref = solver_clause_create(s, s->temp_lits, 0);
294 clause_watch(s, cref);
295 return SATOKO_OK;
296}
unsigned long long size
Definition giaNewBdd.h:39
int lit
Definition satVec.h:130
#define UNDEF
Definition solver.h:35
unsigned solver_propagate(solver_t *s)
Definition solver.c:534
unsigned solver_clause_create(solver_t *s, vec_uint_t *lits, unsigned f_learnt)
Definition solver.c:483
int satoko_add_variable(solver_t *s, char sign)
Definition solver_api.c:237
int status
Definition solver.h:39
vec_act_t * activity
Definition solver.h:55
vec_uint_t * temp_lits
Definition solver.h:73
#define vec_act_size(vec)
Definition types.h:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_add_variable()

int satoko_add_variable ( satoko_t * s,
char sign )
extern

Definition at line 237 of file solver_api.c.

238{
239 unsigned var = vec_act_size(s->activity);
240 vec_wl_push(s->watches);
241 vec_wl_push(s->watches);
243 vec_uint_push_back(s->levels, 0);
244 vec_char_push_back(s->assigns, SATOKO_VAR_UNASSING);
245 vec_char_push_back(s->polarity, sign);
246 vec_uint_push_back(s->reasons, UNDEF);
247 vec_uint_push_back(s->stamps, 0);
248 vec_char_push_back(s->seen, 0);
249 heap_insert(s->var_order, var);
250 if (s->marks)
251 vec_char_push_back(s->marks, 0);
252 return var;
253}
unsigned short var
Definition giaNewBdd.h:35
vec_char_t * assigns
Definition solver.h:59
vec_char_t * seen
Definition solver.h:74
vec_uint_t * levels
Definition solver.h:57
vec_char_t * polarity
Definition solver.h:60
vec_uint_t * stamps
Definition solver.h:89
vec_char_t * marks
Definition solver.h:101
vec_uint_t * reasons
Definition solver.h:58
vec_wl_t * watches
Definition solver.h:48
heap_t * var_order
Definition solver.h:56
#define vec_act_push_back(vec, value)
Definition types.h:32
Here is the caller graph for this function:

◆ satoko_assump_pop()

void satoko_assump_pop ( satoko_t * s)
extern

Definition at line 306 of file solver_api.c.

307{
308 assert(vec_uint_size(s->assumptions) > 0);
309 // printf("[Satoko] Pop assumption: %d\n", vec_uint_pop_back(s->assumptions));
310 vec_uint_pop_back(s->assumptions);
311 solver_cancel_until(s, vec_uint_size(s->assumptions));
312}
void solver_cancel_until(solver_t *s, unsigned level)
Definition solver.c:515
vec_uint_t * assumptions
Definition solver.h:41
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_assump_push()

void satoko_assump_push ( satoko_t * s,
int lit )
extern

Definition at line 298 of file solver_api.c.

299{
300 assert(lit2var(lit) < (unsigned)satoko_varnum(s));
301 // printf("[Satoko] Push assumption: %d\n", lit);
302 vec_uint_push_back(s->assumptions, lit);
303 vec_char_assign(s->polarity, lit2var(lit), lit_polarity(lit));
304}
int satoko_varnum(satoko_t *s)
Definition solver_api.c:625
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_bookmark()

void satoko_bookmark ( satoko_t * s)
extern

Definition at line 443 of file solver_api.c.

444{
445 // printf("[Satoko] Bookmark.\n");
446 assert(s->status == SATOKO_OK);
447 assert(solver_dlevel(s) == 0);
448 s->book_cl_orig = vec_uint_size(s->originals);
449 s->book_cl_lrnt = vec_uint_size(s->learnts);
450 s->book_vars = vec_char_size(s->assigns);
451 s->book_trail = vec_uint_size(s->trail);
452 // s->book_qhead = s->i_qhead;
453 s->opts.no_simplify = 1;
454}
char no_simplify
Definition satoko.h:69
struct satoko_opts opts
Definition solver.h:110
unsigned book_cl_orig
Definition solver.h:93
unsigned book_vars
Definition solver.h:96
vec_uint_t * originals
Definition solver.h:47
unsigned book_trail
Definition solver.h:97
vec_uint_t * learnts
Definition solver.h:46
vec_uint_t * trail
Definition solver.h:63
unsigned book_cl_lrnt
Definition solver.h:94

◆ satoko_clausenum()

int satoko_clausenum ( satoko_t * s)
extern

Definition at line 630 of file solver_api.c.

631{
632 return vec_uint_size(s->originals);
633}
Here is the caller graph for this function:

◆ satoko_configure()

void satoko_configure ( satoko_t * s,
satoko_opts_t * user_opts )
extern

TODO: sanity check on configuration options

Definition at line 196 of file solver_api.c.

197{
198 assert(user_opts);
199 memcpy(&s->opts, user_opts, sizeof(satoko_opts_t));
200}
struct satoko_opts satoko_opts_t
Definition satoko.h:37
char * memcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_conflictnum()

int satoko_conflictnum ( satoko_t * s)
extern

Definition at line 640 of file solver_api.c.

641{
642 return satoko_stats(s)->n_conflicts_all;
643}
satoko_stats_t * satoko_stats(satoko_t *s)
Definition solver_api.c:433
long n_conflicts_all
Definition satoko.h:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_create()

satoko_t * satoko_create ( void )
extern

Definition at line 88 of file solver_api.c.

89{
91
93 s->status = SATOKO_OK;
94 /* User data */
95 s->assumptions = vec_uint_alloc(0);
96 s->final_conflict = vec_uint_alloc(0);
97 /* Clauses Database */
98 s->all_clauses = cdb_alloc(0);
99 s->originals = vec_uint_alloc(0);
100 s->learnts = vec_uint_alloc(0);
101 s->watches = vec_wl_alloc(0);
102 /* Activity heuristic */
105 /* Variable Information */
106 s->activity = vec_act_alloc(0);
107 s->var_order = heap_alloc(s->activity);
108 s->levels = vec_uint_alloc(0);
109 s->reasons = vec_uint_alloc(0);
110 s->assigns = vec_char_alloc(0);
111 s->polarity = vec_char_alloc(0);
112 /* Assignments */
113 s->trail = vec_uint_alloc(0);
114 s->trail_lim = vec_uint_alloc(0);
115 /* Temporary data used by Search method */
116 s->bq_trail = b_queue_alloc(s->opts.sz_trail_bqueue);
117 s->bq_lbd = b_queue_alloc(s->opts.sz_lbd_bqueue);
119 s->RC1 = 1;
120 s->RC2 = s->opts.n_conf_fst_reduce;
121 /* Temporary data used by Analyze */
122 s->temp_lits = vec_uint_alloc(0);
123 s->seen = vec_char_alloc(0);
124 s->tagged = vec_uint_alloc(0);
125 s->stack = vec_uint_alloc(0);
126 s->last_dlevel = vec_uint_alloc(0);
127 /* Misc temporary */
128 s->stamps = vec_uint_alloc(0);
129 return s;
130}
#define satoko_calloc(type, n_elements)
Definition mem.h:18
struct solver_t_ solver_t
Definition solver.h:37
void satoko_default_opts(satoko_opts_t *opts)
Definition solver_api.c:161
unsigned sz_lbd_bqueue
Definition satoko.h:47
unsigned sz_trail_bqueue
Definition satoko.h:48
unsigned n_conf_fst_reduce
Definition satoko.h:51
vec_uint_t * final_conflict
Definition solver.h:42
b_queue_t * bq_lbd
Definition solver.h:81
vec_uint_t * stack
Definition solver.h:76
vec_uint_t * trail_lim
Definition solver.h:64
act_t var_act_inc
Definition solver.h:51
struct cdb * all_clauses
Definition solver.h:45
vec_uint_t * tagged
Definition solver.h:75
long RC2
Definition solver.h:83
b_queue_t * bq_trail
Definition solver.h:80
long RC1
Definition solver.h:82
clause_act_t clause_act_inc
Definition solver.h:52
vec_uint_t * last_dlevel
Definition solver.h:77
long n_confl_bfr_reduce
Definition solver.h:84
#define CLAUSE_ACT_INIT_INC
Definition types.h:35
#define VAR_ACT_INIT_INC
Definition types.h:20
#define vec_act_alloc(size)
Definition types.h:25
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_default_opts()

void satoko_default_opts ( satoko_opts_t * opts)
extern

Definition at line 161 of file solver_api.c.

162{
163 memset(opts, 0, sizeof(satoko_opts_t));
164 opts->verbose = 0;
165 opts->no_simplify = 0;
166 /* Limits */
167 opts->conf_limit = 0;
168 opts->prop_limit = 0;
169 /* Constants used for restart heuristic */
170 opts->f_rst = 0.8;
171 opts->b_rst = 1.4;
172 opts->fst_block_rst = 10000;
173 opts->sz_lbd_bqueue = 50;
174 opts->sz_trail_bqueue = 5000;
175 /* Constants used for clause database reduction heuristic */
176 opts->n_conf_fst_reduce = 2000;
177 opts->inc_reduce = 300;
178 opts->inc_special_reduce = 1000;
179 opts->lbd_freeze_clause = 30;
180 opts->learnt_ratio = 0.5;
181 /* VSIDS heuristic */
184 opts->var_decay = 0.95;
185 opts->clause_decay = (clause_act_t) 0.995;
186 /* Binary resolution */
187 opts->clause_max_sz_bin_resol = 30;
188 opts->clause_min_lbd_bin_resol = 6;
189
190 opts->garbage_max_ratio = (float) 0.3;
191}
unsigned clause_min_lbd_bin_resol
Definition satoko.h:66
double f_rst
Definition satoko.h:44
long prop_limit
Definition satoko.h:41
float garbage_max_ratio
Definition satoko.h:67
act_t var_act_limit
Definition satoko.h:61
double var_decay
Definition satoko.h:58
unsigned fst_block_rst
Definition satoko.h:46
unsigned var_act_rescale
Definition satoko.h:60
unsigned clause_max_sz_bin_resol
Definition satoko.h:65
unsigned inc_reduce
Definition satoko.h:52
float clause_decay
Definition satoko.h:59
unsigned lbd_freeze_clause
Definition satoko.h:54
double b_rst
Definition satoko.h:45
unsigned inc_special_reduce
Definition satoko.h:53
char verbose
Definition satoko.h:68
long conf_limit
Definition satoko.h:40
float learnt_ratio
Definition satoko.h:55
unsigned clause_act_t
Definition types.h:36
#define VAR_ACT_RESCALE
Definition types.h:22
#define VAR_ACT_LIMIT
Definition types.h:21
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_destroy()

void satoko_destroy ( satoko_t * s)
extern

Definition at line 132 of file solver_api.c.

133{
134 vec_uint_free(s->assumptions);
135 vec_uint_free(s->final_conflict);
136 cdb_free(s->all_clauses);
137 vec_uint_free(s->originals);
138 vec_uint_free(s->learnts);
139 vec_wl_free(s->watches);
141 heap_free(s->var_order);
142 vec_uint_free(s->levels);
143 vec_uint_free(s->reasons);
144 vec_char_free(s->assigns);
145 vec_char_free(s->polarity);
146 vec_uint_free(s->trail);
147 vec_uint_free(s->trail_lim);
148 b_queue_free(s->bq_lbd);
149 b_queue_free(s->bq_trail);
150 vec_uint_free(s->temp_lits);
151 vec_char_free(s->seen);
152 vec_uint_free(s->tagged);
153 vec_uint_free(s->stack);
154 vec_uint_free(s->last_dlevel);
155 vec_uint_free(s->stamps);
156 if (s->marks)
157 vec_char_free(s->marks);
158 satoko_free(s);
159}
#define satoko_free(p)
Definition mem.h:20
#define vec_act_free(vec)
Definition types.h:26
Here is the caller graph for this function:

◆ satoko_final_conflict()

int satoko_final_conflict ( satoko_t * s,
int ** out )
extern

Definition at line 427 of file solver_api.c.

428{
429 *out = (int *)vec_uint_data(s->final_conflict);
430 return vec_uint_size(s->final_conflict);
431}
Here is the caller graph for this function:

◆ satoko_learntnum()

int satoko_learntnum ( satoko_t * s)
extern

Definition at line 635 of file solver_api.c.

636{
637 return vec_uint_size(s->learnts);
638}
Here is the caller graph for this function:

◆ satoko_mark_cone()

void satoko_mark_cone ( satoko_t * s,
int * pvars,
int n_vars )
extern

Definition at line 562 of file solver_api.c.

563{
564 int i;
565 if (!solver_has_marks(s))
566 s->marks = vec_char_init(satoko_varnum(s), 0);
567 for (i = 0; i < n_vars; i++) {
568 var_set_mark(s, pvars[i]);
569 vec_sdbl_assign(s->activity, pvars[i], 0);
570 if (!heap_in_heap(s->var_order, pvars[i]))
571 heap_insert(s->var_order, pvars[i]);
572 }
573}
Here is the call graph for this function:

◆ satoko_minimize_assumptions()

int satoko_minimize_assumptions ( satoko_t * s,
int * plits,
int nlits,
int nconflim )
extern

Definition at line 372 of file solver_api.c.

373{
374 int i, nlitsL, nlitsR, nresL, nresR, status;
375 if ( nlits == 1 )
376 {
377 // since the problem is UNSAT, we try to solve it without assuming the last literal
378 // if the result is UNSAT, the last literal can be dropped; otherwise, it is needed
379 status = satoko_solve_assumptions_limit( s, NULL, 0, nconflim );
380 return (int)(status != SATOKO_UNSAT); // return 1 if the problem is not UNSAT
381 }
382 assert( nlits >= 2 );
383 nlitsL = nlits / 2;
384 nlitsR = nlits - nlitsL;
385 // assume the left lits
386 for ( i = 0; i < nlitsL; i++ )
387 satoko_assump_push(s, plits[i]);
388 // solve with these assumptions
389 status = satoko_solve_assumptions_limit( s, NULL, 0, nconflim );
390 if ( status == SATOKO_UNSAT ) // these are enough
391 {
392 for ( i = 0; i < nlitsL; i++ )
394 return satoko_minimize_assumptions( s, plits, nlitsL, nconflim );
395 }
396 // these are not enoguh
397 // solve for the right lits
398 nresL = nlitsR == 1 ? 1 : satoko_minimize_assumptions( s, plits + nlitsL, nlitsR, nconflim );
399 for ( i = 0; i < nlitsL; i++ )
401 // swap literals
402 vec_uint_clear(s->temp_lits);
403 for ( i = 0; i < nlitsL; i++ )
404 vec_uint_push_back(s->temp_lits, plits[i]);
405 for ( i = 0; i < nresL; i++ )
406 plits[i] = plits[nlitsL+i];
407 for ( i = 0; i < nlitsL; i++ )
408 plits[nresL+i] = vec_uint_at(s->temp_lits, i);
409 // assume the right lits
410 for ( i = 0; i < nresL; i++ )
411 satoko_assump_push(s, plits[i]);
412 // solve with these assumptions
413 status = satoko_solve_assumptions_limit( s, NULL, 0, nconflim );
414 if ( status == SATOKO_UNSAT ) // these are enough
415 {
416 for ( i = 0; i < nresL; i++ )
418 return nresL;
419 }
420 // solve for the left lits
421 nresR = nlitsL == 1 ? 1 : satoko_minimize_assumptions( s, plits + nresL, nlitsL, nconflim );
422 for ( i = 0; i < nresL; i++ )
424 return nresL + nresR;
425}
int satoko_minimize_assumptions(satoko_t *s, int *plits, int nlits, int nconflim)
Definition solver_api.c:372
int satoko_solve_assumptions_limit(satoko_t *s, int *plits, int nlits, int nconflim)
Definition solver_api.c:364
void satoko_assump_push(solver_t *s, int lit)
Definition solver_api.c:298
void satoko_assump_pop(solver_t *s)
Definition solver_api.c:306
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_options()

satoko_opts_t * satoko_options ( satoko_t * s)
extern

Definition at line 438 of file solver_api.c.

439{
440 return &s->opts;
441}
Here is the caller graph for this function:

◆ satoko_parse_dimacs()

int satoko_parse_dimacs ( char * fname,
satoko_t ** solver )
extern

Start the solver and reads the DIMAC file.

Returns false upon immediate conflict.

Definition at line 108 of file cnf_reader.c.

109{
110 satoko_t *p = NULL;
111 vec_uint_t *lits = NULL;
112 int n_var;
113 int n_clause;
114 char *buffer = file_open(fname);
115 char *token;
116
117 if (buffer == NULL)
118 return -1;
119
120 token = buffer;
121 while (1) {
122 skip_spaces(&token);
123 if (*token == 0)
124 break;
125 else if (*token == 'c')
126 skip_line(&token);
127 else if (*token == 'p') {
128 token++;
129 skip_spaces(&token);
130 for(; !isspace(*token); token++); /* skip 'cnf' */
131
132 n_var = read_int(&token);
133 n_clause = read_int(&token);
134 skip_line(&token);
135 lits = vec_uint_alloc((unsigned) n_var);
136 p = satoko_create();
137 } else {
138 if (lits == NULL) {
139 printf("There is no parameter line.\n");
140 satoko_free(buffer);
141 return -1;
142 }
143 read_clause(&token, lits);
144 if (!satoko_add_clause(p, (int*)vec_uint_data(lits), vec_uint_size(lits))) {
145 printf("Unable to add clause: ");
146 vec_uint_print(lits);
147 return SATOKO_ERR;
148 }
149 }
150 }
151 vec_uint_free(lits);
152 satoko_free(buffer);
153 *solver = p;
154 return SATOKO_OK;
155}
void skip_line()
Cube * p
Definition exorList.c:222
#define solver
Definition kitten.c:211
int satoko_add_clause(satoko_t *, int *, int)
Definition solver_api.c:255
struct solver_t_ satoko_t
Definition satoko.h:35
satoko_t * satoko_create(void)
Definition solver_api.c:88
typedefABC_NAMESPACE_HEADER_START struct vec_uint_t_ vec_uint_t
Definition vec_uint.h:21
Here is the call graph for this function:

◆ satoko_read_cex_varvalue()

int satoko_read_cex_varvalue ( satoko_t * s,
int ivar )
extern

Definition at line 660 of file solver_api.c.

661{
662 return satoko_var_polarity(s, ivar) == SATOKO_LIT_TRUE;
663}
char satoko_var_polarity(satoko_t *s, unsigned var)
Definition solver_api.c:672
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_reset()

void satoko_reset ( satoko_t * s)
extern

Definition at line 469 of file solver_api.c.

470{
471 // printf("[Satoko] Reset.\n");
472 vec_uint_clear(s->assumptions);
473 vec_uint_clear(s->final_conflict);
474 cdb_clear(s->all_clauses);
475 vec_uint_clear(s->originals);
476 vec_uint_clear(s->learnts);
477 vec_wl_clean(s->watches);
479 heap_clear(s->var_order);
480 vec_uint_clear(s->levels);
481 vec_uint_clear(s->reasons);
482 vec_char_clear(s->assigns);
483 vec_char_clear(s->polarity);
484 vec_uint_clear(s->trail);
485 vec_uint_clear(s->trail_lim);
486 b_queue_clean(s->bq_lbd);
487 b_queue_clean(s->bq_trail);
488 vec_uint_clear(s->temp_lits);
489 vec_char_clear(s->seen);
490 vec_uint_clear(s->tagged);
491 vec_uint_clear(s->stack);
492 vec_uint_clear(s->last_dlevel);
493 vec_uint_clear(s->stamps);
494 s->status = SATOKO_OK;
498 s->RC1 = 1;
499 s->RC2 = s->opts.n_conf_fst_reduce;
500 s->book_cl_orig = 0;
501 s->book_cl_lrnt = 0;
502 s->book_cdb = 0;
503 s->book_vars = 0;
504 s->book_trail = 0;
505 s->i_qhead = 0;
506}
unsigned i_qhead
Definition solver.h:65
unsigned book_cdb
Definition solver.h:95
#define vec_act_clear(vec)
Definition types.h:29
Here is the caller graph for this function:

◆ satoko_rollback()

void satoko_rollback ( satoko_t * s)
extern

Definition at line 508 of file solver_api.c.

509{
510 unsigned i, cref;
511 unsigned n_originals = vec_uint_size(s->originals) - s->book_cl_orig;
512 unsigned n_learnts = vec_uint_size(s->learnts) - s->book_cl_lrnt;
513 struct clause **cl_to_remove;
514
515 // printf("[Satoko] rollback.\n");
516 assert(s->status == SATOKO_OK);
517 assert(solver_dlevel(s) == 0);
518 if (!s->book_vars) {
519 satoko_reset(s);
520 return;
521 }
522 cl_to_remove = satoko_alloc(struct clause *, n_originals + n_learnts);
523 /* Mark clauses */
525 cl_to_remove[i] = clause_fetch(s, cref);
526 vec_uint_foreach_start(s->learnts, cref, i, s->book_cl_lrnt)
527 cl_to_remove[n_originals + i] = clause_fetch(s, cref);
528 for (i = 0; i < n_originals + n_learnts; i++) {
529 clause_unwatch(s, cdb_cref(s->all_clauses, (unsigned *)cl_to_remove[i]));
530 cl_to_remove[i]->f_mark = 1;
531 }
532 satoko_free(cl_to_remove);
533 vec_uint_shrink(s->originals, s->book_cl_orig);
534 vec_uint_shrink(s->learnts, s->book_cl_lrnt);
535 /* Shrink variable related vectors */
536 for (i = s->book_vars; i < 2 * vec_char_size(s->assigns); i++) {
537 vec_wl_at(s->watches, i)->size = 0;
538 vec_wl_at(s->watches, i)->n_bin = 0;
539 }
540 // s->i_qhead = s->book_qhead;
541 s->watches->size = s->book_vars;
542 vec_act_shrink(s->activity, s->book_vars);
543 vec_uint_shrink(s->levels, s->book_vars);
544 vec_uint_shrink(s->reasons, s->book_vars);
545 vec_uint_shrink(s->stamps, s->book_vars);
546 vec_char_shrink(s->assigns, s->book_vars);
547 vec_char_shrink(s->seen, s->book_vars);
548 vec_char_shrink(s->polarity, s->book_vars);
549 solver_rebuild_order(s);
550 /* Rewind solver and cancel level 0 assignments to the trail */
552 vec_uint_shrink(s->trail, s->book_trail);
553 if (s->book_cdb)
554 s->all_clauses->size = s->book_cdb;
555 s->book_cl_orig = 0;
556 s->book_cl_lrnt = 0;
557 s->book_vars = 0;
558 s->book_trail = 0;
559 // s->book_qhead = 0;
560}
#define satoko_alloc(type, n_elements)
Definition mem.h:17
void satoko_reset(satoko_t *s)
Definition solver_api.c:469
for(p=first;p->value< newval;p=p->next)
unsigned f_mark
Definition clause.h:19
#define vec_act_shrink(vec, size)
Definition types.h:30
#define vec_uint_foreach_start(vec, entry, i, start)
Definition vec_uint.h:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_set_runid()

void satoko_set_runid ( satoko_t * s,
int id )
extern

Definition at line 655 of file solver_api.c.

656{
657 s->RunId = id;
658}
int RunId
Definition solver.h:106
Here is the caller graph for this function:

◆ satoko_set_runtime_limit()

abctime satoko_set_runtime_limit ( satoko_t * s,
abctime Limit )
extern

Definition at line 665 of file solver_api.c.

666{
667 abctime nRuntimeLimit = s->nRuntimeLimit;
668 s->nRuntimeLimit = Limit;
669 return nRuntimeLimit;
670}
ABC_INT64_T abctime
Definition abc_global.h:332
abctime nRuntimeLimit
Definition solver.h:104
Here is the caller graph for this function:

◆ satoko_set_stop()

void satoko_set_stop ( satoko_t * s,
int * pstop )
extern

Definition at line 645 of file solver_api.c.

646{
647 s->pstop = pstop;
648}
int * pstop
Definition solver.h:105

◆ satoko_set_stop_func()

void satoko_set_stop_func ( satoko_t * s,
int(* fnct )(int) )
extern

Definition at line 650 of file solver_api.c.

651{
652 s->pFuncStop = fnct;
653}
int(* pFuncStop)(int)
Definition solver.h:107
Here is the caller graph for this function:

◆ satoko_setnvars()

void satoko_setnvars ( satoko_t * s,
int nvars )
extern

Definition at line 230 of file solver_api.c.

231{
232 int i;
233 for (i = satoko_varnum(s); i < nvars; i++)
235}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_simplify()

int satoko_simplify ( satoko_t * s)
extern

Definition at line 202 of file solver_api.c.

203{
204 unsigned i, j = 0;
205 unsigned cref;
206
207 assert(solver_dlevel(s) == 0);
208 if (solver_propagate(s) != UNDEF)
209 return SATOKO_ERR;
210 if (s->n_assigns_simplify == vec_uint_size(s->trail) || s->n_props_simplify > 0)
211 return SATOKO_OK;
212
213 vec_uint_foreach(s->originals, cref, i) {
214 struct clause *clause = clause_fetch(s, cref);
215
216 if (clause_is_satisfied(s, clause)) {
217 clause->f_mark = 1;
219 clause_unwatch(s, cref);
220 } else
221 vec_uint_assign(s->originals, j++, cref);
222 }
223 vec_uint_shrink(s->originals, j);
224 solver_rebuild_order(s);
225 s->n_assigns_simplify = vec_uint_size(s->trail);
227 return SATOKO_OK;
228}
unsigned size
Definition clause.h:37
long n_original_lits
Definition satoko.h:84
long n_learnt_lits
Definition satoko.h:85
long n_props_simplify
Definition solver.h:68
unsigned n_assigns_simplify
Definition solver.h:66
struct satoko_stats stats
Definition solver.h:109
#define vec_uint_foreach(vec, entry, i)
Definition vec_uint.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_solve()

int satoko_solve ( satoko_t * s)
extern

Definition at line 314 of file solver_api.c.

315{
316 int status = SATOKO_UNDEC;
317
318 assert(s);
319 solver_clean_stats(s);
320 //if (s->opts.verbose)
321 // print_opts(s);
322 if (s->status == SATOKO_ERR) {
323 printf("Satoko in inconsistent state\n");
324 return SATOKO_UNDEC;
325 }
326
327 if (!s->opts.no_simplify)
328 if (satoko_simplify(s) != SATOKO_OK)
329 return SATOKO_UNDEC;
330
331 while (status == SATOKO_UNDEC) {
332 status = solver_search(s);
333 if (solver_check_limits(s) == 0 || solver_stop(s))
334 break;
335 if (s->nRuntimeLimit && Abc_Clock() > s->nRuntimeLimit)
336 break;
337 if (s->pFuncStop && s->pFuncStop(s->RunId))
338 break;
339 }
340 if (s->opts.verbose)
341 print_stats(s);
342
343 solver_cancel_until(s, vec_uint_size(s->assumptions));
344 return status;
345}
char solver_search(solver_t *s)
Definition solver.c:627
int satoko_simplify(solver_t *s)
Definition solver_api.c:202
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_solve_assumptions()

int satoko_solve_assumptions ( satoko_t * s,
int * plits,
int nlits )
extern

Definition at line 347 of file solver_api.c.

348{
349 int i, status;
350 // printf("\n[Satoko] Solve with assumptions.. (%d)\n", vec_uint_size(s->assumptions));
351 // printf("[Satoko] + Variables: %d\n", satoko_varnum(s));
352 // printf("[Satoko] + Clauses: %d\n", satoko_clausenum(s));
353 // printf("[Satoko] + Trail size: %d\n", vec_uint_size(s->trail));
354 // printf("[Satoko] + Queue head: %d\n", s->i_qhead);
355 // solver_debug_check_trail(s);
356 for ( i = 0; i < nlits; i++ )
357 satoko_assump_push( s, plits[i] );
358 status = satoko_solve( s );
359 for ( i = 0; i < nlits; i++ )
361 return status;
362}
int satoko_solve(solver_t *s)
Definition solver_api.c:314
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_solve_assumptions_limit()

int satoko_solve_assumptions_limit ( satoko_t * s,
int * plits,
int nlits,
int nconflim )
extern

Definition at line 364 of file solver_api.c.

365{
366 int temp = s->opts.conf_limit, status;
367 s->opts.conf_limit = nconflim ? s->stats.n_conflicts + nconflim : 0;
368 status = satoko_solve_assumptions(s, plits, nlits);
369 s->opts.conf_limit = temp;
370 return status;
371}
int satoko_solve_assumptions(solver_t *s, int *plits, int nlits)
Definition solver_api.c:347
long n_conflicts
Definition satoko.h:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satoko_stats()

satoko_stats_t * satoko_stats ( satoko_t * s)
extern

Definition at line 433 of file solver_api.c.

434{
435 return &s->stats;
436}
Here is the caller graph for this function:

◆ satoko_unbookmark()

void satoko_unbookmark ( satoko_t * s)
extern

Definition at line 456 of file solver_api.c.

457{
458 // printf("[Satoko] Unbookmark.\n");
459 assert(s->status == SATOKO_OK);
460 s->book_cl_orig = 0;
461 s->book_cl_lrnt = 0;
462 s->book_cdb = 0;
463 s->book_vars = 0;
464 s->book_trail = 0;
465 // s->book_qhead = 0;
466 s->opts.no_simplify = 0;
467}

◆ satoko_unmark_cone()

void satoko_unmark_cone ( satoko_t * s,
int * pvars,
int n_vars )
extern

Definition at line 575 of file solver_api.c.

576{
577 int i;
578 assert(solver_has_marks(s));
579 for (i = 0; i < n_vars; i++)
580 var_clean_mark(s, pvars[i]);
581}

◆ satoko_var_polarity()

char satoko_var_polarity ( satoko_t * s,
unsigned var )
extern

Definition at line 672 of file solver_api.c.

673{
674 return vec_char_at(s->polarity, var);
675}
Here is the caller graph for this function:

◆ satoko_varnum()

int satoko_varnum ( satoko_t * s)
extern

Definition at line 625 of file solver_api.c.

626{
627 return vec_char_size(s->assigns);
628}
Here is the caller graph for this function:

◆ satoko_write_dimacs()

void satoko_write_dimacs ( satoko_t * s,
char * fname,
int wrt_lrnt,
int zero_var )
extern

Definition at line 583 of file solver_api.c.

584{
585 FILE *file;
586 unsigned i;
587 unsigned n_vars = vec_act_size(s->activity);
588 unsigned n_orig = vec_uint_size(s->originals) + vec_uint_size(s->trail);
589 unsigned n_lrnts = vec_uint_size(s->learnts);
590 unsigned *array;
591
592 assert(wrt_lrnt == 0 || wrt_lrnt == 1);
593 assert(zero_var == 0 || zero_var == 1);
594 if (fname != NULL)
595 file = fopen(fname, "w");
596 else
597 file = stdout;
598
599 if (file == NULL) {
600 printf( "Error: Cannot open output file.\n");
601 return;
602 }
603 fprintf(file, "p cnf %d %d\n", n_vars, wrt_lrnt ? n_orig + n_lrnts : n_orig);
604 for (i = 0; i < vec_char_size(s->assigns); i++) {
605 if ( var_value(s, i) != SATOKO_VAR_UNASSING ) {
606 if (zero_var)
607 fprintf(file, "%d\n", var_value(s, i) == SATOKO_LIT_FALSE ? -(int)(i) : i);
608 else
609 fprintf(file, "%d 0\n", var_value(s, i) == SATOKO_LIT_FALSE ? -(int)(i + 1) : i + 1);
610 }
611 }
612 array = vec_uint_data(s->originals);
613 for (i = 0; i < vec_uint_size(s->originals); i++)
614 clause_dump(file, clause_fetch(s, array[i]), !zero_var);
615
616 if (wrt_lrnt) {
617 array = vec_uint_data(s->learnts);
618 for (i = 0; i < n_lrnts; i++)
619 clause_dump(file, clause_fetch(s, array[i]), !zero_var);
620 }
621 fclose(file);
622
623}
Definition file.h:23