Boolean Constraint Propagation Library
ClauseArena stores live clauses as
[payload/flags][ClauseId][glue:8|pos:24][literals...]. Payload counts all
words after the first header word: ID, position word and literals for live
clauses, unused words for deleted records. Every record advances by
1 + payload; live literal count is payload - ClauseHeader::META. The
position word holds the search position for circular watch replacement
(propagator scratch, initialized to 2) and an 8-bit glue/score byte.
ClauseRef is a direct word offset below ClauseRef::MAX_OFFSET (2^31), so
that the topmost bit of a reference is free for tagging;
arena.id(ref) and arena.ref(id) map between offsets and stable metadata IDs.
arena.refs() is indexed by ID, with UNDEF entries for deleted clauses.
IDs are not reused until clear().
Iteration scans live records and yields views exposing header(), id(),
ref() and literals(). Mutable views allow literal and user-flag changes.
Ordinal indexing is removed; formulas accept ClauseId or ClauseRef.
shrink(ref, size) retains a literal prefix and turns the tail into padding;
erase(ref) only sets the deletion bit, preserving payload length.
Both preserve other clauses' offsets.
ClauseFlags centralizes named deleted()/learned() accessors and
setDeleted()/setLearned() setters; six bits remain reserved. Flags are
returned by value: modify them and write them back with setFlags().
Public static constexpr masks also support test(mask) (any bit set) and
set(mask, value = true), so adding a flag only requires another mask constant.
Arena/view setters reject deletion flags; use erase() for bookkeeping.
compact() removes dead storage, updates the ID table and returns old/new
reference pairs for live clauses. External offsets must be relocated or rebuilt;
ID-indexed metadata stays valid. Growth can invalidate views; compaction
invalidates all views, iterators and old references. While a propagator is
attached, size and identity changes must be announced to it (see below).
Trail is the assignment stack: values per literal,
reason and level per variable, decision levels, and the propagation queue
[head, size()). It knows nothing about clauses. A level is a contiguous
block of decisions (literals without reason, pushed by the client) followed by
their consequences (assigned by a propagator); this shape is asserted:
newLevel() requires an empty queue, push() on a non-root level requires
that the level has not been propagated yet. After a conflict, backtrack before
pushing again. Out-of-order assignments at lower levels (chronological
backtracking) are kept by backtrackToRetaining() and queued again, while
backtrack()/backtrackTo() assume there are none; literals(level) is
therefore the segment opened at a level and level(var) is authoritative.
Propagator is the interface of unit
propagation over one arena and one trail: attach(ref) (assigns units),
detach(ref), relocate(relocation) after compact(), and propagate(),
which returns the conflicting clause or UNDEF. A propagator owns the order of
literals within clauses. OccurrencePropagator
is the read-only reference implementation with full occurrence lists.
WatchPropagator implements two watched
literals with blocking literals, tagged binary watches (never visiting the
clause) and a circular replacement search resuming at the clause's position
word. Applications select the propagator with -p watch (default) or -p occ.
propagators.h collects the implementations
and creates the one selected by Options (makePropagator(options, arena, trail), names in PROPAGATOR_NAMES). Solver
owns a formula, a trail and a propagator and keeps them consistent:
construction attaches and propagates the root level, add()/learn()
attach, erase() detaches, compact() relocates, newVar() grows all
three, decide()/propagate() drive the search. It is solver state, not a
search procedure; those live in the applications. With -DPROPAN_STATS=ON
propagators maintain counters (Propagator::stats()).
Formulas (CNFFormula,
WCNFFormula) are containers; DIMACS input
is in dimacs.h (readCnf, readWcnf), the only
part of the library that depends on libarchive.
The library is header-only; applications compile it in. They are organized in
tiers under apps/ with shared helpers in apps/common:
apps/solvers(PROPAN_BUILD_SOLVERS): decision procedures.slursat <cnf|wcnf> [-s seed] [-k k] [-p propagator]runs SLUR, SLUR(k) (blocks ofkdecisions per level,k > 1) or SLUR(k) with immediate propagation (k < 0); on WCNF input it takes the hard clauses.apps/tests(PROPAN_BUILD_TESTS): test and benchmark drivers.probe <cnf|wcnf> [-p propagator] [-r rounds]performs failed literal probing with lifting of common implications; on WCNF it additionally probes the soft unit literals, the block of all of them, and a greedy selection. All reported counters depend only on propagation fixpoints and are therefore identical for every propagator, which makes them integration tests of the propagators.
Soft clause semantics (relaxation, activation literals, bounds) are application concerns; the library only parses and stores WCNF.
tests/data/instances holds small mostly-Horn CNF and
WCNF instances from benchmark-database.de
(provenance in its README). tests/integration.cmake
runs probe on each with every propagator against reference counters (label
integration, ctest -L integration), plus slursat on the instances it
solves. tests/benchmark.py runs the same instances and
prints a timing table per propagator; --large downloads bigger instances
listed in tests/data/instances/large.txt into the build directory first.
CNFFormula f("formula.cnf");
Trail trail(f.nVars());
WatchPropagator prop(f.clauses(), trail); // or OccurrencePropagator
if (!prop.attachAll(f.clauses()) || prop.propagate() != ClauseRef()) return UNSAT;
trail.newLevel();
trail.push(Lit(3)); // decision; push(span) for a block of decisions
ClauseRef conflict = prop.propagate(); // UNDEF if none
trail.backtrack();Requires CMake 3.20, a C++20 compiler and libarchive (libarchive-dev).
cmake -S . -B build
cmake --build build
./build/apps/solvers/slursat <formula.cnf> [-s seed] [-k k] [-p watch|occ]
./build/apps/tests/probe <formula.cnf|formula.wcnf> [-p watch|occ]Command lines are parsed with CLI11,
vendored in third_party/CLI11; --help lists the options.
Unit tests use doctest 2.4.12, vendored in
third_party/doctest with its license; applications use
CLI11 2.4.2 from third_party/CLI11. No download is needed.
CTest runs unit tests as one suite and applications end-to-end.
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure-DPROPAN_WERROR=ON treats warnings as errors, -DPROPAN_SANITIZERS=ON builds
with AddressSanitizer and UndefinedBehaviorSanitizer. Integration tests carry
the label integration (ctest -L integration / -LE integration). The test
build also compiles every public header on its own to keep them self-contained.
.github/workflows/ci.yml builds and tests on
every push to main and every pull request: GCC and Clang in Release with
-Werror and in Debug with sanitizers on Ubuntu, plus Clang on macOS. Release
jobs also run the integration tests; the GCC release job attaches the
propagator benchmark table to the job summary.