Import PicoSAT-965
[cl-satwrap.git] / backends / picosat / picosat.h
blob395144803336dea8976b7ad77d937f01276baca5
1 /****************************************************************************
2 <<<<<<< HEAD
3 Copyright (c) 2006 - 2009, Armin Biere, Johannes Kepler University.
4 =======
5 Copyright (c) 2006 - 2015, Armin Biere, Johannes Kepler University.
6 >>>>>>> 7a0fcd7... Import PicoSAT-965
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to
10 deal in the Software without restriction, including without limitation the
11 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 sell copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 IN THE SOFTWARE.
25 ****************************************************************************/
27 #ifndef picosat_h_INCLUDED
28 #define picosat_h_INCLUDED
30 /*------------------------------------------------------------------------*/
32 #include <stdlib.h>
33 #include <stdio.h>
34 <<<<<<< HEAD
35 =======
36 #include <stddef.h>
38 /*------------------------------------------------------------------------*/
39 /* The following macros allows for users to distiguish between different
40 * versions of the API. The first 'PICOSAT_REENTRANT_API' is defined for
41 * the new reentrant API which allows to generate multiple instances of
42 * PicoSAT in one process. The second 'PICOSAT_API_VERSION' defines the
43 * (smallest) version of PicoSAT to which this API conforms.
45 #define PICOSAT_REENTRANT_API
46 #define PICOSAT_API_VERSION 953 /* API version */
47 >>>>>>> 7a0fcd7... Import PicoSAT-965
49 /*------------------------------------------------------------------------*/
50 /* These are the return values for 'picosat_sat' as for instance
51 * standardized by the output format of the SAT competition.
53 #define PICOSAT_UNKNOWN 0
54 #define PICOSAT_SATISFIABLE 10
55 #define PICOSAT_UNSATISFIABLE 20
57 /*------------------------------------------------------------------------*/
59 <<<<<<< HEAD
60 =======
61 typedef struct PicoSAT PicoSAT;
63 /*------------------------------------------------------------------------*/
65 >>>>>>> 7a0fcd7... Import PicoSAT-965
66 const char *picosat_version (void);
67 const char *picosat_config (void);
68 const char *picosat_copyright (void);
70 /*------------------------------------------------------------------------*/
71 <<<<<<< HEAD
72 /* You can make picosat use an external memory manager instead of the one
73 =======
74 /* You can make PicoSAT use an external memory manager instead of the one
75 >>>>>>> 7a0fcd7... Import PicoSAT-965
76 * provided by LIBC. But then you need to call these three function before
77 * 'picosat_init'. The memory manager functions here all have an additional
78 * first argument which is a pointer to the memory manager, but otherwise
79 * are supposed to work as their LIBC counter parts 'malloc', 'realloc' and
80 * 'free'. As exception the 'resize' and 'delete' function have as third
81 * argument the number of bytes of the block given as second argument.
83 <<<<<<< HEAD
84 void picosat_set_new (void * mgr, void * (*)(void *, size_t));
85 void picosat_set_resize (void *, void * (*)(void *, void *, size_t, size_t));
86 void picosat_set_delete (void *, void (*)(void *, void *, size_t));
88 /*------------------------------------------------------------------------*/
90 void picosat_init (void); /* constructor */
91 void picosat_reset (void); /* destructor */
92 =======
94 typedef void * (*picosat_malloc)(void *, size_t);
95 typedef void * (*picosat_realloc)(void*, void *, size_t, size_t);
96 typedef void (*picosat_free)(void*, void*, size_t);
98 /*------------------------------------------------------------------------*/
100 PicoSAT * picosat_init (void); /* constructor */
102 PicoSAT * picosat_minit (void * state,
103 picosat_malloc,
104 picosat_realloc,
105 picosat_free);
107 void picosat_reset (PicoSAT *); /* destructor */
108 >>>>>>> 7a0fcd7... Import PicoSAT-965
110 /*------------------------------------------------------------------------*/
111 /* The following five functions are essentially parameters to 'init', and
112 * thus should be called right after 'picosat_init' before doing anything
113 * else. You should not call any of them after adding a literal.
116 /* Set output file, default is 'stdout'.
118 <<<<<<< HEAD
119 void picosat_set_output (FILE *);
121 /* Measure all time spent in all calls in the solver. By default only the
122 * time spent in 'picosat_sat' is measured. Enabling this function may for
123 * instance tripple the time needed to add large CNFs, since every call to
124 * 'picosat_add' will trigger a call to 'getrusage'.
126 void picosat_measure_all_calls (void);
127 =======
128 void picosat_set_output (PicoSAT *, FILE *);
130 /* Measure all time spent in all calls in the solver. By default only the
131 * time spent in 'picosat_sat' is measured. Enabling this function might
132 * for instance triple the time needed to add large CNFs, since every call
133 * to 'picosat_add' will trigger a call to 'getrusage'.
135 void picosat_measure_all_calls (PicoSAT *);
136 >>>>>>> 7a0fcd7... Import PicoSAT-965
138 /* Set the prefix used for printing verbose messages and statistics.
139 * Default is "c ".
141 <<<<<<< HEAD
142 void picosat_set_prefix (const char *);
144 /* The function 'picosat_set_incremental_rup_file' produces
145 * a proof trace in RUP format on the fly. The resulting RUP file may
146 * contain learned clauses that are not actual in the clausal core.
148 =======
149 void picosat_set_prefix (PicoSAT *, const char *);
150 >>>>>>> 7a0fcd7... Import PicoSAT-965
152 /* Set verbosity level. A verbosity level of 1 and above prints more and
153 * more detailed progress reports on the output file, set by
154 * 'picosat_set_output'. Verbose messages are prefixed with the string set
155 * by 'picosat_set_prefix'.
157 <<<<<<< HEAD
158 void picosat_set_verbosity (int new_verbosity_level);
160 /* Set default initial phase:
162 * negative = false
164 * posivie = true
166 * 0 = Jeroslow-Wang (default)
168 * After a variable has been assigned the first time, it will always
169 * be assigned the previous value if it is picked as decision variable.
170 * The initial assignment can be choosen with this function.
172 void picosat_set_global_default_phase (int);
173 =======
174 void picosat_set_verbosity (PicoSAT *, int new_verbosity_level);
176 /* Disable/Enable all pre-processing, currently only failed literal probing.
178 * new_plain_value != 0 only 'plain' solving, so no preprocessing
179 * new_plain_value == 0 allow preprocessing
181 void picosat_set_plain (PicoSAT *, int new_plain_value);
183 /* Set default initial phase:
185 * 0 = false
186 * 1 = true
187 * 2 = Jeroslow-Wang (default)
188 * 3 = random initial phase
190 * After a variable has been assigned the first time, it will always
191 * be assigned the previous value if it is picked as decision variable.
192 * The initial assignment can be chosen with this function.
194 void picosat_set_global_default_phase (PicoSAT *, int);
195 >>>>>>> 7a0fcd7... Import PicoSAT-965
197 /* Set next/initial phase of a particular variable if picked as decision
198 * variable. Second argument 'phase' has the following meaning:
200 * negative = next value if picked as decision variable is false
202 * positive = next value if picked as decision variable is true
204 * 0 = use global default phase as next value and
205 * assume 'lit' was never assigned
207 * Again if 'lit' is assigned afterwards through a forced assignment,
208 * then this forced assignment is the next phase if this variable is
209 * used as decision variable.
211 <<<<<<< HEAD
212 void picosat_set_default_phase_lit (int lit, int phase);
214 /* Allows to print to internal 'out' file from client.
216 void picosat_message (int verbosity_level, const char * fmt, ...);
218 /* Deprecated!
220 #define picosat_enable_verbosity() picosat_set_verbosity (1)
221 =======
222 void picosat_set_default_phase_lit (PicoSAT *, int lit, int phase);
224 /* You can reset all phases by the following function.
226 void picosat_reset_phases (PicoSAT *);
228 /* Scores can be erased as well. Note, however, that even after erasing
229 * scores and phases, learned clauses are kept. In addition head tail
230 * pointers for literals are not moved either. So expect a difference
231 * between calling the solver in incremental mode or with a fresh copy of
232 * the CNF.
234 void picosat_reset_scores (PicoSAT *);
236 /* Reset assignment if in SAT state and then remove the given percentage of
237 * less active (large) learned clauses. If you specify 100% all large
238 * learned clauses are removed.
240 void picosat_remove_learned (PicoSAT *, unsigned percentage);
242 /* Set some variables to be more important than others. These variables are
243 * always used as decisions before other variables are used. Dually there
244 * is a set of variables that is used last. The default is
245 * to mark all variables as being indifferent only.
247 void picosat_set_more_important_lit (PicoSAT *, int lit);
248 void picosat_set_less_important_lit (PicoSAT *, int lit);
250 /* Allows to print to internal 'out' file from client.
252 void picosat_message (PicoSAT *, int verbosity_level, const char * fmt, ...);
253 >>>>>>> 7a0fcd7... Import PicoSAT-965
255 /* Set a seed for the random number generator. The random number generator
256 * is currently just used for generating random decisions. In our
257 * experiments having random decisions did not really help on industrial
258 * examples, but was rather helpful to randomize the solver in order to
259 * do proper benchmarking of different internal parameter sets.
261 <<<<<<< HEAD
262 void picosat_set_seed (unsigned random_number_generator_seed);
263 =======
264 void picosat_set_seed (PicoSAT *, unsigned random_number_generator_seed);
265 >>>>>>> 7a0fcd7... Import PicoSAT-965
267 /* If you ever want to extract cores or proof traces with the current
268 * instance of PicoSAT initialized with 'picosat_init', then make sure to
269 * call 'picosat_enable_trace_generation' right after 'picosat_init'. This
270 * is not necessary if you only use 'picosat_set_incremental_rup_file'.
272 * NOTE, trace generation code is not necessarily included, e.g. if you
273 <<<<<<< HEAD
274 * configure picosat with full optimzation as './configure -O' or with
275 * './configure --no-trace'. This speeds up the solver slightly. Then you
276 * you do not get any results by trying to generate traces.
278 void picosat_enable_trace_generation (void);
279 =======
280 * configure PicoSAT with full optimzation as './configure.sh -O' or with
282 * you do not get any results by trying to generate traces.
284 * The return value is non-zero if code for generating traces is included
285 * and it is zero if traces can not be generated.
287 int picosat_enable_trace_generation (PicoSAT *);
288 >>>>>>> 7a0fcd7... Import PicoSAT-965
290 /* You can dump proof traces in RUP format incrementally even without
291 * keeping the proof trace in memory. The advantage is a reduction of
292 * memory usage, but the dumped clauses do not necessarily belong to the
293 * clausal core. Beside the file the additional parameters denotes the
294 * maximal number of variables and the number of original clauses.
296 <<<<<<< HEAD
297 void picosat_set_incremental_rup_file (FILE * file, int m, int n);
298 =======
299 void picosat_set_incremental_rup_file (PicoSAT *, FILE * file, int m, int n);
301 /* Save original clauses for 'picosat_deref_partial'. See comments to that
302 * function further down.
304 void picosat_save_original_clauses (PicoSAT *);
306 /* Add a call back which is checked regularly to notify the SAT solver
307 * to terminate earlier. This is useful for setting external time limits
308 * or terminate early in say a portfolio style parallel SAT solver.
310 void picosat_set_interrupt (PicoSAT *,
311 void * external_state,
312 int (*interrupted)(void * external_state));
313 >>>>>>> 7a0fcd7... Import PicoSAT-965
315 /*------------------------------------------------------------------------*/
316 /* This function returns the next available unused variable index and
317 * allocates a variable for it even though this variable does not occur as
318 * assumption, nor in a clause or any other constraints. In future calls to
319 * 'picosat_sat', 'picosat_deref' and particularly for 'picosat_changed',
320 * this variable is treated as if it had been used.
322 <<<<<<< HEAD
323 int picosat_inc_max_var (void);
324 =======
325 int picosat_inc_max_var (PicoSAT *);
327 /*------------------------------------------------------------------------*/
328 /* Push and pop semantics for PicoSAT. 'picosat_push' opens up a new
329 * context. All clauses added in this context are attached to it and
330 * discarded when the context is closed with 'picosat_pop'. It is also
331 * possible to nest contexts.
333 * The current implementation uses a new internal variable for each context.
334 * However, the indices for these internal variables are shared with
335 * ordinary external variables. This means that after any call to
336 * 'picosat_push', new variable indices should be obtained with
337 * 'picosat_inc_max_var' and not just by incrementing the largest variable
338 * index used so far.
340 * The return value is the index of the literal that assumes this context.
341 * This literal can only be used for 'picosat_failed_context' otherwise
342 * it will lead to an API usage error.
344 int picosat_push (PicoSAT *);
346 /* This is as 'picosat_failed_assumption', but only for internal variables
347 * generated by 'picosat_push'.
349 int picosat_failed_context (PicoSAT *, int lit);
351 /* Returns the literal that assumes the current context or zero if the
352 * outer context has been reached.
354 int picosat_context (PicoSAT *);
356 /* Closes the current context and recycles the literal generated for
357 * assuming this context. The return value is the literal for the new
358 * outer context or zero if the outer most context has been reached.
360 int picosat_pop (PicoSAT *);
362 /* Force immmediate removal of all satisfied clauses and clauses that are
363 * added or generated in closed contexts. This function is called
364 * internally if enough units are learned or after a certain number of
365 * contexts have been closed. This number is fixed at compile time
366 * and defined as MAXCILS in 'picosat.c'.
368 * Note that learned clauses which only involve outer contexts are kept.
370 void picosat_simplify (PicoSAT *);
371 >>>>>>> 7a0fcd7... Import PicoSAT-965
373 /*------------------------------------------------------------------------*/
374 /* If you know a good estimate on how many variables you are going to use
375 * then calling this function before adding literals will result in less
376 * resizing of the variable table. But this is just a minor optimization.
377 * Beside exactly allocating enough variables it has the same effect as
378 * calling 'picosat_inc_max_var'.
380 <<<<<<< HEAD
381 void picosat_adjust (int max_idx);
382 =======
383 void picosat_adjust (PicoSAT *, int max_idx);
384 >>>>>>> 7a0fcd7... Import PicoSAT-965
386 /*------------------------------------------------------------------------*/
387 /* Statistics.
389 <<<<<<< HEAD
390 int picosat_variables (void); /* p cnf <m> n */
391 int picosat_added_original_clauses (void); /* p cnf m <n> */
392 size_t picosat_max_bytes_allocated (void);
393 double picosat_time_stamp (void); /* ... in process */
394 void picosat_stats (void); /* > output file */
396 /* The time spent in the library or in 'picosat_sat'. The former is only
397 * returned if, right after initialization 'picosat_measure_all_calls'
398 * is called.
400 double picosat_seconds (void);
401 =======
402 int picosat_variables (PicoSAT *); /* p cnf <m> n */
403 int picosat_added_original_clauses (PicoSAT *); /* p cnf m <n> */
404 size_t picosat_max_bytes_allocated (PicoSAT *);
405 double picosat_time_stamp (void); /* ... in process */
406 void picosat_stats (PicoSAT *); /* > output file */
407 unsigned long long picosat_propagations (PicoSAT *); /* #propagations */
408 unsigned long long picosat_decisions (PicoSAT *); /* #decisions */
409 unsigned long long picosat_visits (PicoSAT *); /* #visits */
411 /* The time spent in calls to the library or in 'picosat_sat' respectively.
412 * The former is returned if, right after initialization
413 * 'picosat_measure_all_calls' is called.
415 double picosat_seconds (PicoSAT *);
416 >>>>>>> 7a0fcd7... Import PicoSAT-965
418 /*------------------------------------------------------------------------*/
419 /* Add a literal of the next clause. A zero terminates the clause. The
420 * solver is incremental. Adding a new literal will reset the previous
421 <<<<<<< HEAD
422 * assignment.
424 void picosat_add (int lit);
426 /* Print the CNF to the given file in DIMACS format.
428 void picosat_print (FILE *);
430 /* You can add arbitrary many assumptions before the next 'picosat_sat'.
431 * This is similar to the using assumptions in MiniSAT, except that you do
432 * not have to collect all your assumptions yourself. In PicoSAT you can
433 * add one after the other before the next call to 'picosat_sat'.
435 * These assumptions can be seen as adding unit clauses with those
436 * assumptions as literals. However these assumption clauses are only valid
437 * for exactly the next call to 'picosat_sat'. And will be removed
438 * afterwards, e.g. in future calls to 'picosat_sat' after the next one they
439 * are not assumed, unless they are assumed again trough 'picosat_assume'.
441 * More precisely, assumptions actually remain valid even after the next
442 * call to 'picosat_sat' returns. Valid means they remain 'assumed' until a
443 * call to 'picosat_add', 'picosat_assume', or another 'picosat_sat,
444 * following the first 'picosat_sat'. They need to stay valid for
445 * 'picosat_failed_assumption' to return correct values.
446 =======
447 * assignment. The return value is the original clause index to which
448 * this literal respectively the trailing zero belong starting at 0.
450 int picosat_add (PicoSAT *, int lit);
452 /* As the previous function, but allows to add a full clause at once with an
453 * at compiled time known size. The list of argument literals has to be
454 * terminated with a zero literal. Literals beyond the first zero literal
455 * are discarded.
457 int picosat_add_arg (PicoSAT *, ...);
459 /* As the previous function but with an at compile time unknown size.
461 int picosat_add_lits (PicoSAT *, int * lits);
463 /* Print the CNF to the given file in DIMACS format.
465 void picosat_print (PicoSAT *, FILE *);
467 /* You can add arbitrary many assumptions before the next 'picosat_sat'
468 * call. This is similar to the using assumptions in MiniSAT, except that
469 * for PicoSAT you do not have to collect all your assumptions in a vector
470 * yourself. In PicoSAT you can add one after the other, to be used in the
471 * next call to 'picosat_sat'.
473 * These assumptions can be interpreted as adding unit clauses with those
474 * assumptions as literals. However these assumption clauses are only valid
475 * for exactly the next call to 'picosat_sat', and will be removed
476 * afterwards, e.g. in following future calls to 'picosat_sat' after the
477 * next 'picosat_sat' call, unless they are assumed again trough
478 * 'picosat_assume'.
480 * More precisely, assumptions actually remain valid even after the next
481 * call to 'picosat_sat' has returned. Valid means they remain 'assumed'
482 * internally until a call to 'picosat_add', 'picosat_assume', or a second
483 * 'picosat_sat', following the first 'picosat_sat'. The reason for keeping
484 * them valid is to allow 'picosat_failed_assumption' to return correct
485 * values.
486 >>>>>>> 7a0fcd7... Import PicoSAT-965
488 * Example:
490 * picosat_assume (1); // assume unit clause '1 0'
491 * picosat_assume (-2); // additionally assume clause '-2 0'
492 * res = picosat_sat (1000); // assumes 1 and -2 to hold
493 * // 1000 decisions max.
495 * if (res == PICOSAT_UNSATISFIABLE)
497 * if (picosat_failed_assumption (1))
498 * // unit clause '1 0' was necessary to derive UNSAT
500 * if (picosat_failed_assumption (-2))
501 * // unit clause '-2 0' was necessary to derive UNSAT
503 * // at least one but also both could be necessary
505 * picosat_assume (17); // previous assumptions are removed
506 * // now assume unit clause '17 0' for
507 * // the next call to 'picosat_sat'
509 * // adding a new clause, actually the first literal of
510 * // a clause would also make the assumptions used in the previous
511 * // call to 'picosat_sat' invalid.
513 * // The first two assumptions above are not assumed anymore. Only
514 * // the assumptions, since the last call to 'picosat_sat' returned
515 * // are assumed, e.g. the unit clause '17 0'.
517 * res = picosat_sat (-1);
519 * else if (res == PICOSAT_SATISFIABLE)
521 * // now the assignment is valid and we can call 'picosat_deref'
523 * assert (picosat_deref (1) == 1));
524 * assert (picosat_deref (-2) == 1));
526 * val = picosat_deref (15);
528 * // previous two assumptions are still valid
530 * // would become invalid if 'picosat_add' or 'picosat_assume' is
531 * // called here, but we immediately call 'picosat_sat'. Now when
532 <<<<<<< HEAD
533 * // entering 'picosat_sat' the solver nows that the previous call
534 * // returned SAT and it can savely reset the previous assumptions
535 =======
536 * // entering 'picosat_sat' the solver knows that the previous call
537 * // returned SAT and it can safely reset the previous assumptions
538 >>>>>>> 7a0fcd7... Import PicoSAT-965
540 * res = picosat_sat (-1);
542 * else
544 * assert (res == PICOSAT_UNKNOWN);
546 * // assumptions valid, but assignment invalid
547 * // except for top level assigned literals which
548 * // necessarily need to have this value if the formula is SAT
550 * // as above the solver nows that the previous call returned UNKWOWN
551 * // and will before doing anything else reset assumptions
553 * picosat_sat (-1);
556 <<<<<<< HEAD
557 void picosat_assume (int lit);
558 =======
559 void picosat_assume (PicoSAT *, int lit);
560 >>>>>>> 7a0fcd7... Import PicoSAT-965
562 /*------------------------------------------------------------------------*/
563 /* This is an experimental feature for handling 'all different constraints'
564 * (ADC). Currently only one global ADC can be handled. The bit-width of
565 * all the bit-vectors entered in this ADC (stored in 'all different
566 * objects' or ADOs) has to be identical.
568 * TODO: also handle top level assigned literals here.
570 <<<<<<< HEAD
571 void picosat_add_ado_lit (int);
572 =======
573 void picosat_add_ado_lit (PicoSAT *, int);
574 >>>>>>> 7a0fcd7... Import PicoSAT-965
576 /*------------------------------------------------------------------------*/
577 /* Call the main SAT routine. A negative decision limit sets no limit on
578 * the number of decisions. The return values are as above, e.g.
579 * 'PICOSAT_UNSATISFIABLE', 'PICOSAT_SATISFIABLE', or 'PICOSAT_UNKNOWN'.
581 <<<<<<< HEAD
582 int picosat_sat (int decision_limit);
583 =======
584 int picosat_sat (PicoSAT *, int decision_limit);
586 /* As alternative to a decision limit you can use the number of propagations
587 * as limit. This is more linearly related to execution time. This has to
588 * be called after 'picosat_init' and before 'picosat_sat'.
590 void picosat_set_propagation_limit (PicoSAT *, unsigned long long limit);
592 /* Return last result of calling 'picosat_sat' or '0' if not called.
594 int picosat_res (PicoSAT *);
595 >>>>>>> 7a0fcd7... Import PicoSAT-965
597 /* After 'picosat_sat' was called and returned 'PICOSAT_SATISFIABLE', then
598 * the satisfying assignment can be obtained by 'dereferencing' literals.
599 * The value of the literal is return as '1' for 'true', '-1' for 'false'
600 * and '0' for an unknown value.
602 <<<<<<< HEAD
603 int picosat_deref (int lit);
604 =======
605 int picosat_deref (PicoSAT *, int lit);
606 >>>>>>> 7a0fcd7... Import PicoSAT-965
608 /* Same as before but just returns true resp. false if the literals is
609 * forced to this assignment at the top level. This function does not
610 * require that 'picosat_sat' was called and also does not internally reset
611 * incremental usage.
613 <<<<<<< HEAD
614 int picosat_deref_toplevel (int lit);
615 =======
616 int picosat_deref_toplevel (PicoSAT *, int lit);
618 /* After 'picosat_sat' was called and returned 'PICOSAT_SATISFIABLE' a
619 * partial satisfying assignment can be obtained as well. It satisfies all
620 * original clauses. The value of the literal is return as '1' for 'true',
621 * '-1' for 'false' and '0' for an unknown value. In order to make this
622 * work all original clauses have to be saved internally, which has to be
623 * enabled by 'picosat_save_original_clauses' right after initialization.
625 int picosat_deref_partial (PicoSAT *, int lit);
626 >>>>>>> 7a0fcd7... Import PicoSAT-965
628 /* Returns non zero if the CNF is unsatisfiable because an empty clause was
629 * added or derived.
631 <<<<<<< HEAD
632 int picosat_inconsistent (void);
633 =======
634 int picosat_inconsistent (PicoSAT *);
635 >>>>>>> 7a0fcd7... Import PicoSAT-965
637 /* Returns non zero if the literal is a failed assumption, which is defined
638 * as an assumption used to derive unsatisfiability. This is as accurate as
639 * generating core literals, but still of course is an overapproximation of
640 * the set of assumptions really necessary. The technique does not need
641 * clausal core generation nor tracing to be enabled and thus can be much
642 <<<<<<< HEAD
643 * more effectice. The function can only called as long the current
644 * assumptions are valid. See 'picosat_assume' for more details.
646 int picosat_failed_assumption (int lit);
647 =======
648 * more effective. The function can only be called as long the current
649 * assumptions are valid. See 'picosat_assume' for more details.
651 int picosat_failed_assumption (PicoSAT *, int lit);
653 /* Returns a zero terminated list of failed assumption in the last call to
654 * 'picosat_sat'. The pointer is valid until the next call to
655 * 'picosat_sat' or 'picosat_failed_assumptions'. It only makes sense if the
656 * last call to 'picosat_sat' returned 'PICOSAT_UNSATISFIABLE'.
658 const int * picosat_failed_assumptions (PicoSAT *);
660 /* Returns a zero terminated minimized list of failed assumption for the last
661 * call to 'picosat_sat'. The pointer is valid until the next call to this
662 * function or 'picosat_sat' or 'picosat_mus_assumptions'. It only makes sense
663 * if the last call to 'picosat_sat' returned 'PICOSAT_UNSATISFIABLE'.
665 * The call back function is called for all successful simplification
666 * attempts. The first argument of the call back function is the state
667 * given as first argument to 'picosat_mus_assumptions'. The second
668 * argument to the call back function is the new reduced list of failed
669 * assumptions.
671 * This function will call 'picosat_assume' and 'picosat_sat' internally but
672 * before returning reestablish a proper UNSAT state, e.g.
673 * 'picosat_failed_assumption' will work afterwards as expected.
675 * The last argument if non zero fixes assumptions. In particular, if an
676 * assumption can not be removed it is permanently assigned true, otherwise
677 * if it turns out to be redundant it is permanently assumed to be false.
679 const int * picosat_mus_assumptions (PicoSAT *, void *,
680 void(*)(void*,const int*),int);
682 /* Compute one maximal subset of satisfiable assumptions. You need to set
683 * the assumptions, call 'picosat_sat' and check for 'picosat_inconsistent',
684 * before calling this function. The result is a zero terminated array of
685 * assumptions that consistently can be asserted at the same time. Before
686 * returing the library 'reassumes' all assumptions.
688 * It could be beneficial to set the default phase of assumptions
689 * to true (positive). This can speed up the computation.
691 const int * picosat_maximal_satisfiable_subset_of_assumptions (PicoSAT *);
693 /* This function assumes that you have set up all assumptions with
694 * 'picosat_assume'. Then it calls 'picosat_sat' internally unless the
695 * formula is already inconsistent without assumptions, i.e. it contains
696 * the empty clause. After that it extracts a maximal satisfiable subset of
697 * assumptions.
699 * The result is a zero terminated maximal subset of consistent assumptions
700 * or a zero pointer if the formula contains the empty clause and thus no
701 * more maximal consistent subsets of assumptions can be extracted. In the
702 * first case, before returning, a blocking clause is added, that rules out
703 * the result for the next call.
705 * NOTE: adding the blocking clause changes the CNF.
707 * So the following idiom
709 * const int * mss;
710 * picosat_assume (a1);
711 * picosat_assume (a2);
712 * picosat_assume (a3);
713 * picosat_assume (a4);
714 * while ((mss = picosat_next_maximal_satisfiable_subset_of_assumptions ()))
715 * process_mss (mss);
717 * can be used to iterate over all maximal consistent subsets of
718 * the set of assumptions {a1,a2,a3,a4}.
720 * It could be beneficial to set the default phase of assumptions
721 * to true (positive). This might speed up the computation.
723 const int *
724 picosat_next_maximal_satisfiable_subset_of_assumptions (PicoSAT *);
726 /* Similarly we can iterate over all minimal correcting assumption sets.
727 * See the CAMUS literature [M. Liffiton, K. Sakallah JAR 2008].
729 * The result contains each assumed literal only once, even if it
730 * was assumed multiple times (in contrast to the maximal consistent
731 * subset functions above).
733 * It could be beneficial to set the default phase of assumptions
734 * to true (positive). This might speed up the computation.
736 const int *
737 picosat_next_minimal_correcting_subset_of_assumptions (PicoSAT *);
739 /* Compute the union of all minmal correcting sets, which is called
740 * the 'high level union of all minimal unsatisfiable subset sets'
741 * or 'HUMUS' in our papers.
743 * It uses 'picosat_next_minimal_correcting_subset_of_assumptions' and
744 * the same notes and advices apply. In particular, this implies that
745 * after calling the function once, the current CNF becomes inconsistent,
746 * and PicoSAT has to be reset. So even this function internally uses
747 * PicoSAT incrementally, it can not be used incrementally itself at this
748 * point.
750 * The 'callback' can be used for progress logging and is called after
751 * each extracted minimal correcting set if non zero. The 'nhumus'
752 * parameter of 'callback' denotes the number of assumptions found to be
753 * part of the HUMUS sofar.
755 const int *
756 picosat_humus (PicoSAT *,
757 void (*callback)(void * state, int nmcs, int nhumus),
758 void * state);
759 >>>>>>> 7a0fcd7... Import PicoSAT-965
761 /*------------------------------------------------------------------------*/
762 /* Assume that a previous call to 'picosat_sat' in incremental usage,
763 * returned 'SATISFIABLE'. Then a couple of clauses and optionally new
764 * variables were added (a new variable is a variable that has an index
765 * larger then the maximum variable added so far). The next call to
766 * 'picosat_sat' also returns 'SATISFIABLE'. If this function
767 * 'picosat_changed' returns '0', then the assignment to the old variables
768 <<<<<<< HEAD
769 * did not change. Otherwise it may have changed. The return value to
770 * this function is only valid until new clauses are added through
771 * 'picosat_add', an assumption is made through 'picosat_assume', or again
772 * 'picosat_sat' is called. This is the same assumption as for
773 * 'picosat_deref'.
775 * TODO currently this function may also return a non zero value even if the
776 * old assignment did not change, because it only checks whether the
777 * assignment of at least one old variable was flipped at least once during
778 * the search. In principle it should be possible to be exact in the other
779 * direcetion as well by using a counter of variables that have an odd
780 * number of flips. But this is not implemented yet.
782 int picosat_changed (void);
784 /*------------------------------------------------------------------------*/
785 /* The following five functions internally extract the variable and clausal
786 =======
787 * is guaranteed to not have changed. Otherwise it might have changed.
789 * The return value to this function is only valid until new clauses are
790 * added through 'picosat_add', an assumption is made through
791 * 'picosat_assume', or again 'picosat_sat' is called. This is the same
792 * assumption as for 'picosat_deref'.
794 * TODO currently this function might also return a non zero value even if
795 * the old assignment did not change, because it only checks whether the
796 * assignment of at least one old variable was flipped at least once during
797 * the search. In principle it should be possible to be exact in the other
798 * direction as well by using a counter of variables that have an odd number
799 * of flips. But this is not implemented yet.
801 int picosat_changed (PicoSAT *);
803 /*------------------------------------------------------------------------*/
804 /* The following six functions internally extract the variable and clausal
805 >>>>>>> 7a0fcd7... Import PicoSAT-965
806 * core and thus require trace generation to be enabled with
807 * 'picosat_enable_trace_generation' right after calling 'picosat_init'.
809 * TODO: using these functions in incremental mode with failed assumptions
810 <<<<<<< HEAD
811 * has only been tested for 'picosat_corelit' thoroughly. The others may
812 * only work in non-incremental mode or without using 'picosat_assume'.
815 /* This function gives access to the variable core, which is made up of the
816 * variables that were resolved in deriving the empty clauses.
818 int picosat_corelit (int lit);
819 =======
820 * has only been tested for 'picosat_corelit' thoroughly. The others
821 * probably only work in non-incremental mode or without using
822 * 'picosat_assume'.
825 /* This function determines whether the i'th added original clause is in the
826 * core. The 'i' is the return value of 'picosat_add', which starts at zero
827 * and is incremented by one after a original clause is added (that is after
828 * 'picosat_add (0)'). For the index 'i' the following has to hold:
830 * 0 <= i < picosat_added_original_clauses ()
832 int picosat_coreclause (PicoSAT *, int i);
834 /* This function gives access to the variable core, which is made up of the
835 * variables that were resolved in deriving the empty clause.
837 int picosat_corelit (PicoSAT *, int lit);
838 >>>>>>> 7a0fcd7... Import PicoSAT-965
840 /* Write the clauses that were used in deriving the empty clause to a file
841 * in DIMACS format.
843 <<<<<<< HEAD
844 void picosat_write_clausal_core (FILE * core_file);
846 /* Write a proof trace in TraceCheck format to a file.
848 void picosat_write_compact_trace (FILE * trace_file);
849 void picosat_write_extended_trace (FILE * trace_file);
850 =======
851 void picosat_write_clausal_core (PicoSAT *, FILE * core_file);
853 /* Write a proof trace in TraceCheck format to a file.
855 void picosat_write_compact_trace (PicoSAT *, FILE * trace_file);
856 void picosat_write_extended_trace (PicoSAT *, FILE * trace_file);
857 >>>>>>> 7a0fcd7... Import PicoSAT-965
859 /* Write a RUP trace to a file. This trace file contains only the learned
860 * core clauses while this is not necessarily the case for the RUP file
861 * obtained with 'picosat_set_incremental_rup_file'.
863 <<<<<<< HEAD
864 void picosat_write_rup_trace (FILE * trace_file);
865 =======
866 void picosat_write_rup_trace (PicoSAT *, FILE * trace_file);
867 >>>>>>> 7a0fcd7... Import PicoSAT-965
869 /*------------------------------------------------------------------------*/
870 /* Keeping the proof trace around is not necessary if an over-approximation
871 * of the core is enough. A literal is 'used' if it was involved in a
872 * resolution to derive a learned clause. The core literals are necessarily
873 * a subset of the 'used' literals.
876 <<<<<<< HEAD
877 int picosat_usedlit (int lit);
878 =======
879 int picosat_usedlit (PicoSAT *, int lit);
880 >>>>>>> 7a0fcd7... Import PicoSAT-965
881 /*------------------------------------------------------------------------*/
882 #endif