This commit is contained in:
MyskYko 2025-03-07 00:25:11 -08:00
parent f544165a88
commit 14b451b52f
163 changed files with 7897 additions and 5828 deletions

View File

@ -28,7 +28,7 @@ MODULES := \
src/opt/cut src/opt/fxu src/opt/fxch src/opt/rwr src/opt/mfs src/opt/sim \
src/opt/ret src/opt/fret src/opt/res src/opt/lpk src/opt/nwk src/opt/rwt src/opt/rar \
src/opt/cgt src/opt/csw src/opt/dar src/opt/dau src/opt/dsc src/opt/sfm src/opt/sbd \
src/sat/bsat src/sat/xsat src/sat/satoko src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc src/sat/glucose src/sat/glucose2 src/sat/kissat \
src/sat/bsat src/sat/xsat src/sat/satoko src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc src/sat/glucose src/sat/glucose2 src/sat/kissat src/sat/cadical \
src/bool/bdc src/bool/deco src/bool/dec src/bool/kit src/bool/lucky \
src/bool/rsb src/bool/rpo \
src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \

View File

@ -2886,6 +2886,374 @@ SOURCE=.\src\sat\kissat\watch.c
SOURCE=.\src\sat\kissat\weaken.c
# End Source File
# End Group
# Begin Group "cadical"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_kitten.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_analyze.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_arena.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_assume.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_averages.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_backtrack.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_backward.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_bins.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_block.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_ccadical.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_checker.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_clause.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_collect.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_compact.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_condition.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_config.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_congruence.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_constrain.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_contract.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_cover.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_decide.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_decompose.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_deduplicate.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_definition.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_drattracer.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_elim.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_elimfast.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_ema.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_extend.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_external.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_external_propagate.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_factor.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_file.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_flags.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_flip.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_format.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_frattracer.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_gates.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_idruptracer.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_instantiate.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_internal.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_ipasir.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_lidruptracer.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_limit.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_logging.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_lookahead.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_lratchecker.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_lrattracer.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_lucky.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_message.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_minimize.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_occs.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_options.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_parse.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_phases.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_probe.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_profile.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_proof.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_propagate.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_queue.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_random.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_reap.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_reduce.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_rephase.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_report.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_resources.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_restart.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_restore.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_score.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_shrink.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_signal.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_solution.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_solver.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_stable.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_stats.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_subsume.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_sweep.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_terminal.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_ternary.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_tier.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_transred.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_unstable.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_util.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_var.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_veripbtracer.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_version.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_vivify.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_walk.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadical_watch.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadicalSolver.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\cadical\cadicalTest.c
# End Source File
# End Group
# End Group
# Begin Group "opt"

View File

@ -56048,6 +56048,9 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv )
}
}
extern void cadical_solver_test();
cadical_solver_test();
return 0;
extern void kissat_solver_test();
kissat_solver_test();
return 0;

View File

@ -1,6 +1,10 @@
#ifndef _arena_hpp_INCLUDED
#define _arena_hpp_INCLUDED
#include "global.h"
ABC_NAMESPACE_CXX_HEADER_START
namespace CaDiCaL {
// This memory allocation arena provides fixed size pre-allocated memory for
@ -36,7 +40,7 @@ namespace CaDiCaL {
// q1 = arena.copy (p1, bytes1);
// ...
// qn = arena.copy (pn, bytesn);
// assert (bytes1 + ... + bytesn <= bytes);
// CADICAL_assert (bytes1 + ... + bytesn <= bytes);
// arena.swap ();
// ...
// if (!arena.contains (q)) delete q;
@ -45,7 +49,7 @@ namespace CaDiCaL {
// q1 = arena.copy (p1, bytes1);
// ...
// qn = arena.copy (pn, bytesn);
// assert (bytes1 + ... + bytesn <= bytes);
// CADICAL_assert (bytes1 + ... + bytesn <= bytes);
// arena.swap ();
// ...
//
@ -88,7 +92,7 @@ public:
char *copy (const char *p, size_t bytes) {
char *res = to.top;
to.top += bytes;
assert (to.top <= to.end);
CADICAL_assert (to.top <= to.end);
memcpy (res, p, bytes);
return res;
}
@ -102,4 +106,6 @@ public:
} // namespace CaDiCaL
ABC_NAMESPACE_CXX_HEADER_END
#endif

View File

@ -1,8 +1,12 @@
#ifndef _averages_hpp_INCLUDED
#define _averages_hpp_INCLUDED
#include "global.h"
#include "ema.hpp" // alphabetically after 'averages.hpp'
ABC_NAMESPACE_CXX_HEADER_START
namespace CaDiCaL {
struct Averages {
@ -34,4 +38,6 @@ struct Averages {
} // namespace CaDiCaL
ABC_NAMESPACE_CXX_HEADER_END
#endif

View File

@ -1,8 +1,12 @@
#ifndef _bins_hpp_INCLUDED
#define _bins_hpp_INCLUDED
#include "global.h"
#include "util.hpp" // Alphabetically after 'bins'.
ABC_NAMESPACE_CXX_HEADER_START
namespace CaDiCaL {
using namespace std;
@ -19,4 +23,6 @@ inline void erase_bins (Bins &bs) { erase_vector (bs); }
} // namespace CaDiCaL
ABC_NAMESPACE_CXX_HEADER_END
#endif

View File

@ -1,8 +1,12 @@
#ifndef _block_hpp_INCLUDED
#define _block_hpp_INCLUDED
#include "global.h"
#include "heap.hpp" // Alphabetically after 'block.hpp'.
ABC_NAMESPACE_CXX_HEADER_START
namespace CaDiCaL {
struct Internal;
@ -34,4 +38,6 @@ class Blocker {
} // namespace CaDiCaL
ABC_NAMESPACE_CXX_HEADER_END
#endif

View File

@ -1,10 +1,14 @@
#ifndef _cadical_hpp_INCLUDED
#define _cadical_hpp_INCLUDED
#include "global.h"
#include <cstdint>
#include <cstdio>
#include <vector>
ABC_NAMESPACE_CXX_HEADER_START
namespace CaDiCaL {
/*========================================================================*/
@ -49,13 +53,13 @@ enum Status {
// solver->add (-TIE), solver->add (-SHIRT), solver->add (0);
//
// int res = solver->solve (); // Solve instance.
// assert (res == 10); // Check it is 'SATISFIABLE'.
// CADICAL_assert (res == 10); // Check it is 'SATISFIABLE'.
//
// res = solver->val (TIE); // Obtain assignment of 'TIE'.
// assert (res < 0); // Check 'TIE' assigned to 'false'.
// CADICAL_assert (res < 0); // Check 'TIE' assigned to 'false'.
//
// res = solver->val (SHIRT); // Obtain assignment of 'SHIRT'.
// assert (res > 0); // Check 'SHIRT' assigned to 'true'.
// CADICAL_assert (res > 0); // Check 'SHIRT' assigned to 'true'.
//
// // ------------------------------------------------------------------
// // Incrementally solve again under one assumption.
@ -63,13 +67,13 @@ enum Status {
// solver->assume (TIE); // Now force 'TIE' to true.
//
// res = solver->solve (); // Solve again incrementally.
// assert (res == 20); // Check it is 'UNSATISFIABLE'.
// CADICAL_assert (res == 20); // Check it is 'UNSATISFIABLE'.
//
// res = solver->failed (TIE); // Check 'TIE' responsible.
// assert (res); // Yes, 'TIE' in core.
// CADICAL_assert (res); // Yes, 'TIE' in core.
//
// res = solver->failed (SHIRT); // Check 'SHIRT' responsible.
// assert (!res); // No, 'SHIRT' not in core.
// CADICAL_assert (!res); // No, 'SHIRT' not in core.
//
// // ------------------------------------------------------------------
// // Incrementally solve once more under another assumption.
@ -77,13 +81,13 @@ enum Status {
// solver->assume (-SHIRT); // Now force 'SHIRT' to false.
//
// res = solver->solve (); // Solve again incrementally.
// assert (res == 20); // Check it is 'UNSATISFIABLE'.
// CADICAL_assert (res == 20); // Check it is 'UNSATISFIABLE'.
//
// res = solver->failed (TIE); // Check 'TIE' responsible.
// assert (!res); // No, 'TIE' not in core.
// CADICAL_assert (!res); // No, 'TIE' not in core.
//
// res = solver->failed (-SHIRT); // Check '!SHIRT' responsible.
// assert (res); // Yes, '!SHIRT' in core.
// CADICAL_assert (res); // Yes, '!SHIRT' in core.
//
// // ------------------------------------------------------------------
//
@ -595,7 +599,7 @@ public:
//
int reserve_difference (int number_of_vars);
#ifndef NTRACING
#ifndef CADICAL_NTRACING
//------------------------------------------------------------------------
// This function can be used to write API calls to a file. The same
// format is used which 'mobical' can read, execute and also shrink
@ -1029,7 +1033,7 @@ private:
friend class Testing; // Access to 'internal' for testing only!
#ifndef NTRACING
#ifndef CADICAL_NTRACING
// The API calls to the solver can be traced by setting the environment
// variable 'CADICAL_API_TRACE' to point to the path of a file to which
// API calls are written. The same format is used which 'mobical' can
@ -1092,10 +1096,13 @@ private:
//
// TODO: support for other compilers (beside 'gcc' and 'clang').
/*
#define CADICAL_ATTRIBUTE_FORMAT(FORMAT_POSITION, \
VARIADIC_ARGUMENT_POSITION) \
__attribute__ ((format (PRINTF_FORMAT, FORMAT_POSITION, \
VARIADIC_ARGUMENT_POSITION)))
*/
#define CADICAL_ATTRIBUTE_FORMAT(FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION)
// Messages in a common style.
//
@ -1339,4 +1346,6 @@ public:
} // namespace CaDiCaL
ABC_NAMESPACE_CXX_HEADER_END
#endif

View File

@ -0,0 +1,305 @@
/**CFile****************************************************************
FileName [cadicalSolver.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [SAT solver CaDiCaL by Armin Biere, University of Freiburg]
Synopsis [https://github.com/arminbiere/cadical]
Author [Integrated into ABC by Yukio Miyasaka]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cadicalSolver.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "ccadical.h"
#include "cadicalSolver.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [allocate solver]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
cadical_solver* cadical_solver_new(void) {
cadical_solver* s = (cadical_solver*)malloc(sizeof(cadical_solver));
s->p = (void*)ccadical_init();
s->nVars = 0;
s->vAssumptions = NULL;
s->vCore = NULL;
return s;
}
/**Function*************************************************************
Synopsis [delete solver]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void cadical_solver_delete(cadical_solver* s) {
ccadical_release((CCaDiCaL*)s->p);
if(s->vAssumptions) {
Vec_IntFree(s->vAssumptions);
}
if(s->vCore) {
Vec_IntFree(s->vCore);
}
free(s);
}
/**Function*************************************************************
Synopsis [add clause]
Description [cadical takes x and -x as a literal for a variable x > 0,
where 0 is an indicator of the end of a clause.
since variables start from 0 in abc, a variable v is
translated into v + 1 in cadical.]
SideEffects []
SeeAlso []
***********************************************************************/
int cadical_solver_addclause(cadical_solver* s, int* begin, int* end) {
for(;begin != end; begin++) {
if(*begin & 1) {
ccadical_add((CCaDiCaL*)s->p, -(1 + ((*begin) >> 1)));
} else {
ccadical_add((CCaDiCaL*)s->p, 1 + ((*begin) >> 1) );
}
}
ccadical_add((CCaDiCaL*)s->p, 0);
return !ccadical_is_inconsistent((CCaDiCaL*)s->p);
}
/**Function*************************************************************
Synopsis [solve with resource limits]
Description [assumptions and inspection limits are not supported.]
SideEffects []
SeeAlso []
***********************************************************************/
int cadical_solver_solve(cadical_solver* s, int* begin, int* end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal) {
// inspection limits are not supported
assert(nInsLimit == 0);
assert(nInsLimitGlobal == 0);
// set conflict limits
if(nConfLimit)
ccadical_limit((CCaDiCaL*)s->p, "conflicts", nConfLimit);
if(nConfLimitGlobal && (nConfLimit == 0 || nConfLimit > nConfLimitGlobal))
ccadical_limit((CCaDiCaL*)s->p, "conflicts", nConfLimitGlobal);
// assumptions
if(begin != end) {
// save
if(s->vAssumptions == NULL) {
s->vAssumptions = Vec_IntAllocArrayCopy(begin, end - begin);
} else {
Vec_IntClear(s->vAssumptions);
Vec_IntGrow(s->vAssumptions, end - begin);
Vec_IntPushArray(s->vAssumptions, begin, end - begin);
}
// assume
for(;begin != end; begin++) {
if(*begin & 1) {
ccadical_assume((CCaDiCaL*)s->p, -(1 + ((*begin) >> 1)));
} else {
ccadical_assume((CCaDiCaL*)s->p, 1 + ((*begin) >> 1) );
}
}
}
// solve
int res = ccadical_solve((CCaDiCaL*)s->p);
// translate this cadical return value into a corresponding ABC status value
switch(res) {
case 0: // UNDETERMINED
return 0;
case 10: // SATISFIABLE
return 1;
case 20: // UNSATISFIABLE
return -1;
default:
assert(0);
}
return 0;
}
/**Function*************************************************************
Synopsis [get unsat core]
Description [following minisat, return number of literals in core,
which consists of responsible assumptions, negated.
array will be freed by solver.]
SideEffects []
SeeAlso []
***********************************************************************/
int cadical_solver_final(cadical_solver* s, int** ppArray) {
int v, i;
if(s->vCore == NULL) {
s->vCore = Vec_IntAlloc(Vec_IntSize(s->vAssumptions));
} else {
Vec_IntClear(s->vCore);
}
Vec_IntForEachEntry(s->vAssumptions, v, i) {
int failed;
if(v & 1) {
failed = ccadical_failed((CCaDiCaL*)s->p, -(1 + (v >> 1)));
} else {
failed = ccadical_failed((CCaDiCaL*)s->p, 1 + (v >> 1) );
}
if(failed) {
Vec_IntPush(s->vCore, Abc_LitNot(v));
}
}
*ppArray = Vec_IntArray(s->vCore);
return Vec_IntSize(s->vCore);
}
/**Function*************************************************************
Synopsis [get number of variables]
Description [emulated using "nVars".]
SideEffects []
SeeAlso []
***********************************************************************/
int cadical_solver_nvars(cadical_solver* s) {
return s->nVars;
}
/**Function*************************************************************
Synopsis [add new variable]
Description [emulated using "nVars".]
SideEffects []
SeeAlso []
***********************************************************************/
int cadical_solver_addvar(cadical_solver* s) {
return s->nVars++;
}
/**Function*************************************************************
Synopsis [set number of variables]
Description [not only emulate with "nVars" but also reserve memory.]
SideEffects []
SeeAlso []
***********************************************************************/
void cadical_solver_setnvars(cadical_solver* s,int n) {
s->nVars = n;
ccadical_reserve((CCaDiCaL*)s->p, n);
}
/**Function*************************************************************
Synopsis [get value of variable]
Description [cadical returns x (true) or -x (false) for a variable x.
note a variable v was translated into v + 1 in cadical.]
SideEffects []
SeeAlso []
***********************************************************************/
int cadical_solver_get_var_value(cadical_solver* s, int v) {
return ccadical_val((CCaDiCaL*)s->p, v + 1) > 0;
}
/**Function*************************************************************
Synopsis [Solves the given CNF using cadical.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * cadical_solve_cnf( Cnf_Dat_t * pCnf, char * pArgs, int nConfs, int nTimeLimit, int fSat, int fUnsat, int fPrintCex, int fVerbose )
{
abctime clk = Abc_Clock();
Vec_Int_t * vRes = NULL;
int i, * pBeg, * pEnd, RetValue;
if ( fVerbose )
printf( "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
cadical_solver *pSat = cadical_solver_new();
cadical_solver_setnvars(pSat, pCnf->nVars);
assert(cadical_solver_nvars(pSat) == pCnf->nVars);
Cnf_CnfForClause( pCnf, pBeg, pEnd, i ) {
if ( !cadical_solver_addclause(pSat, pBeg, pEnd) )
{
assert( 0 ); // if it happens, can return 1 (unsatisfiable)
return NULL;
}
}
RetValue = cadical_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
if ( RetValue == 1 )
printf( "Result: Satisfiable. " );
else if ( RetValue == -1 )
printf( "Result: Unsatisfiable. " );
else
printf( "Result: Undecided. " );
if ( RetValue == 1 ) {
vRes = Vec_IntAlloc( pCnf->nVars );
for ( i = 0; i < pCnf->nVars; i++ )
Vec_IntPush( vRes, cadical_solver_get_var_value(pSat, i) );
}
cadical_solver_delete(pSat);
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
return vRes;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

View File

@ -0,0 +1,76 @@
/**CFile****************************************************************
FileName [cadicalSolver.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [SAT solver CaDiCaL by Armin Biere, University of Freiburg]
Synopsis [https://github.com/arminbiere/cadical]
Author [Integrated into ABC by Yukio Miyasaka]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cadicalSolver.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef ABC_SAT_CADICAL_SOLVER_H_
#define ABC_SAT_CADICAL_SOLVER_H_
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "aig/gia/gia.h"
#include "sat/cnf/cnf.h"
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
typedef struct cadical_solver_ cadical_solver;
struct cadical_solver_
{
void* p;
int nVars;
Vec_Int_t* vAssumptions;
Vec_Int_t* vCore;
};
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
extern cadical_solver* cadical_solver_new(void);
extern void cadical_solver_delete(cadical_solver* s);
extern int cadical_solver_addclause(cadical_solver* s, int* begin, int* end);
extern int cadical_solver_solve(cadical_solver* s, int* begin, int* end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal);
extern int cadical_solver_final(cadical_solver* s, int** ppArray);
extern int cadical_solver_nvars(cadical_solver* s);
extern int cadical_solver_addvar(cadical_solver* s);
extern void cadical_solver_setnvars(cadical_solver* s,int n);
extern int cadical_solver_get_var_value(cadical_solver* s, int v);
extern Vec_Int_t * cadical_solve_cnf( Cnf_Dat_t * pCnf, char * pArgs, int nConfs, int nTimeLimit, int fSat, int fUnsat, int fPrintCex, int fVerbose );
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,210 @@
/**CFile****************************************************************
FileName [cadicalTest.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName []
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cadicalTest.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "cadicalSolver.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
void cadical_solver_test() {
int RetValue;
int Lits[3];
// test 1
{
cadical_solver *pSat = cadical_solver_new();
int a = cadical_solver_addvar(pSat);
int b = cadical_solver_addvar(pSat);
int c = cadical_solver_addvar(pSat);
assert(cadical_solver_nvars(pSat) == 3);
Lits[0] = Abc_Var2Lit(a, 0);
Lits[1] = Abc_Var2Lit(b, 0);
Lits[2] = Abc_Var2Lit(c, 0);
printf("adding (a, b, c)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 3);
assert(RetValue);
Lits[0] = Abc_Var2Lit(a, 0);
Lits[1] = Abc_Var2Lit(b, 1);
printf("adding (a, !b)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
Lits[0] = Abc_Var2Lit(a, 1);
printf("adding (!a)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
RetValue = cadical_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == 1);
int a_val = cadical_solver_get_var_value(pSat, a);
int b_val = cadical_solver_get_var_value(pSat, b);
int c_val = cadical_solver_get_var_value(pSat, c);
printf("a = %d, b = %d, c = %d\n", a_val, b_val, c_val);
assert(a_val == 0);
assert(b_val == 0);
assert(c_val == 1);
cadical_solver_delete(pSat);
printf("test 1 passed\n");
}
// test 2
{
cadical_solver *pSat = cadical_solver_new();
cadical_solver_setnvars(pSat, 2);
assert(cadical_solver_nvars(pSat) == 2);
Lits[0] = Abc_Var2Lit(0, 0);
Lits[1] = Abc_Var2Lit(1, 0);
printf("adding (x0, x1)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 0);
Lits[1] = Abc_Var2Lit(1, 1);
printf("adding (x0, !x1)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 1);
Lits[1] = Abc_Var2Lit(1, 1);
printf("adding (!x0, !x1)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
RetValue = cadical_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == 1);
printf("x0 = %d, x1 = %d\n", cadical_solver_get_var_value(pSat, 0), cadical_solver_get_var_value(pSat, 1));
assert(cadical_solver_get_var_value(pSat, 0) == 1);
assert(cadical_solver_get_var_value(pSat, 1) == 0);
cadical_solver_delete(pSat);
printf("test 2 passed\n");
}
// test 3
{
cadical_solver *pSat = cadical_solver_new();
cadical_solver_setnvars(pSat, 3);
assert(cadical_solver_nvars(pSat) == 3);
Lits[0] = Abc_Var2Lit(0, 1);
Lits[1] = Abc_Var2Lit(1, 0);
Lits[2] = Abc_Var2Lit(2, 1);
printf("adding (!x0, x1, !x2)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 3);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 0);
printf("adding (x0)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
Lits[0] = Abc_Var2Lit(1, 1);
printf("adding (!x1)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
Lits[0] = Abc_Var2Lit(2, 0);
printf("adding (x2)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 1);
RetValue = cadical_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == -1);
cadical_solver_delete(pSat);
printf("test 3 passed\n");
}
// test 4
{
cadical_solver *pSat = cadical_solver_new();
cadical_solver_setnvars(pSat, 3);
assert(cadical_solver_nvars(pSat) == 3);
Lits[0] = Abc_Var2Lit(0, 1);
Lits[1] = Abc_Var2Lit(1, 0);
Lits[2] = Abc_Var2Lit(2, 1);
printf("adding (!x0, x1, !x2)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 3);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 0);
printf("adding (x0)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
Lits[0] = Abc_Var2Lit(1, 1);
printf("assume (!x1)\n");
RetValue = cadical_solver_solve(pSat, Lits, Lits + 1, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == 1);
printf("x0 = %d, x1 = %d, x2 = %d\n", cadical_solver_get_var_value(pSat, 0), cadical_solver_get_var_value(pSat, 1), cadical_solver_get_var_value(pSat, 2));
assert(cadical_solver_get_var_value(pSat, 0) == 1);
assert(cadical_solver_get_var_value(pSat, 1) == 0);
assert(cadical_solver_get_var_value(pSat, 2) == 0);
cadical_solver_delete(pSat);
printf("test 4 passed\n");
}
// test 5
{
cadical_solver *pSat = cadical_solver_new();
cadical_solver_setnvars(pSat, 3);
assert(cadical_solver_nvars(pSat) == 3);
Lits[0] = Abc_Var2Lit(0, 1);
Lits[1] = Abc_Var2Lit(1, 0);
Lits[2] = Abc_Var2Lit(2, 1);
printf("adding (!x0, x1, !x2)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 3);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 1);
Lits[1] = Abc_Var2Lit(1, 1);
Lits[2] = Abc_Var2Lit(2, 1);
printf("adding (!x0, !x1, !x2)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 3);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 0);
printf("adding (x0)\n");
RetValue = cadical_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
Lits[0] = Abc_Var2Lit(1, 0);
Lits[1] = Abc_Var2Lit(2, 0);
printf("assume (x1, x2)\n");
RetValue = cadical_solver_solve(pSat, Lits, Lits + 2, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == -1);
int *pCore;
int nSize = cadical_solver_final(pSat, &pCore);
printf("core: ");
for(int i = 0; i < nSize; i++) {
if(i) {
printf(", ");
}
if(Abc_LitIsCompl(pCore[i])) {
printf("!");
}
printf("x%d", Abc_Lit2Var(pCore[i]));
}
printf("\n");
int neg_x2_in_core = 0;
for(int i = 0; i < nSize; i++) {
if(Abc_LitIsCompl(pCore[i]) && Abc_Lit2Var(pCore[i]) == 2) {
neg_x2_in_core = 1;
}
}
assert(neg_x2_in_core);
cadical_solver_delete(pSat);
printf("test 5 passed\n");
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -13,7 +17,7 @@ namespace CaDiCaL {
/*------------------------------------------------------------------------*/
void Internal::learn_empty_clause () {
assert (!unsat);
CADICAL_assert (!unsat);
build_chain_for_empty ();
LOG ("learned empty clause");
external->check_learned_empty_clause ();
@ -29,7 +33,7 @@ void Internal::learn_empty_clause () {
}
void Internal::learn_unit_clause (int lit) {
assert (!unsat);
CADICAL_assert (!unsat);
LOG ("learned unit clause %d, stored at position %d", lit, vlit (lit));
external->check_learned_unit_clause (lit);
int64_t id = ++clause_id;
@ -50,13 +54,13 @@ void Internal::learn_unit_clause (int lit) {
// whether the 'queue.assigned' pointer has to be moved in 'unassign'.
void Internal::bump_queue (int lit) {
assert (opts.bump);
CADICAL_assert (opts.bump);
const int idx = vidx (lit);
if (!links[idx].next)
return;
queue.dequeue (links, idx);
queue.enqueue (links, idx);
assert (stats.bumped != INT64_MAX);
CADICAL_assert (stats.bumped != INT64_MAX);
btab[idx] = ++stats.bumped;
LOG ("moved to front variable %d and bumped to %" PRId64 "", idx,
btab[idx]);
@ -74,7 +78,7 @@ void Internal::bump_queue (int lit) {
// and simply put a hard limit here. It is less elegant but easy to port.
static inline bool evsids_limit_hit (double score) {
assert (sizeof (score) == 8); // assume IEEE 754 64-bit double
CADICAL_assert (sizeof (score) == 8); // assume IEEE 754 64-bit double
return score > 1e150; // MAX_DOUBLE is around 1.8e308
}
@ -92,7 +96,7 @@ void Internal::rescale_variable_scores () {
}
PHASE ("rescore", stats.rescored, "rescoring %d variable scores by 1/%g",
max_var, divider);
assert (divider > 0);
CADICAL_assert (divider > 0);
double factor = 1.0 / divider;
for (auto idx : vars)
stab[idx] *= factor;
@ -103,19 +107,19 @@ void Internal::rescale_variable_scores () {
}
void Internal::bump_variable_score (int lit) {
assert (opts.bump);
CADICAL_assert (opts.bump);
int idx = vidx (lit);
double old_score = score (idx);
assert (!evsids_limit_hit (old_score));
CADICAL_assert (!evsids_limit_hit (old_score));
double new_score = old_score + score_inc;
if (evsids_limit_hit (new_score)) {
LOG ("bumping %g score of %d hits EVSIDS score limit", old_score, idx);
rescale_variable_scores ();
old_score = score (idx);
assert (!evsids_limit_hit (old_score));
CADICAL_assert (!evsids_limit_hit (old_score));
new_score = old_score + score_inc;
}
assert (!evsids_limit_hit (new_score));
CADICAL_assert (!evsids_limit_hit (new_score));
LOG ("new %g score of %d", new_score, idx);
score (idx) = new_score;
if (scores.contains (idx))
@ -135,8 +139,8 @@ void Internal::bump_variable (int lit) {
// factor (if we are currently using scores).
void Internal::bump_variable_score_inc () {
assert (use_scores ());
assert (!evsids_limit_hit (score_inc));
CADICAL_assert (use_scores ());
CADICAL_assert (!evsids_limit_hit (score_inc));
double f = 1e3 / opts.scorefactor;
double new_score_inc = score_inc * f;
if (evsids_limit_hit (new_score_inc)) {
@ -145,7 +149,7 @@ void Internal::bump_variable_score_inc () {
rescale_variable_scores ();
new_score_inc = score_inc * f;
}
assert (!evsids_limit_hit (new_score_inc));
CADICAL_assert (!evsids_limit_hit (new_score_inc));
LOG ("bumped score increment from %g to %g with factor %g", score_inc,
new_score_inc, f);
score_inc = new_score_inc;
@ -174,7 +178,7 @@ struct analyze_bumped_smaller {
void Internal::bump_variables () {
assert (opts.bump);
CADICAL_assert (opts.bump);
START (bump);
@ -208,7 +212,7 @@ int Internal::recompute_glue (Clause *c) {
const int64_t stamp = ++stats.recomputed;
for (const auto &lit : *c) {
int level = var (lit).level;
assert (gtab[level] <= stamp);
CADICAL_assert (gtab[level] <= stamp);
if (gtab[level] == stamp)
continue;
gtab[level] = stamp;
@ -252,7 +256,7 @@ void Internal::bump_clause2 (Clause *c) { bump_clause (c); }
inline void Internal::analyze_literal (int lit, int &open,
int &resolvent_size,
int &antecedent_size) {
assert (lit);
CADICAL_assert (lit);
Var &v = var (lit);
Flags &f = flags (lit);
@ -261,7 +265,7 @@ inline void Internal::analyze_literal (int lit, int &open,
return;
f.seen = true;
unit_analyzed.push_back (lit);
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
int64_t id = unit_id (-lit);
unit_chain.push_back (id);
return;
@ -272,10 +276,10 @@ inline void Internal::analyze_literal (int lit, int &open,
// before marking as seen, get reason and check for missed unit
assert (val (lit) < 0);
assert (v.level <= level);
CADICAL_assert (val (lit) < 0);
CADICAL_assert (v.level <= level);
if (v.reason == external_reason) {
assert (!opts.exteagerreasons);
CADICAL_assert (!opts.exteagerreasons);
v.reason = learn_external_reason_clause (-lit, 0, true);
if (!v.reason) { // actually a unit
--antecedent_size;
@ -284,10 +288,10 @@ inline void Internal::analyze_literal (int lit, int &open,
return;
f.seen = true;
unit_analyzed.push_back (lit);
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
const unsigned uidx = vlit (-lit);
int64_t id = unit_clauses (uidx);
assert (id);
CADICAL_assert (id);
unit_chain.push_back (id);
return;
}
@ -296,7 +300,7 @@ inline void Internal::analyze_literal (int lit, int &open,
f.seen = true;
analyzed.push_back (lit);
assert (v.reason != external_reason);
CADICAL_assert (v.reason != external_reason);
if (v.level < level)
clause.push_back (lit);
Level &l = control[v.level];
@ -315,8 +319,8 @@ inline void Internal::analyze_literal (int lit, int &open,
inline void Internal::analyze_reason (int lit, Clause *reason, int &open,
int &resolvent_size,
int &antecedent_size) {
assert (reason);
assert (reason != external_reason);
CADICAL_assert (reason);
CADICAL_assert (reason != external_reason);
bump_clause (reason);
if (lrat)
lrat_chain.push_back (reason->id);
@ -339,8 +343,8 @@ inline void Internal::analyze_reason (int lit, Clause *reason, int &open,
// 30 million propagations, which then is increased geometrically by 10%.
inline bool Internal::bump_also_reason_literal (int lit) {
assert (lit);
assert (val (lit) < 0);
CADICAL_assert (lit);
CADICAL_assert (val (lit) < 0);
Flags &f = flags (lit);
if (f.seen)
return false;
@ -357,10 +361,10 @@ inline bool Internal::bump_also_reason_literal (int lit) {
inline void Internal::bump_also_reason_literals (int lit, int depth_limit,
size_t analyzed_limit) {
assert (lit);
assert (depth_limit > 0);
CADICAL_assert (lit);
CADICAL_assert (depth_limit > 0);
const Var &v = var (lit);
assert (val (lit));
CADICAL_assert (val (lit));
if (!v.level)
return;
Clause *reason = v.reason;
@ -381,7 +385,7 @@ inline void Internal::bump_also_reason_literals (int lit, int depth_limit,
}
inline void Internal::bump_also_all_reason_literals () {
assert (opts.bump);
CADICAL_assert (opts.bump);
if (!opts.bumpreason)
return;
if (averages.current.decisions > opts.bumpreasonrate) {
@ -395,7 +399,7 @@ inline void Internal::bump_also_all_reason_literals () {
delay[stable].bumpreasons.limit--;
return;
}
assert (opts.bumpreasondepth > 0);
CADICAL_assert (opts.bumpreasondepth > 0);
const int depth_limit = opts.bumpreasondepth + stable;
size_t saved_analyzed = analyzed.size ();
size_t analyzed_limit = saved_analyzed * opts.bumpreasonlimit;
@ -409,7 +413,7 @@ inline void Internal::bump_also_all_reason_literals () {
for (size_t i = saved_analyzed; i != analyzed.size (); i++) {
const int lit = analyzed[i];
Flags &f = flags (lit);
assert (f.seen);
CADICAL_assert (f.seen);
f.seen = false;
}
delay[stable].bumpreasons.interval++;
@ -428,12 +432,12 @@ void Internal::clear_unit_analyzed_literals () {
LOG ("clearing %zd unit analyzed literals", unit_analyzed.size ());
for (const auto &lit : unit_analyzed) {
Flags &f = flags (lit);
assert (f.seen);
assert (!var (lit).level);
CADICAL_assert (f.seen);
CADICAL_assert (!var (lit).level);
f.seen = false;
assert (!f.keep);
assert (!f.poison);
assert (!f.removable);
CADICAL_assert (!f.keep);
CADICAL_assert (!f.poison);
CADICAL_assert (!f.removable);
}
unit_analyzed.clear ();
}
@ -442,11 +446,11 @@ void Internal::clear_analyzed_literals () {
LOG ("clearing %zd analyzed literals", analyzed.size ());
for (const auto &lit : analyzed) {
Flags &f = flags (lit);
assert (f.seen);
CADICAL_assert (f.seen);
f.seen = false;
assert (!f.keep);
assert (!f.poison);
assert (!f.removable);
CADICAL_assert (!f.keep);
CADICAL_assert (!f.poison);
CADICAL_assert (!f.removable);
}
analyzed.clear ();
#if 0 // to expensive, even for debugging mode
@ -454,7 +458,7 @@ void Internal::clear_analyzed_literals () {
return;
for (auto idx : vars) {
Flags &f = flags (idx);
assert (!f.seen);
CADICAL_assert (!f.seen);
}
#endif
}
@ -517,7 +521,7 @@ Clause *Internal::new_driving_clause (const int glue, int &jump) {
} else {
assert (clause.size () > 1);
CADICAL_assert (clause.size () > 1);
// We have to get the last assigned literals into the watch position.
// Sorting all literals with respect to reverse assignment order is
@ -545,7 +549,7 @@ Clause *Internal::new_driving_clause (const int glue, int &jump) {
// not have to fix the clause
inline int Internal::otfs_find_backtrack_level (int &forced) {
assert (opts.otfs);
CADICAL_assert (opts.otfs);
int res = 0;
for (const auto &lit : *conflict) {
@ -570,8 +574,8 @@ inline int Internal::otfs_find_backtrack_level (int &forced) {
inline int Internal::find_conflict_level (int &forced) {
assert (conflict);
assert (opts.chrono || opts.otfs || external_prop);
CADICAL_assert (conflict);
CADICAL_assert (opts.chrono || opts.otfs || external_prop);
int res = 0, count = 0;
@ -649,7 +653,7 @@ inline int Internal::determine_actual_backtrack_level (int jump) {
int res;
assert (level > jump);
CADICAL_assert (level > jump);
if (!opts.chrono) {
res = jump;
@ -693,7 +697,7 @@ inline int Internal::determine_actual_backtrack_level (int jump) {
}
LOG ("best variable bumped %" PRId64 "", bumped (best_idx));
}
assert (best_idx);
CADICAL_assert (best_idx);
LOG ("best variable %d at trail position %d", best_idx, best_pos);
// Now find the frame and decision level in the control stack of that
@ -725,7 +729,7 @@ inline int Internal::determine_actual_backtrack_level (int jump) {
/*------------------------------------------------------------------------*/
void Internal::eagerly_subsume_recently_learned_clauses (Clause *c) {
assert (opts.eagersubsume);
CADICAL_assert (opts.eagersubsume);
LOG (c, "trying eager subsumption with");
mark (c);
int64_t lim = stats.eagertried + opts.eagersubsumelim;
@ -767,20 +771,20 @@ void Internal::eagerly_subsume_recently_learned_clauses (Clause *c) {
/*------------------------------------------------------------------------*/
Clause *Internal::on_the_fly_strengthen (Clause *new_conflict, int uip) {
assert (new_conflict);
assert (new_conflict->size > 2);
CADICAL_assert (new_conflict);
CADICAL_assert (new_conflict->size > 2);
LOG (new_conflict, "applying OTFS on lit %d", uip);
auto sorted = std::vector<int> ();
sorted.reserve (new_conflict->size);
assert (sorted.empty ());
CADICAL_assert (sorted.empty ());
++stats.otfs.strengthened;
int *lits = new_conflict->literals;
assert (lits[0] == uip || lits[1] == uip);
CADICAL_assert (lits[0] == uip || lits[1] == uip);
const int other_init = lits[0] ^ lits[1] ^ uip;
assert (mini_chain.empty ());
CADICAL_assert (mini_chain.empty ());
const int old_size = new_conflict->size;
int new_size = 0;
@ -793,7 +797,7 @@ Clause *Internal::on_the_fly_strengthen (Clause *new_conflict, int uip) {
LOG (new_conflict, "removing all units in");
assert (lits[0] == uip || lits[1] == uip);
CADICAL_assert (lits[0] == uip || lits[1] == uip);
const int other = lits[0] ^ lits[1] ^ uip;
lits[0] = other;
lits[1] = lits[--new_size];
@ -803,9 +807,9 @@ Clause *Internal::on_the_fly_strengthen (Clause *new_conflict, int uip) {
remove_watch (watches (other_init), new_conflict);
remove_watch (watches (uip), new_conflict);
assert (!lrat || lrat_chain.back () == new_conflict->id);
CADICAL_assert (!lrat || lrat_chain.back () == new_conflict->id);
if (lrat) {
assert (!lrat_chain.empty ());
CADICAL_assert (!lrat_chain.empty ());
for (const auto &id : unit_chain) {
mini_chain.push_back (id);
}
@ -819,16 +823,16 @@ Clause *Internal::on_the_fly_strengthen (Clause *new_conflict, int uip) {
clear_unit_analyzed_literals ();
unit_chain.clear ();
}
assert (unit_analyzed.empty ());
CADICAL_assert (unit_analyzed.empty ());
// sort the clause
{
int highest_pos = 0;
int highest_level = 0;
for (int i = 1; i < new_size; i++) {
const unsigned other = lits[i];
assert (val (other) < 0);
CADICAL_assert (val (other) < 0);
const int level = var (other).level;
assert (level);
CADICAL_assert (level);
LOG ("checking %d", other);
if (level <= highest_level)
continue;
@ -842,11 +846,11 @@ Clause *Internal::on_the_fly_strengthen (Clause *new_conflict, int uip) {
if (new_size == 1) {
LOG (new_conflict, "new size = 1, so interrupting");
assert (!opts.exteagerreasons);
CADICAL_assert (!opts.exteagerreasons);
return 0;
} else {
otfs_strengthen_clause (new_conflict, uip, new_size, sorted);
assert (new_size == new_conflict->size);
CADICAL_assert (new_size == new_conflict->size);
}
}
@ -867,7 +871,7 @@ Clause *Internal::on_the_fly_strengthen (Clause *new_conflict, int uip) {
inline void Internal::otfs_subsume_clause (Clause *subsuming,
Clause *subsumed) {
stats.subsumed++;
assert (subsuming->size <= subsumed->size);
CADICAL_assert (subsuming->size <= subsumed->size);
LOG (subsumed, "subsumed");
if (subsumed->redundant)
stats.subred++;
@ -885,9 +889,9 @@ inline void Internal::otfs_subsume_clause (Clause *subsuming,
stats.current.irredundant++;
stats.added.irredundant++;
stats.irrlits += subsuming->size;
assert (stats.current.redundant > 0);
CADICAL_assert (stats.current.redundant > 0);
stats.current.redundant--;
assert (stats.added.redundant > 0);
CADICAL_assert (stats.added.redundant > 0);
stats.added.redundant--;
// ... and keep 'stats.added.total'.
}
@ -899,7 +903,7 @@ inline void Internal::otfs_subsume_clause (Clause *subsuming,
void Internal::otfs_strengthen_clause (Clause *c, int lit, int new_size,
const std::vector<int> &old) {
stats.strengthened++;
assert (c->size > 2);
CADICAL_assert (c->size > 2);
(void) shrink_clause (c, new_size);
if (proof) {
proof->otfs_strengthen_clause (c, old, mini_chain);
@ -940,11 +944,11 @@ void Internal::analyze () {
START (analyze);
assert (conflict);
assert (lrat_chain.empty ());
assert (unit_chain.empty ());
assert (unit_analyzed.empty ());
assert (clause.empty ());
CADICAL_assert (conflict);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (unit_chain.empty ());
CADICAL_assert (unit_analyzed.empty ());
CADICAL_assert (clause.empty ());
// First update moving averages of trail height at conflict.
//
@ -975,8 +979,8 @@ void Internal::analyze () {
if (forced) {
assert (forced);
assert (conflict_level > 0);
CADICAL_assert (forced);
CADICAL_assert (conflict_level > 0);
LOG ("single highest level literal %d", forced);
// The pseudo code in the SAT'18 paper actually backtracks to the
@ -1042,8 +1046,8 @@ void Internal::analyze () {
Clause *reason = conflict;
LOG (reason, "analyzing conflict");
assert (clause.empty ());
assert (lrat_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (lrat_chain.empty ());
const auto &t = &trail;
int i = t->size (); // Start at end-of-trail.
@ -1060,43 +1064,43 @@ void Internal::analyze () {
analyze_reason (uip, reason, open, resolvent_size, antecedent_size);
if (resolved == 0)
conflict_size = antecedent_size - 1;
assert (resolvent_size == open + (int) clause.size ());
CADICAL_assert (resolvent_size == open + (int) clause.size ());
if (otfs && resolved > 0 && antecedent_size > 2 &&
resolvent_size < antecedent_size) {
assert (reason != conflict);
CADICAL_assert (reason != conflict);
LOG (analyzed, "found candidate for OTFS conflict");
LOG (clause, "found candidate for OTFS conflict");
LOG (reason, "found candidate (size %d) for OTFS resolvent",
antecedent_size);
const int other = reason->literals[0] ^ reason->literals[1] ^ uip;
assert (other != uip);
CADICAL_assert (other != uip);
reason = on_the_fly_strengthen (reason, uip);
if (opts.bump)
bump_variables ();
assert (conflict_size);
CADICAL_assert (conflict_size);
if (!reason) {
uip = -other;
assert (open == 1);
CADICAL_assert (open == 1);
LOG ("clause is actually unit %d, stopping", -uip);
reverse (begin (mini_chain), end (mini_chain));
for (auto id : mini_chain)
lrat_chain.push_back (id);
mini_chain.clear ();
clear_analyzed_levels ();
assert (!opts.exteagerreasons);
CADICAL_assert (!opts.exteagerreasons);
clause.clear ();
break;
}
assert (conflict_size >= 2);
CADICAL_assert (conflict_size >= 2);
if (resolved == 1 && resolvent_size < conflict_size) {
// here both clauses are part of the CNF, so one subsumes the other
otfs_subsume_clause (reason, conflict);
LOG (reason, "changing conflict to");
--conflict_size;
assert (conflict_size == reason->size);
CADICAL_assert (conflict_size == reason->size);
++stats.otfs.subsumed;
++stats.subsumed;
}
@ -1134,14 +1138,14 @@ void Internal::analyze () {
open = 0;
analyze_reason (0, reason, open, resolvent_size, antecedent_size);
conflict_size = antecedent_size - 1;
assert (open > 1);
CADICAL_assert (open > 1);
}
++resolved;
uip = 0;
while (!uip) {
assert (i > 0);
CADICAL_assert (i > 0);
const int lit = (*t)[--i];
if (!flags (lit).seen)
continue;
@ -1152,13 +1156,13 @@ void Internal::analyze () {
break;
reason = var (uip).reason;
if (reason == external_reason) {
assert (!opts.exteagerreasons);
CADICAL_assert (!opts.exteagerreasons);
reason = learn_external_reason_clause (-uip, 0, true);
var (uip).reason = reason;
}
assert (reason != external_reason);
CADICAL_assert (reason != external_reason);
LOG (reason, "analyzing %d reason", uip);
assert (resolvent_size);
CADICAL_assert (resolvent_size);
--resolvent_size;
}
LOG ("first UIP %d", uip);
@ -1173,7 +1177,7 @@ void Internal::analyze () {
UPDATE_AVERAGE (averages.current.glue.slow, glue);
stats.learned.literals += size;
stats.learned.clauses++;
assert (glue < size);
CADICAL_assert (glue < size);
// up to this point lrat_chain contains the proof for current clause in
// reversed order. in minimize and shrink the clause is changed and
@ -1277,3 +1281,5 @@ void Internal::iterate () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
Arena::Arena (Internal *i) {
@ -14,7 +18,7 @@ Arena::~Arena () {
void Arena::prepare (size_t bytes) {
LOG ("preparing 'to' space of arena with %zd bytes", bytes);
assert (!to.start);
CADICAL_assert (!to.start);
to.top = to.start = new char[bytes];
to.end = to.start + bytes;
}
@ -28,3 +32,5 @@ void Arena::swap () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,6 +1,10 @@
#include "global.h"
#include "internal.hpp"
#include "options.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Failed literal handling as pioneered by MiniSAT. This first function
@ -27,26 +31,26 @@ void Internal::assume (int lit) {
// for non-lrat use BFS. TODO: maybe derecursify to avoid stack overflow
//
void Internal::assume_analyze_literal (int lit) {
assert (lit);
CADICAL_assert (lit);
Flags &f = flags (lit);
if (f.seen)
return;
f.seen = true;
analyzed.push_back (lit);
Var &v = var (lit);
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
if (v.reason == external_reason) {
v.reason = wrapped_learn_external_reason_clause (-lit);
assert (v.reason || !v.level);
CADICAL_assert (v.reason || !v.level);
}
assert (v.reason != external_reason);
CADICAL_assert (v.reason != external_reason);
if (!v.level) {
int64_t id = unit_id (-lit);
lrat_chain.push_back (id);
return;
}
if (v.reason) {
assert (v.level);
CADICAL_assert (v.level);
LOG (v.reason, "analyze reason");
for (const auto &other : *v.reason) {
assume_analyze_literal (other);
@ -54,16 +58,16 @@ void Internal::assume_analyze_literal (int lit) {
lrat_chain.push_back (v.reason->id);
return;
}
assert (assumed (-lit));
CADICAL_assert (assumed (-lit));
LOG ("failed assumption %d", -lit);
clause.push_back (lit);
}
void Internal::assume_analyze_reason (int lit, Clause *reason) {
assert (reason);
assert (lrat_chain.empty ());
assert (reason != external_reason);
assert (lrat);
CADICAL_assert (reason);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (reason != external_reason);
CADICAL_assert (lrat);
for (const auto &other : *reason)
if (other != lit)
assume_analyze_literal (other);
@ -80,11 +84,11 @@ void Internal::failing () {
LOG ("analyzing failing assumptions");
assert (analyzed.empty ());
assert (clause.empty ());
assert (lrat_chain.empty ());
assert (!marked_failed);
assert (!conflict_id);
CADICAL_assert (analyzed.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (!marked_failed);
CADICAL_assert (!conflict_id);
if (!unsat_constraint) {
// Search for failing assumptions in the (internal) assumption stack.
@ -130,7 +134,7 @@ void Internal::failing () {
for (const auto &other : *ev.reason) {
if (other == -lit)
continue;
assert (val (other));
CADICAL_assert (val (other));
int tmp = var (other).level;
if (tmp > ev.level)
ev.level = tmp;
@ -141,7 +145,7 @@ void Internal::failing () {
break;
}
}
assert (v.reason != external_reason);
CADICAL_assert (v.reason != external_reason);
if (!v.reason) {
failed_clashing = lit;
efailed = elit;
@ -152,7 +156,7 @@ void Internal::failing () {
}
}
assert (clause.empty ());
CADICAL_assert (clause.empty ());
// Get the 'failed' assumption from one of the three cases.
int failed;
@ -162,25 +166,25 @@ void Internal::failing () {
failed = failed_clashing;
else
failed = first_failed;
assert (failed);
assert (efailed);
CADICAL_assert (failed);
CADICAL_assert (efailed);
// In any case mark literal 'failed' as failed assumption.
{
Flags &f = flags (failed);
const unsigned bit = bign (failed);
assert (!(f.failed & bit));
CADICAL_assert (!(f.failed & bit));
f.failed |= bit;
}
// First case (1).
if (failed_unit) {
assert (failed == failed_unit);
CADICAL_assert (failed == failed_unit);
LOG ("root-level falsified assumption %d", failed);
if (proof) {
if (lrat) {
unsigned eidx = (efailed > 0) + 2u * (unsigned) abs (efailed);
assert ((size_t) eidx < external->ext_units.size ());
CADICAL_assert ((size_t) eidx < external->ext_units.size ());
const int64_t id = external->ext_units[eidx];
if (id) {
lrat_chain.push_back (id);
@ -198,11 +202,11 @@ void Internal::failing () {
// Second case (2).
if (failed_clashing) {
assert (failed == failed_clashing);
CADICAL_assert (failed == failed_clashing);
LOG ("clashing assumptions %d and %d", failed, -failed);
Flags &f = flags (-failed);
const unsigned bit = bign (-failed);
assert (!(f.failed & bit));
CADICAL_assert (!(f.failed & bit));
f.failed |= bit;
if (proof) {
vector<int> clash = {externalize (failed), externalize (-failed)};
@ -217,8 +221,8 @@ void Internal::failing () {
"%d",
first_failed, failed_level);
assert (first_failed);
assert (failed_level > 0);
CADICAL_assert (first_failed);
CADICAL_assert (failed_level > 0);
// The 'analyzed' stack serves as working stack for a BFS through the
// implication graph until decisions, which are all assumptions, or
@ -227,9 +231,9 @@ void Internal::failing () {
{
LOG ("failed assumption %d", first_failed);
Flags &f = flags (first_failed);
assert (!f.seen);
CADICAL_assert (!f.seen);
f.seen = true;
assert (f.failed & bign (first_failed));
CADICAL_assert (f.failed & bign (first_failed));
analyzed.push_back (-first_failed);
clause.push_back (-first_failed);
}
@ -239,7 +243,7 @@ void Internal::failing () {
// collected.
for (auto lit : constraint) {
lit *= -1;
assert (lit != INT_MIN);
CADICAL_assert (lit != INT_MIN);
flags (lit).seen = true;
analyzed.push_back (lit);
}
@ -271,7 +275,7 @@ void Internal::failing () {
size_t next = 0;
while (next < analyzed.size ()) {
const int lit = analyzed[next++];
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
Var &v = var (lit);
if (!v.level)
continue;
@ -282,38 +286,38 @@ void Internal::failing () {
continue;
}
}
assert (v.reason != external_reason);
CADICAL_assert (v.reason != external_reason);
if (v.reason) {
assert (v.level);
CADICAL_assert (v.level);
LOG (v.reason, "analyze reason");
for (const auto &other : *v.reason) {
Flags &f = flags (other);
if (f.seen)
continue;
f.seen = true;
assert (val (other) < 0);
CADICAL_assert (val (other) < 0);
analyzed.push_back (-other);
}
} else {
assert (assumed (lit));
CADICAL_assert (assumed (lit));
LOG ("failed assumption %d", lit);
clause.push_back (-lit);
Flags &f = flags (lit);
const unsigned bit = bign (lit);
assert (!(f.failed & bit));
CADICAL_assert (!(f.failed & bit));
f.failed |= bit;
}
}
clear_analyzed_literals ();
} else if (!unsat_constraint) { // LRAT for case (3)
assert (clause.size () == 1);
CADICAL_assert (clause.size () == 1);
const int lit = clause[0];
Var &v = var (lit);
assert (v.reason);
CADICAL_assert (v.reason);
if (v.reason == external_reason) { // does this even happen?
v.reason = wrapped_learn_external_reason_clause (lit);
}
assert (v.reason != external_reason);
CADICAL_assert (v.reason != external_reason);
if (v.reason)
assume_analyze_reason (lit, v.reason);
else {
@ -328,13 +332,13 @@ void Internal::failing () {
}
clear_analyzed_literals ();
} else { // LRAT for unsat_constraint
assert (clause.empty ());
CADICAL_assert (clause.empty ());
clear_analyzed_literals ();
for (auto lit : constraint) {
// make sure nothing gets marked failed twice
// also might shortcut the case where
// lrat_chain is empty because clause is tautological
assert (lit != INT_MIN);
CADICAL_assert (lit != INT_MIN);
assume_analyze_literal (lit);
vector<int64_t> empty;
vector<int> empty2;
@ -346,7 +350,7 @@ void Internal::failing () {
const unsigned bit = bign (-ign);
if (!(f.failed & bit)) {
sum_constraints.push_back (ign);
assert (!(f.failed & bit));
CADICAL_assert (!(f.failed & bit));
f.failed |= bit;
}
}
@ -386,7 +390,7 @@ void Internal::failing () {
conclusion.push_back (clause_id);
}
} else {
assert (!lrat || (constraint.size () == constraint_clauses.size () &&
CADICAL_assert (!lrat || (constraint.size () == constraint_clauses.size () &&
constraint.size () == constraint_chains.size ()));
for (auto p = constraint.rbegin (); p != constraint.rend (); p++) {
const auto &lit = *p;
@ -419,7 +423,7 @@ void Internal::failing () {
for (auto &elit : econstraints) {
if (lrat) {
unsigned eidx = (elit > 0) + 2u * (unsigned) abs (elit);
assert ((size_t) eidx < external->ext_units.size ());
CADICAL_assert ((size_t) eidx < external->ext_units.size ());
const int64_t id = external->ext_units[eidx];
if (id) {
lrat_chain.push_back (id);
@ -463,7 +467,7 @@ void Internal::conclude_unsat () {
return;
concluded = true;
if (!marked_failed) {
assert (conclusion.empty ());
CADICAL_assert (conclusion.empty ());
if (!conflict_id)
failing ();
marked_failed = true;
@ -486,7 +490,7 @@ void Internal::reset_concluded () {
concluded = false;
}
if (conflict_id) {
assert (conclusion.size () == 1);
CADICAL_assert (conclusion.size () == 1);
return;
}
conclusion.clear ();
@ -548,7 +552,7 @@ struct sort_assumptions_smaller {
// to the first place where the assumptions and the current trail differ.
void Internal::sort_and_reuse_assumptions () {
assert (opts.ilbassumptions);
CADICAL_assert (opts.ilbassumptions);
if (assumptions.empty ())
return;
MSORT (opts.radixsortlim, assumptions.begin (), assumptions.end (),
@ -565,7 +569,7 @@ void Internal::sort_and_reuse_assumptions () {
}
const unsigned size = min (level + 1u, max_level + 1);
assert ((size_t) level == control.size () - 1);
CADICAL_assert ((size_t) level == control.size () - 1);
LOG (assumptions, "sorted assumptions");
int target = 0;
for (unsigned i = 1, j = 0; i < size;) {
@ -585,7 +589,7 @@ void Internal::sort_and_reuse_assumptions () {
break;
}
++i, ++j;
assert (var (lit).level == lev);
CADICAL_assert (var (lit).level == lev);
if (l.decision == alit) {
continue;
}
@ -605,3 +609,5 @@ void Internal::sort_and_reuse_assumptions () {
stats.assumptionsreused += level;
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::init_averages () {
@ -18,7 +22,7 @@ void Internal::init_averages () {
INIT_EMA (averages.current.trail.fast, opts.ematrailfast);
INIT_EMA (averages.current.trail.slow, opts.ematrailslow);
assert (!averages.swapped);
CADICAL_assert (!averages.swapped);
}
void Internal::swap_averages () {
@ -32,3 +36,5 @@ void Internal::swap_averages () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// The global assignment stack can only be (partially) reset through
@ -8,7 +12,7 @@ namespace CaDiCaL {
// specialization for 'probe' nor 'vivify' and thus it is shared.
inline void Internal::unassign (int lit) {
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
set_val (lit, 0);
int idx = vidx (lit);
@ -74,7 +78,7 @@ void Internal::update_target_and_best () {
/*------------------------------------------------------------------------*/
void Internal::backtrack (int new_level) {
assert (new_level <= level);
CADICAL_assert (new_level <= level);
if (new_level == level)
return;
@ -84,13 +88,13 @@ void Internal::backtrack (int new_level) {
void Internal::backtrack_without_updating_phases (int new_level) {
assert (new_level <= level);
CADICAL_assert (new_level <= level);
if (new_level == level)
return;
stats.backtracks++;
assert (num_assigned == trail.size ());
CADICAL_assert (num_assigned == trail.size ());
const size_t assigned = control[new_level + 1].trail;
@ -127,7 +131,7 @@ void Internal::backtrack_without_updating_phases (int new_level) {
// backtracking. It is possible to just keep out-of-order assigned
// literals on the trail without breaking the solver (after some
// modifications to 'analyze' - see 'opts.chrono' guarded code there).
assert (opts.chrono || external_prop || did_external_prop);
CADICAL_assert (opts.chrono || external_prop || did_external_prop);
#ifdef LOGGING
if (!v.level)
LOG ("reassign %d @ 0 unit clause %d", lit, lit);
@ -154,7 +158,7 @@ void Internal::backtrack_without_updating_phases (int new_level) {
propergated = 0; // Always go back to root-level.
assert (notified <= assigned + reassigned);
CADICAL_assert (notified <= assigned + reassigned);
if (reassigned) {
notify_assignments ();
}
@ -162,12 +166,14 @@ void Internal::backtrack_without_updating_phases (int new_level) {
control.resize (new_level + 1);
level = new_level;
if (tainted_literal) {
assert (opts.ilb);
CADICAL_assert (opts.ilb);
if (!val (tainted_literal)) {
tainted_literal = 0;
}
}
assert (num_assigned == trail.size ());
CADICAL_assert (num_assigned == trail.size ());
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -24,7 +28,7 @@ Clause *Eliminator::dequeue () {
return 0;
Clause *res = backward.front ();
backward.pop ();
assert (res->enqueued);
CADICAL_assert (res->enqueued);
res->enqueued = false;
LOG (res, "backward dequeue");
return res;
@ -38,8 +42,8 @@ Eliminator::~Eliminator () {
/*------------------------------------------------------------------------*/
void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
assert (opts.elimbackward);
assert (!c->redundant);
CADICAL_assert (opts.elimbackward);
CADICAL_assert (!c->redundant);
if (c->garbage)
return;
LOG (c, "attempting backward subsumption and strengthening with");
@ -47,7 +51,7 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
unsigned size = 0;
int best = 0;
bool satisfied = false;
assert (mini_chain.empty ());
CADICAL_assert (mini_chain.empty ());
for (const auto &lit : *c) {
const signed char tmp = val (lit);
if (tmp > 0) {
@ -70,7 +74,7 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
} else if (len > (size_t) opts.elimocclim) {
LOG ("skipping backward subsumption due to too many occurrences");
} else {
assert (len);
CADICAL_assert (len);
LOG ("literal %d has smallest number of occurrences %zd", best, len);
LOG ("marked %d literals in clause of size %d", size, c->size);
for (auto &d : occs (best)) {
@ -117,9 +121,9 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
stats.elimbwsub++;
} else {
int unit = 0;
assert (minimize_chain.empty ());
assert (analyzed.empty ());
assert (lrat_chain.empty ());
CADICAL_assert (minimize_chain.empty ());
CADICAL_assert (analyzed.empty ());
CADICAL_assert (lrat_chain.empty ());
// figure out wether we strengthen c or get a new unit
for (const auto &lit : *d) {
const signed char tmp = val (lit);
@ -127,7 +131,7 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
if (!lrat)
continue;
Flags &f = flags (lit);
assert (!f.seen);
CADICAL_assert (!f.seen);
if (f.seen)
continue;
f.seen = true;
@ -151,7 +155,7 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
// {c\d}U{d\c} otherwise just the unit ids from {c\d}
for (const auto &lit : *c) {
const signed char tmp = val (lit);
assert (tmp <= 0);
CADICAL_assert (tmp <= 0);
if (tmp >= 0)
continue;
Flags &f = flags (lit);
@ -183,11 +187,11 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
} else if (lrat)
clear_analyzed_literals ();
if (satisfied) {
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
mark_garbage (d);
elim_update_removed_clause (eliminator, d);
} else if (unit && unit != INT_MIN) {
assert (unit);
CADICAL_assert (unit);
LOG (d, "unit %d through hyper unary resolution with", unit);
assign_unit (unit);
elim_propagate (eliminator, unit);
@ -198,7 +202,7 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
remove_occs (occs (negated), d);
elim_update_removed_lit (eliminator, negated);
stats.elimbwstr++;
assert (negated != best);
CADICAL_assert (negated != best);
eliminator.enqueue (d);
}
lrat_chain.clear ();
@ -214,7 +218,7 @@ void Internal::elim_backward_clause (Eliminator &eliminator, Clause *c) {
void Internal::elim_backward_clauses (Eliminator &eliminator) {
if (!opts.elimbackward) {
assert (eliminator.backward.empty ());
CADICAL_assert (eliminator.backward.empty ());
return;
}
START (backward);
@ -229,3 +233,5 @@ void Internal::elim_backward_clauses (Eliminator &eliminator) {
/*------------------------------------------------------------------------*/
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -7,16 +11,18 @@ namespace CaDiCaL {
// Binary implication graph lists.
void Internal::init_bins () {
assert (big.empty ());
CADICAL_assert (big.empty ());
if (big.size () < 2 * vsize)
big.resize (2 * vsize, Bins ());
LOG ("initialized binary implication graph");
}
void Internal::reset_bins () {
assert (!big.empty ());
CADICAL_assert (!big.empty ());
erase_vector (big);
LOG ("reset binary implication graph");
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -44,13 +48,13 @@ bool Internal::is_blocked_clause (Clause *c, int lit) {
LOG (c, "trying to block on %d", lit);
assert (c->size >= opts.blockminclslim);
assert (c->size <= opts.blockmaxclslim);
assert (active (lit));
assert (!val (lit));
assert (!c->garbage);
assert (!c->redundant);
assert (!level);
CADICAL_assert (c->size >= opts.blockminclslim);
CADICAL_assert (c->size <= opts.blockmaxclslim);
CADICAL_assert (active (lit));
CADICAL_assert (!val (lit));
CADICAL_assert (!c->garbage);
CADICAL_assert (!c->redundant);
CADICAL_assert (!level);
mark (c); // First mark all literals in 'c'.
@ -72,9 +76,9 @@ bool Internal::is_blocked_clause (Clause *c, int lit) {
//
Clause *d = *i;
assert (!d->garbage);
assert (!d->redundant);
assert (d->size <= opts.blockmaxclslim);
CADICAL_assert (!d->garbage);
CADICAL_assert (!d->redundant);
CADICAL_assert (d->size <= opts.blockmaxclslim);
*i = prev_d; // Move previous non-tautological clause
prev_d = d; // backwards but remember clause at this position.
@ -99,9 +103,9 @@ bool Internal::is_blocked_clause (Clause *c, int lit) {
prev_other = other;
if (other == -lit)
continue;
assert (other != lit);
assert (active (other));
assert (!val (other));
CADICAL_assert (other != lit);
CADICAL_assert (active (other));
CADICAL_assert (!val (other));
if (marked (other) < 0) {
LOG ("found tautological literal %d", other);
d->literals[0] = other; // Move to front of 'd'.
@ -132,7 +136,7 @@ bool Internal::is_blocked_clause (Clause *c, int lit) {
// restore the old order of clauses in the occurrence list of '-lit'.
//
if (res) {
assert (i == end_of_os);
CADICAL_assert (i == end_of_os);
const auto boc = os.begin ();
while (i != boc) {
Clause *d = *--i;
@ -172,8 +176,8 @@ void Internal::block_schedule (Blocker &blocker) {
continue;
for (const auto &lit : *c) {
assert (active (lit));
assert (!val (lit));
CADICAL_assert (active (lit));
CADICAL_assert (!val (lit));
occs (lit).push_back (c);
}
}
@ -187,7 +191,7 @@ void Internal::block_schedule (Blocker &blocker) {
for (auto lit : lits) {
if (!active (lit))
continue;
assert (!val (lit));
CADICAL_assert (!val (lit));
Occs &os = occs (lit);
noccs (lit) = os.size ();
}
@ -199,7 +203,7 @@ void Internal::block_schedule (Blocker &blocker) {
// schedule can not be fused with the previous loop (easily) since we
// first have to initialize 'noccs' for both 'lit' and '-lit'.
#ifndef QUIET
#ifndef CADICAL_QUIET
int skipped = 0;
#endif
@ -207,16 +211,16 @@ void Internal::block_schedule (Blocker &blocker) {
if (!active (idx))
continue;
if (frozen (idx)) {
#ifndef QUIET
#ifndef CADICAL_QUIET
skipped += 2;
#endif
continue;
}
assert (!val (idx));
CADICAL_assert (!val (idx));
for (int sign = -1; sign <= 1; sign += 2) {
const int lit = sign * idx;
if (marked_skip (lit)) {
#ifndef QUIET
#ifndef CADICAL_QUIET
skipped++;
#endif
continue;
@ -249,15 +253,15 @@ void Internal::block_schedule (Blocker &blocker) {
void Internal::block_pure_literal (Blocker &blocker, int lit) {
if (frozen (lit))
return;
assert (active (lit));
CADICAL_assert (active (lit));
Occs &pos = occs (lit);
Occs &nos = occs (-lit);
assert (!noccs (-lit));
#ifndef NDEBUG
CADICAL_assert (!noccs (-lit));
#ifndef CADICAL_NDEBUG
for (const auto &c : nos)
assert (c->garbage);
CADICAL_assert (c->garbage);
#endif
stats.blockpurelits++;
LOG ("found pure literal %d", lit);
@ -267,7 +271,7 @@ void Internal::block_pure_literal (Blocker &blocker, int lit) {
for (const auto &c : pos) {
if (c->garbage)
continue;
assert (!c->redundant);
CADICAL_assert (!c->redundant);
LOG (c, "pure literal %d in", lit);
blocker.reschedule.push_back (c);
if (proof) {
@ -297,25 +301,25 @@ void Internal::block_pure_literal (Blocker &blocker, int lit) {
void Internal::block_literal_with_one_negative_occ (Blocker &blocker,
int lit) {
assert (active (lit));
assert (!frozen (lit));
assert (noccs (lit) > 0);
assert (noccs (-lit) == 1);
CADICAL_assert (active (lit));
CADICAL_assert (!frozen (lit));
CADICAL_assert (noccs (lit) > 0);
CADICAL_assert (noccs (-lit) == 1);
Occs &nos = occs (-lit);
assert (nos.size () >= 1);
CADICAL_assert (nos.size () >= 1);
Clause *d = 0;
for (const auto &c : nos) {
if (c->garbage)
continue;
assert (!d);
CADICAL_assert (!d);
d = c;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
break;
#endif
}
assert (d);
CADICAL_assert (d);
nos.resize (1);
nos[0] = d;
@ -324,9 +328,9 @@ void Internal::block_literal_with_one_negative_occ (Blocker &blocker,
return;
}
assert (!d->garbage);
assert (!d->redundant);
assert (d->size <= opts.blockmaxclslim);
CADICAL_assert (!d->garbage);
CADICAL_assert (!d->redundant);
CADICAL_assert (d->size <= opts.blockmaxclslim);
LOG (d, "common %d antecedent", lit);
mark (d);
@ -379,9 +383,9 @@ void Internal::block_literal_with_one_negative_occ (Blocker &blocker,
prev_other = other;
if (other == lit)
continue;
assert (other != -lit);
assert (active (other));
assert (!val (other));
CADICAL_assert (other != -lit);
CADICAL_assert (active (other));
CADICAL_assert (!val (other));
if (marked (other) < 0) {
LOG ("found tautological literal %d", other);
c->literals[0] = other; // Move to front of 'c'.
@ -434,13 +438,13 @@ void Internal::block_literal_with_one_negative_occ (Blocker &blocker,
size_t Internal::block_candidates (Blocker &blocker, int lit) {
assert (blocker.candidates.empty ());
CADICAL_assert (blocker.candidates.empty ());
Occs &pos = occs (lit); // Positive occurrences of 'lit'.
Occs &nos = occs (-lit);
assert ((size_t) noccs (lit) <= pos.size ());
assert ((size_t) noccs (-lit) == nos.size ()); // Already flushed.
CADICAL_assert ((size_t) noccs (lit) <= pos.size ());
CADICAL_assert ((size_t) noccs (-lit) == nos.size ()); // Already flushed.
// Mark all literals in clauses with '-lit'. Note that 'mark2' uses
// separate bits for 'lit' and '-lit'.
@ -457,7 +461,7 @@ size_t Internal::block_candidates (Blocker &blocker, int lit) {
j--;
continue;
}
assert (!c->redundant);
CADICAL_assert (!c->redundant);
if (c->size > opts.blockmaxclslim)
continue;
if (c->size < opts.blockminclslim)
@ -468,9 +472,9 @@ size_t Internal::block_candidates (Blocker &blocker, int lit) {
const int other = *l;
if (other == lit)
continue;
assert (other != -lit);
assert (active (other));
assert (!val (other));
CADICAL_assert (other != -lit);
CADICAL_assert (active (other));
CADICAL_assert (!val (other));
if (marked2 (-other))
break;
}
@ -482,7 +486,7 @@ size_t Internal::block_candidates (Blocker &blocker, int lit) {
else
pos.resize (j - pos.begin ());
assert (pos.size () == (size_t) noccs (lit)); // Now also flushed.
CADICAL_assert (pos.size () == (size_t) noccs (lit)); // Now also flushed.
for (const auto &c : nos)
unmark (c);
@ -498,8 +502,8 @@ size_t Internal::block_candidates (Blocker &blocker, int lit) {
// resolvent with that clause.
Clause *Internal::block_impossible (Blocker &blocker, int lit) {
assert (noccs (-lit) > 1);
assert (blocker.candidates.size () > 1);
CADICAL_assert (noccs (-lit) > 1);
CADICAL_assert (blocker.candidates.size () > 1);
for (const auto &c : blocker.candidates)
mark2 (c);
@ -508,18 +512,18 @@ Clause *Internal::block_impossible (Blocker &blocker, int lit) {
Clause *res = 0;
for (const auto &c : nos) {
assert (!c->garbage);
assert (!c->redundant);
assert (c->size <= opts.blockmaxclslim);
CADICAL_assert (!c->garbage);
CADICAL_assert (!c->redundant);
CADICAL_assert (c->size <= opts.blockmaxclslim);
const const_literal_iterator eoc = c->end ();
const_literal_iterator l;
for (l = c->begin (); l != eoc; l++) {
const int other = *l;
if (other == -lit)
continue;
assert (other != lit);
assert (active (other));
assert (!val (other));
CADICAL_assert (other != lit);
CADICAL_assert (active (other));
CADICAL_assert (!val (other));
if (marked2 (-other))
break;
}
@ -544,13 +548,13 @@ Clause *Internal::block_impossible (Blocker &blocker, int lit) {
void Internal::block_literal_with_at_least_two_negative_occs (
Blocker &blocker, int lit) {
assert (active (lit));
assert (!frozen (lit));
assert (noccs (lit) > 0);
assert (noccs (-lit) > 1);
CADICAL_assert (active (lit));
CADICAL_assert (!frozen (lit));
CADICAL_assert (noccs (lit) > 0);
CADICAL_assert (noccs (-lit) > 1);
Occs &nos = occs (-lit);
assert ((size_t) noccs (-lit) <= nos.size ());
CADICAL_assert ((size_t) noccs (-lit) <= nos.size ());
int max_size = 0;
@ -571,8 +575,8 @@ void Internal::block_literal_with_at_least_two_negative_occs (
else
nos.resize (j - nos.begin ());
assert (nos.size () == (size_t) noccs (-lit));
assert (nos.size () > 1);
CADICAL_assert (nos.size () == (size_t) noccs (-lit));
CADICAL_assert (nos.size () > 1);
// If the maximum size of a negative clause (with '-lit') exceeds the
// maximum clause size limit ignore this candidate literal.
@ -604,7 +608,7 @@ void Internal::block_literal_with_at_least_two_negative_occs (
//
if (candidates > 1 && block_impossible (blocker, lit)) {
LOG ("impossible to block any candidate clause on %d", lit);
assert (blocker.candidates.empty ());
CADICAL_assert (blocker.candidates.empty ());
return;
}
@ -616,8 +620,8 @@ void Internal::block_literal_with_at_least_two_negative_occs (
// Go over all remaining candidates and try to block them on 'lit'.
//
for (const auto &c : blocker.candidates) {
assert (!c->garbage);
assert (!c->redundant);
CADICAL_assert (!c->garbage);
CADICAL_assert (!c->redundant);
if (!is_blocked_clause (c, lit))
continue;
blocked++;
@ -646,15 +650,15 @@ void Internal::block_literal_with_at_least_two_negative_occs (
void Internal::block_reschedule_clause (Blocker &blocker, int lit,
Clause *c) {
#ifdef NDEBUG
#ifdef CADICAL_NDEBUG
(void) lit;
#endif
assert (c->garbage);
CADICAL_assert (c->garbage);
for (const auto &other : *c) {
int64_t &n = noccs (other);
assert (n > 0);
CADICAL_assert (n > 0);
n--;
LOG ("updating %d with %" PRId64 " positive and %" PRId64
@ -669,7 +673,7 @@ void Internal::block_reschedule_clause (Blocker &blocker, int lit,
}
if (blocker.schedule.contains (vlit (other))) {
assert (other != lit);
CADICAL_assert (other != lit);
blocker.schedule.update (vlit (other));
}
}
@ -688,14 +692,14 @@ void Internal::block_reschedule (Blocker &blocker, int lit) {
/*------------------------------------------------------------------------*/
void Internal::block_literal (Blocker &blocker, int lit) {
assert (!marked_skip (lit));
CADICAL_assert (!marked_skip (lit));
if (!active (lit))
return; // Pure literal '-lit'.
if (frozen (lit))
return;
assert (!val (lit));
CADICAL_assert (!val (lit));
// If the maximum number of a negative clauses (with '-lit') exceeds the
// occurrence limit ignore this candidate literal.
@ -709,8 +713,8 @@ void Internal::block_literal (Blocker &blocker, int lit) {
stats.blockcands++;
assert (blocker.reschedule.empty ());
assert (blocker.candidates.empty ());
CADICAL_assert (blocker.reschedule.empty ());
CADICAL_assert (blocker.candidates.empty ());
if (!noccs (-lit))
block_pure_literal (blocker, lit);
@ -728,7 +732,7 @@ void Internal::block_literal (Blocker &blocker, int lit) {
// have to try blocked clause elimination on it again until irredundant
// clauses with its negation are removed.
//
assert (!frozen (lit)); // just to be sure ...
CADICAL_assert (!frozen (lit)); // just to be sure ...
unmark_block (lit);
}
@ -752,7 +756,7 @@ bool Internal::block () {
if (!propagate ()) {
LOG ("propagating units results in empty clause");
learn_empty_clause ();
assert (unsat);
CADICAL_assert (unsat);
}
clear_watches ();
reset_watches ();
@ -766,9 +770,9 @@ bool Internal::block () {
LOG ("block-%" PRId64 "", stats.blockings);
assert (!level);
assert (!watching ());
assert (!occurring ());
CADICAL_assert (!level);
CADICAL_assert (!watching ());
CADICAL_assert (!occurring ());
mark_satisfied_clauses_as_garbage ();
@ -822,3 +826,5 @@ bool Internal::block () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,8 +1,12 @@
#include "global.h"
#include "cadical.hpp"
#include <cstdlib>
#include <cstring>
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
struct Wrapper : Learner, Terminator {
@ -63,12 +67,14 @@ struct Wrapper : Learner, Terminator {
} // namespace CaDiCaL
using namespace CaDiCaL;
extern "C" {
ABC_NAMESPACE_IMPL_END
#include "ccadical.h"
ABC_NAMESPACE_IMPL_START
using namespace CaDiCaL;
const char *ccadical_signature (void) { return Solver::signature (); }
CCaDiCaL *ccadical_init (void) { return (CCaDiCaL *) new Wrapper (); }
@ -193,4 +199,13 @@ int ccadical_vars (CCaDiCaL *ptr) {
int ccadical_reserve_difference (CCaDiCaL *ptr, int number_of_vars) {
return ((Wrapper *) ptr)->solver->reserve_difference (number_of_vars);
}
void ccadical_reserve(CCaDiCaL *ptr, int min_max_var) {
((Wrapper *) ptr)->solver->reserve(min_max_var);
}
int ccadical_is_inconsistent(CCaDiCaL *ptr) {
return ((Wrapper *) ptr)->solver->inconsistent ();
}
ABC_NAMESPACE_IMPL_END

View File

@ -1,12 +1,16 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
inline unsigned Checker::l2u (int lit) {
assert (lit);
assert (lit != INT_MIN);
CADICAL_assert (lit);
CADICAL_assert (lit != INT_MIN);
unsigned res = 2 * (abs (lit) - 1);
if (lit < 0)
res++;
@ -14,22 +18,22 @@ inline unsigned Checker::l2u (int lit) {
}
inline signed char Checker::val (int lit) {
assert (lit);
assert (lit != INT_MIN);
assert (abs (lit) < size_vars);
assert (vals[lit] == -vals[-lit]);
CADICAL_assert (lit);
CADICAL_assert (lit != INT_MIN);
CADICAL_assert (abs (lit) < size_vars);
CADICAL_assert (vals[lit] == -vals[-lit]);
return vals[lit];
}
signed char &Checker::mark (int lit) {
const unsigned u = l2u (lit);
assert (u < marks.size ());
CADICAL_assert (u < marks.size ());
return marks[u];
}
inline CheckerWatcher &Checker::watcher (int lit) {
const unsigned u = l2u (lit);
assert (u < watchers.size ());
CADICAL_assert (u < watchers.size ());
return watchers[u];
}
@ -37,7 +41,7 @@ inline CheckerWatcher &Checker::watcher (int lit) {
CheckerClause *Checker::new_clause () {
const size_t size = simplified.size ();
assert (size > 1), assert (size <= UINT_MAX);
CADICAL_assert (size > 1), CADICAL_assert (size <= UINT_MAX);
const size_t bytes = sizeof (CheckerClause) + (size - 2) * sizeof (int);
CheckerClause *res = (CheckerClause *) new char[bytes];
DeferDeleteArray<char> delete_res ((char *) res);
@ -63,8 +67,8 @@ CheckerClause *Checker::new_clause () {
break;
}
}
assert (!val (literals[0]));
assert (!val (literals[1]));
CADICAL_assert (!val (literals[0]));
CADICAL_assert (!val (literals[1]));
watcher (literals[0]).push_back (CheckerWatch (literals[1], res));
watcher (literals[1]).push_back (CheckerWatch (literals[0], res));
@ -74,18 +78,18 @@ CheckerClause *Checker::new_clause () {
void Checker::delete_clause (CheckerClause *c) {
if (c->size) {
assert (c->size > 1);
assert (num_clauses);
CADICAL_assert (c->size > 1);
CADICAL_assert (num_clauses);
num_clauses--;
} else {
assert (num_garbage);
CADICAL_assert (num_garbage);
num_garbage--;
}
delete[] (char *) c;
}
void Checker::enlarge_clauses () {
assert (num_clauses == size_clauses);
CADICAL_assert (num_clauses == size_clauses);
const uint64_t new_size_clauses = size_clauses ? 2 * size_clauses : 1;
LOG ("CHECKER enlarging clauses of checker from %" PRIu64 " to %" PRIu64,
(uint64_t) size_clauses, (uint64_t) new_size_clauses);
@ -131,7 +135,7 @@ void Checker::collect_garbage_clauses () {
c->next = garbage;
garbage = c;
num_garbage++;
assert (num_clauses);
CADICAL_assert (num_clauses);
num_clauses--;
} else
p = &c->next;
@ -163,7 +167,7 @@ void Checker::collect_garbage_clauses () {
for (CheckerClause *c = garbage, *next; c; c = next)
next = c->next, delete_clause (c);
assert (!num_garbage);
CADICAL_assert (!num_garbage);
garbage = 0;
}
@ -181,7 +185,7 @@ Checker::Checker (Internal *i)
uint64_t nonce = random.next ();
if (!(nonce & 1))
nonce++;
assert (nonce), assert (nonce & 1);
CADICAL_assert (nonce), CADICAL_assert (nonce & 1);
nonces[n] = nonce;
}
@ -213,7 +217,7 @@ Checker::~Checker () {
void Checker::enlarge_vars (int64_t idx) {
assert (0 < idx), assert (idx <= INT_MAX);
CADICAL_assert (0 < idx), CADICAL_assert (idx <= INT_MAX);
int64_t new_size_vars = size_vars ? 2 * size_vars : 2;
while (idx >= new_size_vars)
@ -237,12 +241,12 @@ void Checker::enlarge_vars (int64_t idx) {
watchers.resize (2 * new_size_vars);
marks.resize (2 * new_size_vars);
assert (idx < new_size_vars);
CADICAL_assert (idx < new_size_vars);
}
inline void Checker::import_literal (int lit) {
assert (lit);
assert (lit != INT_MIN);
CADICAL_assert (lit);
CADICAL_assert (lit != INT_MIN);
int idx = abs (lit);
if (idx >= size_vars)
enlarge_vars (idx);
@ -289,7 +293,7 @@ bool Checker::tautological () {
/*------------------------------------------------------------------------*/
uint64_t Checker::reduce_hash (uint64_t hash, uint64_t size) {
assert (size > 0);
CADICAL_assert (size > 0);
unsigned shift = 32;
uint64_t res = hash;
while ((((uint64_t) 1) << shift) > size) {
@ -297,7 +301,7 @@ uint64_t Checker::reduce_hash (uint64_t hash, uint64_t size) {
shift >>= 1;
}
res &= size - 1;
assert (res < size);
CADICAL_assert (res < size);
return res;
}
@ -344,7 +348,7 @@ void Checker::insert () {
/*------------------------------------------------------------------------*/
inline void Checker::assign (int lit) {
assert (!val (lit));
CADICAL_assert (!val (lit));
vals[lit] = 1;
vals[-lit] = -1;
trail.push_back (lit);
@ -354,26 +358,26 @@ inline void Checker::assume (int lit) {
signed char tmp = val (lit);
if (tmp > 0)
return;
assert (!tmp);
CADICAL_assert (!tmp);
stats.assumptions++;
assign (lit);
}
void Checker::backtrack (unsigned previously_propagated) {
assert (previously_propagated <= trail.size ());
CADICAL_assert (previously_propagated <= trail.size ());
while (trail.size () > previously_propagated) {
int lit = trail.back ();
assert (val (lit) > 0);
assert (val (-lit) < 0);
CADICAL_assert (val (lit) > 0);
CADICAL_assert (val (-lit) < 0);
vals[lit] = vals[-lit] = 0;
trail.pop_back ();
}
trail.resize (previously_propagated);
next_to_propagate = previously_propagated;
assert (trail.size () == next_to_propagate);
CADICAL_assert (trail.size () == next_to_propagate);
}
/*------------------------------------------------------------------------*/
@ -386,15 +390,15 @@ bool Checker::propagate () {
while (res && next_to_propagate < trail.size ()) {
int lit = trail[next_to_propagate++];
stats.propagations++;
assert (val (lit) > 0);
assert (abs (lit) < size_vars);
CADICAL_assert (val (lit) > 0);
CADICAL_assert (abs (lit) < size_vars);
CheckerWatcher &ws = watcher (-lit);
const auto end = ws.end ();
auto j = ws.begin (), i = j;
for (; res && i != end; i++) {
CheckerWatch &w = *j++ = *i;
const int blit = w.blit;
assert (blit != -lit);
CADICAL_assert (blit != -lit);
const signed char blit_val = val (blit);
if (blit_val > 0)
continue;
@ -405,16 +409,16 @@ bool Checker::propagate () {
else
assign (w.blit); // but still sound
} else {
assert (size > 2);
CADICAL_assert (size > 2);
CheckerClause *c = w.clause;
if (!c->size) {
j--;
continue;
} // skip garbage clauses
assert (size == c->size);
CADICAL_assert (size == c->size);
int *lits = c->literals;
int other = lits[0] ^ lits[1] ^ (-lit);
assert (other != -lit);
CADICAL_assert (other != -lit);
signed char other_val = val (other);
if (other_val > 0) {
j[-1].blit = other;
@ -511,7 +515,7 @@ void Checker::add_clause (const char *type) {
const signed char tmp = val (lit);
if (tmp < 0)
continue;
assert (!tmp);
CADICAL_assert (!tmp);
if (unit) {
unit = INT_MIN;
break;
@ -598,10 +602,10 @@ void Checker::delete_clause (int64_t id, bool, const vector<int> &c) {
if (!tautological ()) {
CheckerClause **p = find (), *d = *p;
if (d) {
assert (d->size > 1);
CADICAL_assert (d->size > 1);
// Remove from hash table, mark as garbage, connect to garbage list.
num_garbage++;
assert (num_clauses);
CADICAL_assert (num_clauses);
num_clauses--;
*p = d->next;
d->next = garbage;
@ -646,3 +650,5 @@ void Checker::dump () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -41,7 +45,7 @@ void Internal::unmark_clause () {
void Internal::mark_removed (Clause *c, int except) {
LOG (c, "marking removed");
assert (!c->redundant);
CADICAL_assert (!c->redundant);
for (const auto &lit : *c)
if (lit != except)
mark_removed (lit);
@ -68,7 +72,7 @@ inline void Internal::mark_added (int lit, int size, bool redundant) {
void Internal::mark_added (Clause *c) {
LOG (c, "marking added");
assert (likely_to_be_kept_clause (c));
CADICAL_assert (likely_to_be_kept_clause (c));
for (const auto &lit : *c)
mark_added (lit, c->size, c->redundant);
}
@ -77,9 +81,9 @@ void Internal::mark_added (Clause *c) {
Clause *Internal::new_clause (bool red, int glue) {
assert (clause.size () <= (size_t) INT_MAX);
CADICAL_assert (clause.size () <= (size_t) INT_MAX);
const int size = (int) clause.size ();
assert (size >= 2);
CADICAL_assert (size >= 2);
if (glue > size)
glue = size;
@ -119,7 +123,7 @@ Clause *Internal::new_clause (bool red, int glue) {
// Just checking that we did not mess up our sophisticated memory layout.
// This might be compiler dependent though. Crucial for correctness.
//
assert (c->bytes () == bytes);
CADICAL_assert (c->bytes () == bytes);
stats.current.total++;
stats.added.total++;
@ -146,7 +150,7 @@ Clause *Internal::new_clause (bool red, int glue) {
/*------------------------------------------------------------------------*/
void Internal::promote_clause (Clause *c, int new_glue) {
assert (c->redundant);
CADICAL_assert (c->redundant);
const int tier1limit = tier1[false];
const int tier2limit = max (tier1limit, tier2[false]);
if (!c->redundant)
@ -173,7 +177,7 @@ void Internal::promote_clause (Clause *c, int new_glue) {
/*------------------------------------------------------------------------*/
void Internal::promote_clause_glue_only (Clause *c, int new_glue) {
assert (c->redundant);
CADICAL_assert (c->redundant);
if (c->hyper)
return;
int old_glue = c->glue;
@ -209,10 +213,10 @@ void Internal::promote_clause_glue_only (Clause *c, int new_glue) {
size_t Internal::shrink_clause (Clause *c, int new_size) {
if (opts.check && is_external_forgettable (c->id))
mark_garbage_external_forgettable (c->id);
assert (new_size >= 2);
CADICAL_assert (new_size >= 2);
int old_size = c->size;
assert (new_size < old_size);
#ifndef NDEBUG
CADICAL_assert (new_size < old_size);
#ifndef CADICAL_NDEBUG
for (int i = c->size; i < new_size; i++)
c->literals[i] = 0;
#endif
@ -229,7 +233,7 @@ size_t Internal::shrink_clause (Clause *c, int new_size) {
promote_clause_glue_only (c, min (c->size - 1, c->glue));
else {
int delta_size = old_size - new_size;
assert (stats.irrlits >= delta_size);
CADICAL_assert (stats.irrlits >= delta_size);
stats.irrlits -= delta_size;
}
@ -256,11 +260,11 @@ void Internal::delete_clause (Clause *c) {
size_t bytes = c->bytes ();
stats.collected += bytes;
if (c->garbage) {
assert (stats.garbage.bytes >= (int64_t) bytes);
CADICAL_assert (stats.garbage.bytes >= (int64_t) bytes);
stats.garbage.bytes -= bytes;
assert (stats.garbage.clauses > 0);
CADICAL_assert (stats.garbage.clauses > 0);
stats.garbage.clauses--;
assert (stats.garbage.literals >= c->size);
CADICAL_assert (stats.garbage.literals >= c->size);
stats.garbage.literals -= c->size;
// See the discussion in 'propagate' on avoiding to eagerly trace binary
@ -296,7 +300,7 @@ void Internal::delete_clause (Clause *c) {
//
void Internal::mark_garbage (Clause *c) {
assert (!c->garbage);
CADICAL_assert (!c->garbage);
// Delay tracing deletion of binary clauses. See the discussion above in
// 'delete_clause' and also in 'propagate'.
@ -312,17 +316,17 @@ void Internal::mark_garbage (Clause *c) {
if (opts.check && is_external_forgettable (c->id))
mark_garbage_external_forgettable (c->id);
assert (stats.current.total > 0);
CADICAL_assert (stats.current.total > 0);
stats.current.total--;
size_t bytes = c->bytes ();
if (c->redundant) {
assert (stats.current.redundant > 0);
CADICAL_assert (stats.current.redundant > 0);
stats.current.redundant--;
} else {
assert (stats.current.irredundant > 0);
CADICAL_assert (stats.current.irredundant > 0);
stats.current.irredundant--;
assert (stats.irrlits >= c->size);
CADICAL_assert (stats.irrlits >= c->size);
stats.irrlits -= c->size;
mark_removed (c);
}
@ -341,11 +345,11 @@ void Internal::mark_garbage (Clause *c) {
// to learn a new unit clause (which was confusing in log files).
void Internal::assign_original_unit (int64_t id, int lit) {
assert (!level || opts.chrono);
assert (!unsat);
CADICAL_assert (!level || opts.chrono);
CADICAL_assert (!unsat);
const int idx = vidx (lit);
assert (!vals[idx]);
assert (!flags (idx).eliminated ());
CADICAL_assert (!vals[idx]);
CADICAL_assert (!flags (idx).eliminated ());
Var &v = var (idx);
v.level = 0;
v.trail = (int) trail.size ();
@ -358,13 +362,13 @@ void Internal::assign_original_unit (int64_t id, int lit) {
if (lrat || frat)
unit_clauses (uidx) = id;
LOG ("original unit assign %d", lit);
assert (num_assigned == trail.size () || level);
CADICAL_assert (num_assigned == trail.size () || level);
mark_fixed (lit);
if (level)
return;
if (propagate ())
return;
assert (conflict);
CADICAL_assert (conflict);
LOG ("propagation of original unit results in conflict");
learn_empty_clause ();
}
@ -383,14 +387,14 @@ void Internal::add_new_original_clause (int64_t id) {
if (!from_propagator && level && !opts.ilb) {
backtrack ();
} else if (tainted_literal) {
assert (val (tainted_literal));
CADICAL_assert (val (tainted_literal));
int new_level = var (tainted_literal).level - 1;
assert (new_level >= 0);
CADICAL_assert (new_level >= 0);
backtrack (new_level);
}
assert (!tainted_literal);
CADICAL_assert (!tainted_literal);
LOG (original, "original clause");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
bool skip = false;
unordered_set<int> learned_levels;
size_t unassigned = 0;
@ -399,7 +403,7 @@ void Internal::add_new_original_clause (int64_t id) {
LOG ("skipping clause since formula is already inconsistent");
skip = true;
} else {
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (const auto &lit : original) {
int tmp = marked (lit);
if (tmp > 0) {
@ -425,7 +429,7 @@ void Internal::add_new_original_clause (int64_t id) {
skip = true;
} else {
clause.push_back (lit);
assert (flags (lit).status != Flags::UNUSED);
CADICAL_assert (flags (lit).status != Flags::UNUSED);
tmp = val (lit);
if (tmp)
learned_levels.insert (var (lit).level);
@ -477,7 +481,7 @@ void Internal::add_new_original_clause (int64_t id) {
if (!size) {
if (from_propagator)
stats.ext_prop.elearn_conf++;
assert (!unsat);
CADICAL_assert (!unsat);
if (!original.size ())
VERBOSE (1, "found empty original clause");
else
@ -488,12 +492,12 @@ void Internal::add_new_original_clause (int64_t id) {
conclusion.push_back (new_id);
} else if (size == 1) {
if (force_no_backtrack) {
assert (level);
CADICAL_assert (level);
const int idx = vidx (clause[0]);
assert (val (clause[0]) >= 0);
assert (!flags (idx).eliminated ());
CADICAL_assert (val (clause[0]) >= 0);
CADICAL_assert (!flags (idx).eliminated ());
Var &v = var (idx);
assert (val (clause[0]));
CADICAL_assert (val (clause[0]));
v.level = 0;
v.reason = 0;
const unsigned uidx = vlit (clause[0]);
@ -502,20 +506,20 @@ void Internal::add_new_original_clause (int64_t id) {
mark_fixed (clause[0]);
} else {
const int lit = clause[0];
assert (!val (lit) || var (lit).level);
CADICAL_assert (!val (lit) || var (lit).level);
if (val (lit) < 0)
backtrack (var (lit).level - 1);
assert (val (lit) >= 0);
CADICAL_assert (val (lit) >= 0);
handle_external_clause (0);
assign_original_unit (new_id, lit);
}
} else {
move_literals_to_watch ();
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
check_watched_literal_invariants ();
#endif
int glue = (int) (learned_levels.size () + unassigned);
assert (glue <= (int) clause.size ());
CADICAL_assert (glue <= (int) clause.size ());
bool clause_redundancy = from_propagator && ext_clause_forgettable;
Clause *c = new_clause (clause_redundancy, glue);
c->id = new_id;
@ -536,18 +540,18 @@ void Internal::add_new_original_clause (int64_t id) {
// are assigned at the highest decision level.
//
Clause *Internal::new_learned_redundant_clause (int glue) {
assert (clause.size () > 1);
#ifndef NDEBUG
CADICAL_assert (clause.size () > 1);
#ifndef CADICAL_NDEBUG
for (size_t i = 2; i < clause.size (); i++)
assert (var (clause[0]).level >= var (clause[i]).level),
assert (var (clause[1]).level >= var (clause[i]).level);
CADICAL_assert (var (clause[0]).level >= var (clause[i]).level),
CADICAL_assert (var (clause[1]).level >= var (clause[i]).level);
#endif
external->check_learned_clause ();
Clause *res = new_clause (true, glue);
if (proof) {
proof->add_derived_clause (res, lrat_chain);
}
assert (watching ());
CADICAL_assert (watching ());
watch_clause (res);
return res;
}
@ -560,7 +564,7 @@ Clause *Internal::new_hyper_binary_resolved_clause (bool red, int glue) {
if (proof) {
proof->add_derived_clause (res, lrat_chain);
}
assert (watching ());
CADICAL_assert (watching ());
watch_clause (res);
return res;
}
@ -574,7 +578,7 @@ Clause *Internal::new_hyper_ternary_resolved_clause (bool red) {
if (proof) {
proof->add_derived_clause (res, lrat_chain);
}
assert (!watching ());
CADICAL_assert (!watching ());
return res;
}
@ -586,8 +590,8 @@ Clause *Internal::new_factor_clause () {
if (proof) {
proof->add_derived_clause (res, lrat_chain);
}
assert (!watching ());
assert (occurring ());
CADICAL_assert (!watching ());
CADICAL_assert (occurring ());
for (const auto &lit : *res) {
occs (lit).push_back (res);
}
@ -606,7 +610,7 @@ Internal::new_hyper_ternary_resolved_clause_and_watch (bool red,
proof->add_derived_clause (res, lrat_chain);
}
if (full_watching) {
assert (watching ());
CADICAL_assert (watching ());
watch_clause (res);
}
return res;
@ -622,7 +626,7 @@ Clause *Internal::new_clause_as (const Clause *orig) {
if (proof) {
proof->add_derived_clause (res, lrat_chain);
}
assert (watching ());
CADICAL_assert (watching ());
watch_clause (res);
return res;
}
@ -636,8 +640,10 @@ Clause *Internal::new_resolved_irredundant_clause () {
proof->add_derived_clause (clause_id + 1, false, clause, lrat_chain);
}
Clause *res = new_clause (false);
assert (!watching ());
CADICAL_assert (!watching ());
return res;
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -56,7 +60,7 @@ void Internal::remove_falsified_literals (Clause *c) {
literal_iterator j = c->begin ();
for (i = j; i != end; i++) {
const int lit = *j++ = *i, tmp = fixed (lit);
assert (tmp <= 0);
CADICAL_assert (tmp <= 0);
if (tmp >= 0)
continue;
LOG ("flushing %d", lit);
@ -102,23 +106,23 @@ void Internal::mark_satisfied_clauses_as_garbage () {
void Internal::protect_reasons () {
LOG ("protecting reason clauses of all assigned variables on trail");
assert (!protected_reasons);
CADICAL_assert (!protected_reasons);
#ifdef LOGGING
size_t count = 0;
#endif
for (const auto &lit : trail) {
if (!active (lit))
continue;
assert (val (lit));
CADICAL_assert (val (lit));
Var &v = var (lit);
assert (v.level > 0);
CADICAL_assert (v.level > 0);
Clause *reason = v.reason;
if (!reason)
continue;
if (reason == external_reason)
continue;
LOG (reason, "protecting assigned %d reason %p", lit, (void *) reason);
assert (!reason->reason);
CADICAL_assert (!reason->reason);
reason->reason = true;
#ifdef LOGGING
count++;
@ -135,16 +139,16 @@ void Internal::protect_reasons () {
void Internal::unprotect_reasons () {
LOG ("unprotecting reasons clauses of all assigned variables on trail");
assert (protected_reasons);
CADICAL_assert (protected_reasons);
#ifdef LOGGING
size_t count = 0;
#endif
for (const auto &lit : trail) {
if (!active (lit))
continue;
assert (val (lit));
CADICAL_assert (val (lit));
Var &v = var (lit);
assert (v.level > 0);
CADICAL_assert (v.level > 0);
Clause *reason = v.reason;
if (!reason)
continue;
@ -152,7 +156,7 @@ void Internal::unprotect_reasons () {
continue;
LOG (reason, "unprotecting assigned %d reason %p", lit,
(void *) reason);
assert (reason->reason);
CADICAL_assert (reason->reason);
reason->reason = false;
#ifdef LOGGING
count++;
@ -181,7 +185,7 @@ size_t Internal::flush_occs (int lit) {
if (c->collect ())
continue;
*j++ = c->moved ? c->copy : c;
// assert (!c->redundant); // -> not true in sweeping
// CADICAL_assert (!c->redundant); // -> not true in sweeping
res++;
}
os.resize (j - os.begin ());
@ -196,7 +200,7 @@ size_t Internal::flush_occs (int lit) {
// preprocessing is actually redundant.
inline void Internal::flush_watches (int lit, Watches &saved) {
assert (saved.empty ());
CADICAL_assert (saved.empty ());
Watches &ws = watches (lit);
const const_watch_iterator end = ws.end ();
watch_iterator j = ws.begin ();
@ -211,7 +215,7 @@ inline void Internal::flush_watches (int lit, Watches &saved) {
w.size = c->size;
const int new_blit_pos = (c->literals[0] == lit);
LOG (c, "clause in flush_watch starting from %d", lit);
assert (c->literals[!new_blit_pos] == lit); /*FW1*/
CADICAL_assert (c->literals[!new_blit_pos] == lit); /*FW1*/
w.blit = c->literals[new_blit_pos];
if (w.binary ())
*j++ = w;
@ -254,8 +258,8 @@ void Internal::update_reason_references () {
if (c == external_reason)
continue;
LOG (c, "updating assigned %d reason", lit);
assert (c->reason);
assert (c->moved);
CADICAL_assert (c->reason);
CADICAL_assert (c->moved);
Clause *d = c->copy;
v.reason = d;
#ifdef LOGGING
@ -277,7 +281,7 @@ void Internal::delete_garbage_clauses () {
flush_all_occs_and_watches ();
LOG ("deleting garbage clauses");
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t collected_bytes = 0, collected_clauses = 0;
#endif
const auto end = clauses.end ();
@ -286,7 +290,7 @@ void Internal::delete_garbage_clauses () {
Clause *c = *j++ = *i++;
if (!c->collect ())
continue;
#ifndef QUIET
#ifndef CADICAL_QUIET
collected_bytes += c->bytes ();
collected_clauses++;
#endif
@ -310,7 +314,7 @@ void Internal::delete_garbage_clauses () {
//
void Internal::copy_clause (Clause *c) {
LOG (c, "moving");
assert (!c->moved);
CADICAL_assert (!c->moved);
char *p = (char *) c;
char *q = arena.copy (p, c->bytes ());
c->copy = (Clause *) q;
@ -390,7 +394,7 @@ void Internal::copy_non_garbage_clauses () {
// the decision queue and also uses saved phases. It seems faster than
// the MiniSAT version and thus we keep 'opts.arenatype == 3'.
assert (opts.arenatype == 3);
CADICAL_assert (opts.arenatype == 3);
for (int sign = -1; sign <= 1; sign += 2)
for (int idx = queue.last; idx; idx = link (idx).prev)
@ -418,7 +422,7 @@ void Internal::copy_non_garbage_clauses () {
if (c->collect ())
delete_clause (c);
else
assert (c->moved), *j++ = c->copy, deallocate_clause (c);
CADICAL_assert (c->moved), *j++ = c->copy, deallocate_clause (c);
}
clauses.resize (j - clauses.begin ());
if (clauses.size () < clauses.capacity () / 2)
@ -446,7 +450,7 @@ void Internal::copy_non_garbage_clauses () {
// statistics are updated correctly.
void Internal::check_clause_stats () {
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
int64_t irredundant = 0, redundant = 0, total = 0, irrlits = 0;
for (const auto &c : clauses) {
if (c->garbage)
@ -459,10 +463,10 @@ void Internal::check_clause_stats () {
irrlits += c->size;
total++;
}
assert (stats.current.irredundant == irredundant);
assert (stats.current.redundant == redundant);
assert (stats.current.total == total);
assert (stats.irrlits == irrlits);
CADICAL_assert (stats.current.irredundant == irredundant);
CADICAL_assert (stats.current.redundant == redundant);
CADICAL_assert (stats.current.total == total);
CADICAL_assert (stats.irrlits == irrlits);
#endif
}
@ -481,7 +485,7 @@ void Internal::remove_garbage_binaries () {
Watches saved;
for (auto v : vars) {
for (auto lit : {-v, v}) {
assert (saved.empty ());
CADICAL_assert (saved.empty ());
Watches &ws = watches (lit);
const const_watch_iterator end = ws.end ();
watch_iterator j = ws.begin ();
@ -495,7 +499,7 @@ void Internal::remove_garbage_binaries () {
continue;
if (c->reason && c->garbage) {
COVER (true);
assert (c->size == 2);
CADICAL_assert (c->size == 2);
backtrack_level =
min (backtrack_level, var (c->literals[0]).level);
LOG ("need to backtrack to before level %d", backtrack_level);
@ -543,3 +547,5 @@ void Internal::garbage_collection () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -18,7 +22,7 @@ bool Internal::compacting () {
if (stats.conflicts < lim.compact)
return false;
int inactive = max_var - active ();
assert (inactive >= 0);
CADICAL_assert (inactive >= 0);
if (!inactive)
return false;
if (inactive < opts.compactmin)
@ -52,7 +56,7 @@ struct Mapper {
table = new int[internal->max_var + 1u];
clear_n (table, internal->max_var + 1u);
assert (!internal->level);
CADICAL_assert (!internal->level);
for (auto src : internal->vars) {
const Flags &f = internal->flags (src);
@ -72,10 +76,10 @@ struct Mapper {
// Map old variable indices. A result of zero means not mapped.
//
int map_idx (int src) {
assert (0 < src);
assert (src <= internal->max_var);
CADICAL_assert (0 < src);
CADICAL_assert (src <= internal->max_var);
const int res = table[src];
assert (res <= new_max_var);
CADICAL_assert (res <= new_max_var);
return res;
}
@ -89,14 +93,14 @@ struct Mapper {
if (!res) {
const signed char tmp = internal->val (src);
if (tmp) {
assert (first_fixed);
CADICAL_assert (first_fixed);
res = map_first_fixed;
if (tmp != first_fixed_val)
res = -res;
}
} else if ((src) < 0)
res = -res;
assert (abs (res) <= new_max_var);
CADICAL_assert (abs (res) <= new_max_var);
return res;
}
@ -108,8 +112,8 @@ struct Mapper {
const int dst = map_idx (src);
if (!dst)
continue;
assert (0 < dst);
assert (dst <= src);
CADICAL_assert (0 < dst);
CADICAL_assert (dst <= src);
v[dst] = v[src];
}
v.resize (new_vsize);
@ -124,8 +128,8 @@ struct Mapper {
const int dst = map_idx (src);
if (!dst)
continue;
assert (0 < dst);
assert (dst <= src);
CADICAL_assert (0 < dst);
CADICAL_assert (dst <= src);
v[2 * dst] = v[2 * src];
v[2 * dst + 1] = v[2 * src + 1];
}
@ -143,7 +147,7 @@ struct Mapper {
for (; i != end; i++) {
const int src = *i;
int dst = map_idx (abs (src));
assert (abs (dst) <= abs (src));
CADICAL_assert (abs (dst) <= abs (src));
if (!dst)
continue;
if (src < 0)
@ -163,19 +167,19 @@ void Internal::compact () {
START (compact);
assert (active () < max_var);
CADICAL_assert (active () < max_var);
stats.compacts++;
assert (!level);
assert (!unsat);
assert (!conflict);
assert (clause.empty ());
assert (levels.empty ());
assert (analyzed.empty ());
assert (minimized.empty ());
assert (control.size () == 1);
assert (propagated == trail.size ());
CADICAL_assert (!level);
CADICAL_assert (!unsat);
CADICAL_assert (!conflict);
CADICAL_assert (clause.empty ());
CADICAL_assert (levels.empty ());
CADICAL_assert (analyzed.empty ());
CADICAL_assert (minimized.empty ());
CADICAL_assert (control.size () == 1);
CADICAL_assert (propagated == trail.size ());
garbage_collection ();
@ -188,14 +192,14 @@ void Internal::compact () {
LOG ("no variable fixed");
if (!assumptions.empty ()) {
assert (!external->assumptions.empty ());
CADICAL_assert (!external->assumptions.empty ());
LOG ("temporarily reset internal assumptions");
reset_assumptions ();
}
const bool is_constraint = !constraint.empty ();
if (is_constraint) {
assert (!external->constraint.empty ());
CADICAL_assert (!external->constraint.empty ());
LOG ("temporarily reset internal constraint");
reset_constraint ();
}
@ -213,11 +217,11 @@ void Internal::compact () {
continue;
}
if (lrat || frat) {
assert (eidx > 0);
assert (external->ext_units.size () >= (size_t) 2 * eidx + 1);
CADICAL_assert (eidx > 0);
CADICAL_assert (external->ext_units.size () >= (size_t) 2 * eidx + 1);
int64_t id1 = external->ext_units[2 * eidx];
int64_t id2 = external->ext_units[2 * eidx + 1];
assert (!id1 || !id2);
CADICAL_assert (!id1 || !id2);
if (!id1 && !id2) {
int64_t new_id1 = unit_clauses (2 * src);
int64_t new_id2 = unit_clauses (2 * src + 1);
@ -237,7 +241,7 @@ void Internal::compact () {
if (lrat || frat) {
for (auto src : internal->vars) {
const int dst = mapper.map_idx (src);
assert (dst <= src);
CADICAL_assert (dst <= src);
const signed char tmp = internal->val (src);
if (!dst && !tmp) {
unit_clauses (2 * src) = 0;
@ -245,10 +249,10 @@ void Internal::compact () {
continue;
}
if (!tmp || src == mapper.first_fixed) {
assert (0 < dst);
CADICAL_assert (0 < dst);
if (dst == src)
continue;
assert (!unit_clauses (2 * dst) && !unit_clauses (2 * dst + 1));
CADICAL_assert (!unit_clauses (2 * dst) && !unit_clauses (2 * dst + 1));
unit_clauses (2 * dst) = unit_clauses (2 * src);
unit_clauses (2 * dst + 1) = unit_clauses (2 * src + 1);
unit_clauses (2 * src) = 0;
@ -263,7 +267,7 @@ void Internal::compact () {
}
unit_clauses (2 * src) = 0;
unit_clauses (2 * src + 1) = 0;
assert (id);
CADICAL_assert (id);
}
unit_clauses_idx.resize (2 * mapper.new_vsize);
shrink_vector (unit_clauses_idx);
@ -271,12 +275,12 @@ void Internal::compact () {
// Map the literals in all clauses.
//
for (const auto &c : clauses) {
assert (!c->garbage);
CADICAL_assert (!c->garbage);
for (auto &src : *c) {
assert (!val (src));
CADICAL_assert (!val (src));
int dst;
dst = mapper.map_lit (src);
assert (dst || c->garbage);
CADICAL_assert (dst || c->garbage);
src = dst;
}
}
@ -299,7 +303,7 @@ void Internal::compact () {
const int dst = mapper.map_idx (idx);
if (!dst)
continue;
assert (active (idx));
CADICAL_assert (active (idx));
if (prev)
links[prev].next = dst;
else
@ -319,15 +323,15 @@ void Internal::compact () {
// In the second part we map, flush and shrink arrays.
/*======================================================================*/
assert (trail.size () == num_assigned);
CADICAL_assert (trail.size () == num_assigned);
mapper.map_flush_and_shrink_lits (trail);
propagated = trail.size ();
num_assigned = trail.size ();
if (mapper.first_fixed) {
assert (trail.size () == 1);
CADICAL_assert (trail.size () == 1);
var (mapper.first_fixed).trail = 0; // before mapping 'vtab'
} else
assert (trail.empty ());
CADICAL_assert (trail.empty ());
if (!probes.empty ())
mapper.map_flush_and_shrink_lits (probes);
@ -360,7 +364,7 @@ void Internal::compact () {
continue;
if (src == dst)
continue;
assert (dst < src);
CADICAL_assert (dst < src);
if ((size_t) src >= frozentab.size ())
break;
if ((size_t) dst >= frozentab.size ())
@ -380,7 +384,7 @@ void Internal::compact () {
continue;
if (src == dst)
continue;
assert (dst < src);
CADICAL_assert (dst < src);
relevanttab[dst] += relevanttab[src];
relevanttab[src] = 0;
@ -394,12 +398,12 @@ void Internal::compact () {
if (!external->assumptions.empty ()) {
for (const auto &elit : external->assumptions) {
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
int eidx = abs (elit);
assert (eidx <= external->max_var);
CADICAL_assert (eidx <= external->max_var);
int ilit = external->e2i[eidx];
assert (ilit); // Because we froze all!!!
CADICAL_assert (ilit); // Because we froze all!!!
if (elit < 0)
ilit = -ilit;
assume (ilit);
@ -428,14 +432,14 @@ void Internal::compact () {
// 'constrain' uses 'val', so this code has to be after remapping that
if (is_constraint) {
assert (!level);
assert (!external->constraint.back ());
CADICAL_assert (!level);
CADICAL_assert (!external->constraint.back ());
for (auto elit : external->constraint) {
assert (elit != INT_MIN);
CADICAL_assert (elit != INT_MIN);
int eidx = abs (elit);
assert (eidx <= external->max_var);
CADICAL_assert (eidx <= external->max_var);
int ilit = external->e2i[eidx];
assert (!ilit == !elit);
CADICAL_assert (!ilit == !elit);
if (elit < 0)
ilit = -ilit;
LOG ("re adding lit external %d internal %d to constraint", elit,
@ -475,7 +479,7 @@ void Internal::compact () {
// elements with 'zero' destination should be flushed.
vector<int> saved;
assert (saved.empty ());
CADICAL_assert (saved.empty ());
if (!scores.empty ()) {
while (!scores.empty ()) {
const int src = scores.front ();
@ -549,3 +553,5 @@ void Internal::compact () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -39,7 +43,7 @@ bool Internal::conditioning () {
if (!preprocessing && !opts.inprocessing)
return false;
if (preprocessing)
assert (lim.preprocessing);
CADICAL_assert (lim.preprocessing);
// Triggered in regular 'opts.conditionint' conflict intervals.
//
@ -79,13 +83,13 @@ bool Internal::conditioning () {
void Internal::condition_unassign (int lit) {
LOG ("condition unassign %d", lit);
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
set_val (lit, 0);
}
void Internal::condition_assign (int lit) {
LOG ("condition assign %d", lit);
assert (!val (lit));
CADICAL_assert (!val (lit));
set_val (lit, 1);
}
@ -104,15 +108,15 @@ inline bool Internal::is_autarky_literal (int lit) const {
inline void Internal::mark_as_conditional_literal (int lit) {
LOG ("marking %d as conditional literal", lit);
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
setbit (lit, 0);
assert (is_conditional_literal (lit));
assert (!is_autarky_literal (lit));
CADICAL_assert (is_conditional_literal (lit));
CADICAL_assert (!is_autarky_literal (lit));
}
inline void Internal::unmark_as_conditional_literal (int lit) {
LOG ("unmarking %d as conditional literal", lit);
assert (is_conditional_literal (lit));
CADICAL_assert (is_conditional_literal (lit));
unsetbit (lit, 0);
}
@ -130,13 +134,13 @@ inline bool Internal::is_in_candidate_clause (int lit) const {
inline void Internal::mark_in_candidate_clause (int lit) {
LOG ("marking %d as literal of the candidate clause", lit);
mark67 (lit);
assert (is_in_candidate_clause (lit));
assert (!is_in_candidate_clause (-lit));
CADICAL_assert (is_in_candidate_clause (lit));
CADICAL_assert (!is_in_candidate_clause (-lit));
}
inline void Internal::unmark_in_candidate_clause (int lit) {
LOG ("unmarking %d as literal of the candidate clause", lit);
assert (is_in_candidate_clause (lit));
CADICAL_assert (is_in_candidate_clause (lit));
unmark67 (lit);
}
@ -155,7 +159,7 @@ struct less_conditioned {
long Internal::condition_round (long delta) {
long limit;
#ifndef QUIET
#ifndef CADICAL_QUIET
long props = 0;
#endif
if (LONG_MAX - delta < stats.condprops)
@ -170,7 +174,7 @@ long Internal::condition_round (long delta) {
protect_reasons ();
#if defined(LOGGING) || !defined(NDEBUG)
#if defined(LOGGING) || !defined(CADICAL_NDEBUG)
int additionally_assigned = 0;
#endif
@ -202,7 +206,7 @@ long Internal::condition_round (long delta) {
condition_assign (lit);
v.level = level;
trail.push_back (lit);
#if defined(LOGGING) || !defined(NDEBUG)
#if defined(LOGGING) || !defined(CADICAL_NDEBUG)
additionally_assigned++;
#endif
}
@ -260,7 +264,7 @@ long Internal::condition_round (long delta) {
vector<int> conditional;
vector<Clause *> candidates; // Gather candidate clauses.
#ifndef QUIET
#ifndef CADICAL_QUIET
size_t watched = 0; // Number of watched clauses.
#endif
@ -350,12 +354,12 @@ long Internal::condition_round (long delta) {
//
if (negative > 0 && positive > 0) {
LOG (c, "found %d negative literals in candidate", negative);
assert (watch);
assert (val (watch) > 0);
CADICAL_assert (watch);
CADICAL_assert (val (watch) > 0);
Occs &os = occs (watch);
assert (os.size () == minsize);
CADICAL_assert (os.size () == minsize);
os.push_back (c);
#ifndef QUIET
#ifndef CADICAL_QUIET
watched++;
#endif
LOG (c, "watching %d with %zd occurrences in", watch, minsize);
@ -375,7 +379,7 @@ long Internal::condition_round (long delta) {
signed char tmp = val (lit);
if (!tmp)
continue;
assert (tmp < 0);
CADICAL_assert (tmp < 0);
if (!var (lit).level)
continue; // Not unassigned yet!
if (is_conditional_literal (-lit))
@ -389,7 +393,7 @@ long Internal::condition_round (long delta) {
new_conditionals);
initial.conditional += new_conditionals;
assert (initial.autarky >= new_conditionals);
CADICAL_assert (initial.autarky >= new_conditionals);
initial.autarky -= new_conditionals;
}
@ -408,14 +412,14 @@ long Internal::condition_round (long delta) {
#ifdef LOGGING
for (size_t i = 0; i < conditional.size (); i++) {
LOG ("initial conditional %d", conditional[i]);
assert (is_conditional_literal (conditional[i]));
CADICAL_assert (is_conditional_literal (conditional[i]));
}
for (size_t i = 0; i < trail.size (); i++)
if (is_autarky_literal (trail[i]))
LOG ("initial autarky %d", trail[i]);
#endif
assert (initial.conditional == conditional.size ());
assert (initial.assigned == initial.conditional + initial.autarky);
CADICAL_assert (initial.conditional == conditional.size ());
CADICAL_assert (initial.assigned == initial.conditional + initial.autarky);
stats.condassinit += initial.assigned;
stats.condcondinit += initial.conditional;
@ -448,7 +452,7 @@ long Internal::condition_round (long delta) {
//
// TODO consider computing conditioned and unconditioned over all clauses.
//
assert (conditioned + unconditioned == candidates.size ());
CADICAL_assert (conditioned + unconditioned == candidates.size ());
if (conditioned && unconditioned) {
stable_sort (candidates.begin (), candidates.end (),
less_conditioned ());
@ -457,13 +461,13 @@ long Internal::condition_round (long delta) {
unconditioned, percent (unconditioned, candidates.size ()));
} else if (conditioned && !unconditioned) {
for (auto const &c : candidates) {
assert (c->conditioned);
CADICAL_assert (c->conditioned);
c->conditioned = false; // Reset 'conditioned' bit.
}
PHASE ("condition", stats.conditionings,
"all %zd candidates tried before", conditioned);
} else {
assert (!conditioned);
CADICAL_assert (!conditioned);
PHASE ("condition", stats.conditionings, "all %zd candidates are fresh",
unconditioned);
}
@ -478,7 +482,7 @@ long Internal::condition_round (long delta) {
//
long blocked = 0; // Number of Successfully blocked clauses.
//
#ifndef QUIET
#ifndef CADICAL_QUIET
size_t untried = candidates.size ();
#endif
for (const auto &c : candidates) {
@ -503,11 +507,11 @@ long Internal::condition_round (long delta) {
untried, percent (untried, candidates.size ()), props);
break;
}
#ifndef QUIET
#ifndef CADICAL_QUIET
untried--;
#endif
assert (!c->garbage);
assert (!c->redundant);
CADICAL_assert (!c->garbage);
CADICAL_assert (!c->redundant);
LOG (c, "candidate");
c->conditioned = 1; // Next time later.
@ -559,17 +563,17 @@ long Internal::condition_round (long delta) {
size_t conditional, unassigned;
} next = {0, 0};
assert (unassigned.empty ());
assert (conditional.size () == initial.conditional);
CADICAL_assert (unassigned.empty ());
CADICAL_assert (conditional.size () == initial.conditional);
while (watched_autarky_literal && stats.condprops < limit &&
next.conditional < conditional.size ()) {
assert (next.unassigned == unassigned.size ());
CADICAL_assert (next.unassigned == unassigned.size ());
const int conditional_lit = conditional[next.conditional++];
LOG ("processing next conditional %d", conditional_lit);
assert (is_conditional_literal (conditional_lit));
CADICAL_assert (is_conditional_literal (conditional_lit));
if (is_in_candidate_clause (-conditional_lit)) {
LOG ("conditional %d negated in candidate clause", conditional_lit);
@ -580,11 +584,11 @@ long Internal::condition_round (long delta) {
conditional_lit);
condition_unassign (conditional_lit);
assert (!is_conditional_literal (conditional_lit));
CADICAL_assert (!is_conditional_literal (conditional_lit));
unassigned.push_back (conditional_lit);
assert (remain.assigned > 0);
assert (remain.conditional > 0);
CADICAL_assert (remain.assigned > 0);
CADICAL_assert (remain.conditional > 0);
remain.conditional--;
remain.assigned--;
@ -592,8 +596,8 @@ long Internal::condition_round (long delta) {
next.unassigned < unassigned.size ()) {
const int unassigned_lit = unassigned[next.unassigned++];
LOG ("processing next unassigned %d", unassigned_lit);
assert (!val (unassigned_lit));
#ifndef QUIET
CADICAL_assert (!val (unassigned_lit));
#ifndef CADICAL_QUIET
props++;
#endif
stats.condprops++;
@ -635,7 +639,7 @@ long Internal::condition_round (long delta) {
i--; // Drop watch!
LOG (d, "watching %d in", replacement);
assert (replacement != unassigned_lit);
CADICAL_assert (replacement != unassigned_lit);
occs (replacement).push_back (d);
continue; // ... with next watched clause 'd'.
@ -661,7 +665,7 @@ long Internal::condition_round (long delta) {
conditional.push_back (-lit);
remain.conditional++;
assert (remain.autarky > 0);
CADICAL_assert (remain.autarky > 0);
remain.autarky--;
if (-lit != watched_autarky_literal)
@ -713,9 +717,9 @@ long Internal::condition_round (long delta) {
LOG ("remaining conditional part of size %zd", remain.conditional);
LOG ("remaining autarky part of size %zd", remain.autarky);
//
assert (remain.assigned - remain.conditional == remain.autarky);
CADICAL_assert (remain.assigned - remain.conditional == remain.autarky);
//
#if defined(LOGGING) || !defined(NDEBUG)
#if defined(LOGGING) || !defined(CADICAL_NDEBUG)
//
// This is a sanity check, that the size of our implicit representation
// of the autarky part matches our 'remain' counts. We need the same
@ -732,21 +736,21 @@ long Internal::condition_round (long delta) {
check.assigned++;
if (is_conditional_literal (lit)) {
LOG ("remaining conditional %d", lit);
assert (!is_autarky_literal (lit));
CADICAL_assert (!is_autarky_literal (lit));
check.conditional++;
} else {
assert (is_autarky_literal (lit));
CADICAL_assert (is_autarky_literal (lit));
LOG ("remaining autarky %d", lit);
check.autarky++;
}
} else {
assert (!is_autarky_literal (lit));
assert (!is_conditional_literal (lit));
CADICAL_assert (!is_autarky_literal (lit));
CADICAL_assert (!is_conditional_literal (lit));
}
}
assert (remain.assigned == check.assigned);
assert (remain.conditional == check.conditional);
assert (remain.autarky == check.autarky);
CADICAL_assert (remain.assigned == check.assigned);
CADICAL_assert (remain.conditional == check.conditional);
CADICAL_assert (remain.autarky == check.autarky);
#endif
// Success if an autarky literal is left in the clause and
@ -754,8 +758,8 @@ long Internal::condition_round (long delta) {
// limit was hit.
//
if (watched_autarky_literal && stats.condprops < limit) {
assert (is_autarky_literal (watched_autarky_literal));
assert (is_in_candidate_clause (watched_autarky_literal));
CADICAL_assert (is_autarky_literal (watched_autarky_literal));
CADICAL_assert (is_in_candidate_clause (watched_autarky_literal));
blocked++;
stats.conditioned++;
@ -848,20 +852,20 @@ long Internal::condition_round (long delta) {
// Unassign additionally assigned literals.
//
#if defined(LOGGING) || !defined(NDEBUG)
#if defined(LOGGING) || !defined(CADICAL_NDEBUG)
int additionally_unassigned = 0;
#endif
while (trail.size () > initial_trail_level) {
int lit = trail.back ();
trail.pop_back ();
condition_unassign (lit);
#if defined(LOGGING) || !defined(NDEBUG)
#if defined(LOGGING) || !defined(CADICAL_NDEBUG)
additionally_unassigned++;
#endif
}
LOG ("unassigned %d additionally assigned literals",
additionally_unassigned);
assert (additionally_unassigned == additionally_assigned);
CADICAL_assert (additionally_unassigned == additionally_assigned);
if (level > initial_level) {
LOG ("reset condition decision level");
@ -877,14 +881,14 @@ long Internal::condition_round (long delta) {
for (size_t i = 0; i < initial_trail_level; i++) {
const int lit = trail[i];
const signed char tmp = val (lit);
assert (tmp >= 0);
CADICAL_assert (tmp >= 0);
if (!tmp)
condition_assign (lit);
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (const auto &lit : trail)
assert (!marked (lit));
CADICAL_assert (!marked (lit));
#endif
unprotect_reasons ();
@ -913,7 +917,7 @@ void Internal::condition (bool update_limits) {
limit = opts.conditionmineff;
if (limit > opts.conditionmaxeff)
limit = opts.conditionmaxeff;
assert (stats.current.irredundant);
CADICAL_assert (stats.current.irredundant);
limit *= 2.0 * active () / (double) stats.current.irredundant;
limit = max (limit, 2l * active ());
@ -938,3 +942,5 @@ void Internal::condition (bool update_limits) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -75,7 +79,7 @@ bool Config::set (Options &opts, const char *name) {
const NameVal *BEGIN = N##_config; \
const NameVal *END = BEGIN + sizeof N##_config / sizeof (NameVal); \
for (const NameVal *P = BEGIN; P != END; P++) { \
assert (Options::has (P->name)); \
CADICAL_assert (Options::has (P->name)); \
opts.set (P->name, P->val); \
} \
return true; \
@ -99,3 +103,5 @@ const char **Config::begin () { return configs; }
const char **Config::end () { return &configs[num_configs]; }
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::constrain (int lit) {
@ -62,3 +66,5 @@ void Internal::reset_constraint () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,7 +1,11 @@
#ifndef NCONTRACTS
#include "global.h"
#ifndef CADICAL_NCONTRACTS
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void fatal_message_start ();
@ -24,4 +28,6 @@ void require_solver_pointer_to_be_non_zero (const void *ptr,
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
#endif

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -52,10 +56,10 @@ inline void Internal::cover_push_extension (int lit, Coveror &coveror) {
bool found = false;
for (const auto &other : coveror.covered)
if (lit == other)
assert (!found), found = true;
CADICAL_assert (!found), found = true;
else
coveror.extend.push_back (other);
assert (found);
CADICAL_assert (found);
(void) found;
}
@ -63,11 +67,11 @@ inline void Internal::cover_push_extension (int lit, Coveror &coveror) {
inline void Internal::covered_literal_addition (int lit, Coveror &coveror) {
require_mode (COVER);
assert (level == 1);
CADICAL_assert (level == 1);
cover_push_extension (lit, coveror);
for (const auto &other : coveror.intersection) {
LOG ("covered literal addition %d", other);
assert (!vals[other]), assert (!vals[-other]);
CADICAL_assert (!vals[other]), CADICAL_assert (!vals[-other]);
set_val (other, -1);
coveror.covered.push_back (other);
coveror.added.push_back (other);
@ -81,9 +85,9 @@ inline void Internal::covered_literal_addition (int lit, Coveror &coveror) {
inline void Internal::asymmetric_literal_addition (int lit,
Coveror &coveror) {
require_mode (COVER);
assert (level == 1);
CADICAL_assert (level == 1);
LOG ("initial asymmetric literal addition %d", lit);
assert (!vals[lit]), assert (!vals[-lit]);
CADICAL_assert (!vals[lit]), CADICAL_assert (!vals[-lit]);
set_val (lit, -1);
coveror.added.push_back (lit);
coveror.alas++;
@ -101,7 +105,7 @@ bool Internal::cover_propagate_asymmetric (int lit, Clause *ignore,
Coveror &coveror) {
require_mode (COVER);
stats.propagations.cover++;
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
bool subsumed = false;
LOG ("asymmetric literal propagation of %d", lit);
Watches &ws = watches (lit);
@ -141,12 +145,12 @@ bool Internal::cover_propagate_asymmetric (int lit, Clause *ignore,
k++;
if (v < 0) {
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
w.clause->pos = k - lits;
assert (lits + 2 <= k), assert (k <= w.clause->end ());
CADICAL_assert (lits + 2 <= k), CADICAL_assert (k <= w.clause->end ());
if (v > 0)
j[-1].blit = r;
else if (!v) {
@ -156,10 +160,10 @@ bool Internal::cover_propagate_asymmetric (int lit, Clause *ignore,
watch_literal (r, lit, w.clause);
j--;
} else if (!u) {
assert (v < 0);
CADICAL_assert (v < 0);
asymmetric_literal_addition (-other, coveror);
} else {
assert (u < 0), assert (v < 0);
CADICAL_assert (u < 0), CADICAL_assert (v < 0);
LOG (w.clause, "found subsuming");
subsumed = true;
break;
@ -181,7 +185,7 @@ bool Internal::cover_propagate_asymmetric (int lit, Clause *ignore,
bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
require_mode (COVER);
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
if (frozen (lit)) {
LOG ("no covered propagation on frozen literal %d", lit);
return false;
@ -190,7 +194,7 @@ bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
stats.propagations.cover++;
LOG ("covered propagation of %d", lit);
assert (coveror.intersection.empty ());
CADICAL_assert (coveror.intersection.empty ());
Occs &os = occs (-lit);
const auto end = os.end ();
@ -237,7 +241,7 @@ bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
const signed char tmp = val (other);
if (tmp < 0)
continue;
assert (!tmp);
CADICAL_assert (!tmp);
coveror.intersection.push_back (other);
mark (other);
}
@ -254,7 +258,7 @@ bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
signed char tmp = val (other);
if (tmp < 0)
continue;
assert (!tmp);
CADICAL_assert (!tmp);
tmp = marked (other);
if (tmp > 0)
unmark (other);
@ -267,7 +271,7 @@ bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
for (auto k = j; k != end; k++) {
const int other = *j++ = *k;
const int tmp = marked (other);
assert (tmp >= 0);
CADICAL_assert (tmp >= 0);
if (tmp)
j--, unmark (other); // remove marked and unmark it
else
@ -298,7 +302,7 @@ bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
bool res = false;
if (first) {
LOG ("all resolution candidates with %d blocked", -lit);
assert (coveror.intersection.empty ());
CADICAL_assert (coveror.intersection.empty ());
cover_push_extension (lit, coveror);
res = true;
} else if (coveror.intersection.empty ()) {
@ -323,7 +327,7 @@ bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
bool Internal::cover_clause (Clause *c, Coveror &coveror) {
require_mode (COVER);
assert (!c->garbage);
CADICAL_assert (!c->garbage);
LOG (c, "trying covered clauses elimination on");
bool satisfied = false;
@ -337,11 +341,11 @@ bool Internal::cover_clause (Clause *c, Coveror &coveror) {
return false;
}
assert (coveror.added.empty ());
assert (coveror.extend.empty ());
assert (coveror.covered.empty ());
CADICAL_assert (coveror.added.empty ());
CADICAL_assert (coveror.extend.empty ());
CADICAL_assert (coveror.covered.empty ());
assert (!level);
CADICAL_assert (!level);
level = 1;
LOG ("assuming literals of candidate clause");
for (const auto &lit : *c) {
@ -379,7 +383,7 @@ bool Internal::cover_clause (Clause *c, Coveror &coveror) {
bool already_pushed = false;
int64_t last_id = 0;
LOG (c, "covered tautological");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
LOG (coveror.extend, "extension = ");
for (const auto &other : coveror.extend) {
if (!prev) {
@ -450,7 +454,7 @@ bool Internal::cover_clause (Clause *c, Coveror &coveror) {
// Backtrack and 'unassign' all literals.
assert (level == 1);
CADICAL_assert (level == 1);
for (const auto &lit : coveror.added)
set_val (lit, 0);
level = 0;
@ -505,12 +509,12 @@ int64_t Internal::cover_round () {
// First connect all clauses and find all not yet tried clauses.
//
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t untried = 0;
#endif
//
for (auto c : clauses) {
assert (!c->frozen);
CADICAL_assert (!c->frozen);
if (c->garbage)
continue;
if (c->redundant)
@ -539,7 +543,7 @@ int64_t Internal::cover_round () {
if (c->covered)
continue;
schedule.push_back (c);
#ifndef QUIET
#ifndef CADICAL_QUIET
untried++;
#endif
}
@ -561,7 +565,7 @@ int64_t Internal::cover_round () {
continue;
if (c->size > opts.covermaxclslim)
continue;
assert (c->covered);
CADICAL_assert (c->covered);
c->covered = false;
schedule.push_back (c);
}
@ -589,7 +593,7 @@ int64_t Internal::cover_round () {
stable_sort (schedule.begin (), schedule.end (),
clause_covered_or_smaller ());
#ifndef QUIET
#ifndef CADICAL_QUIET
const size_t scheduled = schedule.size ();
PHASE ("cover", stats.cover.count,
"scheduled %zd clauses %.0f%% with %" PRId64 " untried %.0f%%",
@ -621,7 +625,7 @@ int64_t Internal::cover_round () {
covered++;
}
#ifndef QUIET
#ifndef CADICAL_QUIET
const size_t remain = schedule.size ();
const size_t tried = scheduled - remain;
PHASE ("cover", stats.cover.count,
@ -687,11 +691,11 @@ bool Internal::cover () {
LOG ("propagating units before covered clause elimination "
"results in empty clause");
learn_empty_clause ();
assert (unsat);
CADICAL_assert (unsat);
}
reset_watches ();
}
assert (unsat || propagated == trail.size ());
CADICAL_assert (unsat || propagated == trail.size ());
int64_t covered = cover_round ();
@ -702,3 +706,5 @@ bool Internal::cover () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// This function determines the next decision variable on the queue, without
@ -65,7 +69,7 @@ int Internal::decide_phase (int idx, bool target) {
phase = phases.saved[idx];
// The following should not be necessary and in some version we had even
// a hard 'COVER' assertion here to check for this. Unfortunately it
// a hard 'COVER' CADICAL_assertion here to check for this. Unfortunately it
// triggered for some users and we could not get to the root cause of
// 'phase' still not being set here. The logic for phase and target
// saving is pretty complex, particularly in combination with local
@ -100,7 +104,7 @@ bool Internal::satisfied () {
return false;
if (num_assigned < (size_t) max_var)
return false;
assert (num_assigned == (size_t) max_var);
CADICAL_assert (num_assigned == (size_t) max_var);
if (propagated < trail.size ())
return false;
size_t assigned = num_assigned;
@ -120,12 +124,12 @@ bool Internal::better_decision (int lit, int other) {
// that not all variables are assigned.
int Internal::decide () {
assert (!satisfied ());
CADICAL_assert (!satisfied ());
START (decide);
int res = 0;
if ((size_t) level < assumptions.size ()) {
const int lit = assumptions[level];
assert (assumed (lit));
CADICAL_assert (assumed (lit));
const signed char tmp = val (lit);
if (tmp < 0) {
LOG ("assumption %d falsified", lit);
@ -147,7 +151,7 @@ int Internal::decide () {
const size_t size_constraint = constraint.size ();
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
unsigned sum = 0;
for (auto lit : constraint)
sum += lit;
@ -172,7 +176,7 @@ int Internal::decide () {
break;
}
assert (!tmp);
CADICAL_assert (!tmp);
LOG ("constraint literal %d unassigned", lit);
if (!unassigned_lit || better_decision (lit, unassigned_lit))
@ -218,10 +222,10 @@ int Internal::decide () {
}
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (auto lit : constraint)
sum -= lit;
assert (!sum); // Checksum of literal should not change!
CADICAL_assert (!sum); // Checksum of literal should not change!
#endif
} else {
@ -250,3 +254,5 @@ int Internal::decide () {
return res;
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::decompose_analyze_binary_chain (DFS *dfs, int from) {
@ -10,7 +14,7 @@ void Internal::decompose_analyze_binary_chain (DFS *dfs, int from) {
Clause *reason = from_dfs.parent;
if (!reason)
return;
assert (reason->size == 2);
CADICAL_assert (reason->size == 2);
mini_chain.push_back (reason->id);
int other = reason->literals[0];
other = other == from ? -reason->literals[1] : -other;
@ -30,7 +34,7 @@ vector<Clause *> Internal::decompose_analyze_binary_clauses (DFS *dfs,
Clause *reason = from_dfs.parent;
while (reason) {
result.push_back (reason);
assert (reason->size == 2);
CADICAL_assert (reason->size == 2);
int other = reason->literals[0];
other = other == from ? -reason->literals[1] : -other;
Flags &f = flags (other);
@ -48,8 +52,8 @@ vector<Clause *> Internal::decompose_analyze_binary_clauses (DFS *dfs,
void Internal::decompose_conflicting_scc_lrat (DFS *dfs, vector<int> &scc) {
if (!lrat)
return;
assert (lrat_chain.empty ());
assert (mini_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (mini_chain.empty ());
for (auto &lit : scc) {
Flags &f = flags (lit);
if (f.seen)
@ -67,10 +71,10 @@ void Internal::decompose_conflicting_scc_lrat (DFS *dfs, vector<int> &scc) {
void Internal::build_lrat_for_clause (
const vector<vector<Clause *>> &dfs_chains, bool invert) {
assert (lrat);
CADICAL_assert (lrat);
LOG ("building chain for not subsumed clause");
assert (lrat_chain.empty ());
assert (sign_marked.empty ());
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (sign_marked.empty ());
// build chain for each replaced literal
for (const auto lit : clause) {
auto other = lit;
@ -82,7 +86,7 @@ void Internal::build_lrat_for_clause (
lrat_chain.push_back (id);
continue;
}
assert (mini_chain.empty ());
CADICAL_assert (mini_chain.empty ());
for (auto p : dfs_chains[vlit (other)]) {
if (marked_decomposed (other))
continue;
@ -116,7 +120,7 @@ void Internal::build_lrat_for_clause (
void Internal::clear_sign_marked_literals () {
LOG ("clearing %zd marked literals", sign_marked.size ());
for (const auto &lit : sign_marked) {
// assert (marked_signed (lit)); violated on purpose in factor
// CADICAL_assert (marked_signed (lit)); violated on purpose in factor
unmark_decomposed (lit);
}
sign_marked.clear ();
@ -136,7 +140,7 @@ bool Internal::decompose_round () {
if (terminated_asynchronously ())
return false;
assert (!level);
CADICAL_assert (!level);
START_SIMPLIFIER (decompose, DECOMP);
@ -158,7 +162,7 @@ bool Internal::decompose_round () {
}
int substituted = 0;
#ifndef QUIET
#ifndef CADICAL_QUIET
int non_trivial_sccs = 0;
int before = active ();
#endif
@ -180,17 +184,17 @@ bool Internal::decompose_round () {
if (dfs[vlit (root)].min == TRAVERSED)
continue; // skip traversed
LOG ("new dfs search starting at root %d", root);
assert (work.empty ());
assert (scc.empty ());
CADICAL_assert (work.empty ());
CADICAL_assert (scc.empty ());
work.push_back (root);
while (!unsat && !work.empty ()) {
int parent = work.back ();
DFS &parent_dfs = dfs[vlit (parent)];
if (parent_dfs.min == TRAVERSED) { // skip traversed
assert (reprs[vlit (parent)]);
CADICAL_assert (reprs[vlit (parent)]);
work.pop_back ();
} else {
assert (!reprs[vlit (parent)]);
CADICAL_assert (!reprs[vlit (parent)]);
// Go over all implied literals, thus need to iterate over all
// binary watched clauses with the negation of 'parent'.
@ -236,12 +240,12 @@ bool Internal::decompose_round () {
// becomes unsatisfiable.
if (lrat) {
assert (analyzed.empty ());
CADICAL_assert (analyzed.empty ());
int other, first = 0;
bool conflicting = false;
size_t j = scc.size ();
do {
assert (j > 0);
CADICAL_assert (j > 0);
other = scc[--j];
if (!first || vlit (other) < vlit (first))
first = other;
@ -256,7 +260,7 @@ bool Internal::decompose_round () {
analyzed.push_back (other);
} while (other != parent);
assert (!conflicting || first > 0);
CADICAL_assert (!conflicting || first > 0);
vector<int> to_justify;
if (conflicting) {
LOG ("conflicting scc simulating up at %d", parent);
@ -287,13 +291,13 @@ bool Internal::decompose_round () {
}
int other, repr = parent;
#ifndef QUIET
#ifndef CADICAL_QUIET
int size = 0;
#endif
assert (!scc.empty ());
CADICAL_assert (!scc.empty ());
size_t j = scc.size ();
do {
assert (j > 0);
CADICAL_assert (j > 0);
other = scc[--j];
if (other == -parent) {
LOG ("both %d and %d in one SCC", parent, -parent);
@ -307,17 +311,17 @@ bool Internal::decompose_round () {
mini_chain.clear ();
}
assign_unit (parent);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
bool ok =
#endif
propagate ();
assert (!ok);
CADICAL_assert (!ok);
learn_empty_clause ();
lrat_chain.clear ();
} else {
if (abs (other) < abs (repr))
repr = other;
#ifndef QUIET
#ifndef CADICAL_QUIET
size++;
#endif
}
@ -325,11 +329,11 @@ bool Internal::decompose_round () {
if (unsat)
break;
#ifndef QUIET
#ifndef CADICAL_QUIET
LOG ("SCC of representative %d of size %d", repr, size);
#endif
do {
assert (!scc.empty ());
CADICAL_assert (!scc.empty ());
other = scc.back ();
scc.pop_back ();
dfs[vlit (other)].min = TRAVERSED;
@ -344,7 +348,7 @@ bool Internal::decompose_round () {
LOG ("literal %d in SCC of %d", other, repr);
if (!lrat)
continue;
assert (mini_chain.empty ());
CADICAL_assert (mini_chain.empty ());
Flags &f = flags (repr);
f.seen = true;
analyzed.push_back (repr);
@ -355,7 +359,7 @@ bool Internal::decompose_round () {
clear_analyzed_literals ();
} while (other != parent);
#ifndef QUIET
#ifndef CADICAL_QUIET
if (size > 1)
non_trivial_sccs++;
#endif
@ -372,7 +376,7 @@ bool Internal::decompose_round () {
} else { // pre-fix
dfs_idx++;
assert (dfs_idx < TRAVERSED);
CADICAL_assert (dfs_idx < TRAVERSED);
parent_dfs.idx = parent_dfs.min = dfs_idx;
scc.push_back (parent);
@ -429,17 +433,17 @@ bool Internal::decompose_round () {
int other = reprs[vlit (idx)];
if (other == idx)
continue;
assert (!flags (other).eliminated ());
assert (!flags (other).substituted ());
CADICAL_assert (!flags (other).eliminated ());
CADICAL_assert (!flags (other).substituted ());
LOG ("marking equivalence of %d and %d", idx, other);
assert (clause.empty ());
assert (lrat_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (lrat_chain.empty ());
clause.push_back (other);
clause.push_back (-idx);
if (lrat) {
build_lrat_for_clause (dfs_chains);
assert (!lrat_chain.empty ());
CADICAL_assert (!lrat_chain.empty ());
}
const int64_t id1 = ++clause_id;
@ -454,13 +458,13 @@ bool Internal::decompose_round () {
lrat_chain.clear ();
clause.clear ();
assert (clause.empty ());
assert (lrat_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (lrat_chain.empty ());
clause.push_back (idx);
clause.push_back (-other);
if (lrat) {
build_lrat_for_clause (dfs_chains);
assert (!lrat_chain.empty ());
CADICAL_assert (!lrat_chain.empty ());
}
const int64_t id2 = ++clause_id;
if (proof) {
@ -480,7 +484,7 @@ bool Internal::decompose_round () {
// should be substituted by their representative.
size_t clauses_size = clauses.size ();
#ifndef QUIET
#ifndef CADICAL_QUIET
size_t garbage = 0, replaced = 0;
#endif
for (size_t i = 0; substituted && !unsat && i < clauses_size; i++) {
@ -497,7 +501,7 @@ bool Internal::decompose_round () {
if (j == size)
continue;
#ifndef QUIET
#ifndef CADICAL_QUIET
replaced++;
#endif
LOG (c, "first substituted literal %d in", substituted);
@ -507,9 +511,9 @@ bool Internal::decompose_round () {
// literal occurs in both phases or is assigned to true the clause is
// satisfied and can be marked as garbage.
assert (clause.empty ());
assert (lrat_chain.empty ());
assert (analyzed.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (analyzed.empty ());
bool satisfied = false;
for (int k = 0; !satisfied && k < size; k++) {
@ -544,7 +548,7 @@ bool Internal::decompose_round () {
if (other == lit)
continue;
int64_t id = decompose_ids[vlit (-lit)];
assert (id);
CADICAL_assert (id);
lrat_chain.push_back (id);
continue;
} else if (tmp > 0)
@ -562,7 +566,7 @@ bool Internal::decompose_round () {
if (!lrat)
continue;
int64_t id = decompose_ids[vlit (-lit)];
assert (id);
CADICAL_assert (id);
lrat_chain.push_back (id);
}
}
@ -574,7 +578,7 @@ bool Internal::decompose_round () {
if (satisfied) {
LOG (c, "satisfied after substitution (postponed)");
postponed_garbage.push_back (c);
#ifndef QUIET
#ifndef CADICAL_QUIET
garbage++;
#endif
} else if (!clause.size ()) {
@ -585,7 +589,7 @@ bool Internal::decompose_round () {
assign_unit (clause[0]);
mark_garbage (c);
new_unit = true;
#ifndef QUIET
#ifndef CADICAL_QUIET
garbage++;
#endif
} else if (c->literals[0] != clause[0] || c->literals[1] != clause[1]) {
@ -594,16 +598,16 @@ bool Internal::decompose_round () {
new_binary_clause = true;
size_t d_clause_idx = clauses.size ();
Clause *d = new_clause_as (c);
assert (clauses[d_clause_idx] == d);
CADICAL_assert (clauses[d_clause_idx] == d);
clauses[d_clause_idx] = c;
clauses[i] = d;
mark_garbage (c);
#ifndef QUIET
#ifndef CADICAL_QUIET
garbage++;
#endif
} else {
LOG ("simply shrinking clause since watches did not change");
assert (c->size > 2);
CADICAL_assert (c->size > 2);
if (!c->redundant)
mark_removed (c);
if (proof) {
@ -624,11 +628,11 @@ bool Internal::decompose_round () {
(void) shrink_clause (c, l);
} else if (likely_to_be_kept_clause (c))
mark_added (c);
// we have shrunken c->size to l so even though there is an assertion
// we have shrunken c->size to l so even though there is an CADICAL_assertion
// for c->size > 2 at the beginning of this else block, the new size
// can be 2 now.
if (c->size == 2) { // cheaper to update only new binary clauses
assert (new_binary_clause);
CADICAL_assert (new_binary_clause);
update_watch_size (watches (c->literals[0]), c->literals[1], c);
update_watch_size (watches (c->literals[1]), c->literals[0], c);
}
@ -637,7 +641,7 @@ bool Internal::decompose_round () {
while (!clause.empty ()) {
int lit = clause.back ();
clause.pop_back ();
assert (marked (lit) > 0);
CADICAL_assert (marked (lit) > 0);
unmark (lit);
}
lrat_chain.clear ();
@ -653,9 +657,9 @@ bool Internal::decompose_round () {
if (!id1)
continue;
int other = reprs[vlit (idx)];
assert (other != idx);
assert (!flags (other).eliminated ());
assert (!flags (other).substituted ());
CADICAL_assert (other != idx);
CADICAL_assert (!flags (other).eliminated ());
CADICAL_assert (!flags (other).substituted ());
clause.push_back (other);
clause.push_back (-idx);
@ -702,8 +706,8 @@ bool Internal::decompose_round () {
int other = reprs[vlit (idx)];
if (other == idx)
continue;
assert (!flags (other).eliminated ());
assert (!flags (other).substituted ());
CADICAL_assert (!flags (other).eliminated ());
CADICAL_assert (!flags (other).substituted ());
if (!flags (other).fixed ())
mark_substituted (idx);
}
@ -731,3 +735,5 @@ void Internal::decompose () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Equivalent literal substitution in 'decompose' and shrinking in 'subsume'
@ -29,8 +33,8 @@ void Internal::mark_duplicated_binary_clauses_as_garbage () {
START_SIMPLIFIER (deduplicate, DEDUP);
stats.deduplications++;
assert (!level);
assert (watching ());
CADICAL_assert (!level);
CADICAL_assert (watching ());
vector<int> stack; // To save marked literals and unmark them later.
@ -49,7 +53,7 @@ void Internal::mark_duplicated_binary_clauses_as_garbage () {
const int lit = sign * idx; // Consider all literals.
assert (stack.empty ());
CADICAL_assert (stack.empty ());
Watches &ws = watches (lit);
// We are removing references to garbage clause. Thus no 'auto'.
@ -81,7 +85,7 @@ void Internal::mark_duplicated_binary_clauses_as_garbage () {
if (!c->redundant) {
watch_iterator k;
for (k = ws.begin ();; k++) {
assert (k != i);
CADICAL_assert (k != i);
if (!k->binary ())
continue;
if (k->blit != other)
@ -109,12 +113,12 @@ void Internal::mark_duplicated_binary_clauses_as_garbage () {
unit = lit;
if (lrat) {
// taken from fradical
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
lrat_chain.push_back (c->id);
// We've forgotten where the other binary clause is, so go find
// it again
for (watch_iterator k = ws.begin ();; k++) {
assert (k != i);
CADICAL_assert (k != i);
if (!k->binary ())
continue;
if (k->blit != -other)
@ -168,3 +172,5 @@ void Internal::mark_duplicated_binary_clauses_as_garbage () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,10 +1,14 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
#define INVALID_LIT UINT_MAX
// functions below are passed to kitten
// functions below are passed to cadical_kitten
//
struct definition_extractor {
Eliminator *eliminator;
@ -17,7 +21,7 @@ struct definition_extractor {
extern "C" {
// used to extract definitions from kitten
// used to extract definitions from cadical_kitten
//
static void traverse_definition_core (void *state, unsigned id) {
definition_extractor *extractor = (definition_extractor *) state;
@ -27,17 +31,17 @@ static void traverse_definition_core (void *state, unsigned id) {
Eliminator *eliminator = extractor->eliminator;
const size_t size_clauses0 = clauses0.size ();
const size_t size_clauses1 = clauses1.size ();
assert (size_clauses0 <= UINT_MAX);
CADICAL_assert (size_clauses0 <= UINT_MAX);
unsigned sign;
assert (id < size_clauses0 + size_clauses1);
CADICAL_assert (id < size_clauses0 + size_clauses1);
if (id < size_clauses0) {
clause = clauses0[id];
sign = 1;
} else {
unsigned tmp = id - size_clauses0;
#ifndef NDEBUG
assert (size_clauses1 <= UINT_MAX);
assert (tmp < size_clauses1);
#ifndef CADICAL_NDEBUG
CADICAL_assert (size_clauses1 <= UINT_MAX);
CADICAL_assert (tmp < size_clauses1);
#endif
clause = clauses1[tmp];
sign = 2;
@ -73,7 +77,7 @@ static void traverse_one_sided_core_lemma (void *state, bool learned,
for (const unsigned *p = lits; p != end; p++)
pc.literals.push_back (internal->citten2lit (*p)); // conversion
proof_clauses.push_back (pc);
assert (proof);
CADICAL_assert (proof);
proof->add_derived_clause (pc.id, true, pc.literals, pc.chain);
} else {
internal->assign_unit (unit);
@ -97,28 +101,28 @@ static void traverse_one_sided_core_lemma_with_lrat (
const vector<Clause *> &clauses0 = extractor->clauses[0];
const vector<Clause *> &clauses1 = extractor->clauses[1];
vector<proof_clause> &proof_clauses = eliminator->proof_clauses;
if (!learned) { // remember clauses for mapping to kitten internal
assert (size);
assert (!chain_size);
if (!learned) { // remember clauses for mapping to cadical_kitten internal
CADICAL_assert (size);
CADICAL_assert (!chain_size);
proof_clause pc;
pc.cid = cid;
pc.learned = false;
const size_t size_clauses0 = clauses0.size ();
assert (size_clauses0 <= UINT_MAX);
CADICAL_assert (size_clauses0 <= UINT_MAX);
if (id < size_clauses0) {
pc.id = clauses0[id]->id;
} else {
unsigned tmp = id - size_clauses0;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
const size_t size_clauses1 = clauses1.size ();
assert (size_clauses1 <= UINT_MAX);
assert (tmp < size_clauses1);
CADICAL_assert (size_clauses1 <= UINT_MAX);
CADICAL_assert (tmp < size_clauses1);
#endif
pc.id = clauses1[tmp]->id;
}
proof_clauses.push_back (pc);
} else { // actually add to proof
assert (chain_size);
CADICAL_assert (chain_size);
if (size) {
proof_clause pc;
pc.id = ++(internal->clause_id);
@ -136,14 +140,14 @@ static void traverse_one_sided_core_lemma_with_lrat (
break;
}
}
assert (id);
CADICAL_assert (id);
pc.chain.push_back (id);
}
proof_clauses.push_back (pc);
assert (proof);
CADICAL_assert (proof);
proof->add_derived_clause (pc.id, true, pc.literals, pc.chain);
} else { // learn unit finish proof
assert (internal->lrat_chain.empty ());
CADICAL_assert (internal->lrat_chain.empty ());
for (const unsigned *p = chain + chain_size; p != chain; p--) {
int64_t id = 0;
for (const auto &cpc : proof_clauses) {
@ -152,11 +156,11 @@ static void traverse_one_sided_core_lemma_with_lrat (
break;
}
}
assert (id);
CADICAL_assert (id);
internal->lrat_chain.push_back (id);
}
internal->assign_unit (unit);
assert (internal->lrat_chain.empty ());
CADICAL_assert (internal->lrat_chain.empty ());
for (const auto &pc : proof_clauses) {
if (pc.learned)
proof->delete_clause (pc.id, true, pc.literals);
@ -171,8 +175,8 @@ static void traverse_one_sided_core_lemma_with_lrat (
// Code ported from kissat. Kitten (and kissat) use unsigned representation
// for literals whereas CaDiCaL uses signed representation. Conversion is
// necessary for communication using lit2citten and citten2lit.
// This code is called in elim and kitten is initialized beforehand.
// To avoid confusion all cadical interal definitions with kitten are called
// This code is called in elim and cadical_kitten is initialized beforehand.
// To avoid confusion all cadical interal definitions with cadical_kitten are called
// citten.
//
void Internal::find_definition (Eliminator &eliminator, int lit) {
@ -184,9 +188,9 @@ void Internal::find_definition (Eliminator &eliminator, int lit) {
return;
if (!eliminator.gates.empty ())
return;
assert (!val (lit));
assert (!level);
assert (citten);
CADICAL_assert (!val (lit));
CADICAL_assert (!level);
CADICAL_assert (citten);
const int not_lit = -lit;
definition_extractor extractor;
extractor.lit = lit;
@ -200,9 +204,9 @@ void Internal::find_definition (Eliminator &eliminator, int lit) {
const unsigned except = sign ? lit2citten (not_lit) : lit2citten (lit);
for (auto c : extractor.clauses[sign]) {
// to avoid copying the literals of c in their unsigned
// representation we instead implement the translation in kitten
// representation we instead implement the translation in cadical_kitten
if (!c->garbage) {
LOG (c, "adding to kitten");
LOG (c, "adding to cadical_kitten");
citten_clause_with_id_and_exception (citten, exported, c->size,
c->literals, except);
}
@ -211,42 +215,42 @@ void Internal::find_definition (Eliminator &eliminator, int lit) {
}
stats.definitions_checked++;
const size_t limit = opts.elimdefticks;
kitten_set_ticks_limit (citten, limit);
int status = kitten_solve (citten);
cadical_kitten_set_ticks_limit (citten, limit);
int status = cadical_kitten_solve (citten);
if (!exported)
goto ABORT;
if (status == 20) {
LOG ("sub-solver result UNSAT shows definition exists");
uint64_t learned;
unsigned reduced = kitten_compute_clausal_core (citten, &learned);
unsigned reduced = cadical_kitten_compute_clausal_core (citten, &learned);
LOG ("1st sub-solver core of size %u original clauses out of %u",
reduced, exported);
for (int i = 2; i <= opts.elimdefcores; i++) {
kitten_shrink_to_clausal_core (citten);
kitten_shuffle_clauses (citten);
kitten_set_ticks_limit (citten, 10 * limit);
int tmp = kitten_solve (citten);
assert (!tmp || tmp == 20);
cadical_kitten_shrink_to_clausal_core (citten);
cadical_kitten_shuffle_clauses (citten);
cadical_kitten_set_ticks_limit (citten, 10 * limit);
int tmp = cadical_kitten_solve (citten);
CADICAL_assert (!tmp || tmp == 20);
if (!tmp) {
LOG ("aborting core extraction");
goto ABORT;
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
unsigned previous = reduced;
#endif
reduced = kitten_compute_clausal_core (citten, &learned);
reduced = cadical_kitten_compute_clausal_core (citten, &learned);
LOG ("%d sub-solver core of size %u original clauses out of %u", i,
reduced, exported);
assert (reduced <= previous);
#if not defined(LOGGING) && defined(NDEBUG)
CADICAL_assert (reduced <= previous);
#if not defined(LOGGING) && defined(CADICAL_NDEBUG)
(void) reduced;
#endif
}
stats.definitions_extracted++;
eliminator.gatetype = DEF;
eliminator.definition_unit = 0;
kitten_traverse_core_ids (citten, &extractor, traverse_definition_core);
assert (eliminator.definition_unit);
cadical_kitten_traverse_core_ids (citten, &extractor, traverse_definition_core);
CADICAL_assert (eliminator.definition_unit);
int unit = 0;
if (eliminator.definition_unit == 2) {
unit = not_lit;
@ -261,11 +265,11 @@ void Internal::find_definition (Eliminator &eliminator, int lit) {
if (proof) {
if (lrat) {
extractor.unit = unit;
kitten_trace_core (citten, &extractor,
cadical_kitten_trace_core (citten, &extractor,
traverse_one_sided_core_lemma_with_lrat);
} else {
extractor.unit = unit;
kitten_traverse_core_clauses (citten, &extractor,
cadical_kitten_traverse_core_clauses (citten, &extractor,
traverse_one_sided_core_lemma);
}
} else
@ -276,8 +280,10 @@ void Internal::find_definition (Eliminator &eliminator, int lit) {
ABORT:
LOG ("sub-solver failed to show that definition exists");
}
stats.definition_ticks += kitten_current_ticks (citten);
stats.definition_ticks += cadical_kitten_current_ticks (citten);
return;
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,12 +1,16 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
DratTracer::DratTracer (Internal *i, File *f, bool b)
: internal (i), file (f), binary (b)
#ifndef QUIET
#ifndef CADICAL_QUIET
,
added (0), deleted (0)
#endif
@ -28,17 +32,17 @@ DratTracer::~DratTracer () {
/*------------------------------------------------------------------------*/
inline void DratTracer::put_binary_zero () {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
file->put ((unsigned char) 0);
}
inline void DratTracer::put_binary_lit (int lit) {
assert (binary);
assert (file);
assert (lit != INT_MIN);
CADICAL_assert (binary);
CADICAL_assert (file);
CADICAL_assert (lit != INT_MIN);
unsigned idx = abs (lit);
assert (idx < (1u << 31));
CADICAL_assert (idx < (1u << 31));
unsigned x = 2u * idx + (lit < 0);
unsigned char ch;
while (x & ~0x7f) {
@ -90,7 +94,7 @@ void DratTracer::add_derived_clause (int64_t, bool,
return;
LOG ("DRAT TRACER tracing addition of derived clause");
drat_add_clause (clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
added++;
#endif
}
@ -100,7 +104,7 @@ void DratTracer::delete_clause (int64_t, bool, const vector<int> &clause) {
return;
LOG ("DRAT TRACER tracing deletion of clause");
drat_delete_clause (clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
deleted++;
#endif
}
@ -109,7 +113,7 @@ void DratTracer::delete_clause (int64_t, bool, const vector<int> &clause) {
bool DratTracer::closed () { return file->closed (); }
#ifndef QUIET
#ifndef CADICAL_QUIET
void DratTracer::print_statistics () {
uint64_t bytes = file->bytes ();
@ -125,9 +129,9 @@ void DratTracer::print_statistics () {
#endif
void DratTracer::close (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->close ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("DRAT proof file '%s' closed", file->name ());
print_statistics ();
@ -138,9 +142,9 @@ void DratTracer::close (bool print) {
}
void DratTracer::flush (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->flush ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("DRAT proof file '%s' flushed", file->name ());
print_statistics ();
@ -151,3 +155,5 @@ void DratTracer::flush (bool print) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -19,7 +23,7 @@ namespace CaDiCaL {
/*------------------------------------------------------------------------*/
inline double Internal::compute_elim_score (unsigned lit) {
assert (1 <= lit), assert (lit <= (unsigned) max_var);
CADICAL_assert (1 <= lit), CADICAL_assert (lit <= (unsigned) max_var);
const unsigned uidx = 2 * lit;
const double pos = internal->ntab[uidx];
const double neg = internal->ntab[uidx + 1];
@ -65,7 +69,7 @@ bool Internal::ineliminating () {
if (!preprocessing && !opts.inprocessing)
return false;
if (preprocessing)
assert (lim.preprocessing);
CADICAL_assert (lim.preprocessing);
// Respect (increasing) conflict limit.
//
@ -90,7 +94,7 @@ bool Internal::ineliminating () {
void Internal::elim_update_added_clause (Eliminator &eliminator,
Clause *c) {
assert (!c->redundant);
CADICAL_assert (!c->redundant);
ElimSchedule &schedule = eliminator.schedule;
for (const auto &lit : *c) {
if (!active (lit))
@ -111,7 +115,7 @@ void Internal::elim_update_removed_lit (Eliminator &eliminator, int lit) {
if (frozen (lit))
return;
int64_t &score = noccs (lit);
assert (score > 0);
CADICAL_assert (score > 0);
score--;
const int idx = abs (lit);
ElimSchedule &schedule = eliminator.schedule;
@ -125,11 +129,11 @@ void Internal::elim_update_removed_lit (Eliminator &eliminator, int lit) {
void Internal::elim_update_removed_clause (Eliminator &eliminator,
Clause *c, int except) {
assert (!c->redundant);
CADICAL_assert (!c->redundant);
for (const auto &lit : *c) {
if (lit == except)
continue;
assert (lit != -except);
CADICAL_assert (lit != -except);
elim_update_removed_lit (eliminator, lit);
}
}
@ -141,14 +145,14 @@ void Internal::elim_update_removed_clause (Eliminator &eliminator,
// and also marks clauses satisfied by those units as garbage immediately.
void Internal::elim_propagate (Eliminator &eliminator, int root) {
assert (val (root) > 0);
CADICAL_assert (val (root) > 0);
vector<int> work;
size_t i = 0;
work.push_back (root);
while (i < work.size ()) {
int lit = work[i++];
LOG ("elimination propagation of %d", lit);
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
const Occs &ns = occs (-lit);
for (const auto &c : ns) {
if (c->garbage)
@ -212,12 +216,12 @@ void Internal::elim_on_the_fly_self_subsumption (Eliminator &eliminator,
LOG (c, "pivot %d on-the-fly self-subsuming resolution", pivot);
stats.elimotfstr++;
stats.strengthened++;
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (const auto &lit : *c) {
if (lit == pivot)
continue;
const signed char tmp = val (lit);
assert (tmp <= 0);
CADICAL_assert (tmp <= 0);
if (tmp < 0)
continue;
clause.push_back (lit);
@ -266,8 +270,8 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
int pivot, Clause *d,
const bool propagate_eagerly) {
assert (!c->redundant);
assert (!d->redundant);
CADICAL_assert (!c->redundant);
CADICAL_assert (!d->redundant);
stats.elimres++;
@ -278,8 +282,8 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
swap (c, d);
}
assert (!level);
assert (clause.empty ());
CADICAL_assert (!level);
CADICAL_assert (clause.empty ());
int satisfied = 0; // Contains this satisfying literal.
int tautological = 0; // Clashing literal if tautological.
@ -295,7 +299,7 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
s++;
continue;
}
assert (lit != -pivot);
CADICAL_assert (lit != -pivot);
const signed char tmp = val (lit);
if (tmp > 0) {
satisfied = lit;
@ -334,7 +338,7 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
t++;
continue;
}
assert (lit != pivot);
CADICAL_assert (lit != pivot);
signed char tmp = val (lit);
if (tmp > 0) {
satisfied = lit;
@ -356,7 +360,7 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
} else if (!tmp)
clause.push_back (lit), t++;
else
assert (tmp > 0), t++;
CADICAL_assert (tmp > 0), t++;
}
clear_analyzed_literals ();
@ -405,15 +409,15 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
}
LOG (clause, "resolvent");
assert (!lrat || !lrat_chain.empty ());
CADICAL_assert (!lrat || !lrat_chain.empty ());
// Double self-subsuming resolution. The clauses 'c' and 'd' are
// identical except for the pivot which occurs in different phase. The
// resolvent subsumes both antecedents.
if (s > size && t > size) {
assert (s == size + 1);
assert (t == size + 1);
CADICAL_assert (s == size + 1);
CADICAL_assert (t == size + 1);
clause.clear ();
// LRAT is c + d (+ eventual units)
elim_on_the_fly_self_subsumption (eliminator, c, pivot);
@ -430,7 +434,7 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
// with 'pivot' removed and then marking 'c' as garbage.
if (s > size) {
assert (s == size + 1);
CADICAL_assert (s == size + 1);
clause.clear ();
// LRAT is c + d (+ eventual units)
elim_on_the_fly_self_subsumption (eliminator, c, pivot);
@ -440,7 +444,7 @@ bool Internal::resolve_clauses (Eliminator &eliminator, Clause *c,
// Same single self-subsuming resolution situation, but only for 'd'.
if (t > size) {
assert (t == size + 1);
CADICAL_assert (t == size + 1);
clause.clear ();
// LRAT is c + d (+ eventual units) -> same.
elim_on_the_fly_self_subsumption (eliminator, d, -pivot);
@ -469,8 +473,8 @@ bool Internal::elim_resolvents_are_bounded (Eliminator &eliminator,
stats.elimtried++;
assert (!unsat);
assert (active (pivot));
CADICAL_assert (!unsat);
CADICAL_assert (active (pivot));
const Occs &ps = occs (pivot);
const Occs &ns = occs (-pivot);
@ -492,11 +496,11 @@ bool Internal::elim_resolvents_are_bounded (Eliminator &eliminator,
int64_t resolvents = 0; // Non-tautological resolvents.
for (const auto &c : ps) {
assert (!c->redundant);
CADICAL_assert (!c->redundant);
if (c->garbage)
continue;
for (const auto &d : ns) {
assert (!d->redundant);
CADICAL_assert (!d->redundant);
if (d->garbage)
continue;
if (!resolve_gates && substitute && c->gate == d->gate)
@ -562,13 +566,13 @@ inline void Internal::elim_add_resolvents (Eliminator &eliminator,
stats.eliminated_def++;
break;
default:
assert (eliminator.gatetype == NO);
CADICAL_assert (eliminator.gatetype == NO);
}
LOG ("adding all resolvents on %d", pivot);
assert (!val (pivot));
assert (!flags (pivot).eliminated ());
CADICAL_assert (!val (pivot));
CADICAL_assert (!flags (pivot).eliminated ());
const Occs &ps = occs (pivot);
const Occs &ns = occs (-pivot);
@ -589,7 +593,7 @@ inline void Internal::elim_add_resolvents (Eliminator &eliminator,
continue;
if (!resolve_clauses (eliminator, c, pivot, d, false))
continue;
assert (!lrat || !lrat_chain.empty ());
CADICAL_assert (!lrat || !lrat_chain.empty ());
Clause *r = new_resolved_irredundant_clause ();
elim_update_added_clause (eliminator, r);
eliminator.enqueue (r);
@ -611,28 +615,28 @@ inline void Internal::elim_add_resolvents (Eliminator &eliminator,
void Internal::mark_eliminated_clauses_as_garbage (
Eliminator &eliminator, int pivot, bool &deleted_binary_clause) {
assert (!unsat);
CADICAL_assert (!unsat);
LOG ("marking irredundant clauses with %d as garbage", pivot);
const int64_t substitute = eliminator.gates.size ();
if (substitute)
LOG ("pushing %" PRId64 " gate clauses on extension stack", substitute);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
int64_t pushed = 0;
#endif
Occs &ps = occs (pivot);
for (const auto &c : ps) {
if (c->garbage)
continue;
assert (!c->redundant);
CADICAL_assert (!c->redundant);
if (!substitute || c->gate) {
if (proof)
proof->weaken_minus (c);
if (c->size == 2)
deleted_binary_clause = true;
external->push_clause_on_extension_stack (c, pivot);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
pushed++;
#endif
}
@ -647,14 +651,14 @@ void Internal::mark_eliminated_clauses_as_garbage (
for (const auto &d : ns) {
if (d->garbage)
continue;
assert (!d->redundant);
CADICAL_assert (!d->redundant);
if (!substitute || d->gate) {
if (proof)
proof->weaken_minus (d);
if (d->size == 2)
deleted_binary_clause = true;
external->push_clause_on_extension_stack (d, -pivot);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
pushed++;
#endif
}
@ -664,7 +668,7 @@ void Internal::mark_eliminated_clauses_as_garbage (
erase_occs (ns);
if (substitute)
assert (pushed <= substitute);
CADICAL_assert (pushed <= substitute);
// Unfortunately, we can not use the trick by Niklas Soerensson anymore,
// which avoids saving all clauses on the extension stack. This would
@ -679,7 +683,7 @@ void Internal::try_to_eliminate_variable (Eliminator &eliminator, int pivot,
if (!active (pivot))
return;
assert (!frozen (pivot));
CADICAL_assert (!frozen (pivot));
// First flush garbage clauses.
//
@ -693,17 +697,17 @@ void Internal::try_to_eliminate_variable (Eliminator &eliminator, int pivot,
LOG ("pivot %d occurs positively %" PRId64
" times and negatively %" PRId64 " times",
pivot, pos, neg);
assert (!eliminator.schedule.contains (abs (pivot)));
assert (pos <= neg);
CADICAL_assert (!eliminator.schedule.contains (abs (pivot)));
CADICAL_assert (pos <= neg);
if (pos && neg > opts.elimocclim) {
LOG ("too many occurrences thus not eliminated %d", pivot);
assert (!eliminator.schedule.contains (abs (pivot)));
CADICAL_assert (!eliminator.schedule.contains (abs (pivot)));
return;
}
LOG ("trying to eliminate %d", pivot);
assert (!flags (pivot).eliminated ());
CADICAL_assert (!flags (pivot).eliminated ());
// Sort occurrence lists, such that shorter clauses come first.
Occs &ps = occs (pivot);
@ -766,15 +770,15 @@ void Internal::
int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
assert (opts.elim);
assert (!unsat);
CADICAL_assert (opts.elim);
CADICAL_assert (!unsat);
START_SIMPLIFIER (elim, ELIM);
stats.elimrounds++;
int64_t marked_before = last.elim.marked;
last.elim.marked = stats.mark.elim;
assert (!level);
CADICAL_assert (!level);
int64_t resolution_limit;
@ -813,7 +817,7 @@ int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
else if (tmp < 0)
falsified = true;
else
assert (active (lit));
CADICAL_assert (active (lit));
}
if (satisfied)
mark_garbage (c); // forces more precise counts
@ -832,7 +836,7 @@ int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
Eliminator eliminator (this);
ElimSchedule &schedule = eliminator.schedule;
assert (schedule.empty ());
CADICAL_assert (schedule.empty ());
// Now find elimination candidates which occurred in clauses removed since
// the last time we ran bounded variable elimination, which in turned
@ -851,7 +855,7 @@ int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
schedule.shrink ();
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t scheduled = schedule.size ();
#endif
@ -867,7 +871,7 @@ int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
if (active (lit))
occs (lit).push_back (c);
#ifndef QUIET
#ifndef CADICAL_QUIET
const int64_t old_resolutions = stats.elimres;
#endif
const int old_eliminated = stats.all.eliminated;
@ -882,7 +886,7 @@ int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
// schedule is updated dynamically and variables are potentially
// rescheduled to be tried again if they occur in a removed clause.
//
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t tried = 0;
#endif
while (!unsat && !terminated_asynchronously () &&
@ -891,7 +895,7 @@ int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
schedule.pop_front ();
flags (idx).elim = false;
try_to_eliminate_variable (eliminator, idx, deleted_binary_clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
tried++;
#endif
if (stats.garbage.literals <= garbage_limit)
@ -931,7 +935,7 @@ int Internal::elim_round (bool &completed, bool &deleted_binary_clause) {
mark_redundant_clauses_with_eliminated_variables_as_garbage ();
int eliminated = stats.all.eliminated - old_eliminated;
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t resolutions = stats.elimres - old_resolutions;
PHASE ("elim-round", stats.elimrounds,
"eliminated %d variables %.0f%% in %" PRId64 " resolutions",
@ -1000,13 +1004,13 @@ void Internal::increase_elimination_bound () {
void Internal::init_citten () {
if (!opts.elimdef)
return;
assert (!citten);
citten = kitten_init ();
CADICAL_assert (!citten);
citten = cadical_kitten_init ();
}
void Internal::reset_citten () {
if (citten) {
kitten_release (citten);
cadical_kitten_release (citten);
citten = 0;
}
}
@ -1029,11 +1033,11 @@ void Internal::elim (bool update_limits) {
"starting at most %d elimination rounds", opts.elimrounds);
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = true;
}
#ifndef QUIET
#ifndef CADICAL_QUIET
int old_active_variables = active ();
int old_eliminated = stats.all.eliminated;
#endif
@ -1062,13 +1066,13 @@ void Internal::elim (bool update_limits) {
bool phase_complete = false, deleted_binary_clause = false;
int round = 1;
#ifndef QUIET
#ifndef CADICAL_QUIET
int eliminated = 0;
#endif
bool round_complete = false;
while (!unsat && !phase_complete && !terminated_asynchronously ()) {
#ifndef QUIET
#ifndef CADICAL_QUIET
int eliminated =
#endif
elim_round (round_complete, deleted_binary_clause);
@ -1076,7 +1080,7 @@ void Internal::elim (bool update_limits) {
if (!round_complete) {
PHASE ("elim-phase", stats.elimphases, "last round %d incomplete %s",
round, eliminated ? "but successful" : "and unsuccessful");
assert (!phase_complete);
CADICAL_assert (!phase_complete);
break;
}
@ -1085,7 +1089,7 @@ void Internal::elim (bool update_limits) {
round - 1,
eliminated ? "though last round successful"
: "last round unsuccessful anyhow");
assert (!phase_complete);
CADICAL_assert (!phase_complete);
break;
}
@ -1105,7 +1109,7 @@ void Internal::elim (bool update_limits) {
PHASE ("elim-phase", stats.elimphases,
"no new variable elimination candidates");
assert (round_complete);
CADICAL_assert (round_complete);
phase_complete = true;
}
@ -1145,14 +1149,14 @@ void Internal::elim (bool update_limits) {
if (phase_complete)
increase_elimination_bound ();
#ifndef QUIET
#ifndef CADICAL_QUIET
eliminated = stats.all.eliminated - old_eliminated;
PHASE ("elim-phase", stats.elimphases, "eliminated %d variables %.2f%%",
eliminated, percent (eliminated, old_active_variables));
#endif
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = false;
}
@ -1170,3 +1174,5 @@ void Internal::elim (bool update_limits) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -30,7 +34,7 @@ int64_t Internal::flush_elimfast_occs (int lit) {
break;
}
if (++res > occslim) {
assert (opts.fastelimbound < 0 || res == failed);
CADICAL_assert (opts.fastelimbound < 0 || res == failed);
break;
}
}
@ -54,13 +58,13 @@ int64_t Internal::flush_elimfast_occs (int lit) {
bool Internal::elimfast_resolvents_are_bounded (Eliminator &eliminator,
int pivot) {
assert (eliminator.gates.empty ());
assert (!eliminator.definition_unit);
CADICAL_assert (eliminator.gates.empty ());
CADICAL_assert (!eliminator.definition_unit);
stats.elimtried++;
assert (!unsat);
assert (active (pivot));
CADICAL_assert (!unsat);
CADICAL_assert (active (pivot));
const Occs &ps = occs (pivot);
const Occs &ns = occs (-pivot);
@ -95,11 +99,11 @@ bool Internal::elimfast_resolvents_are_bounded (Eliminator &eliminator,
int64_t resolvents = 0; // Non-tautological resolvents.
for (const auto &c : ps) {
assert (!c->redundant);
CADICAL_assert (!c->redundant);
if (c->garbage)
continue;
for (const auto &d : ns) {
assert (!d->redundant);
CADICAL_assert (!d->redundant);
if (d->garbage)
continue;
if (resolve_clauses (eliminator, c, pivot, d, true)) {
@ -139,13 +143,13 @@ bool Internal::elimfast_resolvents_are_bounded (Eliminator &eliminator,
inline void Internal::elimfast_add_resolvents (Eliminator &eliminator,
int pivot) {
assert (eliminator.gates.empty ());
assert (!eliminator.definition_unit);
CADICAL_assert (eliminator.gates.empty ());
CADICAL_assert (!eliminator.definition_unit);
LOG ("adding all resolvents on %d", pivot);
assert (!val (pivot));
assert (!flags (pivot).eliminated ());
CADICAL_assert (!val (pivot));
CADICAL_assert (!flags (pivot).eliminated ());
const Occs &ps = occs (pivot);
const Occs &ns = occs (-pivot);
@ -164,7 +168,7 @@ inline void Internal::elimfast_add_resolvents (Eliminator &eliminator,
continue;
if (!resolve_clauses (eliminator, c, pivot, d, false))
continue;
assert (!lrat || !lrat_chain.empty ());
CADICAL_assert (!lrat || !lrat_chain.empty ());
Clause *r = new_resolved_irredundant_clause ();
elim_update_added_clause (eliminator, r);
eliminator.enqueue (r);
@ -188,7 +192,7 @@ void Internal::try_to_fasteliminate_variable (Eliminator &eliminator,
if (!active (pivot))
return;
assert (!frozen (pivot));
CADICAL_assert (!frozen (pivot));
// First flush garbage clauses and check limits.
@ -197,14 +201,14 @@ void Internal::try_to_fasteliminate_variable (Eliminator &eliminator,
int64_t pos = flush_elimfast_occs (pivot);
if (pos > bound) {
LOG ("too many occurrences thus not eliminated %d", pivot);
assert (!eliminator.schedule.contains (abs (pivot)));
CADICAL_assert (!eliminator.schedule.contains (abs (pivot)));
return;
}
int64_t neg = flush_elimfast_occs (-pivot);
if (neg > bound) {
LOG ("too many occurrences thus not eliminated %d", -pivot);
assert (!eliminator.schedule.contains (abs (pivot)));
CADICAL_assert (!eliminator.schedule.contains (abs (pivot)));
return;
}
@ -222,11 +226,11 @@ void Internal::try_to_fasteliminate_variable (Eliminator &eliminator,
" times and negatively %" PRId64 " times",
pivot, pos, neg);
assert (!eliminator.schedule.contains (abs (pivot)));
assert (pos <= neg);
CADICAL_assert (!eliminator.schedule.contains (abs (pivot)));
CADICAL_assert (pos <= neg);
LOG ("trying to eliminate %d", pivot);
assert (!flags (pivot).eliminated ());
CADICAL_assert (!flags (pivot).eliminated ());
// Sort occurrence lists, such that shorter clauses come first.
Occs &ps = occs (pivot);
@ -264,14 +268,14 @@ void Internal::try_to_fasteliminate_variable (Eliminator &eliminator,
int Internal::elimfast_round (bool &completed,
bool &deleted_binary_clause) {
assert (opts.fastelim);
assert (!unsat);
CADICAL_assert (opts.fastelim);
CADICAL_assert (!unsat);
START_SIMPLIFIER (fastelim, ELIM);
stats.elimfastrounds++;
assert (!level);
CADICAL_assert (!level);
int64_t resolution_limit;
@ -310,7 +314,7 @@ int Internal::elimfast_round (bool &completed,
else if (tmp < 0)
falsified = true;
else
assert (active (lit));
CADICAL_assert (active (lit));
}
if (satisfied)
mark_garbage (c); // forces more precise counts
@ -329,7 +333,7 @@ int Internal::elimfast_round (bool &completed,
Eliminator eliminator (this);
ElimSchedule &schedule = eliminator.schedule;
assert (schedule.empty ());
CADICAL_assert (schedule.empty ());
// Now find elimination candidates which occurred in clauses removed since
// the last time we ran bounded variable elimination, which in turned
@ -348,7 +352,7 @@ int Internal::elimfast_round (bool &completed,
schedule.shrink ();
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t scheduled = schedule.size ();
#endif
@ -364,7 +368,7 @@ int Internal::elimfast_round (bool &completed,
if (active (lit))
occs (lit).push_back (c);
#ifndef QUIET
#ifndef CADICAL_QUIET
const int64_t old_resolutions = stats.elimres;
#endif
const int old_eliminated = stats.all.eliminated;
@ -379,7 +383,7 @@ int Internal::elimfast_round (bool &completed,
// schedule is updated dynamically and variables are potentially
// rescheduled to be tried again if they occur in a removed clause.
//
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t tried = 0;
#endif
while (!unsat && !terminated_asynchronously () &&
@ -388,7 +392,7 @@ int Internal::elimfast_round (bool &completed,
schedule.pop_front ();
flags (idx).elim = false;
try_to_fasteliminate_variable (eliminator, idx, deleted_binary_clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
tried++;
#endif
if (stats.garbage.literals <= garbage_limit)
@ -419,7 +423,7 @@ int Internal::elimfast_round (bool &completed,
int eliminated = stats.all.eliminated - old_eliminated;
stats.all.fasteliminated += eliminated;
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t resolutions = stats.elimres - old_resolutions;
PHASE ("fastelim-round", stats.elimfastrounds,
"eliminated %d variables %.0f%% in %" PRId64 " resolutions",
@ -451,11 +455,11 @@ void Internal::elimfast () {
"starting at most %d elimination rounds", opts.fastelimrounds);
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = true;
}
#ifndef QUIET
#ifndef CADICAL_QUIET
int old_active_variables = active ();
int old_eliminated = stats.all.eliminated;
#endif
@ -476,13 +480,13 @@ void Internal::elimfast () {
bool phase_complete = false, deleted_binary_clause = false;
int round = 1;
#ifndef QUIET
#ifndef CADICAL_QUIET
int eliminated = 0;
#endif
bool round_complete = false;
while (!unsat && !phase_complete && !terminated_asynchronously ()) {
#ifndef QUIET
#ifndef CADICAL_QUIET
int eliminated =
#endif
elimfast_round (round_complete, deleted_binary_clause);
@ -491,7 +495,7 @@ void Internal::elimfast () {
PHASE ("fastelim-phase", stats.elimphases,
"last round %d incomplete %s", round,
eliminated ? "but successful" : "and unsuccessful");
assert (!phase_complete);
CADICAL_assert (!phase_complete);
break;
}
@ -500,7 +504,7 @@ void Internal::elimfast () {
round - 1,
eliminated ? "though last round successful"
: "last round unsuccessful anyhow");
assert (!phase_complete);
CADICAL_assert (!phase_complete);
break;
}
@ -516,7 +520,7 @@ void Internal::elimfast () {
PHASE ("fastelim-phase", stats.elimphases,
"no new variable elimination candidates");
assert (round_complete);
CADICAL_assert (round_complete);
phase_complete = true;
}
@ -554,7 +558,7 @@ void Internal::elimfast () {
}
}
#ifndef QUIET
#ifndef CADICAL_QUIET
eliminated = stats.all.eliminated - old_eliminated;
PHASE ("fastelim-phase", stats.elimphases,
"eliminated %d variables %.2f%%", eliminated,
@ -562,9 +566,11 @@ void Internal::elimfast () {
#endif
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = false;
}
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Updating an exponential moving average is placed here since we want to
@ -70,10 +74,10 @@ void EMA::update (Internal *internal, double y, const char *name) {
double new_exp, div, new_value;
if (old_exp) {
new_exp = old_exp * beta;
assert (new_exp < 1);
CADICAL_assert (new_exp < 1);
exp = new_exp;
div = 1 - new_exp;
assert (div > 0);
CADICAL_assert (div > 0);
new_value = new_biased / div;
} else {
new_value = new_biased;
@ -93,3 +97,5 @@ void EMA::update (Internal *internal, double y, const char *name) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void External::push_zero_on_extension_stack () {
@ -16,18 +20,18 @@ void External::push_id_on_extension_stack (int64_t id) {
}
void External::push_clause_literal_on_extension_stack (int ilit) {
assert (ilit);
CADICAL_assert (ilit);
const int elit = internal->externalize (ilit);
assert (elit);
CADICAL_assert (elit);
extension.push_back (elit);
LOG ("pushing clause literal %d on extension stack (internal %d)", elit,
ilit);
}
void External::push_witness_literal_on_extension_stack (int ilit) {
assert (ilit);
CADICAL_assert (ilit);
const int elit = internal->externalize (ilit);
assert (elit);
CADICAL_assert (elit);
extension.push_back (elit);
LOG ("pushing witness literal %d on extension stack (internal %d)", elit,
ilit);
@ -77,10 +81,10 @@ void External::push_binary_clause_on_extension_stack (int64_t id, int pivot,
void External::push_external_clause_and_witness_on_extension_stack (
const vector<int> &c, const vector<int> &w, int64_t id) {
assert (id);
CADICAL_assert (id);
extension.push_back (0);
for (const auto &elit : w) {
assert (elit != INT_MIN);
CADICAL_assert (elit != INT_MIN);
init (abs (elit));
extension.push_back (elit);
mark (witness, elit);
@ -92,7 +96,7 @@ void External::push_external_clause_and_witness_on_extension_stack (
extension.push_back (lower_bits);
extension.push_back (0);
for (const auto &elit : c) {
assert (elit != INT_MIN);
CADICAL_assert (elit != INT_MIN);
init (abs (elit));
extension.push_back (elit);
}
@ -112,7 +116,7 @@ void External::push_external_clause_and_witness_on_extension_stack (
void External::extend () {
assert (!extended);
CADICAL_assert (!extended);
START (extend);
internal->stats.extensions++;
@ -120,7 +124,7 @@ void External::extend () {
"mapping internal %d assignments to %d assignments",
internal->max_var, max_var);
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t updated = 0;
#endif
for (unsigned i = 1; i <= (unsigned) max_var; i++) {
@ -130,7 +134,7 @@ void External::extend () {
if (i >= vals.size ())
vals.resize (i + 1, false);
vals[i] = (internal->val (ilit) > 0);
#ifndef QUIET
#ifndef CADICAL_QUIET
updated++;
#endif
}
@ -141,50 +145,50 @@ void External::extend () {
extension.size ());
const auto begin = extension.begin ();
auto i = extension.end ();
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t flipped = 0;
#endif
while (i != begin) {
bool satisfied = false;
int lit;
assert (i != begin);
CADICAL_assert (i != begin);
while ((lit = *--i)) {
if (satisfied)
continue;
if (ival (lit) == lit)
satisfied = true;
assert (i != begin);
CADICAL_assert (i != begin);
}
assert (i != begin);
CADICAL_assert (i != begin);
LOG ("id=%" PRId64, ((int64_t) *i << 32) + *(i - 1));
assert (*i || *(i - 1));
CADICAL_assert (*i || *(i - 1));
--i;
assert (i != begin);
CADICAL_assert (i != begin);
--i;
assert (i != begin);
assert (!*i);
CADICAL_assert (i != begin);
CADICAL_assert (!*i);
--i;
assert (i != begin);
CADICAL_assert (i != begin);
if (satisfied)
while (*--i)
assert (i != begin);
CADICAL_assert (i != begin);
else {
while ((lit = *--i)) {
const int tmp = ival (lit); // not 'signed char'!!!
if (tmp != lit) {
LOG ("flipping blocking literal %d", lit);
assert (lit);
assert (lit != INT_MIN);
CADICAL_assert (lit);
CADICAL_assert (lit != INT_MIN);
size_t idx = abs (lit);
if (idx >= vals.size ())
vals.resize (idx + 1, false);
vals[idx] = !vals[idx];
internal->stats.extended++;
#ifndef QUIET
#ifndef CADICAL_QUIET
flipped++;
#endif
}
assert (i != begin);
CADICAL_assert (i != begin);
}
}
}
@ -207,14 +211,14 @@ bool External::traverse_witnesses_backward (WitnessIterator &it) {
int lit;
while ((lit = *--i))
clause.push_back (lit);
assert (!lit);
CADICAL_assert (!lit);
--i;
const int64_t id =
((int64_t) * (i - 1) << 32) + static_cast<int64_t> (*i);
assert (id);
CADICAL_assert (id);
i -= 2;
assert (!*i);
assert (i != begin);
CADICAL_assert (!*i);
CADICAL_assert (i != begin);
while ((lit = *--i))
witness.push_back (lit);
reverse (clause.begin (), clause.end ());
@ -237,18 +241,18 @@ bool External::traverse_witnesses_forward (WitnessIterator &it) {
if (i != end) {
int lit = *i++;
do {
assert (!lit), (void) lit;
CADICAL_assert (!lit), (void) lit;
while ((lit = *i++))
witness.push_back (lit);
assert (!lit);
assert (i != end);
assert (!*i);
CADICAL_assert (!lit);
CADICAL_assert (i != end);
CADICAL_assert (!*i);
const int64_t id =
((int64_t) *i << 32) + static_cast<int64_t> (*(i + 1));
assert (id > 0);
CADICAL_assert (id > 0);
i += 3;
assert (*i);
assert (i != end);
CADICAL_assert (*i);
CADICAL_assert (i != end);
while (i != end && (lit = *i++))
clause.push_back (lit);
if (!it.witness (clause, witness, id))
@ -279,3 +283,5 @@ void External::conclude_sat () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,14 +1,18 @@
#include "global.h"
#include "internal.hpp"
#include <cstdint>
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
External::External (Internal *i)
: internal (i), max_var (0), vsize (0), extended (false),
concluded (false), terminator (0), learner (0), fixed_listener (0),
propagator (0), solution (0), vars (max_var) {
assert (internal);
assert (!internal->external);
CADICAL_assert (internal);
CADICAL_assert (!internal->external);
internal->external = this;
}
@ -19,7 +23,7 @@ External::~External () {
void External::enlarge (int new_max_var) {
assert (!extended);
CADICAL_assert (!extended);
size_t new_vsize = vsize ? 2 * vsize : 1 + (size_t) new_max_var;
while (new_vsize <= (size_t) new_max_var)
@ -29,7 +33,7 @@ void External::enlarge (int new_max_var) {
}
void External::init (int new_max_var, bool extension) {
assert (!extended);
CADICAL_assert (!extended);
if (new_max_var <= max_var)
return;
int new_vars = new_max_var - max_var;
@ -40,31 +44,31 @@ void External::init (int new_max_var, bool extension) {
enlarge (new_max_var);
LOG ("initialized %d external variables", new_vars);
if (!max_var) {
assert (e2i.empty ());
CADICAL_assert (e2i.empty ());
e2i.push_back (0);
ext_units.push_back (0);
ext_units.push_back (0);
ext_flags.push_back (0);
ervars.push_back (0);
assert (internal->i2e.empty ());
CADICAL_assert (internal->i2e.empty ());
internal->i2e.push_back (0);
} else {
assert (e2i.size () == (size_t) max_var + 1);
assert (internal->i2e.size () == (size_t) old_internal_max_var + 1);
CADICAL_assert (e2i.size () == (size_t) max_var + 1);
CADICAL_assert (internal->i2e.size () == (size_t) old_internal_max_var + 1);
}
unsigned iidx = old_internal_max_var + 1, eidx;
for (eidx = max_var + 1u; eidx <= (unsigned) new_max_var;
eidx++, iidx++) {
LOG ("mapping external %u to internal %u", eidx, iidx);
assert (e2i.size () == eidx);
CADICAL_assert (e2i.size () == eidx);
e2i.push_back (iidx);
ext_units.push_back (0);
ext_units.push_back (0);
ext_flags.push_back (0);
ervars.push_back (0);
internal->i2e.push_back (eidx);
assert (internal->i2e[iidx] == (int) eidx);
assert (e2i[eidx] == (int) iidx);
CADICAL_assert (internal->i2e[iidx] == (int) eidx);
CADICAL_assert (e2i[eidx] == (int) iidx);
}
if (extension)
internal->stats.variables_extension += new_vars;
@ -75,9 +79,9 @@ void External::init (int new_max_var, bool extension) {
if (internal->opts.checkfrozen)
if (new_max_var >= (int64_t) moltentab.size ())
moltentab.resize (1 + (size_t) new_max_var, false);
assert (iidx == (size_t) new_internal_max_var + 1);
assert (eidx == (size_t) new_max_var + 1);
assert (ext_units.size () == (size_t) new_max_var * 2 + 2);
CADICAL_assert (iidx == (size_t) new_internal_max_var + 1);
CADICAL_assert (eidx == (size_t) new_max_var + 1);
CADICAL_assert (ext_units.size () == (size_t) new_max_var * 2 + 2);
max_var = new_max_var;
}
@ -116,7 +120,7 @@ void External::reset_limits () { internal->reset_limits (); }
int External::internalize (int elit, bool extension) {
int ilit;
if (elit) {
assert (elit != INT_MIN);
CADICAL_assert (elit != INT_MIN);
const int eidx = abs (elit);
if (extension && eidx <= max_var)
FATAL ("can not add a definition for an already used variable %d",
@ -125,27 +129,27 @@ int External::internalize (int elit, bool extension) {
init (eidx, extension);
}
if (extension) {
assert (ervars.size () > (size_t) eidx);
CADICAL_assert (ervars.size () > (size_t) eidx);
ervars[eidx] = true;
}
ilit = e2i[eidx];
if (elit < 0)
ilit = -ilit;
if (!ilit) {
assert (internal->max_var < INT_MAX);
CADICAL_assert (internal->max_var < INT_MAX);
ilit = internal->max_var + 1u;
internal->init_vars (ilit);
e2i[eidx] = ilit;
LOG ("mapping external %d to internal %d", eidx, ilit);
e2i[eidx] = ilit;
internal->i2e.push_back (eidx);
assert (internal->i2e[ilit] == eidx);
assert (e2i[eidx] == ilit);
CADICAL_assert (internal->i2e[ilit] == eidx);
CADICAL_assert (e2i[eidx] == ilit);
if (elit < 0)
ilit = -ilit;
}
if (internal->opts.checkfrozen) {
assert (eidx < (int64_t) moltentab.size ());
CADICAL_assert (eidx < (int64_t) moltentab.size ());
if (moltentab[eidx])
FATAL ("can not reuse molten literal %d", eidx);
}
@ -155,7 +159,7 @@ int External::internalize (int elit, bool extension) {
else if (f.status != Flags::ACTIVE && f.status != Flags::FIXED)
internal->reactivate (ilit);
if (!marked (tainted, elit) && marked (witness, -elit)) {
assert (!internal->opts.checkfrozen);
CADICAL_assert (!internal->opts.checkfrozen);
LOG ("marking tainted %d", elit);
mark (tainted, elit);
}
@ -165,7 +169,7 @@ int External::internalize (int elit, bool extension) {
}
void External::add (int elit) {
assert (elit != INT_MIN);
CADICAL_assert (elit != INT_MIN);
reset_extended ();
bool forgettable = false;
@ -186,7 +190,7 @@ void External::add (int elit) {
}
const int ilit = internalize (elit);
assert (!elit == !ilit);
CADICAL_assert (!elit == !ilit);
// The external literals of the new clause must be saved for later
// when the proof is printed during add_original_lit (0)
@ -195,7 +199,7 @@ void External::add (int elit) {
if (internal->lrat) {
// actually find unit of -elit (flips elit < 0)
unsigned eidx = (elit > 0) + 2u * (unsigned) abs (elit);
assert ((size_t) eidx < ext_units.size ());
CADICAL_assert ((size_t) eidx < ext_units.size ());
const int64_t id = ext_units[eidx];
bool added = ext_flags[abs (elit)];
if (id && !added) {
@ -221,21 +225,21 @@ void External::add (int elit) {
}
void External::assume (int elit) {
assert (elit);
CADICAL_assert (elit);
reset_extended ();
if (internal->proof)
internal->proof->add_assumption (elit);
assumptions.push_back (elit);
const int ilit = internalize (elit);
assert (ilit);
CADICAL_assert (ilit);
LOG ("assuming external %d as internal %d", elit, ilit);
internal->assume (ilit);
}
bool External::flip (int elit) {
assert (elit);
assert (elit != INT_MIN);
assert (!propagator);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
CADICAL_assert (!propagator);
int eidx = abs (elit);
if (eidx > max_var)
@ -252,9 +256,9 @@ bool External::flip (int elit) {
}
bool External::flippable (int elit) {
assert (elit);
assert (elit != INT_MIN);
assert (!propagator);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
CADICAL_assert (!propagator);
int eidx = abs (elit);
if (eidx > max_var)
@ -268,8 +272,8 @@ bool External::flippable (int elit) {
}
bool External::failed (int elit) {
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
int eidx = abs (elit);
if (eidx > max_var)
return 0;
@ -286,10 +290,10 @@ void External::constrain (int elit) {
LOG (constraint, "replacing previous constraint");
reset_constraint ();
}
assert (elit != INT_MIN);
CADICAL_assert (elit != INT_MIN);
reset_extended ();
const int ilit = internalize (elit);
assert (!elit == !ilit);
CADICAL_assert (!elit == !ilit);
if (elit)
LOG ("adding external %d as internal %d to constraint", elit, ilit);
else if (!elit && internal->proof) {
@ -304,15 +308,15 @@ bool External::failed_constraint () {
}
void External::phase (int elit) {
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
const int ilit = internalize (elit);
internal->phase (ilit);
}
void External::unphase (int elit) {
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
int eidx = abs (elit);
if (eidx > max_var) {
UNUSED:
@ -341,15 +345,15 @@ void External::add_observed_var (int elit) {
return;
}
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
reset_extended (); // tainting!
int eidx = abs (elit);
if (eidx <= max_var &&
(marked (witness, elit) || marked (witness, -elit))) {
LOG ("Error, only clean variables are allowed to become observed.");
assert (false);
CADICAL_assert (false);
// TODO: here needs to come the taint and restore of the newly
// observed variable. Restore_clauses must be called before continue.
@ -395,7 +399,7 @@ void External::add_observed_var (int elit) {
unit);
// internal add-observed-var had to backtrack to root-level already
assert (!internal->level);
CADICAL_assert (!internal->level);
std::vector<int> assigned = {unit};
propagator->notify_assignment (assigned);
@ -425,7 +429,7 @@ void External::remove_observed_var (int elit) {
void External::reset_observed_vars () {
// Shouldn't be called if there is no connected propagator
assert (propagator);
CADICAL_assert (propagator);
reset_extended ();
internal->notified = 0;
@ -434,11 +438,11 @@ void External::reset_observed_vars () {
if (!is_observed.size ())
return;
assert (!max_var || (size_t) max_var + 1 == is_observed.size ());
CADICAL_assert (!max_var || (size_t) max_var + 1 == is_observed.size ());
for (auto elit : vars) {
int eidx = abs (elit);
assert (eidx <= max_var);
CADICAL_assert (eidx <= max_var);
if (is_observed[eidx]) {
int ilit = internalize (elit);
internal->remove_observed_var (ilit);
@ -450,8 +454,8 @@ void External::reset_observed_vars () {
}
bool External::observed (int elit) {
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
int eidx = abs (elit);
if (eidx > max_var)
return false;
@ -462,8 +466,8 @@ bool External::observed (int elit) {
}
bool External::is_witness (int elit) {
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
int eidx = abs (elit);
if (eidx > max_var)
return false;
@ -471,8 +475,8 @@ bool External::is_witness (int elit) {
}
bool External::is_decision (int elit) {
assert (elit);
assert (elit != INT_MIN);
CADICAL_assert (elit);
CADICAL_assert (elit != INT_MIN);
int eidx = abs (elit);
if (eidx > max_var)
return false;
@ -513,7 +517,7 @@ void External::implied (std::vector<int> &trailed) {
trailed.clear();
for (const auto &ilit : ilit_implicants) {
assert (ilit);
CADICAL_assert (ilit);
const int elit = internal->externalize (ilit);
const int eidx = abs (elit);
const bool is_extension_var = ervars[eidx];
@ -578,7 +582,7 @@ void External::check_solve_result (int res) {
void External::update_molten_literals () {
if (!internal->opts.checkfrozen)
return;
assert ((size_t) max_var + 1 == moltentab.size ());
CADICAL_assert ((size_t) max_var + 1 == moltentab.size ());
#ifdef LOGGING
int registered = 0, molten = 0;
#endif
@ -667,9 +671,9 @@ void External::melt (int elit) {
reset_extended ();
int ilit = internalize (elit);
unsigned eidx = vidx (elit);
assert (eidx < frozentab.size ());
CADICAL_assert (eidx < frozentab.size ());
unsigned &ref = frozentab[eidx];
assert (ref > 0);
CADICAL_assert (ref > 0);
if (ref < UINT_MAX) {
if (!--ref) {
if (observed (elit)) {
@ -700,10 +704,10 @@ void External::check_assignment (int (External::*a) (int) const) {
int value_idx = (this->*a) (idx);
int value_neg_idx = (this->*a) (-idx);
if (value_idx == idx)
assert (value_neg_idx == idx);
CADICAL_assert (value_neg_idx == idx);
else {
assert (value_idx == -idx);
assert (value_neg_idx == -idx);
CADICAL_assert (value_idx == -idx);
CADICAL_assert (value_neg_idx == -idx);
}
if (value_idx != value_neg_idx)
FATAL ("inconsistently assigned literals %d and %d", idx, -idx);
@ -714,7 +718,7 @@ void External::check_assignment (int (External::*a) (int) const) {
bool satisfied = false;
const auto end = original.end ();
auto start = original.begin (), i = start;
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t count = 0;
#endif
for (; i != end; i++) {
@ -730,7 +734,7 @@ void External::check_assignment (int (External::*a) (int) const) {
}
satisfied = false;
start = i + 1;
#ifndef QUIET
#ifndef CADICAL_QUIET
count++;
#endif
} else if (!satisfied && (this->*a) (lit) == lit)
@ -747,7 +751,7 @@ void External::check_assignment (int (External::*a) (int) const) {
break;
presence_flag = true;
satisfied = false;
#ifndef QUIET
#ifndef CADICAL_QUIET
count++;
#endif
std::vector<int> literals;
@ -778,7 +782,7 @@ void External::check_assignment (int (External::*a) (int) const) {
fatal_message_end ();
}
}
#ifndef QUIET
#ifndef CADICAL_QUIET
VERBOSE (1, "satisfying assignment checked on %" PRId64 " clauses",
count);
#endif
@ -945,7 +949,7 @@ bool External::traverse_all_non_frozen_units_as_witnesses (
const int ilit = e2i[idx] * (tmp < 0 ? -1 : 1);
// heurstically add + max_var to the id to avoid reusing ids
const int64_t id = internal->lrat ? internal->unit_id (ilit) : 1;
assert (id);
CADICAL_assert (id);
clause_and_witness.push_back (unit);
if (!it.witness (clause_and_witness, clause_and_witness, id + max_var))
return false;
@ -972,8 +976,8 @@ void External::copy_flags (External &other) const {
continue;
if (!other.internal->active (other_ilit))
continue;
assert (this_ilit != INT_MIN);
assert (other_ilit != INT_MIN);
CADICAL_assert (this_ilit != INT_MIN);
CADICAL_assert (other_ilit != INT_MIN);
const Flags &this_flags = this_ftab[abs (this_ilit)];
Flags &other_flags = other_ftab[abs (other_ilit)];
this_flags.copy (other_flags);
@ -983,7 +987,7 @@ void External::copy_flags (External &other) const {
/*------------------------------------------------------------------------*/
void External::export_learned_empty_clause () {
assert (learner);
CADICAL_assert (learner);
if (learner->learning (0)) {
LOG ("exporting learned empty clause");
learner->learn (0);
@ -992,11 +996,11 @@ void External::export_learned_empty_clause () {
}
void External::export_learned_unit_clause (int ilit) {
assert (learner);
CADICAL_assert (learner);
if (learner->learning (1)) {
LOG ("exporting learned unit clause");
const int elit = internal->externalize (ilit);
assert (elit);
CADICAL_assert (elit);
learner->learn (elit);
learner->learn (0);
} else
@ -1004,14 +1008,14 @@ void External::export_learned_unit_clause (int ilit) {
}
void External::export_learned_large_clause (const vector<int> &clause) {
assert (learner);
CADICAL_assert (learner);
size_t size = clause.size ();
assert (size <= (unsigned) INT_MAX);
CADICAL_assert (size <= (unsigned) INT_MAX);
if (learner->learning ((int) size)) {
LOG ("exporting learned clause of size %zu", size);
for (auto ilit : clause) {
const int elit = internal->externalize (ilit);
assert (elit);
CADICAL_assert (elit);
learner->learn (elit);
}
learner->learn (0);
@ -1020,3 +1024,5 @@ void External::export_learned_large_clause (const vector<int> &clause) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*----------------------------------------------------------------------------*/
@ -43,12 +47,12 @@ void Internal::remove_observed_var (int ilit) {
backtrack ();
}
assert (fixed (ilit) || !level);
CADICAL_assert (fixed (ilit) || !level);
const int idx = vidx (ilit);
assert ((size_t) idx < relevanttab.size ());
CADICAL_assert ((size_t) idx < relevanttab.size ());
unsigned &ref = relevanttab[idx];
assert (fixed (ilit) || ref > 0);
CADICAL_assert (fixed (ilit) || ref > 0);
if (fixed (ilit))
ref = 0;
else if (ref < UINT_MAX) {
@ -66,7 +70,7 @@ void Internal::remove_observed_var (int ilit) {
// Supposed to be used only by mobical.
//
bool Internal::observed (int ilit) const {
assert ((size_t) vidx (ilit) < relevanttab.size ());
CADICAL_assert ((size_t) vidx (ilit) < relevanttab.size ());
return relevanttab[vidx (ilit)] > 0;
}
@ -87,7 +91,7 @@ void Internal::set_tainted_literal () {
tainted_literal = idx;
continue;
}
assert (val (tainted_literal));
CADICAL_assert (val (tainted_literal));
if (var (idx).level < var (tainted_literal).level) {
tainted_literal = idx;
}
@ -100,7 +104,7 @@ void Internal::renotify_trail_after_ilb () {
return;
}
LOG ("notify external propagator about new assignments (after ilb)");
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("(decision level: %d, trail size: %zd, notified %zd)", level,
trail.size (), notified);
#endif
@ -113,7 +117,7 @@ void Internal::renotify_trail_after_local_search () {
}
LOG ("notify external propagator about new assignments (after local "
"search)");
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("(decision level: %d, trail size: %zd, notified %zd)", level,
trail.size (), notified);
#endif
@ -161,12 +165,12 @@ void Internal::renotify_full_trail () {
continue;
int elit = externalize (ilit); // TODO: double-check tainting
assert (elit);
CADICAL_assert (elit);
// Fixed variables might get mapped (during compact) to another
// non-observed but fixed variable.
// This happens on root level, so notification about their assignment is
// already done.
assert (external->observed (elit) || fixed (ilit));
CADICAL_assert (external->observed (elit) || fixed (ilit));
if (!external->ervars[abs (elit)])
assigned.push_back (elit);
}
@ -195,7 +199,7 @@ bool Internal::is_decision (int ilit) {
const int idx = vidx (ilit);
Var &v = var (idx);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG (v.reason,
"is_decision: i%d (current level: %d, is_fixed: %d, v.level: %d, "
"is_external_reason: %d, v.reason: )",
@ -203,7 +207,7 @@ bool Internal::is_decision (int ilit) {
#endif
if (!v.level || v.reason)
return false;
assert (!v.reason);
CADICAL_assert (!v.reason);
return true;
}
@ -211,7 +215,7 @@ void Internal::force_backtrack (size_t new_level) {
if (!forced_backt_allowed || level <= 0 || new_level >= (size_t) level)
return;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("external propagator forces backtrack to decision level"
"%zd (from level %d)",
new_level, level);
@ -231,13 +235,13 @@ void Internal::force_backtrack (size_t new_level) {
bool Internal::external_propagate () {
if (level)
require_mode (SEARCH);
assert (!unsat);
CADICAL_assert (!unsat);
size_t before = num_assigned;
bool cb_repropagate_needed = true;
while (cb_repropagate_needed && !conflict && external_prop &&
!external_prop_is_lazy && !private_steps) {
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("external propagation starts (decision level: %d, trail size: "
"%zd, notified %zd)",
level, trail.size (), notified);
@ -251,13 +255,13 @@ bool Internal::external_propagate () {
stats.ext_prop.ext_cb++;
stats.ext_prop.eprop_call++;
while (elit) {
assert (external->is_observed[abs (elit)]);
CADICAL_assert (external->is_observed[abs (elit)]);
int ilit = external->e2i[abs (elit)];
if (elit < 0)
ilit = -ilit;
int tmp = val (ilit);
#ifndef NDEBUG
assert (fixed (ilit) || observed (ilit));
#ifndef CADICAL_NDEBUG
CADICAL_assert (fixed (ilit) || observed (ilit));
LOG ("External propagation of e%d (i%d val: %d)", elit, ilit, tmp);
#endif
if (!tmp) {
@ -308,7 +312,7 @@ bool Internal::external_propagate () {
stats.ext_prop.eprop_call++;
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("External propagation ends (decision level: %d, trail size: %zd, "
"notified %zd)",
level, trail.size (), notified);
@ -331,7 +335,7 @@ bool Internal::external_propagate () {
notify_assignments ();
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
if (has_external_clause)
LOG ("New external clauses are to be added.");
else
@ -367,7 +371,7 @@ bool Internal::external_propagate () {
stats.ext_prop.elearn_call++;
}
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("External clause addition ends on decision level %d at trail "
"size "
"%zd (notified %zd)",
@ -433,7 +437,7 @@ void Internal::move_literals_to_watch () {
highest_level = other_level;
highest_value = other_value;
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("highest position: %d highest level: %d highest value: %d",
highest_position, highest_level, highest_value);
#endif
@ -473,7 +477,7 @@ void Internal::move_literals_to_watch () {
//
void Internal::add_external_clause (int propagated_elit,
bool no_backtrack) {
assert (original.empty ());
CADICAL_assert (original.empty ());
int elit = 0;
if (propagated_elit) {
@ -482,7 +486,7 @@ void Internal::add_external_clause (int propagated_elit,
// propagator can add them as an explicit unforgettable external clause
// or set 'are_reasons_forgettable' to false.
ext_clause_forgettable = external->propagator->are_reasons_forgettable;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG ("add external reason of propagated lit: %d", propagated_elit);
#endif
elit = external->propagator->cb_add_reason_clause_lit (propagated_elit);
@ -497,15 +501,15 @@ void Internal::add_external_clause (int propagated_elit,
clause.clear ();
// Read out the external lemma into original and simplify it into clause
assert (clause.empty ());
assert (original.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (original.empty ());
assert (!force_no_backtrack);
assert (!from_propagator);
CADICAL_assert (!force_no_backtrack);
CADICAL_assert (!from_propagator);
force_no_backtrack = no_backtrack;
from_propagator = true;
while (elit) {
assert (external->is_observed[abs (elit)]);
CADICAL_assert (external->is_observed[abs (elit)]);
external->add (elit);
if (propagated_elit)
elit =
@ -514,8 +518,8 @@ void Internal::add_external_clause (int propagated_elit,
elit = external->propagator->cb_add_external_clause_lit ();
}
external->add (elit);
assert (original.empty ());
assert (clause.empty ());
CADICAL_assert (original.empty ());
CADICAL_assert (clause.empty ());
force_no_backtrack = false;
from_propagator = false;
lrat_chain = std::move (lrat_chain_ext);
@ -530,11 +534,11 @@ void Internal::add_external_clause (int propagated_elit,
void Internal::explain_reason (int ilit, Clause *reason, int &open) {
if (!opts.exteagerreasons)
return;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
LOG (reason, "explain_reason of %d (open: %d)", ilit, open);
#endif
assert (reason);
assert (reason != external_reason);
CADICAL_assert (reason);
CADICAL_assert (reason != external_reason);
for (const auto &other : *reason) {
if (other == ilit)
continue;
@ -544,8 +548,8 @@ void Internal::explain_reason (int ilit, Clause *reason, int &open) {
Var &v = var (other);
if (!v.level)
continue;
assert (val (other) < 0);
assert (v.level <= level);
CADICAL_assert (val (other) < 0);
CADICAL_assert (v.level <= level);
if (v.reason == external_reason) {
v.reason = learn_external_reason_clause (-other, 0, true);
}
@ -577,8 +581,8 @@ void Internal::explain_reason (int ilit, Clause *reason, int &open) {
// over-approximated.
//
void Internal::explain_external_propagations () {
assert (conflict);
assert (clause.empty ());
CADICAL_assert (conflict);
CADICAL_assert (clause.empty ());
Clause *reason = conflict;
std::vector<int> seen_lits;
@ -601,16 +605,16 @@ void Internal::explain_external_propagations () {
if (!open)
break;
}
assert (!open);
CADICAL_assert (!open);
if (!opts.exteagerrecalc) {
for (auto lit : seen_lits) {
Flags &f = flags (lit);
f.seen = false;
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (auto idx : vars) {
assert (!flags (idx).seen);
CADICAL_assert (!flags (idx).seen);
}
#endif
}
@ -636,7 +640,7 @@ void Internal::explain_external_propagations () {
lrat_chain.clear ();
v.reason = 0;
}
assert (v.level >= real_level);
CADICAL_assert (v.level >= real_level);
if (v.level > real_level) {
v.level = real_level;
}
@ -646,7 +650,7 @@ void Internal::explain_external_propagations () {
#if 0 // has been fuzzed extensively
for (auto idx : vars) {
assert (!flags (idx).seen);
CADICAL_assert (!flags (idx).seen);
}
#endif
}
@ -664,18 +668,18 @@ void Internal::explain_external_propagations () {
Clause *Internal::learn_external_reason_clause (int ilit,
int falsified_elit,
bool no_backtrack) {
assert (external->propagator);
CADICAL_assert (external->propagator);
// we cannot modify clause during analysis
auto clause_tmp = std::move (clause);
assert (clause.empty ());
assert (original.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (original.empty ());
stats.ext_prop.eprop_expl++;
int elit = 0;
if (!falsified_elit) {
assert (!fixed (ilit));
CADICAL_assert (!fixed (ilit));
elit = externalize (ilit);
} else
elit = falsified_elit;
@ -683,7 +687,7 @@ Clause *Internal::learn_external_reason_clause (int ilit,
LOG ("ilit: %d, elit: %d", ilit, elit);
add_external_clause (elit, no_backtrack);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
if (!falsified_elit && newest_clause) {
// Check if external propagation is correct wrt to the topological order
// defined by the trail. In case it is a falsified external propagation
@ -691,7 +695,7 @@ Clause *Internal::learn_external_reason_clause (int ilit,
// falsified clause.
const int propagated_ilit = ilit;
for (auto const reason_ilit : *newest_clause) {
assert (var (reason_ilit).trail <= var (propagated_ilit).trail);
CADICAL_assert (var (reason_ilit).trail <= var (propagated_ilit).trail);
}
}
#endif
@ -721,12 +725,12 @@ Clause *Internal::wrapped_learn_external_reason_clause (int ilit) {
// The learn_external_reason clause can leave a literal in clause when
// there is a falsified elit arg. Here it is not allowed to
// happen.
assert (clause.empty ());
CADICAL_assert (clause.empty ());
clause = std::move (clause_tmp);
clause_tmp.clear ();
}
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
lrat_chain = std::move (chain_tmp);
chain_tmp.clear ();
return res;
@ -747,8 +751,8 @@ void Internal::handle_external_clause (Clause *res) {
if (from_propagator)
stats.ext_prop.elearn_prop++;
// new unit clause. For now just backtrack.
assert (!force_no_backtrack);
assert (level);
CADICAL_assert (!force_no_backtrack);
CADICAL_assert (level);
// if (!opts.chrono) {
backtrack ();
// }
@ -756,18 +760,18 @@ void Internal::handle_external_clause (Clause *res) {
}
if (from_propagator)
stats.ext_prop.elearned++;
assert (res->size >= 2);
CADICAL_assert (res->size >= 2);
const int pos0 = res->literals[0];
const int pos1 = res->literals[1];
if (force_no_backtrack) {
assert (val (pos1) < 0);
assert (val (pos0) >= 0);
CADICAL_assert (val (pos1) < 0);
CADICAL_assert (val (pos0) >= 0);
return;
// TODO: maybe fix levels
}
const int l1 = var (pos1).level;
if (val (pos0) < 0) { // conflicting or propagating clause
assert (0 < l1 && l1 <= var (pos0).level);
CADICAL_assert (0 < l1 && l1 <= var (pos0).level);
if (!opts.chrono) {
backtrack (l1);
}
@ -777,7 +781,7 @@ void Internal::handle_external_clause (Clause *res) {
// its better to backtrack instead of analyze
backtrack (l1 - 1);
conflict = 0;
assert (!val (pos0) && !val (pos1));
CADICAL_assert (!val (pos0) && !val (pos1));
}
} else {
search_assign_driving (pos0, res);
@ -850,7 +854,7 @@ bool Internal::external_check_solution () {
continue;
const int lit = external->ival (idx);
etrail.push_back (lit);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
#ifdef LOGGING
bool p = external->vals[idx];
LOG ("evals[%d]: %d ival(%d): %d", idx, p, idx, lit);
@ -943,14 +947,14 @@ void Internal::notify_assignments () {
continue;
int elit = externalize (ilit); // TODO: double-check tainting
assert (elit);
CADICAL_assert (elit);
if (external->ervars[abs (elit)])
continue;
// Fixed variables might get mapped (during compact) to another
// non-observed but fixed variable.
// This happens on root level, so notification about their assignment is
// already done.
assert (external->observed (elit) ||
CADICAL_assert (external->observed (elit) ||
(fixed (ilit) && !external->ervars[abs (elit)]));
assigned.push_back (elit);
}
@ -995,8 +999,8 @@ int Internal::ask_decision () {
if (!external_prop || external_prop_is_lazy || private_steps)
return 0;
assert (!unsat);
assert (!conflict);
CADICAL_assert (!unsat);
CADICAL_assert (!conflict);
notify_assignments ();
int level_before = level;
forced_backt_allowed = true;
@ -1007,8 +1011,8 @@ int Internal::ask_decision () {
if (level_before != level) {
propagate ();
assert (!unsat);
assert (!conflict);
CADICAL_assert (!unsat);
CADICAL_assert (!conflict);
notify_assignments ();
// In case the external propagator forced to backtrack below the
@ -1023,7 +1027,7 @@ int Internal::ask_decision () {
if (!elit)
return 0;
LOG ("external propagator proposes decision: %d", elit);
assert (external->is_observed[abs (elit)]);
CADICAL_assert (external->is_observed[abs (elit)]);
if (!external->is_observed[abs (elit)])
return 0;
@ -1031,7 +1035,7 @@ int Internal::ask_decision () {
if (elit < 0)
ilit = -ilit;
assert (fixed (ilit) || observed (ilit));
CADICAL_assert (fixed (ilit) || observed (ilit));
LOG ("Asking external propagator for decision returned: %d (internal: "
"%d, fixed: %d, val: %d)",
@ -1052,7 +1056,7 @@ int Internal::ask_decision () {
// propagator.
//
bool Internal::is_external_forgettable (int64_t id) {
assert (opts.check);
CADICAL_assert (opts.check);
return (external->forgettable_original.find (id) !=
external->forgettable_original.end ());
}
@ -1064,8 +1068,8 @@ bool Internal::is_external_forgettable (int64_t id) {
// ignore it.
//
void Internal::mark_garbage_external_forgettable (int64_t id) {
assert (opts.check);
assert (is_external_forgettable (id));
CADICAL_assert (opts.check);
CADICAL_assert (is_external_forgettable (id));
LOG (external->forgettable_original[id],
"forgettable external lemma is deleted:");
@ -1079,7 +1083,7 @@ void Internal::mark_garbage_external_forgettable (int64_t id) {
// internally for debug purposes.
//
void Internal::check_watched_literal_invariants () {
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
int v0 = 0;
int v1 = 0;
@ -1092,19 +1096,19 @@ void Internal::check_watched_literal_invariants () {
v1 = 1;
else if (val (clause[1]) < 0)
v1 = -1;
assert (v0 >= v1);
CADICAL_assert (v0 >= v1);
#endif
if (val (clause[0]) > 0) {
if (val (clause[1]) > 0) { // Case 1: Both literals are satisfied
// They are ordered by lower to higher decision level
assert (var (clause[0]).level <= var (clause[1]).level);
CADICAL_assert (var (clause[0]).level <= var (clause[1]).level);
// Every other literal of the clause is either
// - satisfied at higher level
// - unassigned
// - falsified
for (size_t i = 2; i < clause.size (); i++)
assert (val (clause[i]) <= 0 ||
CADICAL_assert (val (clause[i]) <= 0 ||
(var (clause[1]).level <= var (clause[i]).level));
} else if (val (clause[1]) ==
@ -1114,14 +1118,14 @@ void Internal::check_watched_literal_invariants () {
// - unassigned
// - falsified
for (size_t i = 2; i < clause.size (); i++)
assert (val (clause[i]) <= 0);
CADICAL_assert (val (clause[i]) <= 0);
} else { // Case 3: First satisfied, next falsified -> could have been a
// reason of a previous propagation
// Every other literal of the clause is falsified but at a lower
// decision level
for (size_t i = 2; i < clause.size (); i++)
assert (val (clause[i]) < 0 &&
CADICAL_assert (val (clause[i]) < 0 &&
(var (clause[1]).level >= var (clause[i]).level));
}
} else if (val (clause[0]) == 0) {
@ -1131,30 +1135,30 @@ void Internal::check_watched_literal_invariants () {
// - unassigned
// - falsified
for (size_t i = 2; i < clause.size (); i++)
assert (val (clause[i]) <= 0);
CADICAL_assert (val (clause[i]) <= 0);
} else { // Case 5: First unassigned, next falsified -> PROPAGATE
// Every other literal of the clause is falsified but at a lower
// decision level
for (size_t i = 2; i < clause.size (); i++)
assert (val (clause[i]) < 0 &&
CADICAL_assert (val (clause[i]) < 0 &&
(var (clause[1]).level >= var (clause[i]).level));
}
} else {
assert (val (clause[0]) < 0 &&
CADICAL_assert (val (clause[0]) < 0 &&
val (clause[1]) < 0); // Case 6: Both literals are falsified
// They are ordered by higher to lower decision level
assert (var (clause[0]).level >= var (clause[1]).level);
CADICAL_assert (var (clause[0]).level >= var (clause[1]).level);
// Every other literal of the clause is falsified, but at a lower level
for (size_t i = 2; i < clause.size (); i++)
assert (val (clause[i]) < 0 &&
CADICAL_assert (val (clause[i]) < 0 &&
(var (clause[1]).level >= var (clause[i]).level));
}
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
/*----------------------------------------------------------------------------*/
//
@ -1224,3 +1228,5 @@ void Internal::get_all_fixed_literals (std::vector<int> &fixed_lits) {
#endif
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
#define FACTORS 1
@ -20,7 +24,7 @@ inline bool factor_occs_size::operator() (unsigned a, unsigned b) {
void Internal::factor_mode () {
reset_watches ();
assert (!watching ());
CADICAL_assert (!watching ());
init_occs ();
const int size_limit = opts.factorsize;
@ -121,9 +125,9 @@ Factoring::Factoring (Internal *i, int64_t l)
}
Factoring::~Factoring () {
assert (counted.empty ());
assert (nounted.empty ());
assert (flauses.empty ());
CADICAL_assert (counted.empty ());
CADICAL_assert (nounted.empty ());
CADICAL_assert (flauses.empty ());
internal->release_quotients (*this);
schedule.erase (); // actually not necessary
}
@ -143,7 +147,7 @@ double Internal::tied_next_factor_score (int lit) {
// use markfact, unmarkfact, getfact for this purpose.
//
Quotient *Internal::new_quotient (Factoring &factoring, int factor) {
assert (!getfact (factor, FACTORS));
CADICAL_assert (!getfact (factor, FACTORS));
markfact (factor, FACTORS);
Quotient *res = new Quotient (factor);
res->next = 0;
@ -151,12 +155,12 @@ Quotient *Internal::new_quotient (Factoring &factoring, int factor) {
Quotient *last = factoring.quotients.last;
res->bid = 0;
if (last) {
assert (factoring.quotients.first);
assert (!last->next);
CADICAL_assert (factoring.quotients.first);
CADICAL_assert (!last->next);
last->next = res;
res->id = last->id + 1;
} else {
assert (!factoring.quotients.first);
CADICAL_assert (!factoring.quotients.first);
factoring.quotients.first = res;
res->id = 0;
}
@ -170,7 +174,7 @@ void Internal::release_quotients (Factoring &factoring) {
for (Quotient *q = factoring.quotients.first, *next; q; q = next) {
next = q->next;
int factor = q->factor;
assert (getfact (factor, FACTORS));
CADICAL_assert (getfact (factor, FACTORS));
unmarkfact (factor, FACTORS);
delete q;
}
@ -178,7 +182,7 @@ void Internal::release_quotients (Factoring &factoring) {
}
size_t Internal::first_factor (Factoring &factoring, int factor) {
assert (!factoring.quotients.first);
CADICAL_assert (!factoring.quotients.first);
Quotient *quotient = new_quotient (factoring, factor);
vector<Clause *> &qlauses = quotient->qlauses;
int64_t ticks = 0;
@ -189,14 +193,14 @@ size_t Internal::first_factor (Factoring &factoring, int factor) {
size_t res = qlauses.size ();
LOG ("quotient[0] factor %d size %zu", factor, res);
// This invariant can of course be broken by previous factorings
// assert (res > 1);
// CADICAL_assert (res > 1);
stats.ticks.factor += ticks;
return res;
}
void Internal::clear_nounted (vector<int> &nounted) {
for (const auto &lit : nounted) {
assert (getfact (lit, NOUNTED));
CADICAL_assert (getfact (lit, NOUNTED));
unmarkfact (lit, NOUNTED);
}
nounted.clear ();
@ -204,7 +208,7 @@ void Internal::clear_nounted (vector<int> &nounted) {
void Internal::clear_flauses (vector<Clause *> &flauses) {
for (auto c : flauses) {
assert (c->swept);
CADICAL_assert (c->swept);
c->swept = false;
}
flauses.clear ();
@ -248,17 +252,17 @@ Quotient *Internal::best_quotient (Factoring &factoring,
int Internal::next_factor (Factoring &factoring, unsigned *next_count_ptr) {
Quotient *last_quotient = factoring.quotients.last;
assert (last_quotient);
CADICAL_assert (last_quotient);
vector<Clause *> &last_clauses = last_quotient->qlauses;
vector<unsigned> &count = factoring.count;
vector<int> &counted = factoring.counted;
vector<Clause *> &flauses = factoring.flauses;
assert (counted.empty ());
assert (flauses.empty ());
CADICAL_assert (counted.empty ());
CADICAL_assert (flauses.empty ());
const int initial = factoring.initial;
int64_t ticks = 1 + cache_lines (last_clauses.size (), sizeof (Clause *));
for (auto c : last_clauses) {
assert (!c->swept);
CADICAL_assert (!c->swept);
int min_lit = 0;
unsigned factors = 0;
size_t min_size = 0;
@ -268,7 +272,7 @@ int Internal::next_factor (Factoring &factoring, unsigned *next_count_ptr) {
if (factors++)
break;
} else {
assert (!getfact (other, QUOTIENT));
CADICAL_assert (!getfact (other, QUOTIENT));
markfact (other, QUOTIENT);
const size_t other_size = occs (other).size ();
if (!min_lit || other_size < min_size) {
@ -277,12 +281,12 @@ int Internal::next_factor (Factoring &factoring, unsigned *next_count_ptr) {
}
}
}
assert (factors);
CADICAL_assert (factors);
if (factors == 1) {
assert (min_lit);
CADICAL_assert (min_lit);
const int c_size = c->size;
vector<int> &nounted = factoring.nounted;
assert (nounted.empty ());
CADICAL_assert (nounted.empty ());
ticks += 1 + cache_lines (occs (min_lit).size (), sizeof (Clause *));
for (auto d : occs (min_lit)) {
if (c == d)
@ -304,13 +308,13 @@ int Internal::next_factor (Factoring &factoring, unsigned *next_count_ptr) {
goto CONTINUE_WITH_NEXT_MIN_WATCH;
next = other;
}
assert (next);
CADICAL_assert (next);
if (abs (next) > abs (initial))
continue;
if (!active (next))
continue;
assert (!getfact (next, FACTORS));
assert (!getfact (next, NOUNTED));
CADICAL_assert (!getfact (next, FACTORS));
CADICAL_assert (!getfact (next, NOUNTED));
markfact (next, NOUNTED);
nounted.push_back (next);
d->swept = true;
@ -340,10 +344,10 @@ int Internal::next_factor (Factoring &factoring, unsigned *next_count_ptr) {
if (lit_count < next_count)
continue;
if (lit_count == next_count) {
assert (lit_count);
CADICAL_assert (lit_count);
ties++;
} else {
assert (lit_count > next_count);
CADICAL_assert (lit_count > next_count);
next_count = lit_count;
next = lit;
ties = 1;
@ -361,25 +365,25 @@ int Internal::next_factor (Factoring &factoring, unsigned *next_count_ptr) {
if (lit_count != next_count)
continue;
double lit_score = tied_next_factor_score (lit);
assert (lit_score >= 0);
CADICAL_assert (lit_score >= 0);
LOG ("score %g of next factor candidate %d", lit_score, lit);
if (lit_score <= next_score)
continue;
next_score = lit_score;
next = lit;
}
assert (next_score >= 0);
assert (next);
CADICAL_assert (next_score >= 0);
CADICAL_assert (next);
LOG ("best score %g of next factor %d", next_score, next);
} else {
assert (ties == 1);
CADICAL_assert (ties == 1);
LOG ("single next factor %d with count %u", next, next_count);
}
}
for (const auto &lit : counted)
count[vlit (lit)] = 0;
counted.clear ();
assert (!next || next_count > 1);
CADICAL_assert (!next || next_count > 1);
*next_count_ptr = next_count;
return next;
}
@ -389,19 +393,19 @@ void Internal::factorize_next (Factoring &factoring, int next,
Quotient *last_quotient = factoring.quotients.last;
Quotient *next_quotient = new_quotient (factoring, next);
assert (last_quotient);
CADICAL_assert (last_quotient);
vector<Clause *> &last_clauses = last_quotient->qlauses;
vector<Clause *> &next_clauses = next_quotient->qlauses;
vector<size_t> &matches = next_quotient->matches;
vector<Clause *> &flauses = factoring.flauses;
assert (flauses.empty ());
CADICAL_assert (flauses.empty ());
int64_t ticks = 1 + cache_lines (last_clauses.size (), sizeof (Clause *));
size_t i = 0;
for (auto c : last_clauses) {
assert (!c->swept);
CADICAL_assert (!c->swept);
int min_lit = 0;
unsigned factors = 0;
size_t min_size = 0;
@ -411,7 +415,7 @@ void Internal::factorize_next (Factoring &factoring, int next,
if (factors++)
break;
} else {
assert (!getfact (other, QUOTIENT));
CADICAL_assert (!getfact (other, QUOTIENT));
markfact (other, QUOTIENT);
const size_t other_size = occs (other).size ();
if (!min_lit || other_size < min_size) {
@ -420,9 +424,9 @@ void Internal::factorize_next (Factoring &factoring, int next,
}
}
}
assert (factors);
CADICAL_assert (factors);
if (factors == 1) {
assert (min_lit);
CADICAL_assert (min_lit);
const int c_size = c->size;
ticks += 1 + cache_lines (occs (min_lit).size (), sizeof (Clause *));
for (auto d : occs (min_lit)) {
@ -459,14 +463,14 @@ void Internal::factorize_next (Factoring &factoring, int next,
clear_flauses (flauses);
stats.ticks.factor += ticks;
assert (expected_next_count <= next_clauses.size ());
CADICAL_assert (expected_next_count <= next_clauses.size ());
(void) expected_next_count;
}
// We only need to enlarge factoring.count as everything else is
// initialized in internal
void Internal::resize_factoring (Factoring &factoring, int lit) {
assert (lit > 0);
CADICAL_assert (lit > 0);
size_t new_var_size = lit + 1;
size_t new_lit_size = 2 * new_var_size;
enlarge_zero (factoring.count, new_lit_size);
@ -477,13 +481,13 @@ void Internal::flush_unmatched_clauses (Quotient *q) {
vector<size_t> &q_matches = q->matches, &prev_matches = prev->matches;
vector<Clause *> &q_clauses = q->qlauses, &prev_clauses = prev->qlauses;
const size_t n = q_clauses.size ();
assert (n == q_matches.size ());
CADICAL_assert (n == q_matches.size ());
bool prev_is_first = !prev->id;
size_t i = 0;
while (i < q_matches.size ()) {
size_t j = q_matches[i];
q_matches[i] = i;
assert (i <= j);
CADICAL_assert (i <= j);
if (!prev_is_first) {
size_t matches = prev_matches[j];
prev_matches[i] = matches;
@ -506,7 +510,7 @@ void Internal::flush_unmatched_clauses (Quotient *q) {
void Internal::add_self_subsuming_factor (Quotient *q, Quotient *p) {
const int factor = q->factor;
const int not_factor = p->factor;
assert (-factor == not_factor);
CADICAL_assert (-factor == not_factor);
LOG (
"adding self subsuming factor because blocked clause is a tautology");
for (auto c : q->qlauses) {
@ -533,7 +537,7 @@ void Internal::add_self_subsuming_factor (Quotient *q, Quotient *p) {
}
}
lrat_chain.push_back (c->id);
assert (lrat_chain.size () == 2);
CADICAL_assert (lrat_chain.size () == 2);
}
if (clause.size () > 1) {
new_factor_clause ();
@ -566,7 +570,7 @@ bool Internal::self_subsuming_factor (Quotient *q) {
const int factor = p->factor;
Flags &f = flags (factor);
if (f.seen) {
assert (std::find (analyzed.begin (), analyzed.end (), -factor) !=
CADICAL_assert (std::find (analyzed.begin (), analyzed.end (), -factor) !=
analyzed.end ());
found = true;
x = p;
@ -581,7 +585,7 @@ bool Internal::self_subsuming_factor (Quotient *q) {
analyzed.push_back (factor);
f.seen = true;
}
assert (!found || (x && y));
CADICAL_assert (!found || (x && y));
clear_analyzed_literals ();
if (found) {
add_self_subsuming_factor (x, y);
@ -611,11 +615,11 @@ void Internal::blocked_clause (Quotient *q, int not_fresh) {
return;
int64_t new_id = ++clause_id;
q->bid = new_id;
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (Quotient *p = q; p; p = p->prev)
clause.push_back (-p->factor);
clause.push_back (not_fresh);
assert (!lrat || mini_chain.size ());
CADICAL_assert (!lrat || mini_chain.size ());
proof->add_derived_clause (new_id, true, clause, mini_chain);
mini_chain.clear ();
clause.clear ();
@ -627,11 +631,11 @@ void Internal::blocked_clause (Quotient *q, int not_fresh) {
void Internal::add_factored_quotient (Quotient *q, int not_fresh) {
LOG ("adding factored quotient[%zu] clauses", q->id);
const int factor = q->factor;
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
auto qlauses = q->qlauses;
for (unsigned idx = 0; idx < qlauses.size (); idx++) {
const auto c = qlauses[idx];
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (const auto &other : *c) {
if (other == factor) {
continue;
@ -639,8 +643,8 @@ void Internal::add_factored_quotient (Quotient *q, int not_fresh) {
clause.push_back (other);
}
if (lrat) {
assert (proof);
assert (q->bid);
CADICAL_assert (proof);
CADICAL_assert (q->bid);
unsigned idxtoo = idx;
for (Quotient *p = q; p; p = p->prev) {
lrat_chain.push_back (p->qlauses[idxtoo]->id);
@ -677,7 +681,7 @@ void Internal::eagerly_remove_from_occurences (Clause *c) {
if (*q != c)
q++;
}
assert (q + 1 == p);
CADICAL_assert (q + 1 == p);
occ.resize (q - begin);
}
}
@ -730,7 +734,7 @@ bool Internal::apply_factoring (Factoring &factoring, Quotient *q) {
delete_unfactored (p);
for (Quotient *p = q; p; p = p->prev)
update_factored (factoring, p);
assert (fresh > 0);
CADICAL_assert (fresh > 0);
resize_factoring (factoring, fresh);
return true;
}
@ -758,7 +762,7 @@ void Internal::schedule_factorization (Factoring &factoring) {
update_factor_candidate (factoring, not_lit);
}
}
#ifndef QUIET
#ifndef CADICAL_QUIET
size_t size_cands = factoring.schedule.size ();
VERBOSE (2, "scheduled %zu factorization candidate literals %.0f %%",
size_cands, percent (size_cands, max_var));
@ -769,7 +773,7 @@ bool Internal::run_factorization (int64_t limit) {
Factoring factoring = Factoring (this, limit);
schedule_factorization (factoring);
bool done = false;
#ifndef QUIET
#ifndef CADICAL_QUIET
unsigned factored = 0;
#endif
int64_t *ticks = &stats.ticks.factor;
@ -804,7 +808,7 @@ bool Internal::run_factorization (int64_t limit) {
const int next = next_factor (factoring, &next_count);
if (next == 0)
break;
assert (next_count > 1);
CADICAL_assert (next_count > 1);
if (next_count < 2)
break;
factorize_next (factoring, next, next_count);
@ -813,7 +817,7 @@ bool Internal::run_factorization (int64_t limit) {
Quotient *q = best_quotient (factoring, &reduction);
if (q && (int) reduction > factoring.bound) {
if (apply_factoring (factoring, q)) {
#ifndef QUIET
#ifndef CADICAL_QUIET
factored++;
#endif
} else
@ -832,7 +836,7 @@ bool Internal::run_factorization (int64_t limit) {
}
// kissat initializes scores for new variables at this point, however
// this is actually done already during resize of internal
#ifndef QUIET
#ifndef CADICAL_QUIET
report ('f', !factored);
#endif
return completed;
@ -848,7 +852,7 @@ int Internal::get_new_extension_variable () {
reset_watches ();
// it does not enlarge otab, however, so we do this manually
init_occs ();
assert (vlit (new_internal));
CADICAL_assert (vlit (new_internal));
return new_internal;
}
@ -859,9 +863,9 @@ bool Internal::factor () {
return false;
if (!opts.factor)
return false;
// The following assertion fails if there are *only* user propagator
// The following CADICAL_assertion fails if there are *only* user propagator
// clauses (which are redundant).
// assert (stats.mark.factor || clauses.empty ());
// CADICAL_assert (stats.mark.factor || clauses.empty ());
if (last.factor.marked >= stats.mark.factor) {
VERBOSE (3,
"factorization skipped as no literals have been"
@ -869,7 +873,7 @@ bool Internal::factor () {
last.factor.marked, stats.mark.factor);
return false;
}
assert (!level);
CADICAL_assert (!level);
SET_EFFORT_LIMIT (limit, factor, stats.factor);
if (!stats.factor)
@ -878,7 +882,7 @@ bool Internal::factor () {
START_SIMPLIFIER (factor, FACTOR);
stats.factor++;
#ifndef QUIET
#ifndef CADICAL_QUIET
struct {
int64_t variables, clauses, ticks;
} before, after, delta;
@ -896,7 +900,7 @@ bool Internal::factor () {
learn_empty_clause ();
}
#ifndef QUIET
#ifndef CADICAL_QUIET
after.variables = stats.variables_extension + stats.variables_original;
after.clauses = stats.current.irredundant;
after.ticks = stats.ticks.factor;
@ -919,3 +923,5 @@ bool Internal::factor () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,3 +1,5 @@
#include "global.h"
#include "internal.hpp"
/*------------------------------------------------------------------------*/
@ -11,13 +13,28 @@ extern "C" {
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
}
#ifndef _WIN32
#ifdef WIN32
#include <windows.h>
#include <io.h>
#include <cstdio>
#define access _access
#define popen _popen
#define pclose _pclose
#define R_OK 4
#define W_OK 2
#define S_IFIFO _S_IFIFO
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#else
extern "C" {
#include <sys/wait.h>
#include <unistd.h>
}
#endif
@ -33,6 +50,8 @@ extern "C" {
#endif
ABC_NAMESPACE_IMPL_START
/*------------------------------------------------------------------------*/
namespace CaDiCaL {
@ -43,13 +62,13 @@ namespace CaDiCaL {
File::File (Internal *i, bool w, int c, int p, FILE *f, const char *n)
: internal (i),
#if !defined(QUIET) || !defined(NDEBUG)
#if !defined(CADICAL_QUIET) || !defined(CADICAL_NDEBUG)
writing (w),
#endif
close_file (c), child_pid (p), file (f), _name (strdup (n)),
_lineno (1), _bytes (0) {
(void) w;
assert (f), assert (n);
CADICAL_assert (f), CADICAL_assert (n);
}
/*------------------------------------------------------------------------*/
@ -129,7 +148,7 @@ static int sig7z[] = {0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C, EOF};
static int lzmasig[] = {0x5D, EOF};
bool File::match (Internal *internal, const char *path, const int *sig) {
assert (path);
CADICAL_assert (path);
FILE *tmp = fopen (path, "r");
if (!tmp) {
WARNING ("failed to open '%s' to check signature", path);
@ -170,7 +189,7 @@ char *File::find_program (const char *prg) {
size_t pathlen = (q - p) + prglen;
char *path = new char[pathlen + 1];
snprintf (path, pathlen + 1, "%s/%s", p, prg);
assert (strlen (path) == pathlen);
CADICAL_assert (strlen (path) == pathlen);
if (exists (path))
res = path;
else
@ -226,7 +245,7 @@ void File::delete_str_vector (std::vector<char *> &argv) {
FILE *File::open_pipe (Internal *internal, const char *fmt,
const char *path, const char *mode) {
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) internal;
#endif
size_t prglen = 0;
@ -274,14 +293,14 @@ static std::mutex compressed_file_writing_mutex;
FILE *File::write_pipe (Internal *internal, const char *command,
const char *path, int &child_pid) {
assert (command[0] && command[0] != ' ');
CADICAL_assert (command[0] && command[0] != ' ');
MSG ("writing through command '%s' to '%s'", command, path);
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) internal;
#endif
std::vector<char *> args;
split_str (command, args);
assert (!args.empty ());
CADICAL_assert (!args.empty ());
args.push_back (0);
char **argv = args.data ();
char *absolute_command_path = find_program (argv[0]);
@ -328,7 +347,7 @@ FILE *File::write_pipe (Internal *internal, const char *command,
// be closed by the parent process we have to close all of the
// erroneously cloned fds here.
#ifndef NCLOSEFROM
#ifndef CADICAL_NCLOSEFROM
::closefrom (3);
#else
// Simplistic replacement on Unix without 'closefrom'.
@ -341,7 +360,7 @@ FILE *File::write_pipe (Internal *internal, const char *command,
if (absolute_command_path)
delete[] absolute_command_path;
delete_str_vector (args);
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) internal;
#endif
#if defined(__APPLE__) || defined(__MACH__)
@ -421,8 +440,8 @@ File *File::write (Internal *internal, const char *path) {
}
void File::close (bool print) {
assert (file);
#ifndef QUIET
CADICAL_assert (file);
#ifndef CADICAL_QUIET
if (internal->opts.quiet)
print = false;
else if (internal->opts.verbose > 0)
@ -457,7 +476,7 @@ void File::close (bool print) {
// TODO what about error checking for 'fclose', 'pclose' or 'waitpid'?
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
if (writing) {
uint64_t written_bytes = bytes ();
@ -493,7 +512,7 @@ void File::close (bool print) {
}
void File::flush () {
assert (file);
CADICAL_assert (file);
fflush (file);
}
@ -504,3 +523,5 @@ File::~File () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,104 +1,108 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::mark_fixed (int lit) {
if (external->fixed_listener) {
int elit = externalize (lit);
assert (elit);
CADICAL_assert (elit);
const int eidx = abs (elit);
if (!external->ervars[eidx])
external->fixed_listener->notify_fixed_assignment (elit);
}
Flags &f = flags (lit);
assert (f.status == Flags::ACTIVE);
CADICAL_assert (f.status == Flags::ACTIVE);
f.status = Flags::FIXED;
LOG ("fixed %d", abs (lit));
stats.all.fixed++;
stats.now.fixed++;
stats.inactive++;
assert (stats.active);
CADICAL_assert (stats.active);
stats.active--;
assert (!active (lit));
assert (f.fixed ());
CADICAL_assert (!active (lit));
CADICAL_assert (f.fixed ());
if (external_prop && private_steps) {
// If pre/inprocessing found a fixed assignment, we want the propagator
// to know about it.
// But at that point it is not guaranteed to be already on the trail, so
// notification will happen only later.
assert (!level);
CADICAL_assert (!level);
}
}
void Internal::mark_eliminated (int lit) {
Flags &f = flags (lit);
assert (f.status == Flags::ACTIVE);
CADICAL_assert (f.status == Flags::ACTIVE);
f.status = Flags::ELIMINATED;
LOG ("eliminated %d", abs (lit));
stats.all.eliminated++;
stats.now.eliminated++;
stats.inactive++;
assert (stats.active);
CADICAL_assert (stats.active);
stats.active--;
assert (!active (lit));
assert (f.eliminated ());
CADICAL_assert (!active (lit));
CADICAL_assert (f.eliminated ());
}
void Internal::mark_pure (int lit) {
Flags &f = flags (lit);
assert (f.status == Flags::ACTIVE);
CADICAL_assert (f.status == Flags::ACTIVE);
f.status = Flags::PURE;
LOG ("pure %d", abs (lit));
stats.all.pure++;
stats.now.pure++;
stats.inactive++;
assert (stats.active);
CADICAL_assert (stats.active);
stats.active--;
assert (!active (lit));
assert (f.pure ());
CADICAL_assert (!active (lit));
CADICAL_assert (f.pure ());
}
void Internal::mark_substituted (int lit) {
Flags &f = flags (lit);
assert (f.status == Flags::ACTIVE);
CADICAL_assert (f.status == Flags::ACTIVE);
f.status = Flags::SUBSTITUTED;
LOG ("substituted %d", abs (lit));
stats.all.substituted++;
stats.now.substituted++;
stats.inactive++;
assert (stats.active);
CADICAL_assert (stats.active);
stats.active--;
assert (!active (lit));
assert (f.substituted ());
CADICAL_assert (!active (lit));
CADICAL_assert (f.substituted ());
}
void Internal::mark_active (int lit) {
Flags &f = flags (lit);
assert (f.status == Flags::UNUSED);
CADICAL_assert (f.status == Flags::UNUSED);
f.status = Flags::ACTIVE;
LOG ("activate %d previously unused", abs (lit));
assert (stats.inactive);
CADICAL_assert (stats.inactive);
stats.inactive--;
assert (stats.unused);
CADICAL_assert (stats.unused);
stats.unused--;
stats.active++;
assert (active (lit));
CADICAL_assert (active (lit));
}
void Internal::reactivate (int lit) {
assert (!active (lit));
CADICAL_assert (!active (lit));
Flags &f = flags (lit);
assert (f.status != Flags::FIXED);
assert (f.status != Flags::UNUSED);
CADICAL_assert (f.status != Flags::FIXED);
CADICAL_assert (f.status != Flags::UNUSED);
#ifdef LOGGING
const char *msg = 0;
#endif
switch (f.status) {
default:
case Flags::ELIMINATED:
assert (f.status == Flags::ELIMINATED);
assert (stats.now.eliminated > 0);
CADICAL_assert (f.status == Flags::ELIMINATED);
CADICAL_assert (stats.now.eliminated > 0);
stats.now.eliminated--;
#ifdef LOGGING
msg = "eliminated";
@ -108,28 +112,30 @@ void Internal::reactivate (int lit) {
#ifdef LOGGING
msg = "substituted";
#endif
assert (stats.now.substituted > 0);
CADICAL_assert (stats.now.substituted > 0);
stats.now.substituted--;
break;
case Flags::PURE:
#ifdef LOGGING
msg = "pure literal";
#endif
assert (stats.now.pure > 0);
CADICAL_assert (stats.now.pure > 0);
stats.now.pure--;
break;
}
#ifdef LOGGING
assert (msg);
CADICAL_assert (msg);
LOG ("reactivate previously %s %d", msg, abs (lit));
#endif
f.status = Flags::ACTIVE;
f.sweep = false;
assert (active (lit));
CADICAL_assert (active (lit));
stats.reactivated++;
assert (stats.inactive > 0);
CADICAL_assert (stats.inactive > 0);
stats.inactive--;
stats.active++;
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
bool Internal::flip (int lit) {
@ -11,7 +15,7 @@ bool Internal::flip (int lit) {
/*
if (flags (lit).unused ()) {
assert (lit <= max_var);
CADICAL_assert (lit <= max_var);
mark_active (lit);
set_val (lit, 1);
return true;
@ -31,9 +35,9 @@ bool Internal::flip (int lit) {
const int idx = vidx (lit);
const signed char original_value = vals[idx];
assert (original_value);
CADICAL_assert (original_value);
lit = original_value < 0 ? -idx : idx;
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
// Here we go over all the clauses in which 'lit' is watched by 'lit' and
// check whether assigning 'lit' to false would break watching invariants
@ -57,7 +61,7 @@ bool Internal::flip (int lit) {
const signed char b = val (w.blit);
if (b > 0)
continue;
assert (b < 0);
CADICAL_assert (b < 0);
res = false;
break;
}
@ -96,7 +100,7 @@ bool Internal::flip (int lit) {
k++;
if (v < 0) {
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
@ -106,8 +110,8 @@ bool Internal::flip (int lit) {
break;
}
assert (v > 0);
assert (lits + 2 <= k), assert (k <= w.clause->end ());
CADICAL_assert (v > 0);
CADICAL_assert (lits + 2 <= k), CADICAL_assert (k <= w.clause->end ());
w.clause->pos = k - lits;
lits[0] = other, lits[1] = r, *k = lit;
watch_literal (r, lit, w.clause);
@ -133,24 +137,24 @@ bool Internal::flip (int lit) {
const int idx = vidx (lit);
const signed char original_value = vals[idx];
assert (original_value);
CADICAL_assert (original_value);
lit = original_value < 0 ? -idx : idx;
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
LOG ("flipping value of %d = 1 to %d = -1", lit, lit);
set_val (idx, -original_value);
assert (val (-lit) > 0);
assert (val (lit) < 0);
CADICAL_assert (val (-lit) > 0);
CADICAL_assert (val (lit) < 0);
Var &v = var (idx);
assert (trail[v.trail] == lit);
CADICAL_assert (trail[v.trail] == lit);
trail[v.trail] = -lit;
if (opts.ilb) {
if (!tainted_literal)
tainted_literal = lit;
else {
assert (val (tainted_literal));
CADICAL_assert (val (tainted_literal));
if (v.level < var (tainted_literal).level) {
tainted_literal = lit;
}
@ -171,7 +175,7 @@ bool Internal::flippable (int lit) {
/*
if (flags (lit).unused ()) {
assert (lit <= max_var);
CADICAL_assert (lit <= max_var);
mark_active (lit);
return true;
}
@ -189,9 +193,9 @@ bool Internal::flippable (int lit) {
const int idx = vidx (lit);
const signed char original_value = vals[idx];
assert (original_value);
CADICAL_assert (original_value);
lit = original_value < 0 ? -idx : idx;
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
// Here we go over all the clauses in which 'lit' is watched by 'lit' and
// check whether assigning 'lit' to false would break watching invariants
@ -209,7 +213,7 @@ bool Internal::flippable (int lit) {
const signed char b = val (w.blit);
if (b > 0)
continue;
assert (b < 0);
CADICAL_assert (b < 0);
if (w.binary ()) {
res = false;
@ -239,7 +243,7 @@ bool Internal::flippable (int lit) {
k++;
if (v < 0) {
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
@ -249,9 +253,9 @@ bool Internal::flippable (int lit) {
break;
}
assert (v > 0);
assert (lits + 2 <= k);
assert (k <= w.clause->end ());
CADICAL_assert (v > 0);
CADICAL_assert (lits + 2 <= k);
CADICAL_assert (k <= w.clause->end ());
w.clause->pos = k - lits;
i->blit = r;
}
@ -267,3 +271,5 @@ bool Internal::flippable (int lit) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Format::enlarge () {
@ -34,7 +38,7 @@ void Format::push_uint64 (uint64_t u) {
}
static bool match_format (const char *&str, const char *pattern) {
assert (pattern);
CADICAL_assert (pattern);
const char *p = str;
const char *q = pattern;
while (*q)
@ -87,3 +91,5 @@ const char *Format::append (const char *fmt, ...) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,12 +1,16 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
FratTracer::FratTracer (Internal *i, File *f, bool b, bool a)
: internal (i), file (f), binary (b), with_antecedents (a)
#ifndef QUIET
#ifndef CADICAL_QUIET
,
added (0), deleted (0), finalized (0), original (0)
#endif
@ -28,15 +32,15 @@ FratTracer::~FratTracer () {
/*------------------------------------------------------------------------*/
inline void FratTracer::put_binary_zero () {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
file->put ((unsigned char) 0);
}
inline void FratTracer::put_binary_lit (int lit) {
assert (binary);
assert (file);
assert (lit != INT_MIN);
CADICAL_assert (binary);
CADICAL_assert (file);
CADICAL_assert (lit != INT_MIN);
unsigned x = 2 * abs (lit) + (lit < 0);
unsigned char ch;
while (x & ~0x7f) {
@ -49,8 +53,8 @@ inline void FratTracer::put_binary_lit (int lit) {
}
inline void FratTracer::put_binary_id (int64_t id, bool can_be_negative) {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
uint64_t x = abs (id);
if (can_be_negative) {
x = 2 * x + (id < 0);
@ -202,7 +206,7 @@ void FratTracer::add_derived_clause (int64_t id, bool,
frat_add_derived_clause (id, clause, chain);
else
frat_add_derived_clause (id, clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
added++;
#endif
}
@ -213,7 +217,7 @@ void FratTracer::delete_clause (int64_t id, bool,
return;
LOG ("FRAT TRACER tracing deletion of clause");
frat_delete_clause (id, clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
deleted++;
#endif
}
@ -229,7 +233,7 @@ void FratTracer::finalize_clause (int64_t id, const vector<int> &clause) {
bool FratTracer::closed () { return file->closed (); }
#ifndef QUIET
#ifndef CADICAL_QUIET
void FratTracer::print_statistics () {
uint64_t bytes = file->bytes ();
@ -249,9 +253,9 @@ void FratTracer::print_statistics () {
#endif
void FratTracer::close (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->close ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("FRAT proof file '%s' closed", file->name ());
print_statistics ();
@ -262,9 +266,9 @@ void FratTracer::close (bool print) {
}
void FratTracer::flush (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->flush ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("FRAT proof file '%s' flushed", file->name ());
print_statistics ();
@ -275,3 +279,5 @@ void FratTracer::flush (bool print) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -19,7 +23,7 @@ namespace CaDiCaL {
int Internal::second_literal_in_binary_clause (Eliminator &eliminator,
Clause *c, int first) {
assert (!c->garbage);
CADICAL_assert (!c->garbage);
int second = 0;
for (const auto &lit : *c) {
if (lit == first)
@ -42,7 +46,7 @@ int Internal::second_literal_in_binary_clause (Eliminator &eliminator,
return 0;
if (second == INT_MIN)
return 0;
assert (active (second));
CADICAL_assert (active (second));
#ifdef LOGGING
if (c->size == 2)
LOG (c, "found binary");
@ -115,8 +119,8 @@ void Internal::mark_binary_literals (Eliminator &eliminator, int first) {
if (!eliminator.gates.empty ())
return;
assert (!marked (first));
assert (eliminator.marked.empty ());
CADICAL_assert (!marked (first));
CADICAL_assert (eliminator.marked.empty ());
const Occs &os = occs (first);
for (const auto &c : os) {
@ -133,11 +137,11 @@ void Internal::mark_binary_literals (Eliminator &eliminator, int first) {
LOG ("found binary resolved unit %d", first);
if (lrat) {
Clause *d = find_binary_clause (first, -second);
assert (d);
CADICAL_assert (d);
for (auto &lit : *d) {
if (lit == first || lit == -second)
continue;
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
Flags &f = flags (lit);
if (f.seen)
continue;
@ -150,7 +154,7 @@ void Internal::mark_binary_literals (Eliminator &eliminator, int first) {
for (auto &lit : *c) {
if (lit == first || lit == second)
continue;
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
Flags &f = flags (lit);
if (f.seen)
continue;
@ -202,7 +206,7 @@ void Internal::find_equivalence (Eliminator &eliminator, int pivot) {
if (!opts.elimequivs)
return;
assert (opts.elimsubst);
CADICAL_assert (opts.elimsubst);
if (unsat)
return;
@ -231,11 +235,11 @@ void Internal::find_equivalence (Eliminator &eliminator, int pivot) {
// still solved potential issues with flags
if (lrat) {
Clause *d = find_binary_clause (pivot, second);
assert (d);
CADICAL_assert (d);
for (auto &lit : *d) {
if (lit == pivot || lit == second)
continue;
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
Flags &f = flags (lit);
if (f.seen)
continue;
@ -248,7 +252,7 @@ void Internal::find_equivalence (Eliminator &eliminator, int pivot) {
for (auto &lit : *c) {
if (lit == -pivot || lit == second)
continue;
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
Flags &f = flags (lit);
if (f.seen)
continue;
@ -279,7 +283,7 @@ void Internal::find_equivalence (Eliminator &eliminator, int pivot) {
stats.elimgates++;
LOG (c, "first gate clause");
assert (!c->gate);
CADICAL_assert (!c->gate);
c->gate = true;
eliminator.gates.push_back (c);
@ -295,10 +299,10 @@ void Internal::find_equivalence (Eliminator &eliminator, int pivot) {
break;
}
}
assert (d);
CADICAL_assert (d);
LOG (d, "second gate clause");
assert (!d->gate);
CADICAL_assert (!d->gate);
d->gate = true;
eliminator.gates.push_back (d);
eliminator.gatetype = EQUI;
@ -321,7 +325,7 @@ void Internal::find_and_gate (Eliminator &eliminator, int pivot) {
if (!opts.elimands)
return;
assert (opts.elimsubst);
CADICAL_assert (opts.elimsubst);
if (unsat)
return;
@ -348,7 +352,7 @@ void Internal::find_and_gate (Eliminator &eliminator, int pivot) {
for (const auto &lit : *c) {
if (lit == -pivot)
continue;
assert (lit != pivot);
CADICAL_assert (lit != pivot);
signed char tmp = val (lit);
if (tmp < 0)
continue;
@ -383,7 +387,7 @@ void Internal::find_and_gate (Eliminator &eliminator, int pivot) {
for (const auto &lit : *c) {
if (lit == -pivot)
continue;
assert (lit != pivot);
CADICAL_assert (lit != pivot);
if (!first)
fputs (" & ", stdout);
printf ("%d", -lit);
@ -399,18 +403,18 @@ void Internal::find_and_gate (Eliminator &eliminator, int pivot) {
eliminator.gatetype = AND;
(void) arity;
assert (!c->gate);
CADICAL_assert (!c->gate);
c->gate = true;
eliminator.gates.push_back (c);
for (const auto &lit : *c) {
if (lit == -pivot)
continue;
assert (lit != pivot);
CADICAL_assert (lit != pivot);
signed char tmp = val (lit);
if (tmp < 0)
continue;
assert (!tmp);
assert (marked (lit) < 0);
CADICAL_assert (!tmp);
CADICAL_assert (marked (lit) < 0);
marks[vidx (lit)] *= 2;
}
@ -426,12 +430,12 @@ void Internal::find_and_gate (Eliminator &eliminator, int pivot) {
if (tmp != 2)
continue;
LOG (d, "AND gate binary side clause");
assert (!d->gate);
CADICAL_assert (!d->gate);
d->gate = true;
eliminator.gates.push_back (d);
count++;
}
assert (count >= arity);
CADICAL_assert (count >= arity);
(void) count;
break;
@ -503,7 +507,7 @@ void Internal::find_if_then_else (Eliminator &eliminator, int pivot) {
if (!opts.elimites)
return;
assert (opts.elimsubst);
CADICAL_assert (opts.elimsubst);
if (unsat)
return;
@ -523,7 +527,7 @@ void Internal::find_if_then_else (Eliminator &eliminator, int pivot) {
swap (ai, bi);
if (ci == pivot)
swap (ai, ci);
assert (ai == pivot);
CADICAL_assert (ai == pivot);
for (auto j = i + 1; j != end; j++) {
Clause *dj = *j;
int aj, bj, cj;
@ -533,7 +537,7 @@ void Internal::find_if_then_else (Eliminator &eliminator, int pivot) {
swap (aj, bj);
if (cj == pivot)
swap (aj, cj);
assert (aj == pivot);
CADICAL_assert (aj == pivot);
if (abs (bi) == abs (cj))
swap (bj, cj);
if (abs (ci) == abs (cj))
@ -551,10 +555,10 @@ void Internal::find_if_then_else (Eliminator &eliminator, int pivot) {
LOG (d1, "3rd if-then-else");
LOG (d2, "4th if-then-else");
LOG ("found ITE gate %d == (%d ? %d : %d)", pivot, -bi, -ci, -cj);
assert (!di->gate);
assert (!dj->gate);
assert (!d1->gate);
assert (!d2->gate);
CADICAL_assert (!di->gate);
CADICAL_assert (!dj->gate);
CADICAL_assert (!d1->gate);
CADICAL_assert (!d2->gate);
di->gate = true;
dj->gate = true;
d1->gate = true;
@ -634,7 +638,7 @@ void Internal::find_xor_gate (Eliminator &eliminator, int pivot) {
if (!opts.elimxors)
return;
assert (opts.elimsubst);
CADICAL_assert (opts.elimsubst);
if (unsat)
return;
@ -658,7 +662,7 @@ void Internal::find_xor_gate (Eliminator &eliminator, int pivot) {
if (arity > opts.elimxorlim)
continue;
assert (eliminator.gates.empty ());
CADICAL_assert (eliminator.gates.empty ());
unsigned needed = (1u << arity) - 1; // additional clauses
unsigned signs = 0; // literals to negate
@ -685,7 +689,7 @@ void Internal::find_xor_gate (Eliminator &eliminator, int pivot) {
}
eliminator.gates.push_back (d);
assert (eliminator.gates.size () == (1u << arity));
CADICAL_assert (eliminator.gates.size () == (1u << arity));
#ifdef LOGGING
if (opts.log) {
@ -696,7 +700,7 @@ void Internal::find_xor_gate (Eliminator &eliminator, int pivot) {
for (const auto &lit : *d) {
if (lit == pivot)
continue;
assert (lit != -pivot);
CADICAL_assert (lit != -pivot);
if (!first)
fputs (" ^ ", stdout);
printf ("%d", lit);
@ -741,7 +745,7 @@ void Internal::find_gate_clauses (Eliminator &eliminator, int pivot) {
if (val (pivot))
return;
assert (eliminator.gates.empty ());
CADICAL_assert (eliminator.gates.empty ());
find_equivalence (eliminator, pivot);
find_and_gate (eliminator, pivot);
@ -754,7 +758,7 @@ void Internal::find_gate_clauses (Eliminator &eliminator, int pivot) {
void Internal::unmark_gate_clauses (Eliminator &eliminator) {
LOG ("unmarking %zd gate clauses", eliminator.gates.size ());
for (const auto &c : eliminator.gates) {
assert (c->gate);
CADICAL_assert (c->gate);
c->gate = false;
}
eliminator.gates.clear ();
@ -764,3 +768,5 @@ void Internal::unmark_gate_clauses (Eliminator &eliminator) {
/*------------------------------------------------------------------------*/
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -7,7 +11,7 @@ namespace CaDiCaL {
IdrupTracer::IdrupTracer (Internal *i, File *f, bool b)
: internal (i), file (f), binary (b), num_clauses (0), size_clauses (0),
clauses (0), last_hash (0), last_id (0), last_clause (0)
#ifndef QUIET
#ifndef CADICAL_QUIET
,
added (0), deleted (0)
#endif
@ -21,10 +25,10 @@ IdrupTracer::IdrupTracer (Internal *i, File *f, bool b)
uint64_t nonce = random.next ();
if (!(nonce & 1))
nonce++;
assert (nonce), assert (nonce & 1);
CADICAL_assert (nonce), CADICAL_assert (nonce & 1);
nonces[n] = nonce;
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
binary = b;
#else
(void) b;
@ -50,7 +54,7 @@ IdrupTracer::~IdrupTracer () {
/*------------------------------------------------------------------------*/
void IdrupTracer::enlarge_clauses () {
assert (num_clauses == size_clauses);
CADICAL_assert (num_clauses == size_clauses);
const uint64_t new_size_clauses = size_clauses ? 2 * size_clauses : 1;
LOG ("IDRUP Tracer enlarging clauses of tracer from %" PRIu64
" to %" PRIu64,
@ -73,7 +77,7 @@ void IdrupTracer::enlarge_clauses () {
IdrupClause *IdrupTracer::new_clause () {
const size_t size = imported_clause.size ();
assert (size <= UINT_MAX);
CADICAL_assert (size <= UINT_MAX);
const int off = size ? -1 : 0;
const size_t bytes = sizeof (IdrupClause) + (size - off) * sizeof (int);
IdrupClause *res = (IdrupClause *) new char[bytes];
@ -91,13 +95,13 @@ IdrupClause *IdrupTracer::new_clause () {
}
void IdrupTracer::delete_clause (IdrupClause *c) {
assert (c);
CADICAL_assert (c);
num_clauses--;
delete[] (char *) c;
}
uint64_t IdrupTracer::reduce_hash (uint64_t hash, uint64_t size) {
assert (size > 0);
CADICAL_assert (size > 0);
unsigned shift = 32;
uint64_t res = hash;
while ((((uint64_t) 1) << shift) > size) {
@ -105,12 +109,12 @@ uint64_t IdrupTracer::reduce_hash (uint64_t hash, uint64_t size) {
shift >>= 1;
}
res &= size - 1;
assert (res < size);
CADICAL_assert (res < size);
return res;
}
uint64_t IdrupTracer::compute_hash (const int64_t id) {
assert (id > 0);
CADICAL_assert (id > 0);
unsigned j = id % num_nonces;
uint64_t tmp = nonces[j] * (uint64_t) id;
return last_hash = tmp;
@ -131,7 +135,7 @@ bool IdrupTracer::find_and_delete (const int64_t id) {
}
if (!c)
return false;
assert (c && res);
CADICAL_assert (c && res);
*res = c->next;
int *begin = c->literals;
for (size_t i = 0; i < c->size; i++) {
@ -158,15 +162,15 @@ inline void IdrupTracer::flush_if_piping () {
}
inline void IdrupTracer::put_binary_zero () {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
file->put ((unsigned char) 0);
}
inline void IdrupTracer::put_binary_lit (int lit) {
assert (binary);
assert (file);
assert (lit != INT_MIN);
CADICAL_assert (binary);
CADICAL_assert (file);
CADICAL_assert (lit != INT_MIN);
unsigned x = 2 * abs (lit) + (lit < 0);
unsigned char ch;
while (x & ~0x7f) {
@ -179,8 +183,8 @@ inline void IdrupTracer::put_binary_lit (int lit) {
}
inline void IdrupTracer::put_binary_id (int64_t id, bool can_be_negative) {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
uint64_t x = abs (id);
if (can_be_negative) {
x = 2 * x + (id < 0);
@ -251,12 +255,12 @@ void IdrupTracer::idrup_add_original_clause (const vector<int> &clause) {
void IdrupTracer::idrup_delete_clause (int64_t id,
const vector<int> &clause) {
if (find_and_delete (id)) {
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
if (binary)
file->put ('w');
else
file->put ("w ");
#ifndef QUIET
#ifndef CADICAL_QUIET
weakened++;
#endif
} else {
@ -264,7 +268,7 @@ void IdrupTracer::idrup_delete_clause (int64_t id,
file->put ('d');
else
file->put ("d ");
#ifndef QUIET
#ifndef CADICAL_QUIET
deleted++;
#endif
}
@ -392,10 +396,10 @@ void IdrupTracer::add_derived_clause (int64_t, bool,
const vector<int64_t> &) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG (clause, "IDRUP TRACER tracing addition of derived clause");
idrup_add_derived_clause (clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
added++;
#endif
}
@ -405,7 +409,7 @@ void IdrupTracer::add_assumption_clause (int64_t id,
const vector<int64_t> &) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG (clause, "IDRUP TRACER tracing addition of assumption clause");
for (auto &lit : clause)
imported_clause.push_back (lit);
@ -418,7 +422,7 @@ void IdrupTracer::delete_clause (int64_t id, bool,
const vector<int> &clause) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG ("IDRUP TRACER tracing deletion of clause[%" PRId64 "]", id);
idrup_delete_clause (id, clause);
}
@ -426,11 +430,11 @@ void IdrupTracer::delete_clause (int64_t id, bool,
void IdrupTracer::weaken_minus (int64_t id, const vector<int> &) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG ("IDRUP TRACER tracing weaken minus of clause[%" PRId64 "]", id);
last_id = id;
insert ();
#ifndef QUIET
#ifndef CADICAL_QUIET
weakened++;
#endif
}
@ -439,7 +443,7 @@ void IdrupTracer::conclude_unsat (ConclusionType,
const vector<int64_t> &conclusion) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG (conclusion, "IDRUP TRACER tracing conclusion of clause(s)");
idrup_conclude_and_delete (conclusion);
}
@ -451,12 +455,12 @@ void IdrupTracer::add_original_clause (int64_t id, bool,
return;
if (!restored) {
LOG (clause, "IDRUP TRACER tracing addition of original clause");
#ifndef QUIET
#ifndef CADICAL_QUIET
original++;
#endif
return idrup_add_original_clause (clause);
}
assert (restored);
CADICAL_assert (restored);
if (find_and_delete (id)) {
LOG (clause,
"IDRUP TRACER the clause was not yet weakened, so no restore");
@ -464,7 +468,7 @@ void IdrupTracer::add_original_clause (int64_t id, bool,
}
LOG (clause, "IDRUP TRACER tracing addition of restored clause");
idrup_add_restored_clause (clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
restore++;
#endif
}
@ -495,7 +499,7 @@ void IdrupTracer::solve_query () {
return;
LOG (assumptions, "IDRUP TRACER tracing solve query with assumptions");
idrup_solve_query ();
#ifndef QUIET
#ifndef CADICAL_QUIET
solved++;
#endif
}
@ -514,7 +518,7 @@ void IdrupTracer::reset_assumptions () {
bool IdrupTracer::closed () { return file->closed (); }
#ifndef QUIET
#ifndef CADICAL_QUIET
void IdrupTracer::print_statistics () {
// TODO complete this.
@ -538,9 +542,9 @@ void IdrupTracer::print_statistics () {
#endif
void IdrupTracer::close (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->close ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("IDRUP proof file '%s' closed", file->name ());
print_statistics ();
@ -551,9 +555,9 @@ void IdrupTracer::close (bool print) {
}
void IdrupTracer::flush (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->flush ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("IDRUP proof file '%s' flushed", file->name ());
print_statistics ();
@ -564,3 +568,5 @@ void IdrupTracer::flush (bool print) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -13,7 +17,7 @@ namespace CaDiCaL {
void Internal::collect_instantiation_candidates (
Instantiator &instantiator) {
assert (occurring ());
CADICAL_assert (occurring ());
for (auto idx : vars) {
if (frozen (idx))
continue;
@ -63,8 +67,8 @@ void Internal::collect_instantiation_candidates (
inline void Internal::inst_assign (int lit) {
LOG ("instantiate assign %d", lit);
assert (!val (lit));
assert ((int) num_assigned < max_var);
CADICAL_assert (!val (lit));
CADICAL_assert ((int) num_assigned < max_var);
num_assigned++;
set_val (lit, 1);
trail.push_back (lit);
@ -123,12 +127,12 @@ bool Internal::inst_propagate () { // Adapted from 'propagate'.
k++;
if (v < 0) {
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
w.clause->pos = k - lits;
assert (lits + 2 <= k), assert (k <= w.clause->end ());
CADICAL_assert (lits + 2 <= k), CADICAL_assert (k <= w.clause->end ());
if (v > 0) {
j[-1].blit = r;
} else if (!v) {
@ -138,14 +142,14 @@ bool Internal::inst_propagate () { // Adapted from 'propagate'.
watch_literal (r, lit, w.clause);
j--;
} else if (!u) {
assert (v < 0);
CADICAL_assert (v < 0);
if (lrat) {
inst_chain.push_back (w.clause);
}
inst_assign (other);
} else {
assert (u < 0);
assert (v < 0);
CADICAL_assert (u < 0);
CADICAL_assert (v < 0);
if (lrat) {
inst_chain.push_back (w.clause);
}
@ -176,7 +180,7 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
stats.instried++;
if (c->garbage)
return false;
assert (!level);
CADICAL_assert (!level);
bool found = false, satisfied = false, inactive = false;
int unassigned = 0;
for (const auto &other : *c) {
@ -203,13 +207,13 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
if (unassigned < 3)
return false;
size_t before = trail.size ();
assert (propagated == before);
assert (active (lit));
assert (inst_chain.empty ());
CADICAL_assert (propagated == before);
CADICAL_assert (active (lit));
CADICAL_assert (inst_chain.empty ());
LOG (c, "trying to instantiate %d in", lit);
assert (!c->garbage);
CADICAL_assert (!c->garbage);
c->instantiated = true;
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
level++;
inst_assign (lit); // Assume 'lit' to true.
for (const auto &other : *c) {
@ -217,23 +221,23 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
continue;
const signed char tmp = val (other);
if (tmp) {
assert (tmp < 0);
CADICAL_assert (tmp < 0);
continue;
}
inst_assign (-other); // Assume other to false.
}
bool ok = inst_propagate (); // Propagate.
assert (lrat_chain.empty ()); // chain will be built here
CADICAL_assert (lrat_chain.empty ()); // chain will be built here
if (ok) {
inst_chain.clear ();
} else if (lrat) { // analyze conflict for lrat
assert (inst_chain.size ());
CADICAL_assert (inst_chain.size ());
Clause *reason = inst_chain.back ();
inst_chain.pop_back ();
lrat_chain.push_back (reason->id);
for (const auto &other : *reason) {
Flags &f = flags (other);
assert (!f.seen);
CADICAL_assert (!f.seen);
f.seen = true;
analyzed.push_back (other);
}
@ -242,7 +246,7 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
const int other = trail.back ();
LOG ("instantiate unassign %d", other);
trail.pop_back ();
assert (val (other) > 0);
CADICAL_assert (val (other) > 0);
num_assigned--;
set_val (other, 0);
// this is a variant of conflict analysis which is only needed for lrat
@ -263,7 +267,7 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
inst_chain.pop_back ();
}
}
assert (inst_chain.empty ());
CADICAL_assert (inst_chain.empty ());
// post processing step for lrat
if (!ok && lrat) {
if (flags (lit).seen)
@ -284,12 +288,12 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
clear_analyzed_literals ();
reverse (lrat_chain.begin (), lrat_chain.end ());
}
assert (analyzed.empty ());
CADICAL_assert (analyzed.empty ());
propagated = before;
assert (level == 1);
CADICAL_assert (level == 1);
level = 0;
if (ok) {
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
LOG ("instantiation failed");
return false;
}
@ -298,7 +302,7 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
strengthen_clause (c, lit);
watch_clause (c);
lrat_chain.clear ();
assert (c->size > 1);
CADICAL_assert (c->size > 1);
LOG ("instantiation succeeded");
stats.instantiated++;
return true;
@ -310,10 +314,10 @@ bool Internal::instantiate_candidate (int lit, Clause *c) {
// 'collect_instantiation_candidates' routine.
void Internal::instantiate (Instantiator &instantiator) {
assert (opts.instantiate);
CADICAL_assert (opts.instantiate);
START (instantiate);
stats.instrounds++;
#ifndef QUIET
#ifndef CADICAL_QUIET
const int64_t candidates = instantiator.candidates.size ();
int64_t tried = 0;
#endif
@ -324,7 +328,7 @@ void Internal::instantiate (Instantiator &instantiator) {
if (!propagate ()) {
LOG ("propagation after connecting watches failed");
learn_empty_clause ();
assert (unsat);
CADICAL_assert (unsat);
}
}
PHASE ("instantiate", stats.instrounds,
@ -335,7 +339,7 @@ void Internal::instantiate (Instantiator &instantiator) {
!instantiator.candidates.empty ()) {
Instantiator::Candidate cand = instantiator.candidates.back ();
instantiator.candidates.pop_back ();
#ifndef QUIET
#ifndef CADICAL_QUIET
tried++;
#endif
if (!active (cand.lit))
@ -363,3 +367,5 @@ void Internal::instantiate (Instantiator &instantiator) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -25,7 +29,7 @@ Internal::Internal ()
target_assigned (0), no_conflict_until (0), unsat_constraint (false),
marked_failed (true), sweep_incomplete (false), citten (0),
num_assigned (0), proof (0), opts (this),
#ifndef QUIET
#ifndef CADICAL_QUIET
profiles (this), force_phase_messages (false),
#endif
arena (this), prefix ("c "), internal (this), external (0),
@ -51,7 +55,7 @@ Internal::Internal ()
Internal::~Internal () {
// If a memory exception ocurred a profile might still be active.
#ifndef QUIET
#ifndef CADICAL_QUIET
#define PROFILE(NAME, LEVEL) \
if (PROFILE_ACTIVE (NAME)) \
STOP (NAME);
@ -108,7 +112,7 @@ void Internal::enlarge_vals (size_t new_vsize) {
vals -= vsize;
delete[] vals;
} else
assert (!vsize);
CADICAL_assert (!vsize);
vals = new_vals;
}
@ -156,16 +160,16 @@ void Internal::init_vars (int new_max_var) {
new_max_var - max_var, max_var + 1, new_max_var);
if ((size_t) new_max_var >= vsize)
enlarge (new_max_var);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (int64_t i = -new_max_var; i < -max_var; i++)
assert (!vals[i]);
CADICAL_assert (!vals[i]);
for (unsigned i = max_var + 1; i <= (unsigned) new_max_var; i++)
assert (!vals[i]), assert (!btab[i]), assert (!gtab[i]);
CADICAL_assert (!vals[i]), CADICAL_assert (!btab[i]), CADICAL_assert (!gtab[i]);
for (uint64_t i = 2 * ((uint64_t) max_var + 1);
i <= 2 * (uint64_t) new_max_var + 1; i++)
assert (ptab[i] == -1);
CADICAL_assert (ptab[i] == -1);
#endif
assert (!btab[0]);
CADICAL_assert (!btab[0]);
int old_max_var = max_var;
max_var = new_max_var;
init_queue (old_max_var, new_max_var);
@ -178,7 +182,7 @@ void Internal::init_vars (int new_max_var) {
}
void Internal::add_original_lit (int lit) {
assert (abs (lit) <= max_var);
CADICAL_assert (abs (lit) <= max_var);
if (lit) {
original.push_back (lit);
} else {
@ -187,14 +191,14 @@ void Internal::add_original_lit (int lit) {
if (proof) {
// Use the external form of the clause for printing in proof
// Externalize(internalized literal) != external literal
assert (!original.size () || !external->eclause.empty ());
CADICAL_assert (!original.size () || !external->eclause.empty ());
proof->add_external_original_clause (id, false, external->eclause);
}
if (internal->opts.check &&
(internal->opts.checkwitness || internal->opts.checkfailed)) {
bool forgettable = from_propagator && ext_clause_forgettable;
if (forgettable && opts.check) {
assert (!original.size () || !external->eclause.empty ());
CADICAL_assert (!original.size () || !external->eclause.empty ());
// First integer is the presence-flag (even if the clause is empty)
external->forgettable_original[id] = {1};
@ -216,7 +220,7 @@ void Internal::finish_added_clause_with_id (int64_t id, bool restore) {
if (proof) {
// Use the external form of the clause for printing in proof
// Externalize(internalized literal) != external literal
assert (!original.size () || !external->eclause.empty ());
CADICAL_assert (!original.size () || !external->eclause.empty ());
proof->add_external_original_clause (id, false, external->eclause,
restore);
}
@ -229,8 +233,8 @@ void Internal::finish_added_clause_with_id (int64_t id, bool restore) {
void Internal::reserve_ids (int number) {
// return;
LOG ("reserving %d ids", number);
assert (number >= 0);
assert (!clause_id && !reserved_ids && !original_id);
CADICAL_assert (number >= 0);
CADICAL_assert (!clause_id && !reserved_ids && !original_id);
clause_id = reserved_ids = number;
if (proof)
proof->begin_proof (reserved_ids);
@ -350,7 +354,7 @@ int Internal::propagate_assumptions () {
stats.ilbsuccess += (level > 0);
stats.levelsreused += level;
if (level) {
assert (control.size () > 1);
CADICAL_assert (control.size () > 1);
stats.literalsreused += num_assigned - control[1].trail;
}
}
@ -577,7 +581,7 @@ void Internal::init_search_limits () {
init_averages ();
} else if (opts.stabilize && opts.stabilizeonly) {
LOG ("keeping always forced stable phase");
assert (stable);
CADICAL_assert (stable);
} else if (stable) {
LOG ("switching back to default non-stable phase");
stable = false;
@ -655,7 +659,7 @@ bool Internal::preprocess_round (int round) {
before.vars = active ();
before.clauses = stats.current.irredundant;
stats.preprocessings++;
assert (!preprocessing);
CADICAL_assert (!preprocessing);
preprocessing = true;
PHASE ("preprocessing", stats.preprocessings,
"starting round %d with %" PRId64 " variables and %" PRId64
@ -671,7 +675,7 @@ bool Internal::preprocess_round (int round) {
after.vars = active ();
after.clauses = stats.current.irredundant;
assert (preprocessing);
CADICAL_assert (preprocessing);
preprocessing = false;
PHASE ("preprocessing", stats.preprocessings,
"finished round %d with %" PRId64 " variables and %" PRId64
@ -703,7 +707,7 @@ void Internal::preprocess_quickly () {
before.vars = active ();
before.clauses = stats.current.irredundant;
// stats.preprocessings++;
assert (!preprocessing);
CADICAL_assert (!preprocessing);
preprocessing = true;
PHASE ("preprocessing", stats.preprocessings,
"starting with %" PRId64 " variables and %" PRId64 " clauses",
@ -724,7 +728,7 @@ void Internal::preprocess_quickly () {
// condition (false);
after.vars = active ();
after.clauses = stats.current.irredundant;
assert (preprocessing);
CADICAL_assert (preprocessing);
preprocessing = false;
PHASE ("preprocessing", stats.preprocessings,
"finished with %" PRId64 " variables and %" PRId64 " clauses",
@ -747,12 +751,12 @@ int Internal::preprocess () {
int Internal::try_to_satisfy_formula_by_saved_phases () {
LOG ("satisfying formula by saved phases");
assert (!level);
assert (!force_saved_phase);
assert (propagated == trail.size ());
CADICAL_assert (!level);
CADICAL_assert (!force_saved_phase);
CADICAL_assert (propagated == trail.size ());
force_saved_phase = true;
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
LOG ("external notifications are turned off during preprocessing.");
private_steps = true;
}
@ -766,14 +770,14 @@ int Internal::try_to_satisfy_formula_by_saved_phases () {
res = 20;
} else if (!propagate ()) {
LOG ("saved phases do not satisfy redundant clauses");
assert (level > 0);
CADICAL_assert (level > 0);
backtrack ();
conflict = 0; // ignore conflict
assert (!res);
CADICAL_assert (!res);
break;
}
}
assert (force_saved_phase);
CADICAL_assert (force_saved_phase);
force_saved_phase = false;
if (external_prop) {
private_steps = false;
@ -791,10 +795,10 @@ int Internal::try_to_satisfy_formula_by_saved_phases () {
void Internal::produce_failed_assumptions () {
LOG ("producing failed assumptions");
assert (!level);
assert (!assumptions.empty ());
CADICAL_assert (!level);
CADICAL_assert (!assumptions.empty ());
while (!unsat) {
assert (!satisfied ());
CADICAL_assert (!satisfied ());
notify_assignments ();
if (decide ())
break;
@ -812,7 +816,7 @@ void Internal::produce_failed_assumptions () {
int Internal::local_search_round (int round) {
assert (round > 0);
CADICAL_assert (round > 0);
if (unsat)
return false;
@ -820,7 +824,7 @@ int Internal::local_search_round (int round) {
return false;
START_OUTER_WALK ();
assert (!localsearching);
CADICAL_assert (!localsearching);
localsearching = true;
// Determine propagation limit quadratically scaled with rounds.
@ -834,7 +838,7 @@ int Internal::local_search_round (int round) {
int res = walk_round (limit, true);
assert (localsearching);
CADICAL_assert (localsearching);
localsearching = false;
STOP_OUTER_WALK ();
@ -861,11 +865,11 @@ int Internal::local_search () {
if (res == 10) {
LOG ("local search determined formula to be satisfiable");
assert (!stats.walk.minimum);
CADICAL_assert (!stats.walk.minimum);
res = try_to_satisfy_formula_by_saved_phases ();
} else if (res == 20) {
LOG ("local search determined assumptions to be inconsistent");
assert (!assumptions.empty ());
CADICAL_assert (!assumptions.empty ());
produce_failed_assumptions ();
}
@ -878,7 +882,7 @@ int Internal::local_search () {
// such that we do not have to backtrack to level 0.
//
int Internal::solve (bool preprocess_only) {
assert (clause.empty ());
CADICAL_assert (clause.empty ());
START (solve);
if (proof)
proof->solve_query ();
@ -889,7 +893,7 @@ int Internal::solve (bool preprocess_only) {
stats.ilbsuccess += (level > 0);
stats.levelsreused += level;
if (level) {
assert (control.size () > 1);
CADICAL_assert (control.size () > 1);
stats.literalsreused += num_assigned - control[1].trail;
}
if (external->propagator)
@ -998,9 +1002,9 @@ int Internal::restore_clauses () {
}
int Internal::lookahead () {
assert (clause.empty ());
CADICAL_assert (clause.empty ());
START (lookahead);
assert (!lookingahead);
CADICAL_assert (!lookingahead);
lookingahead = true;
if (external_prop) {
if (level) {
@ -1021,7 +1025,7 @@ int Internal::lookahead () {
res = 0;
reset_solving ();
report_solving (tmp);
assert (lookingahead);
CADICAL_assert (lookingahead);
lookingahead = false;
STOP (lookahead);
if (external_prop) {
@ -1041,7 +1045,7 @@ void Internal::finalize (int res) {
// finalize external units
if (frat) {
for (const auto &evar : external->vars) {
assert (evar > 0);
CADICAL_assert (evar > 0);
const auto eidx = 2 * evar;
int sign = 1;
int64_t id = external->ext_units[eidx];
@ -1060,7 +1064,7 @@ void Internal::finalize (int res) {
const unsigned eidx = (elit < 0) + 2u * (unsigned) abs (elit);
const int64_t id = external->ext_units[eidx];
if (id) {
assert (unit_clauses (vlit (lit)) == id);
CADICAL_assert (unit_clauses (vlit (lit)) == id);
continue;
}
}
@ -1188,3 +1192,5 @@ bool Internal::traverse_clauses (ClauseIterator &it) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,7 +1,9 @@
#include "global.h"
#include "ipasir.h"
#include "ccadical.h"
extern "C" {
ABC_NAMESPACE_IMPL_START
const char *ipasir_signature () { return ccadical_signature (); }
@ -40,4 +42,5 @@ void ipasir_set_learn (void *solver, void *state, int max_length,
void (*learn) (void *state, int *clause)) {
ccadical_set_learn ((CCaDiCaL *) solver, state, max_length, learn);
}
}
ABC_NAMESPACE_IMPL_END

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -7,7 +11,7 @@ namespace CaDiCaL {
LidrupTracer::LidrupTracer (Internal *i, File *f, bool b)
: internal (i), file (f), binary (b), num_clauses (0), size_clauses (0),
clauses (0), last_hash (0), last_id (0), last_clause (0)
#ifndef QUIET
#ifndef CADICAL_QUIET
,
added (0), deleted (0)
#endif
@ -21,10 +25,10 @@ LidrupTracer::LidrupTracer (Internal *i, File *f, bool b)
uint64_t nonce = random.next ();
if (!(nonce & 1))
nonce++;
assert (nonce), assert (nonce & 1);
CADICAL_assert (nonce), CADICAL_assert (nonce & 1);
nonces[n] = nonce;
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
binary = b;
#else
(void) b;
@ -50,7 +54,7 @@ LidrupTracer::~LidrupTracer () {
/*------------------------------------------------------------------------*/
void LidrupTracer::enlarge_clauses () {
assert (num_clauses == size_clauses);
CADICAL_assert (num_clauses == size_clauses);
const uint64_t new_size_clauses = size_clauses ? 2 * size_clauses : 1;
LOG ("LIDRUP Tracer enlarging clauses of tracer from %" PRIu64
" to %" PRIu64,
@ -88,13 +92,13 @@ LidrupClause *LidrupTracer::new_clause () {
}
void LidrupTracer::delete_clause (LidrupClause *c) {
assert (c);
CADICAL_assert (c);
num_clauses--;
delete c;
}
uint64_t LidrupTracer::reduce_hash (uint64_t hash, uint64_t size) {
assert (size > 0);
CADICAL_assert (size > 0);
unsigned shift = 32;
uint64_t res = hash;
while ((((uint64_t) 1) << shift) > size) {
@ -102,12 +106,12 @@ uint64_t LidrupTracer::reduce_hash (uint64_t hash, uint64_t size) {
shift >>= 1;
}
res &= size - 1;
assert (res < size);
CADICAL_assert (res < size);
return res;
}
uint64_t LidrupTracer::compute_hash (const int64_t id) {
assert (id > 0);
CADICAL_assert (id > 0);
unsigned j = id % num_nonces;
uint64_t tmp = nonces[j] * (uint64_t) id;
return last_hash = tmp;
@ -128,7 +132,7 @@ bool LidrupTracer::find_and_delete (const int64_t id) {
}
if (!c)
return false;
assert (c && res);
CADICAL_assert (c && res);
*res = c->next;
for (auto &lit : c->literals) {
imported_clause.push_back (lit);
@ -157,15 +161,15 @@ inline void LidrupTracer::flush_if_piping () {
}
inline void LidrupTracer::put_binary_zero () {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
file->put ((unsigned char) 0);
}
inline void LidrupTracer::put_binary_lit (int lit) {
assert (binary);
assert (file);
assert (lit != INT_MIN);
CADICAL_assert (binary);
CADICAL_assert (file);
CADICAL_assert (lit != INT_MIN);
unsigned x = 2 * abs (lit) + (lit < 0);
unsigned char ch;
while (x & ~0x7f) {
@ -178,8 +182,8 @@ inline void LidrupTracer::put_binary_lit (int lit) {
}
inline void LidrupTracer::put_binary_id (int64_t id, bool can_be_negative) {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
uint64_t x = abs (id);
if (can_be_negative) {
x = 2 * x + (id < 0);
@ -256,7 +260,7 @@ void LidrupTracer::lidrup_add_original_clause (int64_t id,
}
void LidrupTracer::lidrup_batch_weaken_restore_and_delete () {
assert (batch_weaken.empty () || batch_delete.empty ());
CADICAL_assert (batch_weaken.empty () || batch_delete.empty ());
if (!batch_weaken.empty ()) {
if (binary) {
file->put ('w');
@ -274,7 +278,7 @@ void LidrupTracer::lidrup_batch_weaken_restore_and_delete () {
put_binary_zero ();
else
file->put ("0\n");
#ifndef QUIET
#ifndef CADICAL_QUIET
batched++;
#endif
}
@ -295,7 +299,7 @@ void LidrupTracer::lidrup_batch_weaken_restore_and_delete () {
put_binary_zero ();
else
file->put ("0\n");
#ifndef QUIET
#ifndef CADICAL_QUIET
batched++;
#endif
}
@ -316,7 +320,7 @@ void LidrupTracer::lidrup_batch_weaken_restore_and_delete () {
put_binary_zero ();
else
file->put ("0\n");
#ifndef QUIET
#ifndef CADICAL_QUIET
batched++;
#endif
}
@ -341,8 +345,8 @@ void LidrupTracer::lidrup_conclude_and_delete (
else
file->put ("u ");
if (!find_and_delete (id)) {
assert (imported_clause.empty ());
assert (conclusion.size () == 1);
CADICAL_assert (imported_clause.empty ());
CADICAL_assert (conclusion.size () == 1);
if (binary) {
put_binary_zero ();
put_binary_id (id);
@ -463,10 +467,10 @@ void LidrupTracer::add_derived_clause (int64_t id, bool,
const vector<int64_t> &chain) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG (clause, "LIDRUP TRACER tracing addition of derived clause");
lidrup_add_derived_clause (id, clause, chain);
#ifndef QUIET
#ifndef CADICAL_QUIET
added++;
#endif
}
@ -476,7 +480,7 @@ void LidrupTracer::add_assumption_clause (int64_t id,
const vector<int64_t> &chain) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG (clause,
"LIDRUP TRACER tracing addition of assumption clause[%" PRId64 "]",
id);
@ -493,21 +497,21 @@ void LidrupTracer::add_assumption_clause (int64_t id,
void LidrupTracer::delete_clause (int64_t id, bool, const vector<int> &) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG ("LIDRUP TRACER tracing deletion of clause[%" PRId64 "]", id);
if (find_and_delete (id)) {
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
if (!batch_delete.empty () || !batch_restore.empty ())
lidrup_batch_weaken_restore_and_delete ();
batch_weaken.push_back (id);
#ifndef QUIET
#ifndef CADICAL_QUIET
weakened++;
#endif
} else {
if (!batch_weaken.empty () || !batch_restore.empty ())
lidrup_batch_weaken_restore_and_delete ();
batch_delete.push_back (id);
#ifndef QUIET
#ifndef CADICAL_QUIET
deleted++;
#endif
}
@ -516,7 +520,7 @@ void LidrupTracer::delete_clause (int64_t id, bool, const vector<int> &) {
void LidrupTracer::weaken_minus (int64_t id, const vector<int> &) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG ("LIDRUP TRACER tracing weaken minus of clause[%" PRId64 "]", id);
last_id = id;
insert ();
@ -526,7 +530,7 @@ void LidrupTracer::conclude_unsat (ConclusionType,
const vector<int64_t> &conclusion) {
if (file->closed ())
return;
assert (imported_clause.empty ());
CADICAL_assert (imported_clause.empty ());
LOG (conclusion, "LIDRUP TRACER tracing conclusion of clause(s)");
lidrup_conclude_and_delete (conclusion);
}
@ -538,12 +542,12 @@ void LidrupTracer::add_original_clause (int64_t id, bool,
return;
if (!restored) {
LOG (clause, "LIDRUP TRACER tracing addition of original clause");
#ifndef QUIET
#ifndef CADICAL_QUIET
original++;
#endif
return lidrup_add_original_clause (id, clause);
}
assert (restored);
CADICAL_assert (restored);
if (find_and_delete (id)) {
LOG (clause,
"LIDRUP TRACER the clause was not yet weakened, so no restore");
@ -551,7 +555,7 @@ void LidrupTracer::add_original_clause (int64_t id, bool,
}
LOG (clause, "LIDRUP TRACER tracing addition of restored clause");
lidrup_add_restored_clause (id);
#ifndef QUIET
#ifndef CADICAL_QUIET
restore++;
#endif
}
@ -582,7 +586,7 @@ void LidrupTracer::solve_query () {
return;
LOG (assumptions, "LIDRUP TRACER tracing solve query with assumptions");
lidrup_solve_query ();
#ifndef QUIET
#ifndef CADICAL_QUIET
solved++;
#endif
}
@ -601,7 +605,7 @@ void LidrupTracer::reset_assumptions () {
bool LidrupTracer::closed () { return file->closed (); }
#ifndef QUIET
#ifndef CADICAL_QUIET
void LidrupTracer::print_statistics () {
// TODO complete this.
@ -627,9 +631,9 @@ void LidrupTracer::print_statistics () {
#endif
void LidrupTracer::close (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->close ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("LIDRUP proof file '%s' closed", file->name ());
print_statistics ();
@ -640,10 +644,10 @@ void LidrupTracer::close (bool print) {
}
void LidrupTracer::flush (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
lidrup_batch_weaken_restore_and_delete ();
file->flush ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("LIDRUP proof file '%s' flushed", file->name ());
print_statistics ();
@ -654,3 +658,5 @@ void LidrupTracer::flush (bool print) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
Limit::Limit () { memset (this, 0, sizeof *this); }
@ -127,3 +131,5 @@ void Internal::reset_limits () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,7 +1,11 @@
#include "global.h"
#ifdef LOGGING
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Logger::print_log_prefix (Internal *internal) {
@ -212,4 +216,6 @@ string Logger::loglit (Internal *internal, int lit) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
#endif

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
struct literal_occ {
@ -93,7 +97,7 @@ struct probe_negated_noccs_rank {
void Internal::lookahead_flush_probes () {
assert (!probes.empty ());
CADICAL_assert (!probes.empty ());
init_noccs ();
for (const auto &c : clauses) {
@ -116,14 +120,14 @@ void Internal::lookahead_flush_probes () {
continue;
if (have_pos_bin_occs)
lit = -lit;
assert (!noccs (lit)), assert (noccs (-lit) > 0);
CADICAL_assert (!noccs (lit)), CADICAL_assert (noccs (-lit) > 0);
if (propfixed (lit) >= stats.all.fixed)
continue;
MSG ("keeping probe %d negated occs %" PRId64 "", lit, noccs (-lit));
*j++ = lit;
}
size_t remain = j - probes.begin ();
#ifndef QUIET
#ifndef CADICAL_QUIET
size_t flushed = probes.size () - remain;
#endif
probes.resize (remain);
@ -140,7 +144,7 @@ void Internal::lookahead_flush_probes () {
void Internal::lookahead_generate_probes () {
assert (probes.empty ());
CADICAL_assert (probes.empty ());
// First determine all the literals which occur in binary clauses. It is
// way faster to go over the clauses once, instead of walking the watch
@ -294,7 +298,7 @@ int Internal::lookahead_probing () {
termination_forced = false;
#ifndef QUIET
#ifndef CADICAL_QUIET
int old_failed = stats.failed;
int64_t old_probed = stats.probed;
#endif
@ -335,7 +339,7 @@ int Internal::lookahead_probing () {
for (int idx = 1; idx <= max_var; idx++)
propfixed (idx) = propfixed (-idx) = -1;
assert (unsat || propagated == trail.size ());
CADICAL_assert (unsat || propagated == trail.size ());
propagated = propagated2 = trail.size ();
int probe;
@ -382,7 +386,7 @@ int Internal::lookahead_probing () {
sort_watches ();
}
#ifndef QUIET
#ifndef CADICAL_QUIET
int failed = stats.failed - old_failed;
int64_t probed = stats.probed - old_probed;
#endif
@ -435,12 +439,12 @@ CubesWithStatus Internal::generate_cubes (int depth, int min_depth) {
reset_limits ();
MSG ("generate cubes with %zu assumptions\n", assumptions.size ());
assert (ntab.empty ());
CADICAL_assert (ntab.empty ());
std::vector<int> current_assumptions{assumptions};
std::vector<std::vector<int>> cubes{{assumptions}};
auto loccs{lookahead_populate_locc ()};
LOG ("loccs populated\n");
assert (ntab.empty ());
CADICAL_assert (ntab.empty ());
for (int i = 0; i < depth; ++i) {
LOG ("Probing at depth %i, currently %zu have been generated", i,
@ -449,8 +453,8 @@ CubesWithStatus Internal::generate_cubes (int depth, int min_depth) {
cubes.clear ();
for (size_t j = 0; j < cubes2.size (); ++j) {
assert (ntab.empty ());
assert (!unsat);
CADICAL_assert (ntab.empty ());
CADICAL_assert (!unsat);
reset_assumptions ();
for (auto lit : cubes2[j])
assume (lit);
@ -478,7 +482,7 @@ CubesWithStatus Internal::generate_cubes (int depth, int min_depth) {
continue;
}
assert (res != 0);
CADICAL_assert (res != 0);
LOG ("splitting on lit %i", res);
std::vector<int> cube1{cubes2[j]};
cube1.push_back (res);
@ -492,7 +496,7 @@ CubesWithStatus Internal::generate_cubes (int depth, int min_depth) {
break;
}
assert (std::for_each (
CADICAL_assert (std::for_each (
std::begin (cubes), std::end (cubes),
[] (std::vector<int> cube) { return non_tautological_cube (cube); }));
reset_assumptions ();
@ -518,3 +522,5 @@ CubesWithStatus Internal::generate_cubes (int depth, int min_depth) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,12 +1,16 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
inline unsigned LratChecker::l2u (int lit) {
assert (lit);
assert (lit != INT_MIN);
CADICAL_assert (lit);
CADICAL_assert (lit != INT_MIN);
unsigned res = 2 * (abs (lit) - 1);
if (lit < 0)
res++;
@ -15,13 +19,13 @@ inline unsigned LratChecker::l2u (int lit) {
signed char &LratChecker::mark (int lit) {
const unsigned u = l2u (lit);
assert (u < marks.size ());
CADICAL_assert (u < marks.size ());
return marks[u];
}
signed char &LratChecker::checked_lit (int lit) {
const unsigned u = l2u (lit);
assert (u < checked_lits.size ());
CADICAL_assert (u < checked_lits.size ());
return checked_lits[u];
}
@ -29,7 +33,7 @@ signed char &LratChecker::checked_lit (int lit) {
LratCheckerClause *LratChecker::new_clause () {
const size_t size = imported_clause.size ();
assert (size <= UINT_MAX);
CADICAL_assert (size <= UINT_MAX);
const int off = size ? 1 : 0;
const size_t bytes =
sizeof (LratCheckerClause) + (size - off) * sizeof (int);
@ -42,9 +46,9 @@ LratCheckerClause *LratChecker::new_clause () {
res->used = false;
res->tautological = false;
int *literals = res->literals, *p = literals;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (auto &b : checked_lits)
assert (!b); // = false;
CADICAL_assert (!b); // = false;
#endif
for (const auto &lit : imported_clause) {
*p++ = lit;
@ -62,19 +66,19 @@ LratCheckerClause *LratChecker::new_clause () {
}
void LratChecker::delete_clause (LratCheckerClause *c) {
assert (c);
CADICAL_assert (c);
if (!c->garbage) {
assert (num_clauses);
CADICAL_assert (num_clauses);
num_clauses--;
} else {
assert (num_garbage);
CADICAL_assert (num_garbage);
num_garbage--;
}
delete[] (char *) c;
}
void LratChecker::enlarge_clauses () {
assert (num_clauses == size_clauses);
CADICAL_assert (num_clauses == size_clauses);
const uint64_t new_size_clauses = size_clauses ? 2 * size_clauses : 1;
LOG ("LRAT CHECKER enlarging clauses of checker from %" PRIu64
" to %" PRIu64,
@ -107,7 +111,7 @@ void LratChecker::collect_garbage_clauses () {
for (LratCheckerClause *c = garbage, *next; c; c = next)
next = c->next, delete_clause (c);
assert (!num_garbage);
CADICAL_assert (!num_garbage);
garbage = 0;
}
@ -125,7 +129,7 @@ LratChecker::LratChecker (Internal *i)
uint64_t nonce = random.next ();
if (!(nonce & 1))
nonce++;
assert (nonce), assert (nonce & 1);
CADICAL_assert (nonce), CADICAL_assert (nonce & 1);
nonces[n] = nonce;
}
@ -151,7 +155,7 @@ LratChecker::~LratChecker () {
void LratChecker::enlarge_vars (int64_t idx) {
assert (0 < idx), assert (idx <= INT_MAX);
CADICAL_assert (0 < idx), CADICAL_assert (idx <= INT_MAX);
int64_t new_size_vars = size_vars ? 2 * size_vars : 2;
while (idx >= new_size_vars)
@ -163,13 +167,13 @@ void LratChecker::enlarge_vars (int64_t idx) {
marks.resize (2 * new_size_vars);
checked_lits.resize (2 * new_size_vars);
assert (idx < new_size_vars);
CADICAL_assert (idx < new_size_vars);
size_vars = new_size_vars;
}
inline void LratChecker::import_literal (int lit) {
assert (lit);
assert (lit != INT_MIN);
CADICAL_assert (lit);
CADICAL_assert (lit != INT_MIN);
int idx = abs (lit);
if (idx >= size_vars)
enlarge_vars (idx);
@ -184,7 +188,7 @@ void LratChecker::import_clause (const vector<int> &c) {
/*------------------------------------------------------------------------*/
uint64_t LratChecker::reduce_hash (uint64_t hash, uint64_t size) {
assert (size > 0);
CADICAL_assert (size > 0);
unsigned shift = 32;
uint64_t res = hash;
while ((((uint64_t) 1) << shift) > size) {
@ -192,12 +196,12 @@ uint64_t LratChecker::reduce_hash (uint64_t hash, uint64_t size) {
shift >>= 1;
}
res &= size - 1;
assert (res < size);
CADICAL_assert (res < size);
return res;
}
uint64_t LratChecker::compute_hash (const int64_t id) {
assert (id > 0);
CADICAL_assert (id > 0);
unsigned j = id % num_nonces;
uint64_t tmp = nonces[j] * (uint64_t) id;
return last_hash = tmp;
@ -236,23 +240,23 @@ bool LratChecker::check_resolution (vector<int64_t> proof_chain) {
return true;
}
// LOG (imported_clause, "LRAT CHECKER checking clause with resolution");
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (auto &b : checked_lits)
assert (!b); // = false;
CADICAL_assert (!b); // = false;
#endif
if (!proof_chain.size () || proof_chain.back () < 0)
return false;
LratCheckerClause *c = *find (proof_chain.back ());
assert (c);
CADICAL_assert (c);
for (int *i = c->literals; i < c->literals + c->size; i++) {
int lit = *i;
checked_lit (lit) = true;
assert (!checked_lit (-lit));
CADICAL_assert (!checked_lit (-lit));
}
for (auto p = proof_chain.end () - 2; p >= proof_chain.begin (); p--) {
auto &id = *p;
c = *find (id);
assert (c); // since this is checked in check already
CADICAL_assert (c); // since this is checked in check already
for (int *i = c->literals; i < c->literals + c->size; i++) {
int lit = *i;
if (!checked_lit (-lit))
@ -298,16 +302,16 @@ bool LratChecker::check_resolution (vector<int64_t> proof_chain) {
bool LratChecker::check (vector<int64_t> proof_chain) {
LOG (imported_clause, "LRAT CHECKER checking clause");
stats.checks++;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (auto &b : checked_lits)
assert (!b); // = false;
CADICAL_assert (!b); // = false;
#endif
bool taut = false;
for (const auto &lit : imported_clause) { // tautological clauses
checked_lit (-lit) = true;
if (checked_lit (lit)) {
LOG (imported_clause, "LRAT CHECKER clause tautological");
assert (!proof_chain.size ()); // would be unnecessary hence a bug
CADICAL_assert (!proof_chain.size ()); // would be unnecessary hence a bug
taut = true;
}
}
@ -468,7 +472,7 @@ void LratChecker::add_original_clause (int64_t id, bool,
fatal_message_end ();
}
}
assert (id);
CADICAL_assert (id);
insert ();
imported_clause.clear ();
STOP (checking);
@ -483,7 +487,7 @@ void LratChecker::add_derived_clause (int64_t id, bool,
stats.derived++;
import_clause (c);
last_id = id;
assert (id == current_id + 1);
CADICAL_assert (id == current_id + 1);
current_id = id;
if (size_clauses) {
LratCheckerClause **p = find (id), *d = *p;
@ -495,7 +499,7 @@ void LratChecker::add_derived_clause (int64_t id, bool,
fatal_message_end ();
}
}
assert (id);
CADICAL_assert (id);
bool failed = true;
if (check (proof_chain) && check_resolution (proof_chain)) {
failed = false;
@ -547,7 +551,7 @@ void LratChecker::add_assumption (int a) { assumptions.push_back (a); }
void LratChecker::add_constraint (const vector<int> &c) {
constraint.clear ();
for (auto &lit : c) {
assert (lit);
CADICAL_assert (lit);
if (std::find (constraint.begin (), constraint.end (), lit) !=
constraint.end ())
continue;
@ -591,7 +595,7 @@ void LratChecker::conclude_unsat (ConclusionType conclusion,
}
return;
} else {
assert (conclusion == CONSTRAINT);
CADICAL_assert (conclusion == CONSTRAINT);
if (constraint.size () != ids.size ()) {
fatal_message_start ();
fputs ("not complete conclusion given for constraint\n", stderr);
@ -646,7 +650,7 @@ void LratChecker::delete_clause (int64_t id, bool, const vector<int> &c) {
// Remove from hash table, mark as garbage, connect to garbage list.
num_garbage++;
assert (num_clauses);
CADICAL_assert (num_clauses);
num_clauses--;
*p = d->next;
d->next = garbage;
@ -676,7 +680,7 @@ void LratChecker::weaken_minus (int64_t id, const vector<int> &c) {
LOG (c, "LRAT CHECKER saving clause[%" PRId64 "] to restore later", id);
import_clause (c);
assert (id <= current_id);
CADICAL_assert (id <= current_id);
last_id = id;
LratCheckerClause **p = find (id), *d = *p;
if (d) {
@ -756,7 +760,7 @@ void LratChecker::finalize_clause (int64_t id, const vector<int> &c) {
stats.finalized++;
num_finalized++;
import_clause (c);
assert (id <= current_id);
CADICAL_assert (id <= current_id);
last_id = id;
LratCheckerClause **p = find (id), *d = *p;
if (d) {
@ -827,3 +831,5 @@ void LratChecker::dump () {
void LratChecker::begin_proof (int64_t id) { current_id = id; }
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,14 +1,18 @@
#include "global.h"
#include "internal.hpp"
#include <limits.h>
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
LratTracer::LratTracer (Internal *i, File *f, bool b)
: internal (i), file (f), binary (b)
#ifndef QUIET
#ifndef CADICAL_QUIET
,
added (0), deleted (0)
#endif
@ -31,17 +35,17 @@ LratTracer::~LratTracer () {
/*------------------------------------------------------------------------*/
inline void LratTracer::put_binary_zero () {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
file->put ((unsigned char) 0);
}
inline void LratTracer::put_binary_lit (int lit) {
assert (binary);
assert (file);
assert (lit != INT_MIN);
CADICAL_assert (binary);
CADICAL_assert (file);
CADICAL_assert (lit != INT_MIN);
unsigned idx = abs (lit);
assert (idx < (1u << 31));
CADICAL_assert (idx < (1u << 31));
unsigned x = 2 * idx + (lit < 0);
unsigned char ch;
while (x & ~0x7f) {
@ -54,8 +58,8 @@ inline void LratTracer::put_binary_lit (int lit) {
}
inline void LratTracer::put_binary_id (int64_t id) {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
uint64_t x = abs (id);
x = 2 * x + (id < 0);
unsigned char ch;
@ -130,7 +134,7 @@ void LratTracer::add_derived_clause (int64_t id, bool,
return;
LOG ("LRAT TRACER tracing addition of derived clause");
lrat_add_clause (id, clause, chain);
#ifndef QUIET
#ifndef CADICAL_QUIET
added++;
#endif
}
@ -140,7 +144,7 @@ void LratTracer::delete_clause (int64_t id, bool, const vector<int> &) {
return;
LOG ("LRAT TRACER tracing deletion of clause");
lrat_delete_clause (id);
#ifndef QUIET
#ifndef CADICAL_QUIET
deleted++;
#endif
}
@ -156,7 +160,7 @@ void LratTracer::begin_proof (int64_t id) {
bool LratTracer::closed () { return file->closed (); }
#ifndef QUIET
#ifndef CADICAL_QUIET
void LratTracer::print_statistics () {
uint64_t bytes = file->bytes ();
@ -172,9 +176,9 @@ void LratTracer::print_statistics () {
#endif
void LratTracer::close (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->close ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("LRAT proof file '%s' closed", file->name ());
print_statistics ();
@ -185,9 +189,9 @@ void LratTracer::close (bool print) {
}
void LratTracer::flush (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->flush ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("LRAT proof file '%s' flushed", file->name ());
print_statistics ();
@ -198,3 +202,5 @@ void LratTracer::flush (bool print) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// It turns out that even in the competition there are formulas which are
@ -29,8 +33,8 @@ int Internal::unlucky (int res) {
int Internal::trivially_false_satisfiable () {
LOG ("checking that all clauses contain a negative literal");
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (const auto &c : clauses) {
if (terminated_asynchronously (100))
return unlucky (-1);
@ -66,7 +70,7 @@ int Internal::trivially_false_satisfiable () {
search_assume_decision (-idx);
if (propagate ())
continue;
assert (level > 0);
CADICAL_assert (level > 0);
LOG ("propagation failed including redundant clauses");
return unlucky (0);
}
@ -76,8 +80,8 @@ int Internal::trivially_false_satisfiable () {
int Internal::trivially_true_satisfiable () {
LOG ("checking that all clauses contain a positive literal");
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (const auto &c : clauses) {
if (terminated_asynchronously (100))
return unlucky (-1);
@ -113,7 +117,7 @@ int Internal::trivially_true_satisfiable () {
search_assume_decision (idx);
if (propagate ())
continue;
assert (level > 0);
CADICAL_assert (level > 0);
LOG ("propagation failed including redundant clauses");
return unlucky (0);
}
@ -136,7 +140,7 @@ inline bool Internal::lucky_propagate_discrepency (int dec) {
return true;
} else {
analyze ();
assert (!level);
CADICAL_assert (!level);
no_conflict = propagate ();
if (!no_conflict) {
analyze ();
@ -149,9 +153,9 @@ inline bool Internal::lucky_propagate_discrepency (int dec) {
int Internal::forward_false_satisfiable () {
LOG ("checking increasing variable index false assignment");
assert (!unsat);
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!unsat);
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (auto idx : vars) {
START:
if (terminated_asynchronously (100))
@ -167,16 +171,16 @@ int Internal::forward_false_satisfiable () {
goto START;
}
VERBOSE (1, "forward assuming variables false satisfies formula");
assert (satisfied ());
CADICAL_assert (satisfied ());
stats.lucky.forward.zero++;
return 10;
}
int Internal::forward_true_satisfiable () {
LOG ("checking increasing variable index true assignment");
assert (!unsat);
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!unsat);
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (auto idx : vars) {
START:
if (terminated_asynchronously (10))
@ -192,7 +196,7 @@ int Internal::forward_true_satisfiable () {
goto START;
}
VERBOSE (1, "forward assuming variables true satisfies formula");
assert (satisfied ());
CADICAL_assert (satisfied ());
stats.lucky.forward.one++;
return 10;
}
@ -201,9 +205,9 @@ int Internal::forward_true_satisfiable () {
int Internal::backward_false_satisfiable () {
LOG ("checking decreasing variable index false assignment");
assert (!unsat);
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!unsat);
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (int idx = max_var; idx > 0; idx--) {
START:
if (terminated_asynchronously (10))
@ -219,16 +223,16 @@ int Internal::backward_false_satisfiable () {
goto START;
}
VERBOSE (1, "backward assuming variables false satisfies formula");
assert (satisfied ());
CADICAL_assert (satisfied ());
stats.lucky.backward.zero++;
return 10;
}
int Internal::backward_true_satisfiable () {
LOG ("checking decreasing variable index true assignment");
assert (!unsat);
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!unsat);
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (int idx = max_var; idx > 0; idx--) {
START:
if (terminated_asynchronously (10))
@ -244,7 +248,7 @@ int Internal::backward_true_satisfiable () {
goto START;
}
VERBOSE (1, "backward assuming variables true satisfies formula");
assert (satisfied ());
CADICAL_assert (satisfied ());
stats.lucky.backward.one++;
return 10;
}
@ -259,8 +263,8 @@ int Internal::backward_true_satisfiable () {
int Internal::positive_horn_satisfiable () {
LOG ("checking that all clauses are positive horn satisfiable");
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (const auto &c : clauses) {
if (terminated_asynchronously (10))
return unlucky (-1);
@ -289,7 +293,7 @@ int Internal::positive_horn_satisfiable () {
LOG (c, "no positive unassigned literal in");
return unlucky (0);
}
assert (positive_literal > 0);
CADICAL_assert (positive_literal > 0);
LOG (c, "found positive literal %d in", positive_literal);
search_assume_decision (positive_literal);
if (propagate ())
@ -310,16 +314,16 @@ int Internal::positive_horn_satisfiable () {
return unlucky (0);
}
VERBOSE (1, "clauses are positive horn satisfied");
assert (!conflict);
assert (satisfied ());
CADICAL_assert (!conflict);
CADICAL_assert (satisfied ());
stats.lucky.horn.positive++;
return 10;
}
int Internal::negative_horn_satisfiable () {
LOG ("checking that all clauses are negative horn satisfiable");
assert (!level);
assert (assumptions.empty ());
CADICAL_assert (!level);
CADICAL_assert (assumptions.empty ());
for (const auto &c : clauses) {
if (terminated_asynchronously (10))
return unlucky (-1);
@ -350,7 +354,7 @@ int Internal::negative_horn_satisfiable () {
LOG (c, "no negative unassigned literal in");
return unlucky (0);
}
assert (negative_literal < 0);
CADICAL_assert (negative_literal < 0);
LOG (c, "found negative literal %d in", negative_literal);
search_assume_decision (negative_literal);
if (propagate ())
@ -371,8 +375,8 @@ int Internal::negative_horn_satisfiable () {
return unlucky (0);
}
VERBOSE (1, "clauses are negative horn satisfied");
assert (!conflict);
assert (satisfied ());
CADICAL_assert (!conflict);
CADICAL_assert (satisfied ());
stats.lucky.horn.negative++;
return 10;
}
@ -380,7 +384,7 @@ int Internal::negative_horn_satisfiable () {
/*------------------------------------------------------------------------*/
int Internal::lucky_phases () {
assert (!level);
CADICAL_assert (!level);
require_mode (SEARCH);
if (!opts.lucky)
return 0;
@ -394,7 +398,7 @@ int Internal::lucky_phases () {
START (search);
START (lucky);
assert (!searching_lucky_phases);
CADICAL_assert (!searching_lucky_phases);
searching_lucky_phases = true;
stats.lucky.tried++;
const int64_t active_before = stats.active;
@ -414,11 +418,11 @@ int Internal::lucky_phases () {
if (!res)
res = negative_horn_satisfiable ();
if (res < 0)
assert (termination_forced), res = 0;
CADICAL_assert (termination_forced), res = 0;
if (res == 10)
stats.lucky.succeeded++;
report ('l', !res);
assert (searching_lucky_phases);
CADICAL_assert (searching_lucky_phases);
const int64_t units = active_before - stats.active;
@ -432,3 +436,5 @@ int Internal::lucky_phases () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,9 +1,13 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
#ifndef QUIET
#ifndef CADICAL_QUIET
/*------------------------------------------------------------------------*/
void Internal::print_prefix () { fputs (prefix.c_str (), stdout); }
@ -130,7 +134,7 @@ void Internal::phase (const char *phase, int64_t count, const char *fmt,
}
/*------------------------------------------------------------------------*/
#endif // ifndef QUIET
#endif // ifndef CADICAL_QUIET
/*------------------------------------------------------------------------*/
void Internal::warning (const char *fmt, ...) {
@ -210,3 +214,5 @@ void fatal (const char *fmt, ...) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Functions for learned clause minimization. We only have the recursive
@ -16,7 +20,7 @@ namespace CaDiCaL {
bool Internal::minimize_literal (int lit, int depth) {
LOG ("attempt to minimize lit %d at depth %d", lit, depth);
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
Flags &f = flags (lit);
Var &v = var (lit);
if (!v.level || f.removable || f.keep)
@ -31,18 +35,18 @@ bool Internal::minimize_literal (int lit, int depth) {
if (depth > opts.minimizedepth)
return false;
bool res = true;
assert (v.reason);
CADICAL_assert (v.reason);
if (opts.minimizeticks)
stats.ticks.search[stable]++;
if (v.reason == external_reason) {
assert (!opts.exteagerreasons);
CADICAL_assert (!opts.exteagerreasons);
v.reason = learn_external_reason_clause (lit, 0, true);
if (!v.reason) {
assert (!v.level);
CADICAL_assert (!v.level);
return true;
}
}
assert (v.reason != external_reason);
CADICAL_assert (v.reason != external_reason);
const const_literal_iterator end = v.reason->end ();
const_literal_iterator i;
for (i = v.reason->begin (); res && i != end; i++) {
@ -71,7 +75,7 @@ struct minimize_trail_positive_rank {
minimize_trail_positive_rank (Internal *s) : internal (s) {}
typedef unsigned Type;
Type operator() (const int &a) const {
assert (internal->val (a));
CADICAL_assert (internal->val (a));
return (unsigned) internal->var (a).trail;
}
};
@ -89,7 +93,7 @@ struct minimize_trail_level_positive_rank {
minimize_trail_level_positive_rank (Internal *s) : internal (s) {}
typedef uint64_t Type;
Type operator() (const int &a) const {
assert (internal->val (a));
CADICAL_assert (internal->val (a));
Var &v = internal->var (a);
uint64_t res = v.level;
res <<= 32;
@ -114,15 +118,15 @@ void Internal::minimize_clause () {
external->check_learned_clause (); // check 1st UIP learned clause first
minimize_sort_clause ();
assert (minimized.empty ());
assert (minimize_chain.empty ());
CADICAL_assert (minimized.empty ());
CADICAL_assert (minimize_chain.empty ());
const auto end = clause.end ();
auto j = clause.begin (), i = j;
std::vector<int> stack;
for (; i != end; i++) {
if (minimize_literal (-*i)) {
if (lrat) {
assert (mini_chain.empty ());
CADICAL_assert (mini_chain.empty ());
calculate_minimize_chain (-*i, stack);
for (auto p : mini_chain) {
minimize_chain.push_back (p);
@ -153,19 +157,19 @@ void Internal::minimize_clause () {
// minimize version. Unlike the minimize version, we have to keep literals
// on the stack in order to push its reason later.
void Internal::calculate_minimize_chain (int lit, std::vector<int> &stack) {
assert (stack.empty ());
CADICAL_assert (stack.empty ());
stack.push_back (vidx (lit));
while (!stack.empty ()) {
const int idx = stack.back ();
assert (idx);
CADICAL_assert (idx);
stack.pop_back ();
if (idx < 0) {
Var &v = var (idx);
mini_chain.push_back (v.reason->id);
continue;
}
assert (idx);
CADICAL_assert (idx);
Flags &f = flags (idx);
Var &v = var (idx);
if (f.keep || f.added || f.poison) {
@ -182,7 +186,7 @@ void Internal::calculate_minimize_chain (int lit, std::vector<int> &stack) {
continue;
}
f.added = true;
assert (v.reason && f.removable);
CADICAL_assert (v.reason && f.removable);
const const_literal_iterator end = v.reason->end ();
const_literal_iterator i;
LOG (v.reason, "LRAT chain for lit %d at depth %zd by going over", lit,
@ -195,7 +199,7 @@ void Internal::calculate_minimize_chain (int lit, std::vector<int> &stack) {
stack.push_back (vidx (other));
}
}
assert (stack.empty ());
CADICAL_assert (stack.empty ());
}
// Sort the literals in reverse assignment order (thus trail order) to
@ -215,10 +219,12 @@ void Internal::clear_minimized_literals () {
f.poison = f.removable = f.shrinkable = f.added = false;
}
for (const auto &lit : clause)
assert (!flags (lit).shrinkable), flags (lit).keep =
CADICAL_assert (!flags (lit).shrinkable), flags (lit).keep =
flags (lit).shrinkable =
flags (lit).added = false;
minimized.clear ();
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -13,13 +17,13 @@ void Internal::init_occs () {
}
void Internal::reset_occs () {
assert (occurring ());
CADICAL_assert (occurring ());
erase_vector (otab);
LOG ("reset occurrence lists");
}
void Internal::clear_occs () {
assert (occurring ());
CADICAL_assert (occurring ());
for (auto &occ : otab)
occ.clear ();
LOG ("clear occurrence lists");
@ -30,23 +34,25 @@ void Internal::clear_occs () {
// One-sided occurrence counter (each literal has its own counter).
void Internal::init_noccs () {
assert (ntab.empty ());
CADICAL_assert (ntab.empty ());
if (ntab.size () < 2 * vsize)
ntab.resize (2 * vsize, 0);
LOG ("initialized two-sided occurrence counters");
}
void Internal::clear_noccs () {
assert (!ntab.empty ());
CADICAL_assert (!ntab.empty ());
for (auto &nt : ntab)
nt = 0;
LOG ("clear two-sided occurrence counters");
}
void Internal::reset_noccs () {
assert (!max_var || !ntab.empty ());
CADICAL_assert (!max_var || !ntab.empty ());
erase_vector (ntab);
LOG ("reset two-sided occurrence counters");
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -81,12 +85,12 @@ void Options::initialize_from_environment (int &val, const char *name,
const int L, const int H) {
char key[80], *q;
const char *p;
assert (strlen (name) + strlen ("CADICAL_") + 1 < sizeof (key));
CADICAL_assert (strlen (name) + strlen ("CADICAL_") + 1 < sizeof (key));
for (p = "CADICAL_", q = key; *p; p++)
*q++ = *p;
for (p = name; *p; p++)
*q++ = toupper (*p);
assert (q < key + sizeof (key));
CADICAL_assert (q < key + sizeof (key));
*q = 0;
const char *val_str = getenv (key);
if (!val_str)
@ -102,7 +106,7 @@ void Options::initialize_from_environment (int &val, const char *name,
// Initialize all the options to their default value 'V'.
Options::Options (Internal *s) : internal (s) {
assert (number_of_options == sizeof Options::table / sizeof (Option));
CADICAL_assert (number_of_options == sizeof Options::table / sizeof (Option));
// First initialize them according to defaults in 'options.hpp'.
//
@ -119,12 +123,12 @@ Options::Options (Internal *s) : internal (s) {
if (strcmp (prev, #N) > 0) \
FATAL ("'%s' ordered before '" #N "' in 'options.hpp'", prev); \
N = (int) (V); \
assert (&val (i) == &N); \
CADICAL_assert (&val (i) == &N); \
/* The order of initializing static data is undefined and thus */ \
/* it might be the case that the 'table' is not initialized yet. */ \
/* Thus this construction just reinitializes the table too even */ \
/* though it might not be necessary. */ \
assert (!table[i].name || !strcmp (table[i].name, #N)); \
CADICAL_assert (!table[i].name || !strcmp (table[i].name, #N)); \
table[i] = {#N, (int) (V), (int) (L), (int) (H), \
(int) (O), (bool) (P), D}; \
prev = #N; \
@ -135,11 +139,11 @@ Options::Options (Internal *s) : internal (s) {
// Check consistency in debugging mode.
//
#ifndef NDEBUG
assert (i == number_of_options);
assert (!has ("aaaaa"));
assert (!has ("non-existing-option"));
assert (!has ("zzzzz"));
#ifndef CADICAL_NDEBUG
CADICAL_assert (i == number_of_options);
CADICAL_assert (!has ("aaaaa"));
CADICAL_assert (!has ("non-existing-option"));
CADICAL_assert (!has ("zzzzz"));
#endif
// Now overwrite default options with environment values.
@ -153,7 +157,7 @@ Options::Options (Internal *s) : internal (s) {
/*------------------------------------------------------------------------*/
void Options::set (Option *o, int new_val) {
assert (o);
CADICAL_assert (o);
int &val = o->val (this), old_val = val;
if (old_val == new_val) {
LOG ("keeping value '%d' of option '%s'", old_val, o->name);
@ -193,7 +197,7 @@ int Options::get (const char *name) {
void Options::print () {
unsigned different = 0;
#ifdef QUIET
#ifdef CADICAL_QUIET
const bool verbose = false;
#endif
char buffer[256];
@ -278,7 +282,7 @@ void Options::optimize (int val) {
LOG ("optimization mode '%d' for '%s' " \
"gives '%" PRId64 "' instead of '%d", \
val, #N, new_val, (int) (V)); \
assert (new_val <= INT_MAX); \
CADICAL_assert (new_val <= INT_MAX); \
N = (int) new_val; \
increased++; \
} while (0);
@ -299,8 +303,8 @@ void Options::disable_preprocessing () {
if (!(N)) \
break; \
LOG ("plain mode disables '%s'", #N); \
assert ((L) == 0); \
assert ((H) == 1); \
CADICAL_assert ((L) == 0); \
CADICAL_assert ((H) == 1); \
count++; \
N = 0; \
} while (0);
@ -357,3 +361,5 @@ void Options::copy (Options &other) const {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
/*------------------------------------------------------------------------*/
namespace CaDiCaL {
@ -37,7 +41,7 @@ inline const char *Parser::parse_string (const char *str, char prev) {
inline const char *Parser::parse_positive_int (int &ch, int &res,
const char *name) {
assert (isdigit (ch));
CADICAL_assert (isdigit (ch));
res = ch - '0';
while (isdigit (ch = parse_char ())) {
int digit = ch - '0';
@ -90,7 +94,7 @@ inline const char *Parser::parse_lit (int &ch, int &lit, int &vars,
const char *Parser::parse_dimacs_non_profiled (int &vars, int strict) {
#ifndef QUIET
#ifndef CADICAL_QUIET
double start = internal->time ();
#endif
@ -143,7 +147,7 @@ const char *Parser::parse_dimacs_non_profiled (int &vars, int strict) {
// or 'p inccnf' of incremental 'INCCNF' file.
//
if (ch == 'c') {
assert (!found_inccnf_header);
CADICAL_assert (!found_inccnf_header);
if (strict == STRICT) {
const char *err = parse_string ("nf ", 'c');
if (err)
@ -266,19 +270,19 @@ const char *Parser::parse_dimacs_non_profiled (int &vars, int strict) {
if (!found_inccnf_header && parsed < clauses && strict != FORCED)
PER ("clause missing");
#ifndef QUIET
#ifndef CADICAL_QUIET
double end = internal->time ();
MSG ("parsed %d clauses in %.2f seconds %s time", parsed, end - start,
internal->opts.realtime ? "real" : "process");
#endif
#ifndef QUIET
#ifndef CADICAL_QUIET
start = end;
size_t num_cubes = 0;
#endif
if (ch == 'a') {
assert (parse_inccnf_too);
assert (found_inccnf_header);
CADICAL_assert (parse_inccnf_too);
CADICAL_assert (found_inccnf_header);
if (!*parse_inccnf_too)
*parse_inccnf_too = true;
for (;;) {
@ -305,7 +309,7 @@ const char *Parser::parse_dimacs_non_profiled (int &vars, int strict) {
if (cubes)
cubes->push_back (lit);
if (!lit) {
#ifndef QUIET
#ifndef CADICAL_QUIET
num_cubes++;
#endif
for (;;) {
@ -332,7 +336,7 @@ const char *Parser::parse_dimacs_non_profiled (int &vars, int strict) {
if (lit)
PER ("last cube without terminating '0'");
}
#ifndef QUIET
#ifndef CADICAL_QUIET
if (found_inccnf_header) {
double end = internal->time ();
MSG ("parsed %zd cubes in %.2f seconds %s time", num_cubes, end - start,
@ -372,7 +376,7 @@ const char *Parser::parse_solution_non_profiled () {
ch = parse_char ();
if (ch != '\n')
PER ("expected new-line after 's SATISFIABLE'");
#ifndef QUIET
#ifndef CADICAL_QUIET
int count = 0;
#endif
for (;;) {
@ -399,7 +403,7 @@ const char *Parser::parse_solution_non_profiled () {
PER ("variable %d occurs twice", abs (lit));
LOG ("solution %d", lit);
external->solution[abs (lit)] = sign (lit);
#ifndef QUIET
#ifndef CADICAL_QUIET
count++;
#endif
if (ch == '\r')
@ -419,7 +423,7 @@ const char *Parser::parse_solution_non_profiled () {
// implicit 'return' in PER in the non-profiled versions.
const char *Parser::parse_dimacs (int &vars, int strict) {
assert (strict == FORCED || strict == RELAXED || strict == STRICT);
CADICAL_assert (strict == FORCED || strict == RELAXED || strict == STRICT);
START (parse);
const char *err = parse_dimacs_non_profiled (vars, strict);
STOP (parse);
@ -434,3 +438,5 @@ const char *Parser::parse_solution () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::copy_phases (vector<signed char> &dst) {
@ -42,3 +46,5 @@ void Internal::unphase (int lit) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -19,7 +23,7 @@ bool Internal::inprobing () {
if (!preprocessing && !opts.inprocessing)
return false;
if (preprocessing)
assert (lim.preprocessing);
CADICAL_assert (lim.preprocessing);
if (stats.inprobingphases && last.inprobe.reductions == stats.reductions)
return false;
return lim.inprobe <= stats.conflicts;
@ -86,9 +90,9 @@ void Internal::init_probehbr_lrat () {
void Internal::get_probehbr_lrat (int lit, int uip) {
if (!lrat || opts.probehbr)
return;
assert (lit);
assert (lrat_chain.empty ());
assert (val (uip) < 0);
CADICAL_assert (lit);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (val (uip) < 0);
lrat_chain = probehbr_chains[vlit (lit)][vlit (uip)];
int64_t id = unit_id (-uip);
lrat_chain.push_back (id);
@ -100,9 +104,9 @@ void Internal::get_probehbr_lrat (int lit, int uip) {
void Internal::set_probehbr_lrat (int lit, int uip) {
if (!lrat || opts.probehbr)
return;
assert (lit);
assert (lrat_chain.size ());
assert (probehbr_chains[vlit (lit)][vlit (uip)].empty ());
CADICAL_assert (lit);
CADICAL_assert (lrat_chain.size ());
CADICAL_assert (probehbr_chains[vlit (lit)][vlit (uip)].empty ());
probehbr_chains[vlit (lit)][vlit (uip)] = lrat_chain;
lrat_chain.clear ();
}
@ -151,20 +155,20 @@ int Internal::probe_dominator (int a, int b) {
require_mode (PROBE);
int l = a, k = b;
Var *u = &var (l), *v = &var (k);
assert (val (l) > 0), assert (val (k) > 0);
assert (u->level == 1), assert (v->level == 1);
CADICAL_assert (val (l) > 0), CADICAL_assert (val (k) > 0);
CADICAL_assert (u->level == 1), CADICAL_assert (v->level == 1);
while (l != k) {
if (u->trail > v->trail)
swap (l, k), swap (u, v);
if (!get_parent_reason_literal (l))
return l;
int parent = get_parent_reason_literal (k);
assert (parent), assert (val (parent) > 0);
CADICAL_assert (parent), CADICAL_assert (val (parent) > 0);
v = &var (k = parent);
assert (v->level == 1);
CADICAL_assert (v->level == 1);
}
LOG ("dominator %d of %d and %d", l, a, b);
assert (val (l) > 0);
CADICAL_assert (val (l) > 0);
return l;
}
@ -217,17 +221,17 @@ int Internal::probe_dominator (int a, int b) {
inline int Internal::hyper_binary_resolve (Clause *reason) {
require_mode (PROBE);
assert (level == 1);
assert (reason->size > 2);
CADICAL_assert (level == 1);
CADICAL_assert (reason->size > 2);
const const_literal_iterator end = reason->end ();
const int *lits = reason->literals;
const_literal_iterator k;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
// First literal unassigned, all others false.
assert (!val (lits[0]));
CADICAL_assert (!val (lits[0]));
for (k = lits + 1; k != end; k++)
assert (val (*k) < 0);
assert (var (lits[1]).level == 1);
CADICAL_assert (val (*k) < 0);
CADICAL_assert (var (lits[1]).level == 1);
#endif
LOG (reason, "hyper binary resolving");
stats.hbrs++;
@ -236,7 +240,7 @@ inline int Internal::hyper_binary_resolve (Clause *reason) {
int dom = -lit, non_root_level_literals = 0;
for (k = lits + 2; k != end; k++) {
const int other = -*k;
assert (val (other) > 0);
CADICAL_assert (val (other) > 0);
if (!var (other).level)
continue;
dom = probe_dominator (dom, other);
@ -252,7 +256,7 @@ inline int Internal::hyper_binary_resolve (Clause *reason) {
stats.hbreds++;
LOG ("new %s hyper binary resolvent %d %d",
(red ? "redundant" : "irredundant"), -dom, lits[0]);
assert (clause.empty ());
CADICAL_assert (clause.empty ());
clause.push_back (-dom);
clause.push_back (lits[0]);
probe_dominator_lrat (dom, reason);
@ -271,7 +275,7 @@ inline int Internal::hyper_binary_resolve (Clause *reason) {
}
} else if (non_root_level_literals && lrat) {
// still calculate LRAT and remember for later
assert (!opts.probehbr);
CADICAL_assert (!opts.probehbr);
probe_dominator_lrat (dom, reason);
clear_analyzed_literals ();
set_probehbr_lrat (dom, lits[0]);
@ -292,13 +296,13 @@ inline int Internal::hyper_binary_resolve (Clause *reason) {
inline void Internal::probe_assign (int lit, int parent) {
require_mode (PROBE);
int idx = vidx (lit);
assert (!val (idx));
assert (!flags (idx).eliminated () || !parent);
assert (!parent || val (parent) > 0);
CADICAL_assert (!val (idx));
CADICAL_assert (!flags (idx).eliminated () || !parent);
CADICAL_assert (!parent || val (parent) > 0);
Var &v = var (idx);
v.level = level;
v.trail = (int) trail.size ();
assert ((int) num_assigned < max_var);
CADICAL_assert ((int) num_assigned < max_var);
num_assigned++;
v.reason = level ? probe_reason : 0;
probe_reason = 0;
@ -306,11 +310,11 @@ inline void Internal::probe_assign (int lit, int parent) {
if (!level)
learn_unit_clause (lit);
else
assert (level == 1);
CADICAL_assert (level == 1);
const signed char tmp = sign (lit);
set_val (idx, tmp);
assert (val (lit) > 0);
assert (val (-lit) < 0);
CADICAL_assert (val (lit) > 0);
CADICAL_assert (val (-lit) < 0);
trail.push_back (lit);
// Do not save the current phase during inprocessing but remember the
@ -331,8 +335,8 @@ inline void Internal::probe_assign (int lit, int parent) {
void Internal::probe_assign_decision (int lit) {
require_mode (PROBE);
assert (!level);
assert (propagated == trail.size ());
CADICAL_assert (!level);
CADICAL_assert (propagated == trail.size ());
level++;
control.push_back (Level (lit, trail.size ()));
probe_assign (lit, 0);
@ -340,8 +344,8 @@ void Internal::probe_assign_decision (int lit) {
void Internal::probe_assign_unit (int lit) {
require_mode (PROBE);
assert (!level);
assert (active (lit));
CADICAL_assert (!level);
CADICAL_assert (active (lit));
probe_assign (lit, 0);
}
@ -355,12 +359,12 @@ inline void Internal::probe_lrat_for_units (int lit) {
if (level)
return; // not decision level 0
LOG ("building chain for units");
assert (lrat_chain.empty ());
assert (probe_reason);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (probe_reason);
for (auto &reason_lit : *probe_reason) {
if (lit == reason_lit)
continue;
assert (val (reason_lit));
CADICAL_assert (val (reason_lit));
if (!val (reason_lit))
continue;
const int signed_reason_lit = val (reason_lit) * reason_lit;
@ -398,8 +402,8 @@ inline void Internal::probe_propagate2 () {
if (b < 0)
conflict = w.clause; // but continue
else {
assert (lrat_chain.empty ());
assert (!probe_reason);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (!probe_reason);
probe_reason = w.clause;
probe_lrat_for_units (w.blit);
probe_assign (w.blit, -lit);
@ -411,7 +415,7 @@ inline void Internal::probe_propagate2 () {
bool Internal::probe_propagate () {
require_mode (PROBE);
assert (!unsat);
CADICAL_assert (!unsat);
START (propagate);
int64_t before = propagated2 = propagated;
int64_t &ticks = stats.ticks.probe;
@ -452,12 +456,12 @@ bool Internal::probe_propagate () {
k++;
if (v < 0) {
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
w.clause->pos = k - lits;
assert (lits + 2 <= k), assert (k <= w.clause->end ());
CADICAL_assert (lits + 2 <= k), CADICAL_assert (k <= w.clause->end ());
if (v > 0)
ws[j - 1].blit = r;
else if (!v) {
@ -472,14 +476,14 @@ bool Internal::probe_propagate () {
ticks++;
if (level == 1) {
lits[0] = other, lits[1] = lit;
assert (lrat_chain.empty ());
assert (!probe_reason);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (!probe_reason);
int dom = hyper_binary_resolve (w.clause);
probe_assign (other, dom);
} else {
ticks++;
assert (lrat_chain.empty ());
assert (!probe_reason);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (!probe_reason);
probe_reason = w.clause;
probe_lrat_for_units (other);
probe_assign_unit (other);
@ -516,11 +520,11 @@ void Internal::failed_literal (int failed) {
stats.failed++;
stats.probefailed++;
assert (!unsat);
assert (conflict);
assert (level == 1);
assert (analyzed.empty ());
assert (lrat_chain.empty ());
CADICAL_assert (!unsat);
CADICAL_assert (conflict);
CADICAL_assert (level == 1);
CADICAL_assert (analyzed.empty ());
CADICAL_assert (lrat_chain.empty ());
START (analyze);
@ -530,7 +534,7 @@ void Internal::failed_literal (int failed) {
for (const auto &lit : *conflict) {
const int other = -lit;
if (!var (other).level) {
assert (val (other) > 0);
CADICAL_assert (val (other) > 0);
continue;
}
uip = uip ? probe_dominator (uip, other) : other;
@ -540,7 +544,7 @@ void Internal::failed_literal (int failed) {
clear_analyzed_literals ();
LOG ("found probing UIP %d", uip);
assert (uip);
CADICAL_assert (uip);
vector<int> work;
@ -548,14 +552,14 @@ void Internal::failed_literal (int failed) {
while (parent != failed) {
const int next = get_parent_reason_literal (parent);
parent = next;
assert (parent);
CADICAL_assert (parent);
work.push_back (parent);
}
backtrack ();
conflict = 0;
assert (!val (uip));
CADICAL_assert (!val (uip));
probe_assign_unit (-uip);
lrat_chain.clear ();
@ -564,16 +568,16 @@ void Internal::failed_literal (int failed) {
size_t j = 0;
while (!unsat && j < work.size ()) {
// assert (!opts.probehbr); assertion fails ...
// CADICAL_assert (!opts.probehbr); CADICAL_assertion fails ...
const int parent = work[j++];
const signed char tmp = val (parent);
if (tmp > 0) {
assert (!opts.probehbr); // ... assertion should hold here
CADICAL_assert (!opts.probehbr); // ... CADICAL_assertion should hold here
get_probehbr_lrat (parent, uip);
LOG ("clashing failed parent %d", parent);
learn_empty_clause ();
} else if (tmp == 0) {
assert (!opts.probehbr); // ... and here
CADICAL_assert (!opts.probehbr); // ... and here
LOG ("found unassigned failed parent %d", parent);
get_probehbr_lrat (parent, uip); // this is computed during
probe_assign_unit (-parent); // propagation and can include
@ -588,13 +592,13 @@ void Internal::failed_literal (int failed) {
STOP (analyze);
assert (unsat || val (failed) < 0);
CADICAL_assert (unsat || val (failed) < 0);
}
/*------------------------------------------------------------------------*/
bool Internal::is_binary_clause (Clause *c, int &a, int &b) {
assert (!level);
CADICAL_assert (!level);
if (c->garbage)
return false;
int first = 0, second = 0;
@ -632,7 +636,7 @@ struct probe_negated_noccs_rank {
void Internal::generate_probes () {
assert (probes.empty ());
CADICAL_assert (probes.empty ());
int64_t &ticks = stats.ticks.probe;
@ -697,7 +701,7 @@ void Internal::generate_probes () {
void Internal::flush_probes () {
assert (!probes.empty ());
CADICAL_assert (!probes.empty ());
int64_t &ticks = stats.ticks.probe;
init_noccs ();
@ -724,14 +728,14 @@ void Internal::flush_probes () {
continue;
if (have_pos_bin_occs)
lit = -lit;
assert (!noccs (lit)), assert (noccs (-lit) > 0);
CADICAL_assert (!noccs (lit)), CADICAL_assert (noccs (-lit) > 0);
if (propfixed (lit) >= stats.all.fixed)
continue;
LOG ("keeping probe %d negated occs %" PRId64 "", lit, noccs (-lit));
*j++ = lit;
}
size_t remain = j - probes.begin ();
#ifndef QUIET
#ifndef CADICAL_QUIET
size_t flushed = probes.size () - remain;
#endif
probes.resize (remain);
@ -808,7 +812,7 @@ bool Internal::probe () {
"probing limit of %" PRId64 " propagations ", limit);
int old_failed = stats.failed;
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t old_probed = stats.probed;
#endif
int64_t old_hbrs = stats.hbrs;
@ -823,7 +827,7 @@ bool Internal::probe () {
for (auto idx : vars)
propfixed (idx) = propfixed (-idx) = -1;
assert (unsat || propagated == trail.size ());
CADICAL_assert (unsat || propagated == trail.size ());
propagated = propagated2 = trail.size ();
int probe;
@ -853,7 +857,7 @@ bool Internal::probe () {
}
int failed = stats.failed - old_failed;
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t probed = stats.probed - old_probed;
#endif
int64_t hbrs = stats.hbrs - old_hbrs;
@ -924,7 +928,7 @@ void CaDiCaL::Internal::inprobe (bool update_limits) {
stats.inprobingphases++;
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = true;
}
const int before = active ();
@ -950,7 +954,7 @@ void CaDiCaL::Internal::inprobe (bool update_limits) {
}
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = false;
}
@ -960,9 +964,9 @@ void CaDiCaL::Internal::inprobe (bool update_limits) {
const int after = active ();
const int after_extended = stats.variables_extension;
const int diff_extended = after_extended - before_extended;
assert (diff_extended >= 0);
CADICAL_assert (diff_extended >= 0);
const int removed = before - after + diff_extended;
assert (removed >= 0);
CADICAL_assert (removed >= 0);
if (removed) {
stats.inprobesuccess++;
@ -985,3 +989,5 @@ void CaDiCaL::Internal::inprobe (bool update_limits) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,7 +1,11 @@
#ifndef QUIET
#include "global.h"
#ifndef CADICAL_QUIET
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Initialize all profile counters with constant name and profiling level.
@ -15,15 +19,15 @@ Profiles::Profiles (Internal *s)
}
void Internal::start_profiling (Profile &profile, double s) {
assert (profile.level <= opts.profile);
assert (!profile.active);
CADICAL_assert (profile.level <= opts.profile);
CADICAL_assert (!profile.active);
profile.started = s;
profile.active = true;
}
void Internal::stop_profiling (Profile &profile, double s) {
assert (profile.level <= opts.profile);
assert (profile.active);
CADICAL_assert (profile.level <= opts.profile);
CADICAL_assert (profile.active);
profile.value += s - profile.started;
profile.active = false;
}
@ -34,7 +38,7 @@ double Internal::update_profiles () {
do { \
Profile &profile = profiles.NAME; \
if (profile.active) { \
assert (profile.level <= opts.profile); \
CADICAL_assert (profile.level <= opts.profile); \
profile.value += now - profile.started; \
profile.started = now; \
} \
@ -77,7 +81,7 @@ void Internal::print_profile () {
PROFILES
#undef PROFILE
assert (n <= size);
CADICAL_assert (n <= size);
// Explicit bubble sort to avoid heap allocation since 'print_profile'
// is also called during catching a signal after out of heap memory.
@ -104,4 +108,6 @@ void Internal::print_profile () {
} // namespace CaDiCaL
#endif // ifndef QUIET
ABC_NAMESPACE_IMPL_END
#endif // ifndef CADICAL_QUIET

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
using namespace std;
@ -23,7 +27,7 @@ void Internal::resize_unit_clauses_idx () {
void Internal::force_lrat () {
if (lrat)
return;
assert (proof);
CADICAL_assert (proof);
lrat = true;
}
@ -83,7 +87,7 @@ bool Internal::disconnect_proof_tracer (Tracer *tracer) {
auto it = std::find (tracers.begin (), tracers.end (), tracer);
if (it != tracers.end ()) {
tracers.erase (it);
assert (proof);
CADICAL_assert (proof);
proof->disconnect (tracer);
return true;
}
@ -94,7 +98,7 @@ bool Internal::disconnect_proof_tracer (StatTracer *tracer) {
auto it = std::find (stat_tracers.begin (), stat_tracers.end (), tracer);
if (it != stat_tracers.end ()) {
stat_tracers.erase (it);
assert (proof);
CADICAL_assert (proof);
proof->disconnect (tracer);
return true;
}
@ -105,7 +109,7 @@ bool Internal::disconnect_proof_tracer (FileTracer *tracer) {
auto it = std::find (file_tracers.begin (), file_tracers.end (), tracer);
if (it != file_tracers.end ()) {
file_tracers.erase (it);
assert (proof);
CADICAL_assert (proof);
proof->disconnect (tracer);
return true;
}
@ -230,7 +234,7 @@ void Proof::add_external_original_clause (int64_t id, bool r,
const vector<int> &c,
bool restore) {
// literals of c are already external
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (auto const &lit : c)
clause.push_back (lit);
clause_id = id;
@ -241,7 +245,7 @@ void Proof::add_external_original_clause (int64_t id, bool r,
void Proof::delete_external_original_clause (int64_t id, bool r,
const vector<int> &c) {
// literals of c are already external
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (auto const &lit : c)
clause.push_back (lit);
clause_id = id;
@ -252,8 +256,8 @@ void Proof::delete_external_original_clause (int64_t id, bool r,
void Proof::add_derived_empty_clause (int64_t id,
const vector<int64_t> &chain) {
LOG ("PROOF adding empty clause");
assert (clause.empty ());
assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
for (const auto &cid : chain)
proof_chain.push_back (cid);
clause_id = id;
@ -264,8 +268,8 @@ void Proof::add_derived_empty_clause (int64_t id,
void Proof::add_derived_unit_clause (int64_t id, int internal_unit,
const vector<int64_t> &chain) {
LOG ("PROOF adding unit clause %d", internal_unit);
assert (proof_chain.empty ());
assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
add_literal (internal_unit);
for (const auto &cid : chain)
proof_chain.push_back (cid);
@ -278,8 +282,8 @@ void Proof::add_derived_unit_clause (int64_t id, int internal_unit,
void Proof::add_derived_clause (Clause *c, const vector<int64_t> &chain) {
LOG (c, "PROOF adding to proof derived");
assert (clause.empty ());
assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
add_literals (c);
for (const auto &cid : chain)
proof_chain.push_back (cid);
@ -291,8 +295,8 @@ void Proof::add_derived_clause (Clause *c, const vector<int64_t> &chain) {
void Proof::add_derived_clause (int64_t id, bool r, const vector<int> &c,
const vector<int64_t> &chain) {
LOG (c, "PROOF adding derived clause");
assert (clause.empty ());
assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
for (const auto &lit : c)
add_literal (lit);
for (const auto &cid : chain)
@ -305,8 +309,8 @@ void Proof::add_derived_clause (int64_t id, bool r, const vector<int> &c,
void Proof::add_assumption_clause (int64_t id, const vector<int> &c,
const vector<int64_t> &chain) {
// literals of c are already external
assert (clause.empty ());
assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
for (const auto &lit : c)
clause.push_back (lit);
for (const auto &cid : chain)
@ -317,16 +321,16 @@ void Proof::add_assumption_clause (int64_t id, const vector<int> &c,
void Proof::add_assumption (int a) {
// a is already external
assert (clause.empty ());
assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
clause.push_back (a);
add_assumption ();
}
void Proof::add_constraint (const vector<int> &c) {
// literals of c are already external
assert (clause.empty ());
assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
for (const auto &lit : c)
clause.push_back (lit);
add_constraint ();
@ -334,8 +338,8 @@ void Proof::add_constraint (const vector<int> &c) {
void Proof::add_assumption_clause (int64_t id, int lit,
const vector<int64_t> &chain) {
assert (clause.empty ());
assert (proof_chain.empty ());
CADICAL_assert (clause.empty ());
CADICAL_assert (proof_chain.empty ());
clause.push_back (lit);
for (const auto &cid : chain)
proof_chain.push_back (cid);
@ -354,7 +358,7 @@ void Proof::delete_clause (Clause *c) {
void Proof::delete_clause (int64_t id, bool r, const vector<int> &c) {
LOG (c, "PROOF deleting from proof");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
add_literals (c);
clause_id = id;
redundant = r;
@ -363,7 +367,7 @@ void Proof::delete_clause (int64_t id, bool r, const vector<int> &c) {
void Proof::weaken_minus (Clause *c) {
LOG (c, "PROOF weaken minus of");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
add_literals (c);
clause_id = c->id;
weaken_minus ();
@ -371,7 +375,7 @@ void Proof::weaken_minus (Clause *c) {
void Proof::weaken_minus (int64_t id, const vector<int> &c) {
LOG (c, "PROOF deleting from proof");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
add_literals (c);
clause_id = id;
weaken_minus ();
@ -389,7 +393,7 @@ void Proof::weaken_plus (int64_t id, const vector<int> &c) {
void Proof::delete_unit_clause (int64_t id, const int lit) {
LOG ("PROOF deleting unit from proof %d", lit);
assert (clause.empty ());
CADICAL_assert (clause.empty ());
add_literal (lit);
clause_id = id;
redundant = false;
@ -398,7 +402,7 @@ void Proof::delete_unit_clause (int64_t id, const int lit) {
void Proof::finalize_clause (Clause *c) {
LOG (c, "PROOF finalizing clause");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
add_literals (c);
clause_id = c->id;
finalize_clause ();
@ -406,7 +410,7 @@ void Proof::finalize_clause (Clause *c) {
void Proof::finalize_clause (int64_t id, const vector<int> &c) {
LOG (c, "PROOF finalizing clause");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (const auto &lit : c)
add_literal (lit);
clause_id = id;
@ -415,7 +419,7 @@ void Proof::finalize_clause (int64_t id, const vector<int> &c) {
void Proof::finalize_unit (int64_t id, int lit) {
LOG ("PROOF finalizing clause %d", lit);
assert (clause.empty ());
CADICAL_assert (clause.empty ());
add_literal (lit);
clause_id = id;
finalize_clause ();
@ -423,7 +427,7 @@ void Proof::finalize_unit (int64_t id, int lit) {
void Proof::finalize_external_unit (int64_t id, int lit) {
LOG ("PROOF finalizing clause %d", lit);
assert (clause.empty ());
CADICAL_assert (clause.empty ());
clause.push_back (lit);
clause_id = id;
finalize_clause ();
@ -437,7 +441,7 @@ void Proof::finalize_external_unit (int64_t id, int lit) {
void Proof::flush_clause (Clause *c) {
LOG (c, "PROOF flushing falsified literals in");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
const bool antecedents = (internal->lrat || internal->frat);
for (int i = 0; i < c->size; i++) {
int internal_lit = c->literals[i];
@ -468,7 +472,7 @@ void Proof::flush_clause (Clause *c) {
void Proof::strengthen_clause (Clause *c, int remove,
const vector<int64_t> &chain) {
LOG (c, "PROOF strengthen by removing %d in", remove);
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (int i = 0; i < c->size; i++) {
int internal_lit = c->literals[i];
if (internal_lit == remove)
@ -488,7 +492,7 @@ void Proof::strengthen_clause (Clause *c, int remove,
void Proof::otfs_strengthen_clause (Clause *c, const std::vector<int> &old,
const vector<int64_t> &chain) {
LOG (c, "PROOF otfs strengthen");
assert (clause.empty ());
CADICAL_assert (clause.empty ());
for (int i = 0; i < c->size; i++) {
int internal_lit = c->literals[i];
add_literal (internal_lit);
@ -512,7 +516,7 @@ void Proof::strengthen (int64_t id) {
void Proof::add_original_clause (bool restore) {
LOG (clause, "PROOF adding original external clause");
assert (clause_id);
CADICAL_assert (clause_id);
for (auto &tracer : tracers) {
tracer->add_original_clause (clause_id, false, clause, restore);
@ -524,7 +528,7 @@ void Proof::add_original_clause (bool restore) {
void Proof::add_derived_clause () {
LOG (clause, "PROOF adding derived external clause (redundant: %d)",
redundant);
assert (clause_id);
CADICAL_assert (clause_id);
for (auto &tracer : tracers) {
tracer->add_derived_clause (clause_id, redundant, clause, proof_chain);
}
@ -544,7 +548,7 @@ void Proof::delete_clause () {
void Proof::demote_clause () {
LOG (clause, "PROOF demoting external clause");
assert (!redundant);
CADICAL_assert (!redundant);
for (auto &tracer : tracers) {
tracer->demote_clause (clause_id, clause);
}
@ -589,7 +593,7 @@ void Proof::add_assumption_clause () {
void Proof::add_assumption () {
LOG (clause, "PROOF adding assumption");
assert (clause.size () == 1);
CADICAL_assert (clause.size () == 1);
for (auto &tracer : tracers) {
tracer->add_assumption (clause.back ());
}
@ -655,3 +659,5 @@ void Proof::conclude_unknown (const vector<int> &trail) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -37,7 +41,7 @@ static Clause *decision_reason = &decision_reason_clause;
inline int Internal::assignment_level (int lit, Clause *reason) {
assert (opts.chrono || external_prop);
CADICAL_assert (opts.chrono || external_prop);
if (!reason || reason == external_reason)
return level;
@ -46,7 +50,7 @@ inline int Internal::assignment_level (int lit, Clause *reason) {
for (const auto &other : *reason) {
if (other == lit)
continue;
assert (val (other));
CADICAL_assert (val (other));
int tmp = var (other).level;
if (tmp > res)
res = tmp;
@ -65,11 +69,11 @@ void Internal::build_chain_for_units (int lit, Clause *reason,
return;
else if (!opts.chrono && level && !forced)
return; // not decision level 0
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
for (auto &reason_lit : *reason) {
if (lit == reason_lit)
continue;
assert (val (reason_lit));
CADICAL_assert (val (reason_lit));
if (!val (reason_lit))
continue;
const int signed_reason_lit = val (reason_lit) * reason_lit;
@ -85,12 +89,12 @@ void Internal::build_chain_for_units (int lit, Clause *reason,
void Internal::build_chain_for_empty () {
if (!lrat || !lrat_chain.empty ())
return;
assert (!level);
assert (lrat_chain.empty ());
assert (conflict);
CADICAL_assert (!level);
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (conflict);
LOG (conflict, "lrat for global empty clause with conflict");
for (auto &lit : *conflict) {
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
int64_t id = unit_id (-lit);
lrat_chain.push_back (id);
}
@ -106,12 +110,12 @@ inline void Internal::search_assign (int lit, Clause *reason) {
const int idx = vidx (lit);
const bool from_external = reason == external_reason;
assert (!val (idx));
assert (!flags (idx).eliminated () || reason == decision_reason ||
CADICAL_assert (!val (idx));
CADICAL_assert (!flags (idx).eliminated () || reason == decision_reason ||
reason == external_reason);
Var &v = var (idx);
int lit_level;
assert (!lrat || level || reason == external_reason ||
CADICAL_assert (!lrat || level || reason == external_reason ||
reason == decision_reason || !lrat_chain.empty ());
// The following cases are explained in the two comments above before
// 'decision_reason' and 'assignment_level'.
@ -137,16 +141,16 @@ inline void Internal::search_assign (int lit, Clause *reason) {
v.level = lit_level;
v.trail = trail.size ();
v.reason = reason;
assert ((int) num_assigned < max_var);
assert (num_assigned == trail.size ());
CADICAL_assert ((int) num_assigned < max_var);
CADICAL_assert (num_assigned == trail.size ());
num_assigned++;
if (!lit_level && !from_external)
learn_unit_clause (lit); // increases 'stats.fixed'
assert (lit_level || !from_external);
CADICAL_assert (lit_level || !from_external);
const signed char tmp = sign (lit);
set_val (idx, tmp);
assert (val (lit) > 0); // Just a bit paranoid but useful.
assert (val (-lit) < 0); // Ditto.
CADICAL_assert (val (lit) > 0); // Just a bit paranoid but useful.
CADICAL_assert (val (-lit) < 0); // Ditto.
if (!searching_lucky_phases)
phases.saved[idx] = tmp; // phase saving during search
trail.push_back (lit);
@ -161,7 +165,9 @@ inline void Internal::search_assign (int lit, Clause *reason) {
const Watches &ws = watches (-lit);
if (!ws.empty ()) {
const Watch &w = ws[0];
#ifndef WIN32
__builtin_prefetch (&w, 0, 1);
#endif
}
}
lrat_chain.clear ();
@ -176,7 +182,7 @@ inline void Internal::search_assign (int lit, Clause *reason) {
// which is called directly in 'propagate' below and thus is inlined.
void Internal::assign_unit (int lit) {
assert (!level);
CADICAL_assert (!level);
search_assign (lit, 0);
}
@ -185,7 +191,7 @@ void Internal::assign_unit (int lit) {
void Internal::search_assume_decision (int lit) {
require_mode (SEARCH);
assert (propagated == trail.size ());
CADICAL_assert (propagated == trail.size ());
new_trail_level (lit);
notify_decision ();
LOG ("search decide %d", lit);
@ -227,7 +233,7 @@ bool Internal::propagate () {
if (level)
require_mode (SEARCH);
assert (!unsat);
CADICAL_assert (!unsat);
LOG ("starting propagate");
START (propagate);
@ -259,7 +265,7 @@ bool Internal::propagate () {
if (w.binary ()) {
// assert (w.clause->redundant || !w.clause->garbage);
// CADICAL_assert (w.clause->redundant || !w.clause->garbage);
// In principle we can ignore garbage binary clauses too, but that
// would require to dereference the clause pointer all the time with
@ -296,7 +302,7 @@ bool Internal::propagate () {
}
} else {
assert (w.clause->size > 2);
CADICAL_assert (w.clause->size > 2);
if (conflict)
break; // Stop if there was a binary conflict already.
@ -355,14 +361,14 @@ bool Internal::propagate () {
if (v < 0) { // need second search starting at the head?
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
w.clause->pos = k - lits; // always save position
assert (lits + 2 <= k), assert (k <= w.clause->end ());
CADICAL_assert (lits + 2 <= k), CADICAL_assert (k <= w.clause->end ());
if (v > 0) {
@ -388,7 +394,7 @@ bool Internal::propagate () {
} else if (!u) {
assert (v < 0);
CADICAL_assert (v < 0);
// The other watch is unassigned ('!u') and all other literals
// assigned to false (still 'v < 0'), thus we found a unit.
@ -414,7 +420,7 @@ bool Internal::propagate () {
// another literal in the clause at that higher assignment
// level and watch that instead of 'lit'.
assert (size > 2);
CADICAL_assert (size > 2);
int pos, s = 0;
@ -422,8 +428,8 @@ bool Internal::propagate () {
if (var (s = lits[pos]).level == other_level)
break;
assert (s);
assert (pos < size);
CADICAL_assert (s);
CADICAL_assert (pos < size);
LOG (w.clause, "unwatch %d in", lit);
lits[pos] = lit;
@ -436,8 +442,8 @@ bool Internal::propagate () {
}
} else {
assert (u < 0);
assert (v < 0);
CADICAL_assert (u < 0);
CADICAL_assert (v < 0);
// The other watch is assigned false ('u < 0') and all other
// literals as well (still 'v < 0'), thus we found a conflict.
@ -495,8 +501,8 @@ bool Internal::propagate () {
void Internal::propergate () {
assert (!conflict);
assert (propagated == trail.size ());
CADICAL_assert (!conflict);
CADICAL_assert (propagated == trail.size ());
while (propergated != trail.size ()) {
@ -513,7 +519,7 @@ void Internal::propergate () {
const Watch w = *j++ = *i++;
if (w.binary ()) {
assert (val (w.blit) > 0);
CADICAL_assert (val (w.blit) > 0);
continue;
}
if (w.clause->garbage) {
@ -529,7 +535,7 @@ void Internal::propergate () {
// TODO: check if u == 0 can happen.
if (u > 0)
continue;
assert (u < 0);
CADICAL_assert (u < 0);
const int size = w.clause->size;
const literal_iterator middle = lits + w.clause->pos;
@ -544,15 +550,15 @@ void Internal::propergate () {
if (v < 0) {
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
assert (lits + 2 <= k), assert (k <= w.clause->end ());
CADICAL_assert (lits + 2 <= k), CADICAL_assert (k <= w.clause->end ());
w.clause->pos = k - lits;
assert (v > 0);
CADICAL_assert (v > 0);
LOG (w.clause, "unwatch %d in", lit);
@ -576,3 +582,5 @@ void Internal::propergate () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Slightly different than 'bump_variable' since the variable is not
@ -10,15 +14,15 @@ inline void Internal::init_enqueue (int idx) {
if (opts.reverse) {
l.prev = 0;
if (queue.first) {
assert (!links[queue.first].prev);
CADICAL_assert (!links[queue.first].prev);
links[queue.first].prev = idx;
btab[idx] = btab[queue.first] - 1;
} else {
assert (!queue.last);
CADICAL_assert (!queue.last);
queue.last = idx;
btab[idx] = 0;
}
assert (btab[idx] <= stats.bumped);
CADICAL_assert (btab[idx] <= stats.bumped);
l.next = queue.first;
queue.first = idx;
if (!queue.unassigned)
@ -26,10 +30,10 @@ inline void Internal::init_enqueue (int idx) {
} else {
l.next = 0;
if (queue.last) {
assert (!links[queue.last].next);
CADICAL_assert (!links[queue.last].next);
links[queue.last].next = idx;
} else {
assert (!queue.first);
CADICAL_assert (!queue.first);
queue.first = idx;
}
btab[idx] = ++stats.bumped;
@ -47,7 +51,7 @@ inline void Internal::init_enqueue (int idx) {
void Internal::init_queue (int old_max_var, int new_max_var) {
LOG ("initializing VMTF queue from %d to %d", old_max_var + 1,
new_max_var);
assert (old_max_var < new_max_var);
CADICAL_assert (old_max_var < new_max_var);
// New variables can be created that can invoke enlarge anytime (eg via
// calls during ipasir-up call-backs), thus assuming (!level) is not
// correct
@ -88,3 +92,5 @@ void Internal::shuffle_queue () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,3 +1,5 @@
#include "global.h"
#include "internal.hpp"
/*------------------------------------------------------------------------*/
@ -46,6 +48,8 @@
// does not have any effect. TODO: add a similar machine identity hashing
// function for other operating systems (Windows and macOS).
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
static uint64_t hash_machine_identifier () {
@ -55,7 +59,7 @@ static uint64_t hash_machine_identifier () {
char buffer[128];
memset (buffer, 0, sizeof buffer);
size_t bytes = fread (buffer, 1, sizeof buffer - 1, file);
assert (bytes);
CADICAL_assert (bytes);
fclose (file);
if (bytes && bytes < sizeof buffer) {
buffer[bytes] = 0;
@ -68,6 +72,8 @@ static uint64_t hash_machine_identifier () {
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
/*------------------------------------------------------------------------*/
// On our Linux cluster where we used an NFS mounted root disk the
@ -78,7 +84,7 @@ static uint64_t hash_machine_identifier () {
// work. As an additional measure to increase the possibility to get
// different seeds we are now also using network addresses (explicitly).
#ifndef __WIN32
#ifndef WIN32
extern "C" {
#include <ifaddrs.h>
@ -91,6 +97,8 @@ extern "C" {
#endif
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
static uint64_t hash_network_addresses () {
@ -102,7 +110,7 @@ static uint64_t hash_network_addresses () {
// you really need to run 'mobical' on a Windows cluster where each node
// has identical IP addresses.
#ifndef __WIN32
#ifndef WIN32
struct ifaddrs *addrs;
if (!getifaddrs (&addrs)) {
for (struct ifaddrs *addr = addrs; addr; addr = addr->ifa_next) {
@ -135,6 +143,8 @@ static uint64_t hash_network_addresses () {
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
/*------------------------------------------------------------------------*/
// Hash the current wall-clock time in seconds.
@ -143,6 +153,8 @@ extern "C" {
#include <time.h>
}
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
static uint64_t hash_time () {
@ -153,15 +165,23 @@ static uint64_t hash_time () {
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
/*------------------------------------------------------------------------*/
// Hash the process identified.
extern "C" {
#include <sys/types.h>
#ifdef WIN32
#include <process.h>
#else
#include <unistd.h>
#endif
}
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
static uint64_t hash_process () {
@ -172,12 +192,16 @@ static uint64_t hash_process () {
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
/*------------------------------------------------------------------------*/
// Hash the current number of clock cycles.
#include <ctime>
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
static uint64_t hash_clock_cycles () {
@ -205,3 +229,5 @@ Random::Random () : state (1) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,15 +1,28 @@
#include "global.h"
#include "reap.hpp"
#include <cassert>
#include <climits>
#include <cstring>
#ifdef _MSC_VER
#include <intrin.h>
static inline int __builtin_clz(unsigned x) {
unsigned long r;
_BitScanReverse(&r, x);
return (int)(r ^ 31);
}
#endif
ABC_NAMESPACE_IMPL_START
void Reap::init () {
for (auto &bucket : buckets)
bucket = {0};
assert (!num_elements);
assert (!last_deleted);
CADICAL_assert (!num_elements);
CADICAL_assert (!last_deleted);
min_bucket = 32;
assert (!max_bucket);
CADICAL_assert (!max_bucket);
}
void Reap::release () {
@ -31,7 +44,7 @@ static inline unsigned leading_zeroes_of_unsigned (unsigned x) {
}
void Reap::push (unsigned e) {
assert (last_deleted <= e);
CADICAL_assert (last_deleted <= e);
const unsigned diff = e ^ last_deleted;
const unsigned bucket = 32 - leading_zeroes_of_unsigned (diff);
buckets[bucket].push_back (e);
@ -39,16 +52,16 @@ void Reap::push (unsigned e) {
min_bucket = bucket;
if (max_bucket < bucket)
max_bucket = bucket;
assert (num_elements != UINT_MAX);
CADICAL_assert (num_elements != UINT_MAX);
num_elements++;
}
unsigned Reap::pop () {
assert (num_elements > 0);
CADICAL_assert (num_elements > 0);
unsigned i = min_bucket;
for (;;) {
assert (i < 33);
assert (i <= max_bucket);
CADICAL_assert (i < 33);
CADICAL_assert (i <= max_bucket);
std::vector<unsigned> &s = buckets[i];
if (s.empty ()) {
min_bucket = ++i;
@ -60,7 +73,7 @@ unsigned Reap::pop () {
const auto begin = std::begin (s);
const auto end = std::end (s);
auto q = std::begin (s);
assert (begin < end);
CADICAL_assert (begin < end);
for (auto p = begin; p != end; ++p) {
const unsigned tmp = *p;
if (tmp >= res)
@ -74,9 +87,9 @@ unsigned Reap::pop () {
continue;
const unsigned other = *p;
const unsigned diff = other ^ res;
assert (sizeof (unsigned) == 4);
CADICAL_assert (sizeof (unsigned) == 4);
const unsigned j = 32 - leading_zeroes_of_unsigned (diff);
assert (j < i);
CADICAL_assert (j < i);
buckets[j].push_back (other);
if (min_bucket > j)
min_bucket = j;
@ -85,31 +98,31 @@ unsigned Reap::pop () {
s.clear ();
if (i && max_bucket == i) {
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (unsigned j = i + 1; j < 33; j++)
assert (buckets[j].empty ());
CADICAL_assert (buckets[j].empty ());
#endif
if (s.empty ())
max_bucket = i - 1;
}
} else {
res = last_deleted;
assert (!buckets[0].empty ());
assert (buckets[0].at (0) == res);
CADICAL_assert (!buckets[0].empty ());
CADICAL_assert (buckets[0].at (0) == res);
buckets[0].pop_back ();
}
if (min_bucket == i) {
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
for (unsigned j = 0; j < i; j++)
assert (buckets[j].empty ());
CADICAL_assert (buckets[j].empty ());
#endif
if (s.empty ())
min_bucket = std::min ((int) (i + 1), 32);
}
--num_elements;
assert (last_deleted <= res);
CADICAL_assert (last_deleted <= res);
last_deleted = res;
return res;
@ -117,7 +130,7 @@ unsigned Reap::pop () {
}
void Reap::clear () {
assert (max_bucket <= 32);
CADICAL_assert (max_bucket <= 32);
for (unsigned i = 0; i < 33; i++)
buckets[i].clear ();
num_elements = 0;
@ -125,3 +138,5 @@ void Reap::clear () {
min_bucket = 32;
max_bucket = 0;
}
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -114,7 +118,7 @@ void Internal::mark_useless_redundant_clauses_as_garbage () {
if (c->glue <= tier2limit && used >= max_used - 1)
continue;
if (c->hyper) { // Hyper binary and ternary resolvents
assert (c->size <= 3); // are only kept for one reduce round
CADICAL_assert (c->size <= 3); // are only kept for one reduce round
if (!used)
mark_garbage (c); // unless
continue; // used recently.
@ -167,7 +171,7 @@ void Internal::mark_useless_redundant_clauses_as_garbage () {
// If chronological backtracking produces out-of-order assigned units, then
// it is necessary to completely propagate them at the root level in order
// to derive all implied units. Otherwise the blocking literals in
// 'flush_watches' are messed up and assertion 'FW1' fails.
// 'flush_watches' are messed up and CADICAL_assertion 'FW1' fails.
bool Internal::propagate_out_of_order_units () {
if (!level)
@ -175,7 +179,7 @@ bool Internal::propagate_out_of_order_units () {
int oou = 0;
for (size_t i = control[1].trail; !oou && i < trail.size (); i++) {
const int lit = trail[i];
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
if (var (lit).level)
continue;
LOG ("found out-of-order assigned unit %d", oou);
@ -183,7 +187,7 @@ bool Internal::propagate_out_of_order_units () {
}
if (!oou)
return true;
assert (opts.chrono || external_prop);
CADICAL_assert (opts.chrono || external_prop);
backtrack (0);
if (propagate ())
return true;
@ -276,3 +280,5 @@ DONE:
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -281,7 +285,7 @@ void Internal::rephase () {
break;
}
} else {
assert (!stable && opts.walk && opts.walknonstable);
CADICAL_assert (!stable && opts.walk && opts.walknonstable);
// flipping,(random,best,walk,flipping,best,walk)^\omega
if (!count)
type = rephase_flipping ();
@ -310,7 +314,7 @@ void Internal::rephase () {
break;
}
}
assert (type);
CADICAL_assert (type);
int64_t delta = opts.rephaseint * (stats.rephased.total + 1);
lim.rephase = stats.conflicts + delta;
@ -334,3 +338,5 @@ void Internal::rephase () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,8 +1,12 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
#ifndef QUIET
#ifndef CADICAL_QUIET
/*------------------------------------------------------------------------*/
@ -167,7 +171,7 @@ void Internal::report (char type, int verbose) {
if (opts.quiet || (verbose > opts.verbose))
return;
if (!reported) {
assert (!lim.report);
CADICAL_assert (!lim.report);
reported = true;
MSG ("%stime measured in %s time %s%s", tout.magenta_code (),
internal->opts.realtime ? "real" : "process",
@ -177,7 +181,7 @@ void Internal::report (char type, int verbose) {
Report reports[num_reports];
int n = 0;
#define REPORT(HEAD, PREC, MIN, EXPR) \
assert (n < num_reports); \
CADICAL_assert (n < num_reports); \
reports[n++] = Report (HEAD, PREC, MIN, (double) (EXPR));
REPORTS
#undef REPORT
@ -287,10 +291,12 @@ void Internal::report (char type, int verbose) {
fflush (stdout);
}
#else // ifndef QUIET
#else // ifndef CADICAL_QUIET
void Internal::report (char, int) {}
#endif
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,3 +1,5 @@
#include "global.h"
#include "internal.hpp"
/*------------------------------------------------------------------------*/
@ -9,7 +11,7 @@
extern "C" {
#ifdef __WIN32
#ifdef WIN32
#ifndef __WIN32_WINNT
#define __WIN32_WINNT 0x0600
@ -37,11 +39,13 @@ extern "C" {
#include <string.h>
}
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
#ifdef __WIN32
#ifdef WIN32
double absolute_real_time () {
FILETIME f;
@ -104,7 +108,7 @@ double Internal::process_time () const {
/*------------------------------------------------------------------------*/
#ifdef __WIN32
#ifdef WIN32
uint64_t current_resident_set_size () {
PROCESS_MEMORY_COUNTERS pmc;
@ -158,3 +162,5 @@ uint64_t current_resident_set_size () {
/*------------------------------------------------------------------------*/
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// As observed by Chanseok Oh and implemented in MapleSAT solvers too,
@ -21,7 +25,7 @@ bool Internal::stabilizing () {
if (stable && opts.stabilizeonly)
return true;
if (!inc.stabilize) {
assert (!stable);
CADICAL_assert (!stable);
if (stats.conflicts <= lim.stabilize)
return false;
} else if (stats.ticks.search[stable] <= lim.stabilize)
@ -112,7 +116,7 @@ int Internal::reuse_trail () {
if (!opts.restartreusetrail)
return trivial_decisions;
int next_decision = next_decision_variable ();
assert (1 <= next_decision);
CADICAL_assert (1 <= next_decision);
int res = trivial_decisions;
if (use_scores ()) {
while (res < level) {
@ -157,3 +161,5 @@ void Internal::restart () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -51,14 +55,14 @@ void External::restore_clause (const vector<int>::const_iterator &begin,
const vector<int>::const_iterator &end,
const int64_t id) {
LOG (begin, end, "restoring external clause[%" PRId64 "]", id);
assert (eclause.empty ());
assert (id);
CADICAL_assert (eclause.empty ());
CADICAL_assert (id);
for (auto p = begin; p != end; p++) {
eclause.push_back (*p);
if (internal->proof && internal->lrat) {
const auto &elit = *p;
unsigned eidx = (elit > 0) + 2u * (unsigned) abs (elit);
assert ((size_t) eidx < ext_units.size ());
CADICAL_assert ((size_t) eidx < ext_units.size ());
const int64_t id = ext_units[eidx];
bool added = ext_flags[abs (elit)];
if (id && !added) {
@ -83,7 +87,7 @@ void External::restore_clause (const vector<int>::const_iterator &begin,
void External::restore_clauses () {
assert (internal->opts.restoreall == 2 || !tainted.empty ());
CADICAL_assert (internal->opts.restoreall == 2 || !tainted.empty ());
START (restore);
internal->stats.restorations++;
@ -97,7 +101,7 @@ void External::restore_clauses () {
PHASE ("restore", internal->stats.restorations,
"forced to restore all clauses");
#ifndef QUIET
#ifndef CADICAL_QUIET
{
unsigned numtainted = 0;
for (const auto b : tainted)
@ -120,7 +124,7 @@ void External::restore_clauses () {
clauses.weakened++;
assert (!*p);
CADICAL_assert (!*p);
const auto saved = q; // Save old start.
*q++ = *p++; // Copy zero '0'.
@ -129,7 +133,7 @@ void External::restore_clauses () {
int tlit = 0; // Negation tainted.
int elit;
//
assert (p != end_of_extension);
CADICAL_assert (p != end_of_extension);
//
while ((elit = *q++ = *p++)) {
@ -138,7 +142,7 @@ void External::restore_clauses () {
LOG ("negation of witness literal %d tainted", tlit);
}
assert (p != end_of_extension);
CADICAL_assert (p != end_of_extension);
}
// now copy the id of the clause
@ -146,8 +150,8 @@ void External::restore_clauses () {
LOG ("id is %" PRId64, id);
*q++ = *p++;
*q++ = *p++;
assert (id);
assert (!*p);
CADICAL_assert (id);
CADICAL_assert (!*p);
*q++ = *p++;
// Now find 'end_of_clause' (clause starts at 'p') and at the same time
@ -160,7 +164,7 @@ void External::restore_clauses () {
satisfied = elit;
end_of_clause++;
}
assert (id);
CADICAL_assert (id);
// Do not apply our 'FLUSH' rule to remove satisfied (implied) clauses
// if the corresponding option is set simply by resetting 'satisfied'.
@ -199,7 +203,7 @@ void External::restore_clauses () {
extension.resize (q - extension.begin ());
shrink_vector (extension);
#ifndef QUIET
#ifndef CADICAL_QUIET
if (clauses.satisfied)
PHASE ("restore", internal->stats.restorations,
"removed %" PRId64 " satisfied %.0f%% of %" PRId64
@ -244,20 +248,20 @@ void External::restore_clauses () {
p = extension.end ();
while (p != begin_of_extension) {
while (*--p)
assert (p != begin_of_extension);
CADICAL_assert (p != begin_of_extension);
int elit;
assert (p != begin_of_extension);
CADICAL_assert (p != begin_of_extension);
--p;
assert (p != begin_of_extension);
assert (*p || *(p - 1));
CADICAL_assert (p != begin_of_extension);
CADICAL_assert (*p || *(p - 1));
--p;
assert (p != begin_of_extension);
assert (!*p);
CADICAL_assert (p != begin_of_extension);
CADICAL_assert (!*p);
--p;
assert (p != begin_of_extension);
CADICAL_assert (p != begin_of_extension);
while ((elit = *--p)) {
mark (witness, elit);
assert (p != begin_of_extension);
CADICAL_assert (p != begin_of_extension);
}
}
@ -265,3 +269,5 @@ void External::restore_clauses () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// This initializes variables on the binary 'scores' heap also with
@ -20,7 +24,7 @@ void Internal::shuffle_scores () {
return;
if (!opts.shufflescores)
return;
assert (!level);
CADICAL_assert (!level);
stats.shuffled++;
LOG ("shuffling scores");
vector<int> shuffle;
@ -49,3 +53,5 @@ void Internal::shuffle_scores () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,6 +1,10 @@
#include "global.h"
#include "internal.hpp"
#include "reap.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::reset_shrinkable () {
@ -10,7 +14,7 @@ void Internal::reset_shrinkable () {
for (const auto &lit : shrinkable) {
LOG ("resetting lit %i", lit);
Flags &f = flags (lit);
assert (f.shrinkable);
CADICAL_assert (f.shrinkable);
f.shrinkable = false;
#ifdef LOGGING
++reset;
@ -24,14 +28,14 @@ void Internal::mark_shrinkable_as_removable (
#ifdef LOGGING
size_t marked = 0, reset = 0;
#endif
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
unsigned kept = 0, minireset = 0;
for (; minimized_start < minimized.size (); ++minimized_start) {
const int lit = minimized[minimized_start];
Flags &f = flags (lit);
const Var &v = var (lit);
if (v.level == blevel) {
assert (!f.poison);
CADICAL_assert (!f.poison);
++minireset;
} else
++kept;
@ -45,8 +49,8 @@ void Internal::mark_shrinkable_as_removable (
for (const int lit : shrinkable) {
Flags &f = flags (lit);
assert (f.shrinkable);
assert (!f.poison);
CADICAL_assert (f.shrinkable);
CADICAL_assert (!f.poison);
f.shrinkable = false;
#ifdef LOGGING
++reset;
@ -65,11 +69,11 @@ void Internal::mark_shrinkable_as_removable (
int inline Internal::shrink_literal (int lit, int blevel,
unsigned max_trail) {
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
Flags &f = flags (lit);
Var &v = var (lit);
assert (v.level <= blevel);
CADICAL_assert (v.level <= blevel);
if (!v.level) {
LOG ("skipping root level assigned %d", (lit));
@ -77,14 +81,14 @@ int inline Internal::shrink_literal (int lit, int blevel,
}
if (v.reason == external_reason) {
assert (!opts.exteagerreasons);
CADICAL_assert (!opts.exteagerreasons);
v.reason = learn_external_reason_clause (-lit, 0, true);
if (!v.reason) {
assert (!v.level);
CADICAL_assert (!v.level);
return 0;
}
}
assert (v.reason != external_reason);
CADICAL_assert (v.reason != external_reason);
if (f.shrinkable) {
LOG ("skipping already shrinkable literal %d", (lit));
return 0;
@ -110,7 +114,7 @@ int inline Internal::shrink_literal (int lit, int blevel,
f.poison = false;
shrinkable.push_back (lit);
if (opts.shrinkreap) {
assert (max_trail < trail.size ());
CADICAL_assert (max_trail < trail.size ());
const unsigned dist = max_trail - v.trail;
reap.push (dist);
}
@ -121,11 +125,11 @@ unsigned Internal::shrunken_block_uip (
int uip, int blevel, std::vector<int>::reverse_iterator &rbegin_block,
std::vector<int>::reverse_iterator &rend_block,
std::vector<int>::size_type minimized_start, const int uip0) {
assert (clause[0] == uip0);
CADICAL_assert (clause[0] == uip0);
LOG ("UIP on level %u, uip: %i (replacing by %i)", blevel, uip, uip0);
assert (rend_block > rbegin_block);
assert (rend_block < clause.rend ());
CADICAL_assert (rend_block > rbegin_block);
CADICAL_assert (rend_block < clause.rend ());
unsigned block_shrunken = 0;
*rbegin_block = -uip;
Var &v = var (-uip);
@ -147,10 +151,10 @@ unsigned Internal::shrunken_block_uip (
*p = uip0;
// if (lit == -uip) continue;
++block_shrunken;
assert (clause[0] == uip0);
CADICAL_assert (clause[0] == uip0);
}
mark_shrinkable_as_removable (blevel, minimized_start);
assert (clause[0] == uip0);
CADICAL_assert (clause[0] == uip0);
return block_shrunken;
}
@ -160,18 +164,18 @@ void inline Internal::shrunken_block_no_uip (
unsigned &block_minimized, const int uip0) {
STOP (shrink);
START (minimize);
assert (rend_block > rbegin_block);
CADICAL_assert (rend_block > rbegin_block);
LOG ("no UIP found, now minimizing");
for (auto p = rbegin_block; p != rend_block; ++p) {
assert (p != clause.rend () - 1);
CADICAL_assert (p != clause.rend () - 1);
const int lit = *p;
if (opts.minimize && minimize_literal (-lit)) {
assert (!flags (lit).keep);
CADICAL_assert (!flags (lit).keep);
++block_minimized;
*p = uip0;
} else {
flags (lit).keep = true;
assert (flags (lit).keep);
CADICAL_assert (flags (lit).keep);
}
}
STOP (minimize);
@ -182,17 +186,17 @@ void Internal::push_literals_of_block (
const std::vector<int>::reverse_iterator &rbegin_block,
const std::vector<int>::reverse_iterator &rend_block, int blevel,
unsigned max_trail) {
assert (rbegin_block < rend_block);
CADICAL_assert (rbegin_block < rend_block);
for (auto p = rbegin_block; p != rend_block; ++p) {
assert (p != clause.rend () - 1);
assert (!flags (*p).keep);
CADICAL_assert (p != clause.rend () - 1);
CADICAL_assert (!flags (*p).keep);
const int lit = *p;
LOG ("pushing lit %i of blevel %i", lit, var (lit).level);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
int tmp =
#endif
shrink_literal (lit, blevel, max_trail);
assert (tmp > 0);
CADICAL_assert (tmp > 0);
}
}
@ -200,24 +204,24 @@ unsigned inline Internal::shrink_next (int blevel, unsigned &open,
unsigned &max_trail) {
const auto &t = &trail;
if (opts.shrinkreap) {
assert (!reap.empty ());
CADICAL_assert (!reap.empty ());
const unsigned dist = reap.pop ();
--open;
assert (dist <= max_trail);
CADICAL_assert (dist <= max_trail);
const unsigned pos = max_trail - dist;
assert (pos < t->size ());
CADICAL_assert (pos < t->size ());
const int uip = (*t)[pos];
assert (val (uip) > 0);
CADICAL_assert (val (uip) > 0);
LOG ("trying to shrink literal %d at trail[%u] and level %d", uip, pos,
blevel);
return uip;
} else {
int uip;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
unsigned init_max_trail = max_trail;
#endif
do {
assert (max_trail <= init_max_trail);
CADICAL_assert (max_trail <= init_max_trail);
uip = (*t)[max_trail--];
} while (!flags (uip).shrinkable);
--open;
@ -233,14 +237,14 @@ unsigned inline Internal::shrink_along_reason (int uip, int blevel,
unsigned max_trail) {
LOG ("shrinking along the reason of lit %i", uip);
unsigned open = 0;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
const Flags &f = flags (uip);
#endif
const Var &v = var (uip);
assert (f.shrinkable);
assert (v.level == blevel);
assert (v.reason);
CADICAL_assert (f.shrinkable);
CADICAL_assert (v.level == blevel);
CADICAL_assert (v.reason);
if (opts.minimizeticks)
stats.ticks.search[stable]++;
@ -251,7 +255,7 @@ unsigned inline Internal::shrink_along_reason (int uip, int blevel,
for (int lit : c) {
if (lit == uip)
continue;
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
int tmp = shrink_literal (lit, blevel, max_trail);
if (tmp < 0) {
failed_ptr = true;
@ -273,13 +277,13 @@ Internal::shrink_block (std::vector<int>::reverse_iterator &rbegin_lits,
int blevel, unsigned &open,
unsigned &block_minimized, const int uip0,
unsigned max_trail) {
assert (shrinkable.empty ());
assert (blevel <= this->level);
assert (open < clause.size ());
assert (rbegin_lits >= clause.rbegin ());
assert (rend_block < clause.rend ());
assert (rbegin_lits < rend_block);
assert (opts.shrink);
CADICAL_assert (shrinkable.empty ());
CADICAL_assert (blevel <= this->level);
CADICAL_assert (open < clause.size ());
CADICAL_assert (rbegin_lits >= clause.rbegin ());
CADICAL_assert (rend_block < clause.rend ());
CADICAL_assert (rbegin_lits < rend_block);
CADICAL_assert (opts.shrink);
#ifdef LOGGING
@ -301,18 +305,18 @@ Internal::shrink_block (std::vector<int>::reverse_iterator &rbegin_lits,
if (!failed) {
push_literals_of_block (rbegin_lits, rend_block, blevel, max_trail);
assert (!opts.shrinkreap || reap.size () == open);
CADICAL_assert (!opts.shrinkreap || reap.size () == open);
assert (open > 0);
CADICAL_assert (open > 0);
while (!failed) {
assert (!opts.shrinkreap || reap.size () == open);
CADICAL_assert (!opts.shrinkreap || reap.size () == open);
uip = shrink_next (blevel, open, max_trail);
if (open == 0) {
break;
}
open += shrink_along_reason (uip, blevel, resolve_large_clauses,
failed, max_trail2);
assert (open >= 1);
CADICAL_assert (open >= 1);
}
if (!failed)
@ -370,7 +374,7 @@ std::vector<int>::reverse_iterator Internal::minimize_and_shrink_block (
{
LOG ("shrinking block");
assert (rbegin_block < clause.rend () - 1);
CADICAL_assert (rbegin_block < clause.rend () - 1);
int blevel;
unsigned open = 0;
unsigned max_trail;
@ -378,7 +382,7 @@ std::vector<int>::reverse_iterator Internal::minimize_and_shrink_block (
// find begining of block;
std::vector<int>::reverse_iterator rend_block;
{
assert (rbegin_block <= clause.rend ());
CADICAL_assert (rbegin_block <= clause.rend ());
const int lit = *rbegin_block;
const int idx = vidx (lit);
blevel = vtab[idx].level;
@ -388,7 +392,7 @@ std::vector<int>::reverse_iterator Internal::minimize_and_shrink_block (
rend_block = rbegin_block;
bool finished;
do {
assert (rend_block < clause.rend () - 1);
CADICAL_assert (rend_block < clause.rend () - 1);
const int lit = *(++rend_block);
const int idx = vidx (lit);
finished = (blevel != vtab[idx].level);
@ -401,10 +405,10 @@ std::vector<int>::reverse_iterator Internal::minimize_and_shrink_block (
} while (!finished);
}
assert (open > 0);
assert (open < clause.size ());
assert (rbegin_block < clause.rend ());
assert (rend_block < clause.rend ());
CADICAL_assert (open > 0);
CADICAL_assert (open < clause.size ());
CADICAL_assert (rbegin_block < clause.rend ());
CADICAL_assert (rend_block < clause.rend ());
unsigned block_shrunken = 0, block_minimized = 0;
if (open < 2) {
@ -424,7 +428,7 @@ std::vector<int>::reverse_iterator Internal::minimize_and_shrink_block (
}
void Internal::shrink_and_minimize_clause () {
assert (opts.minimize || opts.shrink > 0);
CADICAL_assert (opts.minimize || opts.shrink > 0);
LOG (clause, "shrink first UIP clause");
START (shrink);
@ -434,7 +438,7 @@ void Internal::shrink_and_minimize_clause () {
unsigned total_shrunken = 0;
unsigned total_minimized = 0;
LOG (clause, "shrink first UIP clause (asserting lit: %i)", clause[0]);
LOG (clause, "shrink first UIP clause (CADICAL_asserting lit: %i)", clause[0]);
auto rend_lits = clause.rend () - 1;
auto rend_block = clause.rbegin ();
@ -442,7 +446,7 @@ void Internal::shrink_and_minimize_clause () {
// for direct LRAT we remember how the clause used to look
vector<int> old_clause_lrat;
assert (minimize_chain.empty ());
CADICAL_assert (minimize_chain.empty ());
if (lrat)
for (auto &i : clause)
old_clause_lrat.push_back (i);
@ -455,18 +459,18 @@ void Internal::shrink_and_minimize_clause () {
LOG (clause,
"post shrink pass (with uips, not removed) first UIP clause");
LOG (old_clause_lrat, "(used for lratdirect) before shrink: clause");
#if defined(LOGGING) || !defined(NDEBUG)
#if defined(LOGGING) || !defined(CADICAL_NDEBUG)
const unsigned old_size = clause.size ();
#endif
std::vector<int> stack;
{
std::vector<int>::size_type i = 1;
for (std::vector<int>::size_type j = 1; j < clause.size (); ++j) {
assert (i <= j);
CADICAL_assert (i <= j);
clause[i] = clause[j];
if (lrat) {
assert (j < old_clause_lrat.size ());
assert (mini_chain.empty ());
CADICAL_assert (j < old_clause_lrat.size ());
CADICAL_assert (mini_chain.empty ());
if (clause[j] != old_clause_lrat[j]) {
calculate_minimize_chain (-old_clause_lrat[j], stack);
for (auto p : mini_chain) {
@ -478,13 +482,13 @@ void Internal::shrink_and_minimize_clause () {
if (clause[j] == uip0) {
continue;
}
assert (flags (clause[i]).keep);
CADICAL_assert (flags (clause[i]).keep);
++i;
LOG ("keeping literal %i", clause[j]);
}
clause.resize (i);
}
assert (old_size ==
CADICAL_assert (old_size ==
(unsigned) clause.size () + total_shrunken + total_minimized);
LOG (clause, "after shrinking first UIP clause");
LOG ("clause shrunken by %zd literals (including %u minimized)",
@ -505,3 +509,5 @@ void Internal::shrink_and_minimize_clause () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,3 +1,5 @@
#include "global.h"
#include "signal.hpp"
#include "cadical.hpp"
#include "resources.hpp"
@ -9,9 +11,13 @@
/*------------------------------------------------------------------------*/
#ifndef WIN32
extern "C" {
#include <unistd.h>
}
#endif
ABC_NAMESPACE_IMPL_START
/*------------------------------------------------------------------------*/
@ -22,7 +28,7 @@ namespace CaDiCaL {
static volatile bool caught_signal = false;
static Handler *signal_handler;
#ifndef __WIN32
#ifndef WIN32
static volatile bool caught_alarm = false;
static volatile bool alarm_set = false;
@ -42,7 +48,7 @@ void Handler::catch_alarm () { catch_signal (SIGALRM); }
SIGNALS
#undef SIGNAL
#ifndef __WIN32
#ifndef WIN32
static void (*SIGALRM_handler) (int);
@ -65,7 +71,7 @@ void Signal::reset () {
SIG##_handler = 0;
SIGNALS
#undef SIGNAL
#ifndef __WIN32
#ifndef WIN32
reset_alarm ();
#endif
caught_signal = false;
@ -77,7 +83,7 @@ const char *Signal::name (int sig) {
return #SIG;
SIGNALS
#undef SIGNAL
#ifndef __WIN32
#ifndef WIN32
if (sig == SIGALRM)
return "SIGALRM";
#endif
@ -91,7 +97,7 @@ const char *Signal::name (int sig) {
// exclusive access to. All these solutions are painful and not elegant.
static void catch_signal (int sig) {
#ifndef __WIN32
#ifndef WIN32
if (sig == SIGALRM && absolute_real_time () >= alarm_time) {
if (!caught_alarm) {
caught_alarm = true;
@ -119,12 +125,12 @@ void Signal::set (Handler *h) {
#undef SIGNAL
}
#ifndef __WIN32
#ifndef WIN32
void Signal::alarm (int seconds) {
assert (seconds >= 0);
assert (!alarm_set);
assert (alarm_time < 0);
CADICAL_assert (seconds >= 0);
CADICAL_assert (!alarm_set);
CADICAL_assert (alarm_time < 0);
SIGALRM_handler = signal (SIGALRM, catch_signal);
alarm_set = true;
alarm_time = absolute_real_time () + seconds;
@ -134,3 +140,5 @@ void Signal::alarm (int seconds) {
#endif
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Sam Buss suggested to debug the case where a solver incorrectly claims
@ -11,7 +15,7 @@ namespace CaDiCaL {
// a symbolic debugger immediately.
void External::check_solution_on_learned_clause () {
assert (solution);
CADICAL_assert (solution);
for (const auto &lit : internal->clause)
if (sol (internal->externalize (lit)) == lit)
return;
@ -24,7 +28,7 @@ void External::check_solution_on_learned_clause () {
}
void External::check_solution_on_shrunken_clause (Clause *c) {
assert (solution);
CADICAL_assert (solution);
for (const auto &lit : *c)
if (sol (internal->externalize (lit)) == lit)
return;
@ -36,15 +40,17 @@ void External::check_solution_on_shrunken_clause (Clause *c) {
}
void External::check_no_solution_after_learning_empty_clause () {
assert (solution);
CADICAL_assert (solution);
FATAL ("learned empty clause but got solution");
}
void External::check_solution_on_learned_unit_clause (int unit) {
assert (solution);
CADICAL_assert (solution);
if (sol (internal->externalize (unit)) == unit)
return;
FATAL ("learned unit %d contradicts solution", unit);
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
/*------------------------------------------------------------------------*/
namespace CaDiCaL {
@ -29,7 +33,7 @@ namespace CaDiCaL {
#define STATE(S) \
do { \
assert (is_power_of_two (S)); \
CADICAL_assert (is_power_of_two (S)); \
if (_state == S) \
break; \
_state = S; \
@ -249,7 +253,7 @@ static void log_api_call_returns (Internal *internal, const char *name,
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
#ifndef NTRACING
#ifndef CADICAL_NTRACING
/*------------------------------------------------------------------------*/
#define TRACE(...) \
@ -264,28 +268,28 @@ static void log_api_call_returns (Internal *internal, const char *name,
} while (0)
void Solver::trace_api_call (const char *s0) const {
assert (trace_api_file);
CADICAL_assert (trace_api_file);
LOG ("TRACE %s", s0);
fprintf (trace_api_file, "%s\n", s0);
fflush (trace_api_file);
}
void Solver::trace_api_call (const char *s0, int i1) const {
assert (trace_api_file);
CADICAL_assert (trace_api_file);
LOG ("TRACE %s %d", s0, i1);
fprintf (trace_api_file, "%s %d\n", s0, i1);
fflush (trace_api_file);
}
void Solver::trace_api_call (const char *s0, const char *s1) const {
assert (trace_api_file);
CADICAL_assert (trace_api_file);
LOG ("TRACE %s %s", s0, s1);
fprintf (trace_api_file, "%s %s\n", s0, s1);
fflush (trace_api_file);
}
void Solver::trace_api_call (const char *s0, const char *s1, int i2) const {
assert (trace_api_file);
CADICAL_assert (trace_api_file);
LOG ("TRACE %s %s %d", s0, s1, i2);
fprintf (trace_api_file, "%s %s %d\n", s0, s1, i2);
fflush (trace_api_file);
@ -306,7 +310,7 @@ void Solver::trace_api_call (const char *s0, const char *s1, int i2) const {
static bool tracing_api_calls_through_environment_variable_method;
/*------------------------------------------------------------------------*/
#else // NTRACING
#else // CADICAL_NTRACING
/*------------------------------------------------------------------------*/
#define TRACE(...) \
@ -321,7 +325,7 @@ static bool tracing_nb_lidrup_env_var_method = false;
Solver::Solver () {
#ifndef NTRACING
#ifndef CADICAL_NTRACING
const char *path = getenv ("CADICAL_API_TRACE");
if (!path)
path = getenv ("CADICALAPITRACE");
@ -351,7 +355,7 @@ Solver::Solver () {
external = new External (internal);
DeferDeletePtr<External> delete_external (external);
STATE (CONFIGURING);
#ifndef NTRACING
#ifndef CADICAL_NTRACING
if (tracing_api_calls_through_environment_variable_method)
message ("tracing API calls to '%s'", path);
#endif
@ -399,11 +403,11 @@ Solver::~Solver () {
delete internal;
delete external;
#ifndef NTRACING
#ifndef CADICAL_NTRACING
if (close_trace_api_file) {
close_trace_api_file = false;
assert (trace_api_file);
assert (tracing_api_calls_through_environment_variable_method);
CADICAL_assert (trace_api_file);
CADICAL_assert (tracing_api_calls_through_environment_variable_method);
fclose (trace_api_file);
tracing_api_calls_through_environment_variable_method = false;
}
@ -454,7 +458,7 @@ int Solver::reserve_difference (int number_of_vars) {
}
/*------------------------------------------------------------------------*/
#ifndef NTRACING
#ifndef CADICAL_NTRACING
void Solver::trace_api_calls (FILE *file) {
LOG_API_CALL_BEGIN ("trace_api_calls");
@ -739,7 +743,7 @@ void Solver::implied (std::vector<int> &entrailed) {
int Solver::call_external_solve_and_check_results (bool preprocess_only) {
transition_to_steady_state ();
assert (state () & READY);
CADICAL_assert (state () & READY);
STATE (SOLVING);
const int res = external->solve (preprocess_only);
if (res == 10)
@ -812,8 +816,8 @@ int Solver::val (int lit) {
external->conclude_sat ();
int res = external->ival (lit);
LOG_API_CALL_RETURNS ("val", lit, res);
assert (state () == SATISFIED);
assert (res == lit || res == -lit);
CADICAL_assert (state () == SATISFIED);
CADICAL_assert (res == lit || res == -lit);
return res;
}
@ -826,7 +830,7 @@ bool Solver::flip (int lit) {
"can only flip when no external propagator is present");
bool res = external->flip (lit);
LOG_API_CALL_RETURNS ("flip", lit, res);
assert (state () == SATISFIED);
CADICAL_assert (state () == SATISFIED);
return res;
}
@ -839,7 +843,7 @@ bool Solver::flippable (int lit) {
"can only flip when no external propagator is present");
bool res = external->flippable (lit);
LOG_API_CALL_RETURNS ("flippable", lit, res);
assert (state () == SATISFIED);
CADICAL_assert (state () == SATISFIED);
return res;
}
@ -851,7 +855,7 @@ bool Solver::failed (int lit) {
"can only get failed assumptions in unsatisfied state");
bool res = external->failed (lit);
LOG_API_CALL_RETURNS ("failed", lit, res);
assert (state () == UNSATISFIED);
CADICAL_assert (state () == UNSATISFIED);
return res;
}
@ -862,7 +866,7 @@ bool Solver::constraint_failed () {
"can only determine if constraint failed in unsatisfied state");
bool res = external->failed_constraint ();
LOG_API_CALL_RETURNS ("constraint_failed", res);
assert (state () == UNSATISFIED);
CADICAL_assert (state () == UNSATISFIED);
return res;
}
@ -1125,7 +1129,7 @@ bool Solver::trace_proof (FILE *external_file, const char *name) {
"can only start proof tracing to '%s' right after initialization",
name);
File *internal_file = File::write (internal, external_file, name);
assert (internal_file);
CADICAL_assert (internal_file);
internal->trace (internal_file);
LOG_API_CALL_RETURNS ("trace_proof", name, true);
return true;
@ -1252,7 +1256,7 @@ void Solver::conclude () {
external->conclude_sat ();
else if (state () == INCONCLUSIVE)
external->conclude_unknown ();
assert (state () == UNSATISFIED || state () == SATISFIED ||
CADICAL_assert (state () == UNSATISFIED || state () == SATISFIED ||
state () == INCONCLUSIVE);
LOG_API_CALL_END ("conclude");
}
@ -1261,7 +1265,7 @@ void Solver::conclude () {
void Solver::build (FILE *file, const char *prefix) {
assert (file == stdout || file == stderr);
CADICAL_assert (file == stdout || file == stderr);
Terminal *terminal;
@ -1278,7 +1282,7 @@ void Solver::build (FILE *file, const char *prefix) {
const char *b = date ();
const char *f = flags ();
assert (v);
CADICAL_assert (v);
fputs (prefix, file);
if (terminal)
@ -1375,7 +1379,7 @@ const char *Solver::read_dimacs (FILE *external_file, const char *name,
REQUIRE (state () == CONFIGURING,
"can only read DIMACS file right after initialization");
File *file = File::read (internal, external_file, name);
assert (file);
CADICAL_assert (file);
const char *err = read_dimacs (file, vars, strict);
delete file;
LOG_API_CALL_RETURNS ("read_dimacs", name, err);
@ -1405,7 +1409,7 @@ const char *Solver::read_dimacs (FILE *external_file, const char *name,
REQUIRE (state () == CONFIGURING,
"can only read DIMACS file right after initialization");
File *file = File::read (internal, external_file, name);
assert (file);
CADICAL_assert (file);
const char *err = read_dimacs (file, vars, strict, &incremental, &cubes);
delete file;
LOG_API_CALL_RETURNS ("read_dimacs", name, err);
@ -1532,7 +1536,7 @@ public:
ClauseCounter () : vars (0), clauses (0) {}
bool clause (const vector<int> &c) {
for (const auto &lit : c) {
assert (lit != INT_MIN);
CADICAL_assert (lit != INT_MIN);
int idx = abs (lit);
if (idx > vars)
vars = idx;
@ -1561,7 +1565,7 @@ public:
const char *Solver::write_dimacs (const char *path, int min_max_var) {
LOG_API_CALL_BEGIN ("write_dimacs", path, min_max_var);
REQUIRE_VALID_STATE ();
#ifndef QUIET
#ifndef CADICAL_QUIET
const double start = internal->time ();
#endif
internal->restore_clauses ();
@ -1588,7 +1592,7 @@ const char *Solver::write_dimacs (const char *path, int min_max_var) {
} else
res = internal->error_message.init (
"failed to open DIMACS file '%s' for writing", path);
#ifndef QUIET
#ifndef CADICAL_QUIET
if (!res) {
const double end = internal->time ();
MSG ("wrote %" PRId64 " clauses in %.2f seconds %s time",
@ -1633,7 +1637,7 @@ const char *Solver::write_extension (const char *path) {
LOG_API_CALL_BEGIN ("write_extension", path);
REQUIRE_VALID_STATE ();
const char *res = 0;
#ifndef QUIET
#ifndef CADICAL_QUIET
const double start = internal->time ();
#endif
File *file = File::write (internal, path);
@ -1646,7 +1650,7 @@ const char *Solver::write_extension (const char *path) {
} else
res = internal->error_message.init (
"failed to open extension file '%s' for writing", path);
#ifndef QUIET
#ifndef CADICAL_QUIET
if (!res) {
const double end = internal->time ();
MSG ("wrote %" PRId64 " witnesses in %.2f seconds %s time",
@ -1700,7 +1704,7 @@ void Solver::copy (Solver &other) const {
void Solver::section (const char *title) {
if (state () == DELETING)
return;
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) title;
#endif
REQUIRE_INITIALIZED ();
@ -1710,7 +1714,7 @@ void Solver::section (const char *title) {
void Solver::message (const char *fmt, ...) {
if (state () == DELETING)
return;
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) fmt;
#else
REQUIRE_INITIALIZED ();
@ -1725,7 +1729,7 @@ void Solver::message () {
if (state () == DELETING)
return;
REQUIRE_INITIALIZED ();
#ifndef QUIET
#ifndef CADICAL_QUIET
internal->message ();
#endif
}
@ -1734,7 +1738,7 @@ void Solver::verbose (int level, const char *fmt, ...) {
if (state () == DELETING)
return;
REQUIRE_VALID_OR_SOLVING_STATE ();
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) level;
(void) fmt;
#else
@ -1756,3 +1760,5 @@ void Solver::error (const char *fmt, ...) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,11 +1,15 @@
#include "global.h"
#ifdef PROFILE_MODE
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
bool Internal::propagate_stable () {
assert (stable);
CADICAL_assert (stable);
START (propstable);
bool res = propagate ();
STOP (propstable);
@ -13,19 +17,23 @@ bool Internal::propagate_stable () {
}
void Internal::analyze_stable () {
assert (stable);
CADICAL_assert (stable);
START (analyzestable);
analyze ();
STOP (analyzestable);
}
int Internal::decide_stable () {
assert (stable);
CADICAL_assert (stable);
return decide ();
}
}; // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
#else
ABC_NAMESPACE_IMPL_START
int stable_if_not_profile_mode_dummy;
ABC_NAMESPACE_IMPL_END
#endif

View File

@ -1,7 +1,11 @@
// vim: set tw=300: set VIM text width to 300 characters for this file.
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -28,7 +32,7 @@ Stats::Stats () {
void Stats::print (Internal *internal) {
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) internal;
#else
@ -684,7 +688,7 @@ void Stats::print (Internal *internal) {
if (all || stats.walk.count) {
PRT ("walked: %15" PRId64 " %10.2f interval",
stats.walk.count, relative (stats.conflicts, stats.walk.count));
#ifndef QUIET
#ifndef CADICAL_QUIET
if (internal->profiles.walk.value > 0)
PRT (" flips: %15" PRId64 " %10.2f M per second",
stats.walk.flips,
@ -746,11 +750,11 @@ void Stats::print (Internal *internal) {
tout.magenta_code (), internal->opts.realtime ? "real" : "process",
tout.normal_code ());
#endif // ifndef QUIET
#endif // ifndef CADICAL_QUIET
}
void Internal::print_resource_usage () {
#ifndef QUIET
#ifndef CADICAL_QUIET
SECTION ("resources");
uint64_t m = maximum_resident_set_size ();
MSG ("total process time since initialization: %12.2f seconds",
@ -818,3 +822,5 @@ void LratChecker::print_stats () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -72,16 +76,16 @@ namespace CaDiCaL {
// removed is returned.
inline int Internal::subsume_check (Clause *subsuming, Clause *subsumed) {
#ifdef NDEBUG
#ifdef CADICAL_NDEBUG
(void) subsumed;
#endif
// Only use 'subsumed' for these following assertion checks. Otherwise we
// Only use 'subsumed' for these following CADICAL_assertion checks. Otherwise we
// only require that 'subsumed' has all its literals marked.
//
assert (!subsumed->garbage);
assert (!subsuming->garbage);
assert (subsuming != subsumed);
assert (subsuming->size <= subsumed->size);
CADICAL_assert (!subsumed->garbage);
CADICAL_assert (!subsuming->garbage);
CADICAL_assert (subsuming != subsumed);
CADICAL_assert (subsuming->size <= subsumed->size);
stats.subchecks++;
if (subsuming->size == 2)
@ -104,8 +108,8 @@ inline int Internal::subsume_check (Clause *subsuming, Clause *subsumed) {
else
flipped = lit;
}
assert (prev);
assert (!subsuming->literals[0]);
CADICAL_assert (prev);
CADICAL_assert (!subsuming->literals[0]);
subsuming->literals[0] = prev;
if (failed)
return 0;
@ -124,7 +128,7 @@ inline int Internal::subsume_check (Clause *subsuming, Clause *subsumed) {
inline void Internal::subsume_clause (Clause *subsuming, Clause *subsumed) {
stats.subsumed++;
assert (subsuming->size <= subsumed->size);
CADICAL_assert (subsuming->size <= subsumed->size);
LOG (subsumed, "subsumed");
if (subsumed->redundant)
stats.subred++;
@ -142,9 +146,9 @@ inline void Internal::subsume_clause (Clause *subsuming, Clause *subsumed) {
stats.current.irredundant++;
stats.added.irredundant++;
stats.irrlits += subsuming->size;
assert (stats.current.redundant > 0);
CADICAL_assert (stats.current.redundant > 0);
stats.current.redundant--;
assert (stats.added.redundant > 0);
CADICAL_assert (stats.added.redundant > 0);
stats.added.redundant--;
// ... and keep 'stats.added.total'.
}
@ -157,7 +161,7 @@ void Internal::strengthen_clause (Clause *c, int lit) {
if (opts.check && is_external_forgettable (c->id))
mark_garbage_external_forgettable (c->id);
stats.strengthened++;
assert (c->size > 2);
CADICAL_assert (c->size > 2);
LOG (c, "removing %d in", lit);
if (proof) {
LOG (lrat_chain, "strengthening clause with chain");
@ -166,7 +170,7 @@ void Internal::strengthen_clause (Clause *c, int lit) {
if (!c->redundant)
mark_removed (lit);
auto new_end = remove (c->begin (), c->end (), lit);
assert (new_end + 1 == c->end ()), (void) new_end;
CADICAL_assert (new_end + 1 == c->end ()), (void) new_end;
(void) shrink_clause (c, c->size - 1);
// bump_clause2 (c);
LOG (c, "strengthened");
@ -185,7 +189,7 @@ inline int Internal::try_to_subsume_clause (Clause *c,
vector<Clause *> &shrunken) {
stats.subtried++;
assert (!level);
CADICAL_assert (!level);
LOG (c, "trying to subsume");
mark (c); // signed!
@ -262,7 +266,7 @@ inline int Internal::try_to_subsume_clause (Clause *c,
//
const Occs &os = occs (sign * lit);
for (const auto &e : os) {
assert (!e->garbage); // sanity check
CADICAL_assert (!e->garbage); // sanity check
if (e->garbage)
continue; // defensive: not needed
flipped = subsume_check (e, c);
@ -288,7 +292,7 @@ inline int Internal::try_to_subsume_clause (Clause *c,
if (flipped) {
LOG (d, "strengthening");
if (lrat) {
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
lrat_chain.push_back (c->id);
lrat_chain.push_back (d->id);
}
@ -296,7 +300,7 @@ inline int Internal::try_to_subsume_clause (Clause *c,
c->used = d->used;
strengthen_clause (c, -flipped);
lrat_chain.clear ();
assert (likely_to_be_kept_clause (c));
CADICAL_assert (likely_to_be_kept_clause (c));
shrunken.push_back (c);
return -1;
}
@ -369,7 +373,7 @@ bool Internal::subsume_round () {
int old_marked_candidate_variables_for_elimination = stats.mark.elim;
assert (!level);
CADICAL_assert (!level);
// Allocate schedule and occurrence lists.
//
@ -432,7 +436,7 @@ bool Internal::subsume_round () {
if (cs.clause->size > 2)
cs.clause->subsume = true;
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t scheduled = schedule.size ();
int64_t total = stats.current.irredundant + stats.current.redundant;
PHASE ("subsume-round", stats.subsumerounds,
@ -461,7 +465,7 @@ bool Internal::subsume_round () {
break;
Clause *c = s.clause;
assert (!c->garbage);
CADICAL_assert (!c->garbage);
checked++;
@ -621,7 +625,7 @@ void Internal::subsume () {
stats.subsumephases++;
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = true;
}
@ -638,9 +642,11 @@ void Internal::subsume () {
transred ();
if (external_prop) {
assert (!level);
CADICAL_assert (!level);
private_steps = false;
}
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
Sweeper::Sweeper (Internal *i)
@ -19,9 +23,9 @@ Sweeper::~Sweeper () {
int Internal::sweep_solve () {
START (sweepsolve);
kitten_randomize_phases (citten);
cadical_kitten_randomize_phases (citten);
stats.sweep_solved++;
int res = kitten_solve (citten);
int res = cadical_kitten_solve (citten);
if (res == 10)
stats.sweep_sat++;
if (res == 20)
@ -32,25 +36,25 @@ int Internal::sweep_solve () {
bool Internal::sweep_flip (int lit) {
START (sweepflip);
bool res = kitten_flip_signed_literal (citten, lit);
bool res = cadical_kitten_flip_signed_literal (citten, lit);
STOP (sweepflip);
return res;
}
int Internal::sweep_flip_and_implicant (int lit) {
START (sweepimplicant);
int res = kitten_flip_and_implicant_for_signed_literal (citten, lit);
int res = cadical_kitten_flip_and_implicant_for_signed_literal (citten, lit);
STOP (sweepimplicant);
return res;
}
void Internal::sweep_set_kitten_ticks_limit (Sweeper &sweeper) {
void Internal::sweep_set_cadical_kitten_ticks_limit (Sweeper &sweeper) {
uint64_t remaining = 0;
const uint64_t current = sweeper.current_ticks;
if (current < sweeper.limit.ticks)
remaining = sweeper.limit.ticks - current;
LOG ("'kitten_ticks' remaining %" PRIu64, remaining);
kitten_set_ticks_limit (citten, remaining);
LOG ("'cadical_kitten_ticks' remaining %" PRIu64, remaining);
cadical_kitten_set_ticks_limit (citten, remaining);
}
void Internal::sweep_update_noccs (Clause *c) {
@ -133,7 +137,7 @@ void Internal::sweep_dense_propagate (Sweeper &sweeper) {
while (i < work.size ()) {
int lit = work[i++];
LOG ("sweeping propagation of %d", lit);
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
ticks += 1 + cache_lines (occs (-lit).size (), sizeof (Clause *));
const Occs &ns = occs (-lit);
for (const auto &c : ns) {
@ -194,11 +198,11 @@ void Internal::sweep_dense_propagate (Sweeper &sweeper) {
work.clear ();
}
bool Internal::kitten_ticks_limit_hit (Sweeper &sweeper, const char *when) {
bool Internal::cadical_kitten_ticks_limit_hit (Sweeper &sweeper, const char *when) {
const uint64_t current =
kitten_current_ticks (citten) + sweeper.current_ticks;
cadical_kitten_current_ticks (citten) + sweeper.current_ticks;
if (current >= sweeper.limit.ticks) {
LOG ("'kitten_ticks' limit of %" PRIu64 " ticks hit after %" PRIu64
LOG ("'cadical_kitten_ticks' limit of %" PRIu64 " ticks hit after %" PRIu64
" ticks during %s",
sweeper.limit.ticks, current, when);
return true;
@ -225,8 +229,8 @@ void Internal::init_sweeper (Sweeper &sweeper) {
.size (); // initialize with the cost of building full occ list.
sweeper.current_ticks +=
2 + 2 * cache_lines (clauses.size (), sizeof (Clause *));
assert (!citten);
citten = kitten_init ();
CADICAL_assert (!citten);
citten = cadical_kitten_init ();
citten_clear_track_log_terminate ();
sweep_dense_mode_and_watch_irredundant (); // full occurence list
@ -284,7 +288,7 @@ void Internal::release_sweeper (Sweeper &sweeper) {
for (unsigned i = 0; i < 2; i++)
erase_vector (sweeper.core[i]);
kitten_release (citten);
cadical_kitten_release (citten);
citten = 0;
stats.ticks.sweep += sweeper.current_ticks;
sweep_sparse_mode ();
@ -293,23 +297,23 @@ void Internal::release_sweeper (Sweeper &sweeper) {
void Internal::clear_sweeper (Sweeper &sweeper) {
LOG ("clearing sweeping environment");
sweeper.current_ticks += kitten_current_ticks (citten);
sweeper.current_ticks += cadical_kitten_current_ticks (citten);
citten_clear_track_log_terminate ();
for (auto &idx : sweeper.vars) {
assert (sweeper.depths[idx]);
CADICAL_assert (sweeper.depths[idx]);
sweeper.depths[idx] = 0;
}
sweeper.vars.clear ();
for (auto c : sweeper.clauses) {
assert (c->swept);
CADICAL_assert (c->swept);
c->swept = false;
}
sweeper.clauses.clear ();
sweeper.backbone.clear ();
sweeper.partition.clear ();
sweeper.encoded = 0;
sweep_set_kitten_ticks_limit (sweeper);
sweep_set_cadical_kitten_ticks_limit (sweeper);
}
int Internal::sweep_repr (Sweeper &sweeper, int lit) {
@ -331,7 +335,7 @@ int Internal::sweep_repr (Sweeper &sweeper, int lit) {
sweeper.reprs[prev] = res;
prev = next;
}
assert (sweeper.reprs[-prev] == not_res);
CADICAL_assert (sweeper.reprs[-prev] == not_res);
}
return res;
}
@ -344,16 +348,16 @@ void Internal::add_literal_to_environment (Sweeper &sweeper, unsigned depth,
const int idx = abs (lit);
if (sweeper.depths[idx])
return;
assert (depth < UINT_MAX);
CADICAL_assert (depth < UINT_MAX);
sweeper.depths[idx] = depth + 1;
assert (idx);
CADICAL_assert (idx);
sweeper.vars.push_back (idx);
LOG ("sweeping[%u] adding literal %d", depth, lit);
}
void Internal::sweep_add_clause (Sweeper &sweeper, unsigned depth) {
// TODO: assertion fails, check if this an issue or can be avoided
// assert (sweeper.clause.size () > 1);
// TODO: CADICAL_assertion fails, check if this an issue or can be avoided
// CADICAL_assert (sweeper.clause.size () > 1);
for (const auto &lit : sweeper.clause)
add_literal_to_environment (sweeper, depth, lit);
citten_clause_with_id (citten, sweeper.clauses.size (),
@ -366,9 +370,9 @@ void Internal::sweep_add_clause (Sweeper &sweeper, unsigned depth) {
void Internal::sweep_clause (Sweeper &sweeper, unsigned depth, Clause *c) {
if (c->swept)
return;
assert (can_sweep_clause (c));
CADICAL_assert (can_sweep_clause (c));
LOG (c, "sweeping[%u]", depth);
assert (sweeper.clause.empty ());
CADICAL_assert (sweeper.clause.empty ());
for (const auto &lit : *c) {
const signed char tmp = val (lit);
if (tmp > 0) {
@ -403,7 +407,7 @@ static void save_core_clause (void *state, unsigned id, bool learned,
pc.cad_id = INVALID64; // delay giving ids
} else {
pc.sweep_id = id; // necessary
assert (id < sweeper->clauses.size ());
CADICAL_assert (id < sweeper->clauses.size ());
pc.cad_id = sweeper->clauses[id]->id;
}
pc.kit_id = 0;
@ -436,17 +440,17 @@ static void save_core_clause_with_lrat (void *state, unsigned cid,
pc.sweep_id = INVALID;
pc.cad_id = INVALID64;
if (!learned) {
assert (size);
assert (!chain_size);
assert (id < clauses.size ());
CADICAL_assert (size);
CADICAL_assert (!chain_size);
CADICAL_assert (id < clauses.size ());
pc.sweep_id = id;
assert (id < clauses.size ());
CADICAL_assert (id < clauses.size ());
pc.cad_id = clauses[id]->id;
for (const auto &lit : *clauses[id]) {
pc.literals.push_back (lit);
}
} else {
assert (chain_size);
CADICAL_assert (chain_size);
pc.sweep_id = INVALID;
pc.cad_id = INVALID64; // delay giving ids
const unsigned *end = lits + size;
@ -462,7 +466,7 @@ static void save_core_clause_with_lrat (void *state, unsigned cid,
LOG (pc.literals, "traced %s",
pc.learned == true ? "learned" : "original");
else {
assert (id < clauses.size ());
CADICAL_assert (id < clauses.size ());
LOG (clauses[id], "traced");
}
#endif
@ -476,14 +480,14 @@ static int citten_terminate (void *data) {
} // end extern C
void Internal::citten_clear_track_log_terminate () {
assert (citten);
kitten_clear (citten);
kitten_track_antecedents (citten);
CADICAL_assert (citten);
cadical_kitten_clear (citten);
cadical_kitten_track_antecedents (citten);
if (external->terminator)
kitten_set_terminator (citten, internal, citten_terminate);
cadical_kitten_set_terminator (citten, internal, citten_terminate);
#ifdef LOGGING
if (opts.log)
kitten_set_logging (citten);
cadical_kitten_set_logging (citten);
#endif
}
@ -491,10 +495,10 @@ void Internal::add_core (Sweeper &sweeper, unsigned core_idx) {
if (unsat)
return;
LOG ("check and add extracted core[%u] lemmas to proof", core_idx);
assert (core_idx == 0 || core_idx == 1);
CADICAL_assert (core_idx == 0 || core_idx == 1);
vector<sweep_proof_clause> &core = sweeper.core[core_idx];
assert (!lrat || proof);
CADICAL_assert (!lrat || proof);
unsigned unsat_size = 0;
for (auto &pc : core) {
@ -502,18 +506,18 @@ void Internal::add_core (Sweeper &sweeper, unsigned core_idx) {
if (!pc.learned) {
LOG (pc.literals,
"not adding already present core[%u] kitten[%u] clause",
"not adding already present core[%u] cadical_kitten[%u] clause",
core_idx, pc.kit_id);
continue;
}
LOG (pc.literals, "adding extracted core[%u] kitten[%u] lemma",
LOG (pc.literals, "adding extracted core[%u] cadical_kitten[%u] lemma",
core_idx, pc.kit_id);
const unsigned new_size = pc.literals.size ();
if (lrat) {
assert (pc.cad_id == INVALID64);
CADICAL_assert (pc.cad_id == INVALID64);
for (auto &cid : pc.chain) {
int64_t id = 0;
for (const auto &cpc : core) {
@ -522,8 +526,8 @@ void Internal::add_core (Sweeper &sweeper, unsigned core_idx) {
id = cpc.cad_id;
else {
id = cpc.cad_id;
assert (cpc.cad_id == sweeper.clauses[cpc.sweep_id]->id);
assert (!sweeper.clauses[cpc.sweep_id]->garbage);
CADICAL_assert (cpc.cad_id == sweeper.clauses[cpc.sweep_id]->id);
CADICAL_assert (!sweeper.clauses[cpc.sweep_id]->garbage);
// avoid duplicate ids of units with seen flags
for (const auto &lit : cpc.literals) {
if (val (lit) >= 0)
@ -542,7 +546,7 @@ void Internal::add_core (Sweeper &sweeper, unsigned core_idx) {
break;
}
}
assert (id);
CADICAL_assert (id);
if (id != INVALID64)
lrat_chain.push_back (id);
}
@ -581,8 +585,8 @@ void Internal::add_core (Sweeper &sweeper, unsigned core_idx) {
continue;
}
assert (new_size > 1);
assert (pc.learned);
CADICAL_assert (new_size > 1);
CADICAL_assert (pc.learned);
if (proof) {
pc.cad_id = ++clause_id;
@ -594,19 +598,19 @@ void Internal::add_core (Sweeper &sweeper, unsigned core_idx) {
void Internal::save_core (Sweeper &sweeper, unsigned core) {
LOG ("saving extracted core[%u] lemmas", core);
assert (core == 0 || core == 1);
assert (sweeper.core[core].empty ());
CADICAL_assert (core == 0 || core == 1);
CADICAL_assert (sweeper.core[core].empty ());
sweeper.save = core;
kitten_compute_clausal_core (citten, 0);
cadical_kitten_compute_clausal_core (citten, 0);
if (lrat)
kitten_trace_core (citten, &sweeper, save_core_clause_with_lrat);
cadical_kitten_trace_core (citten, &sweeper, save_core_clause_with_lrat);
else
kitten_traverse_core_clauses_with_id (citten, &sweeper,
cadical_kitten_traverse_core_clauses_with_id (citten, &sweeper,
save_core_clause);
}
void Internal::clear_core (Sweeper &sweeper, unsigned core_idx) {
assert (core_idx == 0 || core_idx == 1);
CADICAL_assert (core_idx == 0 || core_idx == 1);
LOG ("clearing core[%u] lemmas", core_idx);
vector<sweep_proof_clause> &core = sweeper.core[core_idx];
if (proof) {
@ -632,10 +636,10 @@ void Internal::init_backbone_and_partition (Sweeper &sweeper) {
for (const auto &idx : sweeper.vars) {
if (!active (idx))
continue;
assert (idx > 0);
CADICAL_assert (idx > 0);
const int lit = idx;
const int not_lit = -lit;
const signed char tmp = kitten_signed_value (citten, lit);
const signed char tmp = cadical_kitten_signed_value (citten, lit);
const int candidate = (tmp < 0) ? not_lit : lit;
LOG ("sweeping candidate %d", candidate);
sweeper.backbone.push_back (candidate);
@ -648,9 +652,9 @@ void Internal::init_backbone_and_partition (Sweeper &sweeper) {
}
void Internal::sweep_empty_clause (Sweeper &sweeper) {
assert (!unsat);
CADICAL_assert (!unsat);
save_add_clear_core (sweeper);
assert (unsat);
CADICAL_assert (unsat);
}
void Internal::sweep_refine_partition (Sweeper &sweeper) {
@ -671,7 +675,7 @@ void Internal::sweep_refine_partition (Sweeper &sweeper) {
continue;
if (val (other))
continue;
signed char value = kitten_signed_value (citten, other);
signed char value = cadical_kitten_signed_value (citten, other);
if (!value)
LOG ("dropping sub-solver unassigned %d", other);
else if (value > 0) {
@ -708,7 +712,7 @@ void Internal::sweep_refine_partition (Sweeper &sweeper) {
continue;
if (val (other))
continue;
signed char value = kitten_signed_value (citten, other);
signed char value = cadical_kitten_signed_value (citten, other);
if (value < 0) {
new_partition.push_back (other);
assigned_false++;
@ -746,7 +750,7 @@ void Internal::sweep_refine_backbone (Sweeper &sweeper) {
const int lit = *p;
if (val (lit))
continue;
signed char value = kitten_signed_value (citten, lit);
signed char value = cadical_kitten_signed_value (citten, lit);
if (!value)
LOG ("dropping sub-solver unassigned %d", lit);
else if (value > 0)
@ -756,7 +760,7 @@ void Internal::sweep_refine_backbone (Sweeper &sweeper) {
}
void Internal::sweep_refine (Sweeper &sweeper) {
assert (kitten_status (citten) == 10);
CADICAL_assert (cadical_kitten_status (citten) == 10);
if (sweeper.backbone.empty ())
LOG ("no need to refine empty backbone candidates");
else
@ -771,8 +775,8 @@ void Internal::flip_backbone_literals (Sweeper &sweeper) {
const unsigned max_rounds = opts.sweepfliprounds;
if (!max_rounds)
return;
assert (sweeper.backbone.size ());
if (kitten_status (citten) != 10)
CADICAL_assert (sweeper.backbone.size ());
if (cadical_kitten_status (citten) != 10)
return;
#ifdef LOGGING
unsigned total_flipped = 0;
@ -811,7 +815,7 @@ void Internal::flip_backbone_literals (Sweeper &sweeper) {
break;
if (terminated_asynchronously ())
break;
if (kitten_ticks_limit_hit (sweeper, "backbone flipping"))
if (cadical_kitten_ticks_limit_hit (sweeper, "backbone flipping"))
break;
if (refine)
sweep_refine (sweeper);
@ -823,13 +827,13 @@ void Internal::flip_backbone_literals (Sweeper &sweeper) {
bool Internal::sweep_extract_fixed (Sweeper &sweeper, int lit) {
const int not_lit = -lit;
stats.sweep_solved_backbone++;
kitten_assume_signed (citten, not_lit);
cadical_kitten_assume_signed (citten, not_lit);
int res = sweep_solve ();
if (!res) {
stats.sweep_unknown_backbone++;
return false;
}
assert (res == 20);
CADICAL_assert (res == 20);
LOG ("sweep unit %d", lit);
save_add_clear_core (sweeper);
stats.sweep_unsat_backbone++;
@ -838,10 +842,10 @@ bool Internal::sweep_extract_fixed (Sweeper &sweeper, int lit) {
bool Internal::sweep_backbone_candidate (Sweeper &sweeper, int lit) {
LOG ("trying backbone candidate %d", lit);
signed char value = kitten_fixed_signed (citten, lit);
signed char value = cadical_kitten_fixed_signed (citten, lit);
if (value) {
stats.sweep_fixed_backbone++;
assert (value > 0);
CADICAL_assert (value > 0);
if (val (lit) <= 0) {
return sweep_extract_fixed (sweeper, lit);
} else
@ -849,7 +853,7 @@ bool Internal::sweep_backbone_candidate (Sweeper &sweeper, int lit) {
return false;
}
int res = kitten_status (citten);
int res = cadical_kitten_status (citten);
if (res != 10) {
LOG ("not flipping due to status %d != 10", res);
}
@ -864,7 +868,7 @@ bool Internal::sweep_backbone_candidate (Sweeper &sweeper, int lit) {
LOG ("flipping %d failed", lit);
const int not_lit = -lit;
stats.sweep_solved_backbone++;
kitten_assume_signed (citten, not_lit);
cadical_kitten_assume_signed (citten, not_lit);
res = sweep_solve ();
if (res == 10) {
LOG ("sweeping backbone candidate %d failed", lit);
@ -876,7 +880,7 @@ bool Internal::sweep_backbone_candidate (Sweeper &sweeper, int lit) {
if (res == 20) {
LOG ("sweep unit %d", lit);
save_add_clear_core (sweeper);
assert (val (lit));
CADICAL_assert (val (lit));
stats.sweep_unsat_backbone++;
return true;
}
@ -894,11 +898,11 @@ bool Internal::sweep_backbone_candidate (Sweeper &sweeper, int lit) {
//
int64_t Internal::add_sweep_binary (sweep_proof_clause pc, int lit,
int other) {
assert (!unsat);
CADICAL_assert (!unsat);
if (unsat)
return 0; // sanity check, should be fuzzed
assert (!val (lit) && !val (other));
CADICAL_assert (!val (lit) && !val (other));
if (val (lit) || val (other))
return 0;
@ -940,28 +944,28 @@ bool Internal::scheduled_variable (Sweeper &sweeper, int idx) {
}
void Internal::schedule_inner (Sweeper &sweeper, int idx) {
assert (idx);
CADICAL_assert (idx);
if (!active (idx))
return;
const int next = sweeper.next[idx];
if (next != 0) {
LOG ("rescheduling inner %d as last", idx);
const unsigned prev = sweeper.prev[idx];
assert (sweeper.prev[next] == idx);
CADICAL_assert (sweeper.prev[next] == idx);
sweeper.prev[next] = prev;
if (prev == 0) {
assert (sweeper.first == idx);
CADICAL_assert (sweeper.first == idx);
sweeper.first = next;
} else {
assert (sweeper.next[prev] == idx);
CADICAL_assert (sweeper.next[prev] == idx);
sweeper.next[prev] = next;
}
const unsigned last = sweeper.last;
if (last == 0) {
assert (sweeper.first == 0);
CADICAL_assert (sweeper.first == 0);
sweeper.first = idx;
} else {
assert (sweeper.next[last] == 0);
CADICAL_assert (sweeper.next[last] == 0);
sweeper.next[last] = idx;
}
sweeper.prev[idx] = last;
@ -971,13 +975,13 @@ void Internal::schedule_inner (Sweeper &sweeper, int idx) {
LOG ("scheduling inner %d as last", idx);
const unsigned last = sweeper.last;
if (last == 0) {
assert (sweeper.first == 0);
CADICAL_assert (sweeper.first == 0);
sweeper.first = idx;
} else {
assert (sweeper.next[last] == 0);
CADICAL_assert (sweeper.next[last] == 0);
sweeper.next[last] = idx;
}
assert (sweeper.next[idx] == 0);
CADICAL_assert (sweeper.next[idx] == 0);
sweeper.prev[idx] = last;
sweeper.last = idx;
} else
@ -985,17 +989,17 @@ void Internal::schedule_inner (Sweeper &sweeper, int idx) {
}
void Internal::schedule_outer (Sweeper &sweeper, int idx) {
assert (!scheduled_variable (sweeper, idx));
assert (active (idx));
CADICAL_assert (!scheduled_variable (sweeper, idx));
CADICAL_assert (active (idx));
const int first = sweeper.first;
if (first == 0) {
assert (sweeper.last == 0);
CADICAL_assert (sweeper.last == 0);
sweeper.last = idx;
} else {
assert (sweeper.prev[first] == 0);
CADICAL_assert (sweeper.prev[first] == 0);
sweeper.prev[first] = idx;
}
assert (sweeper.prev[idx] == 0);
CADICAL_assert (sweeper.prev[idx] == 0);
sweeper.next[idx] = first;
sweeper.first = idx;
LOG ("scheduling outer %d as first", idx);
@ -1007,16 +1011,16 @@ int Internal::next_scheduled (Sweeper &sweeper) {
LOG ("no more scheduled variables left");
return 0;
}
assert (res > 0);
CADICAL_assert (res > 0);
LOG ("dequeuing next scheduled %d", res);
const unsigned prev = sweeper.prev[res];
assert (sweeper.next[res] == 0);
CADICAL_assert (sweeper.next[res] == 0);
sweeper.prev[res] = 0;
if (prev == 0) {
assert (sweeper.first == res);
CADICAL_assert (sweeper.first == res);
sweeper.first = 0;
} else {
assert (sweeper.next[prev] == res);
CADICAL_assert (sweeper.next[prev] == res);
sweeper.next[prev] = 0;
}
sweeper.last = prev;
@ -1027,7 +1031,7 @@ void Internal::sweep_substitute_lrat (Clause *c, int64_t id) {
if (!lrat)
return;
for (const auto &lit : *c) {
assert (val (lit) <= 0);
CADICAL_assert (val (lit) <= 0);
if (val (lit) < 0) {
int64_t id = unit_id (-lit);
lrat_chain.push_back (id);
@ -1054,11 +1058,11 @@ void Internal::substitute_connected_clauses (Sweeper &sweeper, int lit,
return;
LOG ("substituting %d with %d in all irredundant clauses", lit, repr);
assert (lit != repr);
assert (lit != -repr);
CADICAL_assert (lit != repr);
CADICAL_assert (lit != -repr);
assert (active (lit));
assert (active (repr));
CADICAL_assert (active (lit));
CADICAL_assert (active (repr));
uint64_t &ticks = sweeper.current_ticks;
@ -1074,25 +1078,25 @@ void Internal::substitute_connected_clauses (Sweeper &sweeper, int lit,
ticks++;
if (c->garbage)
continue;
assert (clause.empty ());
CADICAL_assert (clause.empty ());
bool satisfied = false;
bool repr_already_watched = false;
const int not_repr = -repr;
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
bool found = false;
#endif
for (const auto &other : *c) {
if (other == lit) {
#ifndef NDEBUG
assert (!found);
#ifndef CADICAL_NDEBUG
CADICAL_assert (!found);
found = true;
#endif
clause.push_back (repr);
continue;
}
assert (other != -lit);
CADICAL_assert (other != -lit);
if (other == repr) {
assert (!repr_already_watched);
CADICAL_assert (!repr_already_watched);
repr_already_watched = true;
continue;
}
@ -1115,12 +1119,12 @@ void Internal::substitute_connected_clauses (Sweeper &sweeper, int lit,
sweep_update_noccs (c);
continue;
}
assert (found);
CADICAL_assert (found);
const unsigned new_size = clause.size ();
sweep_substitute_lrat (c, id);
if (new_size == 0) {
LOG (c, "substituted empty clause");
assert (!unsat);
CADICAL_assert (!unsat);
learn_empty_clause ();
break;
}
@ -1136,7 +1140,7 @@ void Internal::substitute_connected_clauses (Sweeper &sweeper, int lit,
stats.sweep_units++;
break;
}
assert (c->size >= 2);
CADICAL_assert (c->size >= 2);
if (!c->redundant)
mark_removed (c);
uint64_t new_id = ++clause_id;
@ -1179,7 +1183,7 @@ void Internal::sweep_substitute_new_equivalences (Sweeper &sweeper) {
return;
unsigned count = 0;
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
for (const auto &sb : sweeper.binaries) {
count++;
@ -1190,7 +1194,7 @@ void Internal::sweep_substitute_new_equivalences (Sweeper &sweeper) {
} else {
substitute_connected_clauses (sweeper, -lit, other, sb.id);
}
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
if (val (lit) < 0) {
if (lrat) {
const int64_t lid = unit_id (-lit);
@ -1218,7 +1222,7 @@ void Internal::sweep_substitute_new_equivalences (Sweeper &sweeper) {
}
assign_unit (lit);
} else
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
}
lrat_chain.clear ();
delete_sweep_binary (sb);
@ -1230,19 +1234,19 @@ void Internal::sweep_substitute_new_equivalences (Sweeper &sweeper) {
}
count = 0;
}
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
}
sweeper.binaries.clear ();
}
void Internal::sweep_remove (Sweeper &sweeper, int lit) {
assert (sweeper.reprs[lit] != lit);
CADICAL_assert (sweeper.reprs[lit] != lit);
vector<int> &partition = sweeper.partition;
const auto begin_partition = partition.begin ();
auto p = begin_partition;
const auto end_partition = partition.end ();
for (; *p != lit; p++)
assert (p + 1 != end_partition);
CADICAL_assert (p + 1 != end_partition);
auto begin_class = p;
while (begin_class != begin_partition && begin_class[-1] != 0)
begin_class--;
@ -1252,7 +1256,7 @@ void Internal::sweep_remove (Sweeper &sweeper, int lit) {
const unsigned size = end_class - begin_class;
LOG ("removing non-representative %d from equivalence class of size %u",
lit, size);
assert (size > 1);
CADICAL_assert (size > 1);
auto q = begin_class;
if (size == 2) {
LOG ("completely squashing equivalence class of %d", lit);
@ -1270,8 +1274,8 @@ void Internal::flip_partition_literals (Sweeper &sweeper) {
const unsigned max_rounds = opts.sweepfliprounds;
if (!max_rounds)
return;
assert (sweeper.partition.size ());
if (kitten_status (citten) != 10)
CADICAL_assert (sweeper.partition.size ());
if (cadical_kitten_status (citten) != 10)
return;
#ifdef LOGGING
unsigned total_flipped = 0;
@ -1286,17 +1290,17 @@ void Internal::flip_partition_literals (Sweeper &sweeper) {
const auto end = sweeper.partition.end ();
while (src != end) {
auto end_src = src;
while (assert (end_src != end), *end_src != 0)
while (CADICAL_assert (end_src != end), *end_src != 0)
end_src++;
unsigned size = end_src - src;
assert (size > 1);
CADICAL_assert (size > 1);
auto q = dst;
for (auto p = src; p != end_src; p++) {
const int lit = *p;
if (limit_hit) {
*q++ = lit;
continue;
} else if (kitten_ticks_limit_hit (sweeper, "partition flipping")) {
} else if (cadical_kitten_ticks_limit_hit (sweeper, "partition flipping")) {
*q++ = lit;
limit_hit = true;
continue;
@ -1325,7 +1329,7 @@ void Internal::flip_partition_literals (Sweeper &sweeper) {
LOG ("flipped %u equivalence candidates in round %u", flipped, round);
if (terminated_asynchronously ())
break;
if (kitten_ticks_limit_hit (sweeper, "partition flipping"))
if (cadical_kitten_ticks_limit_hit (sweeper, "partition flipping"))
break;
if (refine)
sweep_refine (sweeper);
@ -1339,11 +1343,11 @@ bool Internal::sweep_equivalence_candidates (Sweeper &sweeper, int lit,
LOG ("trying equivalence candidates %d = %d", lit, other);
const auto begin = sweeper.partition.begin ();
auto const end = sweeper.partition.end ();
assert (begin + 3 <= end);
assert (end[-3] == lit);
assert (end[-2] == other);
CADICAL_assert (begin + 3 <= end);
CADICAL_assert (end[-3] == lit);
CADICAL_assert (end[-2] == other);
const int third = (end - begin == 3) ? 0 : end[-4];
int res = kitten_status (citten);
int res = cadical_kitten_status (citten);
if (res == 10) {
stats.sweep_flip_equivalences++;
if (sweep_flip (lit)) {
@ -1406,8 +1410,8 @@ bool Internal::sweep_equivalence_candidates (Sweeper &sweeper, int lit,
const int not_other = -other;
const int not_lit = -lit;
LOG ("flipping %d and %d both failed", lit, other);
kitten_assume_signed (citten, not_lit);
kitten_assume_signed (citten, other);
cadical_kitten_assume_signed (citten, not_lit);
cadical_kitten_assume_signed (citten, other);
stats.sweep_solved_equivalences++;
res = sweep_solve ();
if (res == 10) {
@ -1427,8 +1431,8 @@ bool Internal::sweep_equivalence_candidates (Sweeper &sweeper, int lit,
save_core (sweeper, 0);
kitten_assume_signed (citten, lit);
kitten_assume_signed (citten, not_other);
cadical_kitten_assume_signed (citten, lit);
cadical_kitten_assume_signed (citten, not_other);
res = sweep_solve ();
stats.sweep_solved_equivalences++;
if (res == 10) {
@ -1446,7 +1450,7 @@ bool Internal::sweep_equivalence_candidates (Sweeper &sweeper, int lit,
return false;
}
assert (res == 20);
CADICAL_assert (res == 20);
stats.sweep_unsat_equivalences++;
LOG ("second sweeping implication %d <- %d succeeded too", other, lit);
@ -1455,15 +1459,15 @@ bool Internal::sweep_equivalence_candidates (Sweeper &sweeper, int lit,
LOG ("sweep equivalence %d = %d", lit, other);
// If kitten behaves as expected, the two binaries of the equivalence
// If cadical_kitten behaves as expected, the two binaries of the equivalence
// should be stored at sweeper.core[i].back () for i in {0, 1}.
// We pick the smaller absolute valued literal as representative and
// store the equivalence .
add_core (sweeper, 0);
add_core (sweeper, 1);
if (!val (lit) && !val (other)) {
assert (sweeper.core[0].size ());
assert (sweeper.core[1].size ());
CADICAL_assert (sweeper.core[0].size ());
CADICAL_assert (sweeper.core[1].size ());
stats.sweep_equivalences++;
sweep_binary bin1;
sweep_binary bin2;
@ -1508,22 +1512,22 @@ bool Internal::sweep_equivalence_candidates (Sweeper &sweeper, int lit,
}
const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
assert (!unsat);
CADICAL_assert (!unsat);
if (!active (idx))
return "inactive variable";
const int start = idx;
if (sweeper.reprs[start] != start)
return "non-representative variable";
assert (sweeper.vars.empty ());
assert (sweeper.clauses.empty ());
assert (sweeper.backbone.empty ());
assert (sweeper.partition.empty ());
assert (!sweeper.encoded);
CADICAL_assert (sweeper.vars.empty ());
CADICAL_assert (sweeper.clauses.empty ());
CADICAL_assert (sweeper.backbone.empty ());
CADICAL_assert (sweeper.partition.empty ());
CADICAL_assert (!sweeper.encoded);
stats.sweep_variables++;
LOG ("sweeping %d", idx);
assert (!val (start));
CADICAL_assert (!val (start));
LOG ("starting sweeping[0]");
add_literal_to_environment (sweeper, 0, start);
LOG ("finished sweeping[0]");
@ -1559,7 +1563,7 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
if (opts.sweeprand && choices > 1) {
const unsigned swaps = sweeper.random.pick_int (0, choices - 1);
if (swaps) {
assert (expand + swaps < sweeper.vars.size ());
CADICAL_assert (expand + swaps < sweeper.vars.size ());
swap (sweeper.vars[expand], sweeper.vars[expand + swaps]);
}
}
@ -1602,14 +1606,14 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
LOG ("sub-solver returns '%d'", res);
if (res == 10) {
init_backbone_and_partition (sweeper);
#ifndef QUIET
#ifndef CADICAL_QUIET
uint64_t units = stats.sweep_units;
uint64_t solved = stats.sweep_solved;
#endif
START (sweepbackbone);
while (sweeper.backbone.size ()) {
if (unsat || terminated_asynchronously () ||
kitten_ticks_limit_hit (sweeper, "backbone refinement")) {
cadical_kitten_ticks_limit_hit (sweeper, "backbone refinement")) {
limit_reached = true;
STOP_SWEEP_BACKBONE:
STOP (sweepbackbone);
@ -1617,7 +1621,7 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
}
flip_backbone_literals (sweeper);
if (terminated_asynchronously () ||
kitten_ticks_limit_hit (sweeper, "backbone refinement")) {
cadical_kitten_ticks_limit_hit (sweeper, "backbone refinement")) {
limit_reached = true;
goto STOP_SWEEP_BACKBONE;
}
@ -1631,7 +1635,7 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
success = true;
}
STOP (sweepbackbone);
#ifndef QUIET
#ifndef CADICAL_QUIET
units = stats.sweep_units - units;
solved = stats.sweep_solved - solved;
#endif
@ -1639,15 +1643,15 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
"complete swept variable %d backbone with %" PRIu64
" units in %" PRIu64 " solver calls",
externalize (idx), units, solved);
assert (sweeper.backbone.empty ());
#ifndef QUIET
CADICAL_assert (sweeper.backbone.empty ());
#ifndef CADICAL_QUIET
uint64_t equivalences = stats.sweep_equivalences;
solved = stats.sweep_solved;
#endif
START (sweepequivalences);
while (sweeper.partition.size ()) {
if (unsat || terminated_asynchronously () ||
kitten_ticks_limit_hit (sweeper, "partition refinement")) {
cadical_kitten_ticks_limit_hit (sweeper, "partition refinement")) {
limit_reached = true;
STOP_SWEEP_EQUIVALENCES:
STOP (sweepequivalences);
@ -1655,7 +1659,7 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
}
flip_partition_literals (sweeper);
if (terminated_asynchronously () ||
kitten_ticks_limit_hit (sweeper, "backbone refinement")) {
cadical_kitten_ticks_limit_hit (sweeper, "backbone refinement")) {
limit_reached = true;
goto STOP_SWEEP_EQUIVALENCES;
}
@ -1663,7 +1667,7 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
break;
if (sweeper.partition.size () > 2) {
const auto end = sweeper.partition.end ();
assert (end[-1] == 0);
CADICAL_assert (end[-1] == 0);
int lit = end[-3];
int other = end[-2];
if (sweep_equivalence_candidates (sweeper, lit, other))
@ -1672,7 +1676,7 @@ const char *Internal::sweep_variable (Sweeper &sweeper, int idx) {
sweeper.partition.clear ();
}
STOP (sweepequivalences);
#ifndef QUIET
#ifndef CADICAL_QUIET
equivalences = stats.sweep_equivalences - equivalences;
solved = stats.sweep_solved - solved;
if (equivalences)
@ -1698,7 +1702,7 @@ DONE:
return "unsuccessfully without reaching limit";
else if (success && !limit_reached)
return "successfully without reaching limit";
assert (!success && limit_reached);
CADICAL_assert (!success && limit_reached);
return "unsuccessfully and reached limit";
}
@ -1709,8 +1713,8 @@ struct sweep_candidate {
struct rank_sweep_candidate {
bool operator() (sweep_candidate a, sweep_candidate b) const {
assert (a.rank && b.rank);
assert (a.idx > 0 && b.idx > 0);
CADICAL_assert (a.rank && b.rank);
CADICAL_assert (a.idx > 0 && b.idx > 0);
if (a.rank < b.rank)
return true;
if (b.rank < a.rank)
@ -1759,7 +1763,7 @@ unsigned Internal::schedule_all_other_not_scheduled_yet (Sweeper &sweeper) {
fresh.push_back (cand);
}
const size_t size = fresh.size ();
assert (size <= UINT_MAX);
CADICAL_assert (size <= UINT_MAX);
sort (fresh.begin (), fresh.end (), rank_sweep_candidate ());
for (auto &cand : fresh)
schedule_outer (sweeper, cand.idx);
@ -1807,7 +1811,7 @@ void Internal::mark_incomplete (Sweeper &sweeper) {
}
}
sweep_incomplete = true;
#ifndef QUIET
#ifndef CADICAL_QUIET
VERBOSE (2, "marked %u scheduled sweeping variables as incomplete",
marked);
#else
@ -1820,7 +1824,7 @@ unsigned Internal::schedule_sweeping (Sweeper &sweeper) {
const unsigned fresh = schedule_all_other_not_scheduled_yet (sweeper);
const unsigned scheduled = fresh + rescheduled;
const unsigned incomplete = incomplete_variables ();
#ifndef QUIET
#ifndef CADICAL_QUIET
PHASE ("sweep", stats.sweep,
"scheduled %u variables %.0f%% "
"(%u rescheduled %.0f%%, %u incomplete %.0f%%)",
@ -1829,7 +1833,7 @@ unsigned Internal::schedule_sweeping (Sweeper &sweeper) {
percent (incomplete, scheduled));
#endif
if (incomplete)
assert (sweep_incomplete);
CADICAL_assert (sweep_incomplete);
else {
if (sweep_incomplete)
stats.sweep_completed++;
@ -1840,17 +1844,17 @@ unsigned Internal::schedule_sweeping (Sweeper &sweeper) {
void Internal::unschedule_sweeping (Sweeper &sweeper, unsigned swept,
unsigned scheduled) {
#ifdef QUIET
#ifdef CADICAL_QUIET
(void) scheduled, (void) swept;
#endif
assert (sweep_schedule.empty ());
assert (sweep_incomplete);
CADICAL_assert (sweep_schedule.empty ());
CADICAL_assert (sweep_incomplete);
for (all_scheduled (idx))
if (active (idx)) {
sweep_schedule.push_back (idx);
LOG ("untried scheduled %d", idx);
}
#ifndef QUIET
#ifndef CADICAL_QUIET
const unsigned retained = sweep_schedule.size ();
#endif
VERBOSE (3, "retained %u variables %.0f%% to be swept next time",
@ -1883,7 +1887,7 @@ bool Internal::sweep () {
SET_EFFORT_LIMIT (tickslimit, sweep, !opts.sweepcomplete);
delaying_sweep.bumpreasons.unbypass_delay ();
assert (!level);
CADICAL_assert (!level);
START_SIMPLIFIER (sweep, SWEEP);
stats.sweep++;
uint64_t equivalences = stats.sweep_equivalences;
@ -1893,7 +1897,7 @@ bool Internal::sweep () {
sweeper.limit.ticks = INT64_MAX;
else
sweeper.limit.ticks = tickslimit - stats.ticks.sweep;
sweep_set_kitten_ticks_limit (sweeper);
sweep_set_cadical_kitten_ticks_limit (sweeper);
const unsigned scheduled = schedule_sweeping (sweeper);
uint64_t swept = 0, limit = 10;
for (;;) {
@ -1901,13 +1905,13 @@ bool Internal::sweep () {
break;
if (terminated_asynchronously ())
break;
if (kitten_ticks_limit_hit (sweeper, "sweeping loop"))
if (cadical_kitten_ticks_limit_hit (sweeper, "sweeping loop"))
break;
int idx = next_scheduled (sweeper);
if (idx == 0)
break;
flags (idx).sweep = false;
#ifndef QUIET
#ifndef CADICAL_QUIET
const char *res =
#endif
sweep_variable (sweeper, idx);
@ -1951,3 +1955,5 @@ bool Internal::sweep () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,11 +1,20 @@
#include "global.h"
#include "internal.hpp"
#ifdef WIN32
#include <io.h>
#define isatty _isatty
#endif
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
Terminal::Terminal (FILE *f) : file (f), reset_on_exit (false) {
assert (file);
CADICAL_assert (file);
int fd = fileno (f);
assert (fd == 1 || fd == 2);
CADICAL_assert (fd == 1 || fd == 2);
use_colors = connected = isatty (fd);
}
@ -36,3 +45,5 @@ Terminal tout (stdout);
Terminal terr (stderr);
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -23,9 +27,9 @@ namespace CaDiCaL {
// literals already exists.
bool Internal::ternary_find_binary_clause (int a, int b) {
assert (occurring ());
assert (active (a));
assert (active (b));
CADICAL_assert (occurring ());
CADICAL_assert (active (a));
CADICAL_assert (active (b));
size_t s = occs (a).size ();
size_t t = occs (b).size ();
int lit = s < t ? a : b;
@ -49,10 +53,10 @@ bool Internal::ternary_find_binary_clause (int a, int b) {
// literals already exists or is subsumed by an existing binary clause.
bool Internal::ternary_find_ternary_clause (int a, int b, int c) {
assert (occurring ());
assert (active (a));
assert (active (b));
assert (active (c));
CADICAL_assert (occurring ());
CADICAL_assert (active (a));
CADICAL_assert (active (b));
CADICAL_assert (active (c));
size_t r = occs (a).size ();
size_t s = occs (b).size ();
size_t t = occs (c).size ();
@ -79,7 +83,7 @@ bool Internal::ternary_find_ternary_clause (int a, int b, int c) {
if (lits[0] == c && lits[1] == b)
return true;
} else {
assert (d->size == 3);
CADICAL_assert (d->size == 3);
if (lits[0] == a && lits[1] == b && lits[2] == c)
return true;
if (lits[0] == a && lits[1] == c && lits[2] == b)
@ -111,9 +115,9 @@ bool Internal::hyper_ternary_resolve (Clause *c, int pivot, Clause *d) {
LOG (c, "1st antecedent");
LOG (d, "2nd antecedent");
stats.ternres++;
assert (c->size == 3);
assert (d->size == 3);
assert (clause.empty ());
CADICAL_assert (c->size == 3);
CADICAL_assert (d->size == 3);
CADICAL_assert (clause.empty ());
for (const auto &lit : *c)
if (lit != pivot)
clause.push_back (lit);
@ -160,7 +164,7 @@ void Internal::ternary_lit (int pivot, int64_t &steps, int64_t &htrs) {
if (c->garbage)
continue;
if (c->size != 3) {
assert (c->size == 2);
CADICAL_assert (c->size == 2);
continue;
}
if (--steps < 0)
@ -182,7 +186,7 @@ void Internal::ternary_lit (int pivot, int64_t &steps, int64_t &htrs) {
if (d->garbage)
continue;
if (d->size != 3) {
assert (d->size == 2);
CADICAL_assert (d->size == 2);
continue;
}
for (const auto &lit : *d)
@ -192,13 +196,13 @@ void Internal::ternary_lit (int pivot, int64_t &steps, int64_t &htrs) {
}
if (assigned)
continue;
assert (clause.empty ());
CADICAL_assert (clause.empty ());
htrs--;
if (hyper_ternary_resolve (c, pivot, d)) {
size_t size = clause.size ();
bool red = (size == 3 || (c->redundant && d->redundant));
if (lrat) {
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
lrat_chain.push_back (c->id);
lrat_chain.push_back (d->id);
}
@ -218,7 +222,7 @@ void Internal::ternary_lit (int pivot, int64_t &steps, int64_t &htrs) {
stats.htrs2++;
break;
} else {
assert (r->size == 3);
CADICAL_assert (r->size == 3);
stats.htrs3++;
}
} else {
@ -235,8 +239,8 @@ void Internal::ternary_lit (int pivot, int64_t &steps, int64_t &htrs) {
// number of positive and negative occurrence.
void Internal::ternary_idx (int idx, int64_t &steps, int64_t &htrs) {
assert (0 < idx);
assert (idx <= max_var);
CADICAL_assert (0 < idx);
CADICAL_assert (idx <= max_var);
steps -= 3;
if (!active (idx))
return;
@ -266,9 +270,9 @@ void Internal::ternary_idx (int idx, int64_t &steps, int64_t &htrs) {
bool Internal::ternary_round (int64_t &steps_limit, int64_t &htrs_limit) {
assert (!unsat);
CADICAL_assert (!unsat);
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t bincon = 0;
int64_t terncon = 0;
#endif
@ -294,14 +298,14 @@ bool Internal::ternary_round (int64_t &steps_limit, int64_t &htrs_limit) {
if (assigned)
continue;
if (c->size == 2) {
#ifndef QUIET
#ifndef CADICAL_QUIET
bincon++;
#endif
} else {
assert (c->size == 3);
CADICAL_assert (c->size == 3);
if (!marked)
continue;
#ifndef QUIET
#ifndef CADICAL_QUIET
terncon++;
#endif
}
@ -347,7 +351,7 @@ bool Internal::ternary_round (int64_t &steps_limit, int64_t &htrs_limit) {
PHASE ("ternary", stats.ternary, "completed hyper ternary resolution");
reset_occs ();
assert (!unsat);
CADICAL_assert (!unsat);
return remain; // Are there variables that should be tried again?
}
@ -373,9 +377,9 @@ bool Internal::ternary () {
START_SIMPLIFIER (ternary, TERNARY);
stats.ternary++;
assert (!level);
CADICAL_assert (!level);
assert (!unsat);
CADICAL_assert (!unsat);
if (watching ())
reset_watches ();
@ -430,8 +434,8 @@ bool Internal::ternary () {
break;
}
assert (!occurring ());
assert (!unsat);
CADICAL_assert (!occurring ());
CADICAL_assert (!unsat);
init_watches ();
connect_watches ();
if (!propagate ()) {
@ -448,3 +452,5 @@ bool Internal::ternary () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::recompute_tier () {
@ -12,11 +16,11 @@ void Internal::recompute_tier () {
lim.recompute_tier = stats.conflicts + delta;
LOG ("rescheduling in %zd at %zd (conflicts at %zd)", delta,
lim.recompute_tier, stats.conflicts);
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
uint64_t total_used = 0;
for (auto u : stats.used[stable])
total_used += u;
assert (total_used == stats.bump_used[stable]);
CADICAL_assert (total_used == stats.bump_used[stable]);
#endif
if (!stats.bump_used[stable]) {
@ -50,4 +54,6 @@ void Internal::recompute_tier () {
stable ? "stable" : "focused");
}
} // namespace CaDiCaL
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
// Implement transitive reduction in the binary implication graph. This is
@ -18,8 +22,8 @@ void Internal::transred () {
if (!stats.current.redundant && !stats.current.irredundant)
return;
assert (opts.transred);
assert (!level);
CADICAL_assert (opts.transred);
CADICAL_assert (!level);
START_SIMPLIFIER (transred, TRANSRED);
stats.transreds++;
@ -127,7 +131,7 @@ void Internal::transred () {
//
const bool irredundant = !c->redundant;
assert (work.empty ());
CADICAL_assert (work.empty ());
mark (src);
work.push_back (src);
LOG ("transred assign %d", src);
@ -137,13 +141,13 @@ void Internal::transred () {
size_t j = 0; // 'propagated' in BFS
assert (lrat_chain.empty ());
assert (mini_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
CADICAL_assert (mini_chain.empty ());
vector<int> parents;
while (!transitive && !failed && j < work.size ()) {
const int lit = work[j++];
assert (marked (lit) > 0);
CADICAL_assert (marked (lit) > 0);
LOG ("transred propagating %d", lit);
propagations++;
const Watches &ws = watches (-lit);
@ -198,7 +202,7 @@ void Internal::transred () {
const int lit = work.back ();
work.pop_back ();
if (lrat && failed && !work.empty ()) {
assert (!parents.empty () && !mini_chain.empty ());
CADICAL_assert (!parents.empty () && !mini_chain.empty ());
LOG ("transred LRAT current lit %d next pos %d next neg %d", lit,
next_pos, next_neg);
if (lit == failed_lit || lit == next_pos) {
@ -214,7 +218,7 @@ void Internal::transred () {
unmark (lit);
}
mini_chain.clear ();
assert (mini_chain.empty ());
CADICAL_assert (mini_chain.empty ());
if (lrat && failed) {
reverse (lrat_chain.begin (), lrat_chain.end ());
}
@ -251,3 +255,5 @@ void Internal::transred () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,10 +1,14 @@
#include "global.h"
#ifdef PROFILE_MODE
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
bool Internal::propagate_unstable () {
assert (!stable);
CADICAL_assert (!stable);
START (propunstable);
bool res = propagate ();
STOP (propunstable);
@ -12,18 +16,23 @@ bool Internal::propagate_unstable () {
}
void Internal::analyze_unstable () {
assert (!stable);
CADICAL_assert (!stable);
START (analyzeunstable);
analyze ();
STOP (analyzeunstable);
}
int Internal::decide_unstable () {
assert (!stable);
CADICAL_assert (!stable);
return decide ();
}
}; // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END
#else
ABC_NAMESPACE_IMPL_START
int unstable_if_no_profile_mode;
ABC_NAMESPACE_IMPL_END
#endif

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -46,7 +50,7 @@ bool parse_int_str (const char *val_str, int &val) {
} else if (ch)
return false;
assert (exponent <= 10);
CADICAL_assert (exponent <= 10);
int64_t val64 = mantissa;
for (int i = 0; i < exponent; i++)
val64 *= 10;
@ -60,8 +64,8 @@ bool parse_int_str (const char *val_str, int &val) {
val64 = INT_MAX;
}
assert (INT_MIN <= val64);
assert (val64 <= INT_MAX);
CADICAL_assert (INT_MIN <= val64);
CADICAL_assert (val64 <= INT_MAX);
val = val64;
}
@ -127,3 +131,5 @@ uint64_t hash_string (const char *str) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::reset_subsume_bits () {
@ -9,7 +13,7 @@ void Internal::reset_subsume_bits () {
}
void Internal::check_var_stats () {
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
int64_t fixed = 0, eliminated = 0, substituted = 0, pure = 0, unused = 0;
for (auto idx : vars) {
Flags &f = flags (idx);
@ -26,14 +30,16 @@ void Internal::check_var_stats () {
if (f.pure ())
pure++;
}
assert (stats.now.fixed == fixed);
assert (stats.now.eliminated == eliminated);
assert (stats.now.substituted == substituted);
assert (stats.now.pure == pure);
CADICAL_assert (stats.now.fixed == fixed);
CADICAL_assert (stats.now.eliminated == eliminated);
CADICAL_assert (stats.now.substituted == substituted);
CADICAL_assert (stats.now.pure == pure);
int64_t inactive = unused + fixed + eliminated + substituted + pure;
assert (stats.inactive == inactive);
assert (max_var == stats.active + stats.inactive);
CADICAL_assert (stats.inactive == inactive);
CADICAL_assert (max_var == stats.active + stats.inactive);
#endif
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -8,7 +12,7 @@ VeripbTracer::VeripbTracer (Internal *i, File *f, bool b, bool a, bool c)
: internal (i), file (f), with_antecedents (a), checked_deletions (c),
num_clauses (0), size_clauses (0), clauses (0), last_hash (0),
last_id (0), last_clause (0)
#ifndef QUIET
#ifndef CADICAL_QUIET
,
added (0), deleted (0)
#endif
@ -22,10 +26,10 @@ VeripbTracer::VeripbTracer (Internal *i, File *f, bool b, bool a, bool c)
uint64_t nonce = random.next ();
if (!(nonce & 1))
nonce++;
assert (nonce), assert (nonce & 1);
CADICAL_assert (nonce), CADICAL_assert (nonce & 1);
nonces[n] = nonce;
}
#ifndef NDEBUG
#ifndef CADICAL_NDEBUG
binary = b;
#else
(void) b;
@ -50,7 +54,7 @@ VeripbTracer::~VeripbTracer () {
/*------------------------------------------------------------------------*/
void VeripbTracer::enlarge_clauses () {
assert (num_clauses == size_clauses);
CADICAL_assert (num_clauses == size_clauses);
const uint64_t new_size_clauses = size_clauses ? 2 * size_clauses : 1;
LOG ("VeriPB Tracer enlarging clauses from %" PRIu64 " to %" PRIu64,
(uint64_t) size_clauses, (uint64_t) new_size_clauses);
@ -81,13 +85,13 @@ HashId *VeripbTracer::new_clause () {
}
void VeripbTracer::delete_clause (HashId *c) {
assert (c);
CADICAL_assert (c);
num_clauses--;
delete c;
}
uint64_t VeripbTracer::reduce_hash (uint64_t hash, uint64_t size) {
assert (size > 0);
CADICAL_assert (size > 0);
unsigned shift = 32;
uint64_t res = hash;
while ((((uint64_t) 1) << shift) > size) {
@ -95,12 +99,12 @@ uint64_t VeripbTracer::reduce_hash (uint64_t hash, uint64_t size) {
shift >>= 1;
}
res &= size - 1;
assert (res < size);
CADICAL_assert (res < size);
return res;
}
uint64_t VeripbTracer::compute_hash (const int64_t id) {
assert (id > 0);
CADICAL_assert (id > 0);
unsigned j = id % num_nonces; // Dont know if this is a good
uint64_t tmp = nonces[j] * (uint64_t) id; // hash funktion or even better
return last_hash = tmp; // than just using id.
@ -129,7 +133,7 @@ bool VeripbTracer::find_and_delete (const int64_t id) {
}
if (!c)
return false;
assert (c && res);
CADICAL_assert (c && res);
*res = c->next;
delete_clause (c);
return true;
@ -147,15 +151,15 @@ void VeripbTracer::insert () {
/*------------------------------------------------------------------------*/
inline void VeripbTracer::put_binary_zero () {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
file->put ((unsigned char) 0);
}
inline void VeripbTracer::put_binary_lit (int lit) {
assert (binary);
assert (file);
assert (lit != INT_MIN);
CADICAL_assert (binary);
CADICAL_assert (file);
CADICAL_assert (lit != INT_MIN);
unsigned x = 2 * abs (lit) + (lit < 0);
unsigned char ch;
while (x & ~0x7f) {
@ -168,8 +172,8 @@ inline void VeripbTracer::put_binary_lit (int lit) {
}
inline void VeripbTracer::put_binary_id (int64_t id, bool can_be_negative) {
assert (binary);
assert (file);
CADICAL_assert (binary);
CADICAL_assert (file);
uint64_t x = abs (id);
if (can_be_negative) {
x = 2 * x + (id < 0);
@ -300,7 +304,7 @@ void VeripbTracer::add_derived_clause (int64_t id, bool redundant,
veripb_add_derived_clause (id, redundant, clause, chain);
else
veripb_add_derived_clause (id, redundant, clause);
#ifndef QUIET
#ifndef CADICAL_QUIET
added++;
#endif
}
@ -311,7 +315,7 @@ void VeripbTracer::delete_clause (int64_t id, bool redundant,
return;
LOG ("VERIPB TRACER tracing deletion of clause[%" PRId64 "]", id);
veripb_delete_clause (id, redundant);
#ifndef QUIET
#ifndef CADICAL_QUIET
deleted++;
#endif
}
@ -349,7 +353,7 @@ void VeripbTracer::strengthen (int64_t id) {
bool VeripbTracer::closed () { return file->closed (); }
#ifndef QUIET
#ifndef CADICAL_QUIET
void VeripbTracer::print_statistics () {
// TODO complete
@ -366,9 +370,9 @@ void VeripbTracer::print_statistics () {
#endif
void VeripbTracer::close (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->close ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("VeriPB proof file '%s' closed", file->name ());
print_statistics ();
@ -379,9 +383,9 @@ void VeripbTracer::close (bool print) {
}
void VeripbTracer::flush (bool print) {
assert (!closed ());
CADICAL_assert (!closed ());
file->flush ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (print) {
MSG ("VeriPB proof file '%s' flushed", file->name ());
print_statistics ();
@ -392,3 +396,5 @@ void VeripbTracer::flush (bool print) {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,10 +1,12 @@
#include "global.h"
/*------------------------------------------------------------------------*/
// To simplify the build process without 'make', you can disable the
// generation of 'build.hpp' through '../scripts/make-build-header.sh' by
// defining '-DNBUILD'. Then we try to guess part of the configuration.
// defining '-DCADICAL_NBUILD'. Then we try to guess part of the configuration.
#ifndef NBUILD
#ifndef CADICAL_NBUILD
#if __GNUC__ > 4
#if __has_include(<build.hpp>)
#include "build.hpp"
@ -12,7 +14,7 @@
#else
#include "build.hpp"
#endif // __GNUC > 4
#endif // NBUILD
#endif // CADICAL_NBUILD
/*------------------------------------------------------------------------*/
@ -22,11 +24,11 @@
// the file '../VERSION' with '../scripts/update-version.sh'. The standard
// build process relies on 'VERSION' to be defined in 'build.hpp'.
#ifdef NBUILD
#ifdef CADICAL_NBUILD
#ifndef VERSION
#define VERSION "2.2.0-rc1"
#endif // VERSION
#endif // NBUILD
#endif // CADICAL_NBUILD
/*------------------------------------------------------------------------*/
@ -40,7 +42,7 @@ static const char *AFFILIATIONS =
/*------------------------------------------------------------------------*/
// Again if we do not have 'NBUILD' or if something during configuration is
// Again if we do not have 'CADICAL_NBUILD' or if something during configuration is
// broken we still want to be able to compile the solver. In this case we
// then try our best to figure out 'COMPILER' and 'DATE', but for
// 'IDENTIFIER' and 'FLAGS' we can only use the '0' string, which marks
@ -92,6 +94,8 @@ static const char *AFFILIATIONS =
#include "version.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
const char *version () { return VERSION; }
@ -105,3 +109,5 @@ const char *date () { return DATE; }
const char *flags () { return FLAGS; }
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,3 +1,5 @@
#include "global.h"
#include "vivify.hpp"
#include "internal.hpp"
#include "util.hpp"
@ -5,6 +7,8 @@
#include <limits>
#include <utility>
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -50,26 +54,26 @@ inline void Internal::vivify_subsume_clause (Clause *subsuming,
Clause *subsumed) {
stats.subsumed++;
stats.vivifysubs++;
#ifndef NDEBUG
assert (subsuming);
assert (subsumed);
assert (subsuming != subsumed);
assert (!subsumed->garbage);
#ifndef CADICAL_NDEBUG
CADICAL_assert (subsuming);
CADICAL_assert (subsumed);
CADICAL_assert (subsuming != subsumed);
CADICAL_assert (!subsumed->garbage);
// size after removeing units;
int real_size_subsuming = 0, real_size_subsumed = 0;
for (auto lit : *subsuming) {
if (!val (lit) || var (lit).level)
++real_size_subsuming;
else
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
}
for (auto lit : *subsumed) {
if (!val (lit) || var (lit).level)
++real_size_subsumed;
else
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
}
assert (real_size_subsuming <= real_size_subsumed);
CADICAL_assert (real_size_subsuming <= real_size_subsumed);
#endif
LOG (subsumed, "subsumed");
if (subsumed->redundant) {
@ -80,7 +84,7 @@ inline void Internal::vivify_subsume_clause (Clause *subsuming,
++stats.vivifysubirr;
}
if (subsuming->garbage) {
assert (subsuming->size == 2);
CADICAL_assert (subsuming->size == 2);
LOG (subsuming,
"binary subsuming clause was already deleted, so undeleting");
subsuming->garbage = false;
@ -104,9 +108,9 @@ inline void Internal::vivify_subsume_clause (Clause *subsuming,
stats.current.irredundant++;
stats.added.irredundant++;
stats.irrlits += subsuming->size;
assert (stats.current.redundant > 0);
CADICAL_assert (stats.current.redundant > 0);
stats.current.redundant--;
assert (stats.added.redundant > 0);
CADICAL_assert (stats.added.redundant > 0);
stats.added.redundant--;
// ... and keep 'stats.added.total'.
}
@ -117,12 +121,12 @@ inline void Internal::demote_clause (Clause *c) {
stats.subsumed++;
stats.vivifydemote++;
LOG (c, "demoting");
assert (!c->redundant);
CADICAL_assert (!c->redundant);
mark_removed (c);
c->redundant = true;
assert (stats.current.irredundant > 0);
CADICAL_assert (stats.current.irredundant > 0);
stats.current.irredundant--;
assert (stats.added.irredundant > 0);
CADICAL_assert (stats.added.irredundant > 0);
stats.added.irredundant--;
stats.irrlits -= c->size;
stats.current.redundant++;
@ -142,12 +146,12 @@ inline void Internal::demote_clause (Clause *c) {
inline void Internal::vivify_assign (int lit, Clause *reason) {
require_mode (VIVIFY);
const int idx = vidx (lit);
assert (!vals[idx]);
assert (!flags (idx).eliminated () || !reason);
CADICAL_assert (!vals[idx]);
CADICAL_assert (!flags (idx).eliminated () || !reason);
Var &v = var (idx);
v.level = level; // required to reuse decisions
v.trail = (int) trail.size (); // used in 'vivify_better_watch'
assert ((int) num_assigned < max_var);
CADICAL_assert ((int) num_assigned < max_var);
num_assigned++;
v.reason = level ? reason : 0; // for conflict analysis
if (!level)
@ -155,8 +159,8 @@ inline void Internal::vivify_assign (int lit, Clause *reason) {
const signed char tmp = sign (lit);
vals[idx] = tmp;
vals[-idx] = -tmp;
assert (val (lit) > 0);
assert (val (-lit) < 0);
CADICAL_assert (val (lit) > 0);
CADICAL_assert (val (-lit) < 0);
trail.push_back (lit);
LOG (reason, "vivify assign %d", lit);
}
@ -168,8 +172,8 @@ void Internal::vivify_assume (int lit) {
level++;
control.push_back (Level (lit, trail.size ()));
LOG ("vivify decide %d", lit);
assert (level > 0);
assert (propagated == trail.size ());
CADICAL_assert (level > 0);
CADICAL_assert (propagated == trail.size ());
vivify_assign (lit, 0);
}
@ -179,7 +183,7 @@ void Internal::vivify_assume (int lit) {
bool Internal::vivify_propagate (int64_t &ticks) {
require_mode (VIVIFY);
assert (!unsat);
CADICAL_assert (!unsat);
START (propagate);
int64_t before = propagated2 = propagated;
for (;;) {
@ -239,12 +243,12 @@ bool Internal::vivify_propagate (int64_t &ticks) {
k++;
if (v < 0) {
k = lits + 2;
assert (w.clause->pos <= size);
CADICAL_assert (w.clause->pos <= size);
while (k != middle && (v = val (r = *k)) < 0)
k++;
}
w.clause->pos = k - lits;
assert (lits + 2 <= k), assert (k <= w.clause->end ());
CADICAL_assert (lits + 2 <= k), CADICAL_assert (k <= w.clause->end ());
if (v > 0)
j[-1].blit = r;
else if (!v) {
@ -261,7 +265,7 @@ bool Internal::vivify_propagate (int64_t &ticks) {
continue;
}
ticks++;
assert (v < 0);
CADICAL_assert (v < 0);
vivify_chain_for_units (other, w.clause);
vivify_assign (other, w.clause);
lrat_chain.clear ();
@ -270,8 +274,8 @@ bool Internal::vivify_propagate (int64_t &ticks) {
LOG ("ignoring conflict due to clause to vivify");
continue;
}
assert (u < 0);
assert (v < 0);
CADICAL_assert (u < 0);
CADICAL_assert (v < 0);
conflict = w.clause;
break;
}
@ -395,7 +399,7 @@ struct vivify_clause_later {
// Among redundant clauses (in redundant mode) prefer small glue.
//
if (a->redundant) {
assert (b->redundant);
CADICAL_assert (b->redundant);
if (a->glue > b->glue)
return true;
if (a->glue < b->glue)
@ -474,9 +478,9 @@ void Internal::flush_vivification_schedule (std::vector<Clause *> &schedule,
if (k == eop) {
LOG (c, "found subsumed");
LOG (prev, "subsuming");
assert (!c->garbage);
assert (!prev->garbage);
assert (c->redundant || !prev->redundant);
CADICAL_assert (!c->garbage);
CADICAL_assert (!prev->garbage);
CADICAL_assert (c->redundant || !prev->redundant);
mark_garbage (c);
subsumed++;
j--;
@ -494,7 +498,7 @@ void Internal::flush_vivification_schedule (std::vector<Clause *> &schedule,
schedule.resize (j - schedule.begin ());
shrink_vector (schedule);
} else
assert (j == end);
CADICAL_assert (j == end);
}
/*------------------------------------------------------------------------*/
@ -513,7 +517,7 @@ bool Internal::consider_to_vivify_clause (Clause *c) {
return false;
if (!c->redundant)
return true;
assert (c->redundant);
CADICAL_assert (c->redundant);
// likely_to_be_kept_clause is too aggressive at removing tier-3 clauses
return true;
@ -550,14 +554,14 @@ struct vivify_better_watch {
void Internal::vivify_strengthen (Clause *c) {
assert (!clause.empty ());
CADICAL_assert (!clause.empty ());
if (clause.size () == 1) {
backtrack_without_updating_phases ();
const int unit = clause[0];
LOG (c, "vivification shrunken to unit %d", unit);
assert (!val (unit));
CADICAL_assert (!val (unit));
assign_unit (unit);
// lrat_chain.clear (); done in search_assign
stats.vivifyunits++;
@ -590,12 +594,12 @@ void Internal::vivify_strengthen (Clause *c) {
new_level = level1 - 1;
}
assert (new_level >= 0);
CADICAL_assert (new_level >= 0);
if (new_level < level)
backtrack (new_level);
assert (val (lit0) >= 0);
assert (val (lit1) >= 0 || (val (lit0) > 0 && val (lit1) < 0 &&
CADICAL_assert (val (lit0) >= 0);
CADICAL_assert (val (lit1) >= 0 || (val (lit0) > 0 && val (lit1) < 0 &&
var (lit0).level <= var (lit1).level));
Clause *d = new_clause_as (c);
@ -631,12 +635,12 @@ void Internal::vivify_sort_watched (Clause *c) {
new_level = level1 - 1;
}
assert (new_level >= 0);
CADICAL_assert (new_level >= 0);
if (new_level < level)
backtrack (new_level);
assert (val (lit0) >= 0);
assert (val (lit1) >= 0 || (val (lit0) > 0 && val (lit1) < 0 &&
CADICAL_assert (val (lit0) >= 0);
CADICAL_assert (val (lit1) >= 0 || (val (lit0) > 0 && val (lit1) < 0 &&
var (lit0).level <= var (lit1).level));
}
// Conflict analysis from 'start' which learns a decision only clause.
@ -652,8 +656,8 @@ void Internal::vivify_analyze (Clause *start, bool &subsumes,
const auto &t = &trail; // normal trail, so next_trail is wrong
int i = t->size (); // Start at end-of-trail.
Clause *reason = start;
assert (reason);
assert (!trail.empty ());
CADICAL_assert (reason);
CADICAL_assert (!trail.empty ());
int uip = trail.back ();
bool mark_implied = (implied);
@ -692,7 +696,7 @@ void Internal::vivify_analyze (Clause *start, bool &subsumes,
continue;
}
assert (val (other));
CADICAL_assert (val (other));
if (f.seen)
continue;
LOG ("pushing lit %d", other);
@ -704,7 +708,7 @@ void Internal::vivify_analyze (Clause *start, bool &subsumes,
promote_clause (start, new_glue);
}
if (subsumes) {
assert (reason);
CADICAL_assert (reason);
LOG (reason, "clause found subsuming");
LOG (candidate, "clause found subsumed");
*subsuming = reason;
@ -718,7 +722,7 @@ void Internal::vivify_analyze (Clause *start, bool &subsumes,
uip = 0;
while (!uip && i > 0) {
assert (i > 0);
CADICAL_assert (i > 0);
const int lit = (*t)[--i];
if (!var (lit).level)
continue;
@ -739,16 +743,16 @@ void Internal::vivify_analyze (Clause *start, bool &subsumes,
void Internal::vivify_deduce (Clause *candidate, Clause *conflict,
int implied, Clause **subsuming,
bool &redundant) {
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
bool subsumes;
Clause *reason;
assert (clause.empty ());
CADICAL_assert (clause.empty ());
if (implied) {
reason = candidate;
mark2 (candidate);
const int not_implied = -implied;
assert (var (not_implied).level);
CADICAL_assert (var (not_implied).level);
Flags &f = flags (not_implied);
f.seen = true;
LOG ("pushing implied lit %d", not_implied);
@ -756,8 +760,8 @@ void Internal::vivify_deduce (Clause *candidate, Clause *conflict,
clause.push_back (implied);
} else {
reason = (conflict ? conflict : candidate);
assert (reason);
assert (!reason->garbage);
CADICAL_assert (reason);
CADICAL_assert (!reason->garbage);
mark2 (candidate);
subsumes = (candidate != reason);
redundant = reason->redundant;
@ -767,7 +771,7 @@ void Internal::vivify_deduce (Clause *candidate, Clause *conflict,
for (auto lit : *reason) {
const Var &v = var (lit);
Flags &f = flags (lit);
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
if (!v.level) {
if (!lrat)
continue;
@ -783,7 +787,7 @@ void Internal::vivify_deduce (Clause *candidate, Clause *conflict,
analyzed.push_back (lit);
continue;
}
assert (v.level);
CADICAL_assert (v.level);
if (!marked2 (lit)) {
LOG ("lit %d is not marked", lit);
subsumes = false;
@ -798,8 +802,8 @@ void Internal::vivify_deduce (Clause *candidate, Clause *conflict,
promote_clause (reason, new_glue);
}
if (subsumes) {
assert (candidate != reason);
#ifndef NDEBUG
CADICAL_assert (candidate != reason);
#ifndef CADICAL_NDEBUG
int nonfalse_reason = 0;
for (auto lit : *reason)
if (!fixed (lit))
@ -810,7 +814,7 @@ void Internal::vivify_deduce (Clause *candidate, Clause *conflict,
if (!fixed (lit))
++nonfalse_candidate;
assert (nonfalse_reason <= nonfalse_candidate);
CADICAL_assert (nonfalse_reason <= nonfalse_candidate);
#endif
LOG (candidate, "vivify subsumed 0");
LOG (reason, "vivify subsuming 0");
@ -826,7 +830,7 @@ void Internal::vivify_deduce (Clause *candidate, Clause *conflict,
redundant);
unmark (candidate);
if (subsumes) {
assert (*subsuming);
CADICAL_assert (*subsuming);
LOG (candidate, "vivify subsumed");
LOG (*subsuming, "vivify subsuming");
if (lrat)
@ -854,7 +858,7 @@ bool Internal::vivify_shrinkable (const std::vector<int> &sorted,
return true;
}
} else {
assert (value < 0);
CADICAL_assert (value < 0);
const Var &v = var (lit);
const Flags &f = flags (lit);
if (!v.level)
@ -885,7 +889,7 @@ inline void Internal::vivify_increment_stats (const Vivifier &vivifier) {
++stats.vivifystred3;
break;
default:
assert (vivifier.tier == Vivify_Mode::IRREDUNDANT);
CADICAL_assert (vivifier.tier == Vivify_Mode::IRREDUNDANT);
++stats.vivifystrirr;
break;
}
@ -902,11 +906,11 @@ bool Internal::vivify_instantiate (
conflict = nullptr;
const int lit = sorted.back ();
LOG ("vivify instantiation");
assert (!var (lit).reason);
assert (var (lit).level);
assert (val (lit));
CADICAL_assert (!var (lit).reason);
CADICAL_assert (var (lit).level);
CADICAL_assert (val (lit));
backtrack (level - 1);
assert (val (lit) == 0);
CADICAL_assert (val (lit) == 0);
stats.vivifydecs++;
vivify_assume (lit);
bool ok = vivify_propagate (ticks);
@ -916,7 +920,7 @@ bool Internal::vivify_instantiate (
// strengthen clause
if (lrat) {
clear_analyzed_literals ();
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
vivify_build_lrat (0, c, lrat_stack);
vivify_build_lrat (0, conflict, lrat_stack);
clear_analyzed_literals ();
@ -928,7 +932,7 @@ bool Internal::vivify_instantiate (
strengthen_clause (c, remove);
vivify_sort_watched (c);
watch_clause (c);
assert (!conflict);
CADICAL_assert (!conflict);
return true;
} else {
LOG ("vivify instantiation failed");
@ -942,13 +946,13 @@ bool Internal::vivify_instantiate (
bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
assert (c->size > 2); // see (NO-BINARY) below
assert (analyzed.empty ());
CADICAL_assert (c->size > 2); // see (NO-BINARY) below
CADICAL_assert (analyzed.empty ());
c->vivify = false; // mark as checked / tried
c->vivified = true; // and globally remember
assert (!c->garbage);
CADICAL_assert (!c->garbage);
auto &lrat_stack = vivifier.lrat_stack;
auto &ticks = vivifier.ticks;
@ -973,7 +977,7 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
sorted.push_back (lit);
}
assert (sorted.size () > 1);
CADICAL_assert (sorted.size () > 1);
if (sorted.size () == 2) {
LOG ("skipping actual binary");
return false;
@ -1027,7 +1031,7 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
}
if (forced) {
LOG ("clause is reason forcing %d", forced);
assert (var (forced).level);
CADICAL_assert (var (forced).level);
backtrack_without_updating_phases (var (forced).level - 1);
}
@ -1039,7 +1043,7 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
int l = 1; // This is the decision level we want to reuse.
for (const auto &lit : sorted) {
assert (!fixed (lit));
CADICAL_assert (!fixed (lit));
const int decision = control[l].decision;
if (-lit == decision) {
LOG ("reusing decision %d at decision level %d", decision, l);
@ -1103,25 +1107,25 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
if (tmp) { // literal already assigned
const Var &v = var (lit);
assert (v.level);
CADICAL_assert (v.level);
if (!v.reason) {
LOG ("skipping decision %d", lit);
continue;
}
if (tmp < 0) {
assert (v.level);
CADICAL_assert (v.level);
LOG ("literal %d is already false and can be removed", lit);
continue;
}
assert (tmp > 0);
CADICAL_assert (tmp > 0);
LOG ("subsumed since literal %d already true", lit);
subsume = lit; // will be able to subsume candidate '@5'
break;
}
assert (!tmp);
CADICAL_assert (!tmp);
stats.vivifydecs++;
vivify_assume (-lit);
@ -1150,7 +1154,7 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
Clause *subsuming = nullptr;
bool redundant = false;
const int level_after_assumptions = level;
assert (level_after_assumptions);
CADICAL_assert (level_after_assumptions);
vivify_deduce (c, conflict, subsume, &subsuming, redundant);
bool res;
@ -1166,7 +1170,7 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
}
if (subsuming) {
assert (c != subsuming);
CADICAL_assert (c != subsuming);
LOG (c, "deleting subsumed clause");
if (c->redundant && subsuming->redundant && c->glue < subsuming->glue) {
promote_clause (c, c->glue);
@ -1203,19 +1207,19 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
} else if (subsume) {
LOG (c, "no vivification instantiation with implied literal %d",
subsume);
assert (!c->redundant);
assert (redundant);
CADICAL_assert (!c->redundant);
CADICAL_assert (redundant);
res = false;
++stats.vivifyimplied;
} else {
assert (level > 2);
assert ((size_t) level == sorted.size ());
CADICAL_assert (level > 2);
CADICAL_assert ((size_t) level == sorted.size ());
LOG (c, "vivification failed on");
lrat_chain.clear ();
assert (!subsume);
CADICAL_assert (!subsume);
if (!subsume && opts.vivifyinst) {
res = vivify_instantiate (sorted, c, lrat_stack, ticks);
assert (!conflict);
CADICAL_assert (!conflict);
} else {
LOG ("cannot apply instantiation");
res = false;
@ -1253,7 +1257,7 @@ bool Internal::vivify_clause (Vivifier &vivifier, Clause *c) {
void Internal::vivify_build_lrat (
int lit, Clause *reason,
std::vector<std::tuple<int, Clause *, bool>> &stack) {
assert (stack.empty ());
CADICAL_assert (stack.empty ());
stack.push_back ({lit, reason, false});
while (!stack.empty ()) {
int lit;
@ -1271,8 +1275,8 @@ void Internal::vivify_build_lrat (
if (lit && reason) {
Flags &f = flags (lit);
f.seen = true;
analyzed.push_back (lit); // assert (val (other) < 0);
assert (flags (lit).seen);
analyzed.push_back (lit); // CADICAL_assert (val (other) < 0);
CADICAL_assert (flags (lit).seen);
}
continue;
} else
@ -1309,11 +1313,11 @@ inline void Internal::vivify_chain_for_units (int lit, Clause *reason) {
// equivalence if (opts.chrono && assignment_level (lit, reason)) return;
if (level)
return; // not decision level 0
assert (lrat_chain.empty ());
CADICAL_assert (lrat_chain.empty ());
for (auto &reason_lit : *reason) {
if (lit == reason_lit)
continue;
assert (val (reason_lit));
CADICAL_assert (val (reason_lit));
const int signed_reason_lit = val (reason_lit) * reason_lit;
int64_t id = unit_id (signed_reason_lit);
lrat_chain.push_back (id);
@ -1344,7 +1348,7 @@ vivify_ref create_ref (Internal *internal, Clause *c) {
}
{
const int64_t lit_count = internal->noccs (lit);
assert (lit_count);
CADICAL_assert (lit_count);
LOG ("checking literal %d with %zd occurrences", lit, lit_count);
if (lit_count <= best_count)
continue;
@ -1353,9 +1357,9 @@ vivify_ref create_ref (Internal *internal, Clause *c) {
}
CONTINUE_WITH_NEXT_LITERAL:;
}
assert (best);
assert (best_count);
assert (best_count < UINT32_MAX);
CADICAL_assert (best);
CADICAL_assert (best_count);
CADICAL_assert (best_count < UINT32_MAX);
ref.count[i] =
((uint64_t) best_count << 32) + (uint64_t) internal->vlit (best);
LOG ("final count at position %d is %d - %d: %lu", i, best, best_count,
@ -1402,7 +1406,7 @@ void Internal::vivify_initialize (Vivifier &vivifier, int64_t &ticks) {
// Disconnect all watches since we sort literals within clauses.
//
assert (watching ());
CADICAL_assert (watching ());
#if 0
clear_watches ();
#endif
@ -1497,7 +1501,11 @@ inline std::vector<vivify_ref> &current_refs_schedule (Vivifier &vivifier) {
return vivifier.refs_schedule_irred;
break;
}
#ifdef WIN32
__assume(false);
#else
__builtin_unreachable ();
#endif
}
inline std::vector<Clause *> &current_schedule (Vivifier &vivifier) {
@ -1515,13 +1523,17 @@ inline std::vector<Clause *> &current_schedule (Vivifier &vivifier) {
return vivifier.schedule_irred;
break;
}
#ifdef WIN32
__assume(false);
#else
__builtin_unreachable ();
#endif
}
struct vivify_refcount_rank {
int offset;
vivify_refcount_rank (int j) : offset (j) {
assert (offset < COUNTREF_COUNTS);
CADICAL_assert (offset < COUNTREF_COUNTS);
}
typedef uint64_t Type;
Type operator() (const vivify_ref &a) const { return a.count[offset]; }
@ -1530,7 +1542,7 @@ struct vivify_refcount_rank {
struct vivify_refcount_smaller {
int offset;
vivify_refcount_smaller (int j) : offset (j) {
assert (offset < COUNTREF_COUNTS);
CADICAL_assert (offset < COUNTREF_COUNTS);
}
bool operator() (const vivify_ref &a, const vivify_ref &b) const {
const auto s = vivify_refcount_rank (offset) (a);
@ -1576,7 +1588,7 @@ void Internal::vivify_round (Vivifier &vivifier, int64_t ticks_limit) {
"starting %c vivification round ticks limit %" PRId64 "",
vivifier.tag, ticks_limit);
assert (watching ());
CADICAL_assert (watching ());
auto &refs_schedule = current_refs_schedule (vivifier);
auto &schedule = current_schedule (vivifier);
@ -1645,7 +1657,7 @@ void Internal::vivify_round (Vivifier &vivifier, int64_t ticks_limit) {
// Limit the number of propagations during vivification as in 'probe'.
//
const int64_t limit = ticks_limit - stats.ticks.vivify;
assert (limit >= 0);
CADICAL_assert (limit >= 0);
// the clauses might still contain set literals, so propagation since the
// beginning
@ -1770,7 +1782,7 @@ void set_vivifier_mode (Vivifier &vivifier, Vivify_Mode tier) {
vivifier.tag = 'w';
break;
default:
assert (tier == Vivify_Mode::IRREDUNDANT);
CADICAL_assert (tier == Vivify_Mode::IRREDUNDANT);
vivifier.tag = 'x';
break;
}
@ -1801,8 +1813,8 @@ bool Internal::vivify () {
return false;
if (level)
backtrack ();
assert (opts.vivify);
assert (!level);
CADICAL_assert (opts.vivify);
CADICAL_assert (!level);
SET_EFFORT_LIMIT (totallimit, vivify, true);
@ -1854,12 +1866,12 @@ bool Internal::vivify () {
if (limit < stats.ticks.vivify)
limit = stats.ticks.vivify;
const double effort = (total * tier1effort) / sumeffort;
assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
CADICAL_assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
limit);
limit += effort;
if (limit - shared_effort > stats.ticks.vivify) {
limit -= shared_effort;
assert (limit >= 0);
CADICAL_assert (limit >= 0);
vivify_round (vivifier, limit);
} else {
LOG ("building the schedule already used our entire ticks budget for "
@ -1874,12 +1886,12 @@ bool Internal::vivify () {
if (limit < stats.ticks.vivify)
limit = stats.ticks.vivify;
const double effort = (total * tier2effort) / sumeffort;
assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
CADICAL_assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
limit);
limit += effort;
if (limit - shared_effort > stats.ticks.vivify) {
limit -= shared_effort;
assert (limit >= 0);
CADICAL_assert (limit >= 0);
set_vivifier_mode (vivifier, Vivify_Mode::TIER2);
vivify_round (vivifier, limit);
} else {
@ -1893,12 +1905,12 @@ bool Internal::vivify () {
if (limit < stats.ticks.vivify)
limit = stats.ticks.vivify;
const double effort = (total * tier3effort) / sumeffort;
assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
CADICAL_assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
limit);
limit += effort;
if (limit - shared_effort > stats.ticks.vivify) {
limit -= shared_effort;
assert (limit >= 0);
CADICAL_assert (limit >= 0);
set_vivifier_mode (vivifier, Vivify_Mode::TIER3);
vivify_round (vivifier, limit);
} else {
@ -1912,12 +1924,12 @@ bool Internal::vivify () {
if (limit < stats.ticks.vivify)
limit = stats.ticks.vivify;
const double effort = (total * irreffort) / sumeffort;
assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
CADICAL_assert (std::numeric_limits<int64_t>::max () - (int64_t) effort >=
limit);
limit += effort;
if (limit - shared_effort > stats.ticks.vivify) {
limit -= shared_effort;
assert (limit >= 0);
CADICAL_assert (limit >= 0);
set_vivifier_mode (vivifier, Vivify_Mode::IRREDUNDANT);
const int old = stats.vivifystrirr;
const int old_tried = stats.vivifychecks;
@ -1946,3 +1958,5 @@ bool Internal::vivify () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,9 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
/*------------------------------------------------------------------------*/
@ -52,9 +56,9 @@ inline static double fitcbval (double size) {
const double x2 = cbvals[i + 1][0], x1 = cbvals[i][0];
const double y2 = cbvals[i + 1][1], y1 = cbvals[i][1];
const double dx = x2 - x1, dy = y2 - y1;
assert (dx);
CADICAL_assert (dx);
const double res = dy * (size - x1) / dx + y1;
assert (res > 0);
CADICAL_assert (res > 0);
return res;
}
@ -71,7 +75,7 @@ Walker::Walker (Internal *i, double size, int64_t l)
//
const bool use_size_based_cb = (internal->stats.walk.count & 1);
const double cb = use_size_based_cb ? fitcbval (size) : 2.0;
assert (cb);
CADICAL_assert (cb);
const double base = 1 / cb; // scores are 'base^0,base^1,base^2,...
double next = 1;
@ -95,7 +99,7 @@ inline double Walker::score (unsigned i) {
Clause *Internal::walk_pick_clause (Walker &walker) {
require_mode (WALK);
assert (!walker.broken.empty ());
CADICAL_assert (!walker.broken.empty ());
int64_t size = walker.broken.size ();
if (size > INT_MAX)
size = INT_MAX;
@ -113,12 +117,12 @@ Clause *Internal::walk_pick_clause (Walker &walker) {
unsigned Internal::walk_break_value (int lit) {
require_mode (WALK);
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
unsigned res = 0; // The computed break-count of 'lit'.
for (auto &w : watches (lit)) {
assert (w.blit != lit);
CADICAL_assert (w.blit != lit);
if (val (w.blit) > 0)
continue;
if (w.binary ()) {
@ -127,7 +131,7 @@ unsigned Internal::walk_break_value (int lit) {
}
Clause *c = w.clause;
assert (lit == c->literals[0]);
CADICAL_assert (lit == c->literals[0]);
// Now try to find a second satisfied literal starting at 'literals[1]'
// shifting all the traversed literals to right by one position in order
@ -186,16 +190,16 @@ unsigned Internal::walk_break_value (int lit) {
int Internal::walk_pick_lit (Walker &walker, Clause *c) {
LOG ("picking literal by break-count");
assert (walker.scores.empty ());
CADICAL_assert (walker.scores.empty ());
double sum = 0;
int64_t propagations = 0;
for (const auto lit : *c) {
assert (active (lit));
CADICAL_assert (active (lit));
if (var (lit).level == 1) {
LOG ("skipping assumption %d for scoring", -lit);
continue;
}
assert (active (lit));
CADICAL_assert (active (lit));
propagations++;
unsigned tmp = walk_break_value (-lit);
double score = walker.score (tmp);
@ -204,10 +208,10 @@ int Internal::walk_pick_lit (Walker &walker, Clause *c) {
sum += score;
}
LOG ("scored %zd literals", walker.scores.size ());
assert (!walker.scores.empty ());
CADICAL_assert (!walker.scores.empty ());
walker.propagations += propagations;
stats.propagations.walk += propagations;
assert (walker.scores.size () <= (size_t) c->size);
CADICAL_assert (walker.scores.size () <= (size_t) c->size);
const double lim = sum * walker.random.generate_double ();
LOG ("score sum %g limit %g", sum, lim);
const auto end = c->end ();
@ -215,7 +219,7 @@ int Internal::walk_pick_lit (Walker &walker, Clause *c) {
auto j = walker.scores.begin ();
int res;
for (;;) {
assert (i != end);
CADICAL_assert (i != end);
res = *i++;
if (var (res).level > 1)
break;
@ -241,14 +245,14 @@ void Internal::walk_flip_lit (Walker &walker, int lit) {
require_mode (WALK);
LOG ("flipping assign %d", lit);
assert (val (lit) < 0);
CADICAL_assert (val (lit) < 0);
// First flip the literal value.
//
const int tmp = sign (lit);
const int idx = abs (lit);
set_val (idx, tmp);
assert (val (lit) > 0);
CADICAL_assert (val (lit) > 0);
// Then remove 'c' and all other now satisfied (made) clauses.
{
@ -288,12 +292,12 @@ void Internal::walk_flip_lit (Walker &walker, int lit) {
const int size = d->size;
for (int i = 0; i < size; i++) {
const int other = literals[i];
assert (active (other));
CADICAL_assert (active (other));
literals[i] = prev;
prev = other;
if (other == lit)
break;
assert (val (other) < 0);
CADICAL_assert (val (other) < 0);
}
// If 'lit' is in 'd' then move it to the front to watch it.
@ -348,11 +352,11 @@ void Internal::walk_flip_lit (Walker &walker, int lit) {
Clause *d = w.clause;
LOG (d, "unwatch %d in", -lit);
int *literals = d->literals, replacement = 0, prev = -lit;
assert (literals[0] == -lit);
CADICAL_assert (literals[0] == -lit);
const int size = d->size;
for (int i = 1; i < size; i++) {
const int other = literals[i];
assert (active (other));
CADICAL_assert (active (other));
literals[i] = prev; // shift all to right
prev = other;
const signed char tmp = val (other);
@ -364,7 +368,7 @@ void Internal::walk_flip_lit (Walker &walker, int lit) {
if (replacement) {
literals[1] = -lit;
literals[0] = replacement;
assert (-lit != replacement);
CADICAL_assert (-lit != replacement);
watch_literal (replacement, -lit, d);
} else {
for (int i = size - 1; i > 0; i--) { // undo shift
@ -372,7 +376,7 @@ void Internal::walk_flip_lit (Walker &walker, int lit) {
literals[i] = prev;
prev = other;
}
assert (literals[0] == -lit);
CADICAL_assert (literals[0] == -lit);
LOG (d, "broken");
walker.broken.push_back (d);
#ifdef LOGGING
@ -422,11 +426,11 @@ int Internal::walk_round (int64_t limit, bool prev) {
if (last.collect.fixed < stats.all.fixed)
garbage_collection ();
#ifndef QUIET
#ifndef CADICAL_QUIET
// We want to see more messages during initial local search.
//
if (localsearching) {
assert (!force_phase_messages);
CADICAL_assert (!force_phase_messages);
force_phase_messages = true;
}
#endif
@ -483,7 +487,7 @@ int Internal::walk_round (int64_t limit, bool prev) {
const int idx = abs (lit);
LOG ("initial assign %d to assumption phase", tmp < 0 ? -idx : idx);
set_val (idx, tmp);
assert (level == 1);
CADICAL_assert (level == 1);
var (idx).level = 1;
}
if (!failed)
@ -500,7 +504,7 @@ int Internal::walk_round (int64_t limit, bool prev) {
continue;
}
if (vals[idx]) {
assert (var (idx).level == 1);
CADICAL_assert (var (idx).level == 1);
LOG ("skipping assumed variable %d", idx);
continue;
}
@ -509,9 +513,9 @@ int Internal::walk_round (int64_t limit, bool prev) {
tmp = phases.prev[idx];
if (!tmp)
tmp = sign (decide_phase (idx, true));
assert (tmp == 1 || tmp == -1);
CADICAL_assert (tmp == 1 || tmp == -1);
set_val (idx, tmp);
assert (level == 2);
CADICAL_assert (level == 2);
var (idx).level = 2;
LOG ("initial assign %d to decision phase", tmp < 0 ? -idx : idx);
}
@ -542,7 +546,7 @@ int Internal::walk_round (int64_t limit, bool prev) {
//
for (int i = 0; satisfied < 2 && i < size; i++) {
const int lit = lits[i];
assert (active (lit)); // Due to garbage collection.
CADICAL_assert (active (lit)); // Due to garbage collection.
if (val (lit) > 0) {
swap (lits[satisfied], lits[i]);
if (!satisfied++)
@ -566,7 +570,7 @@ int Internal::walk_round (int64_t limit, bool prev) {
watched++;
#endif
} else {
assert (satisfiable); // at least one non-assumed variable ...
CADICAL_assert (satisfiable); // at least one non-assumed variable ...
LOG (c, "broken");
walker.broken.push_back (c);
}
@ -599,12 +603,12 @@ int Internal::walk_round (int64_t limit, bool prev) {
walk_save_minimum (walker);
int64_t minimum = broken;
#ifndef QUIET
#ifndef CADICAL_QUIET
int64_t flips = 0;
#endif
while (!terminated_asynchronously () && !walker.broken.empty () &&
walker.propagations < walker.limit) {
#ifndef QUIET
#ifndef CADICAL_QUIET
flips++;
#endif
stats.walk.flips++;
@ -673,15 +677,15 @@ int Internal::walk_round (int64_t limit, bool prev) {
if (active (idx))
set_val (idx, 0);
assert (level == 2);
CADICAL_assert (level == 2);
level = 0;
clear_watches ();
connect_watches ();
#ifndef QUIET
#ifndef CADICAL_QUIET
if (localsearching) {
assert (force_phase_messages);
CADICAL_assert (force_phase_messages);
force_phase_messages = false;
}
#endif
@ -702,3 +706,5 @@ void Internal::walk () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

View File

@ -1,9 +1,13 @@
#include "global.h"
#include "internal.hpp"
ABC_NAMESPACE_IMPL_START
namespace CaDiCaL {
void Internal::init_watches () {
assert (wtab.empty ());
CADICAL_assert (wtab.empty ());
if (wtab.size () < 2 * vsize)
wtab.resize (2 * vsize, Watches ());
LOG ("initialized watcher tables");
@ -15,7 +19,7 @@ void Internal::clear_watches () {
}
void Internal::reset_watches () {
assert (!wtab.empty ());
CADICAL_assert (!wtab.empty ());
erase_vector (wtab);
LOG ("reset watcher tables");
}
@ -25,7 +29,7 @@ void Internal::reset_watches () {
void Internal::connect_watches (bool irredundant_only) {
START (connect);
assert (watching ());
CADICAL_assert (watching ());
LOG ("watching all %sclauses", irredundant_only ? "irredundant " : "");
@ -81,7 +85,7 @@ void Internal::connect_watches (bool irredundant_only) {
void Internal::connect_binary_watches () {
START (connect);
assert (watching ());
CADICAL_assert (watching ());
LOG ("watching binary clauses");
@ -97,7 +101,7 @@ void Internal::connect_binary_watches () {
}
void Internal::sort_watches () {
assert (watching ());
CADICAL_assert (watching ());
LOG ("sorting watches");
Watches saved;
for (auto lit : lits) {
@ -107,7 +111,7 @@ void Internal::sort_watches () {
watch_iterator j = ws.begin ();
const_watch_iterator i;
assert (saved.empty ());
CADICAL_assert (saved.empty ());
for (i = j; i != end; i++) {
const Watch w = *i;
@ -124,3 +128,5 @@ void Internal::sort_watches () {
}
} // namespace CaDiCaL
ABC_NAMESPACE_IMPL_END

Some files were not shown because too many files have changed in this diff Show More