# Solver Notes

## Formula Notes

- Target family is `graceful-production`.
- The official SAT Competition 2022 description says Graceful Production uses
  parameters `(D, m, k, u)`: `D` days, `u` production units, capacity `m`
  fixed to 1000 for the submitted set, and an at-least target `u*k`. The
  constraints require daily production totals to meet the target, totals to be
  nondecreasing across consecutive days, and daily minima to be nondecreasing.
- Comment-free CNFs have a regular long-clause signature. For files named
  `GP_D_U_K`, the formulas contain exactly `2*(D-1)` all-positive clauses of
  size `U`. This is recoverable structurally from the CNF and does not require
  comments or filenames at runtime.
- The CNFs appear to be Picat-generated finite-domain/bit-vector encodings.
  Long clauses encode domain choices around the robust/minimum constraints.
  Many small clauses are comparator, equality, and Tseitin support clauses.
- All visible training instances and the provided baseline entries are SAT. No
  UNSAT proof path is implemented.

## Current Solver

- `solver.cpp` now implements a from-scratch watched-literal propagator, a
  buffered DIMACS parser, and buffered model output.
- It performs deterministic greedy completion in positive variable order:
  assign an unassigned variable true, propagate, and if that immediate branch
  conflicts, roll back and try false. If both branches conflict, return
  `UNKNOWN`.
- This positive phase matches the monotone Picat encoding well. On the local
  train split it solved all 16 instances with independently verified models.
- Before printing `s SATISFIABLE`, the solver scans every original CNF clause
  against the completed assignment. Any failed verification returns `UNKNOWN`.
- The solver never prints `UNSATISFIABLE`.

## Local Results

All `/data/train/*.cnf.xz` instances solved locally after decompression with a
180s timeout. After parser/output optimization, local wall-clock average was
about 4.23s. Slowest local cases were the `GP_100_950*`/`GP_100_951*`
instances at about 6.2s. Peak local memory on those cases was about 2.2 GB.

## Techniques Tried

- CNF profiling over all training instances: variable/clause counts,
  clause-size distributions, long one-of group detection, and variable-range
  checks. The profiler lives in `tools/profile.py`.
- A from-scratch WalkSAT-style local search engine over the full CNF with final
  model verification. It was sound but did not converge on a representative
  instance within local test windows.
- Greedy false-first unit-propagation completion. It quickly found conflicts in
  this encoding and returned `UNKNOWN`.
- Positive-first watched completion. This is the current winning path.

## Remaining Things To Try

- Reduce memory by replacing `vector<vector<int>>` watch lists with a compact
  linked-array representation. This should improve broker scalability on
  larger hidden instances.
- Add structural detection for the long-clause signature and switch to
  `UNKNOWN` earlier on clearly unsupported formulas.
- Fully reconstruct the high-level production variables and emit a model by
  assigning the Picat input variables directly, then using propagation only for
  auxiliaries.
- If UNSAT instances appear in future splits, design a VeriPB strategy before
  claiming UNSAT.

## Known Limitations

- The solver is SAT-only.
- The greedy completion has only one level of local branch repair. It is sound
  because of final verification, but incomplete.
- Current memory use is higher than necessary because watch lists use STL
  vectors for every literal.

## Changelog

- Initial scaffold replaced with C++ CNF parser and exploratory local-search
  implementation.
- Added long-clause group detection, arithmetic trial assignment experiments,
  greedy positive initialization, and a greedy unit-propagation completion
  experiment.
- Disabled untrusted solving paths in the parent submission; runtime returned
  `UNKNOWN` after parsing to preserve soundness.
- Added `tools/profile.py` for clause-size and long-domain profiling.
- Replaced the conservative stub with a watched-literal positive-first greedy
  SAT model builder plus full model verification.
- Updated `meta.json` to describe the watched positive-phase solver.
- Replaced stream-based parsing and per-literal `printf` model output with
  buffered implementations; added watch-list reserve counts to reduce runtime.
