# Solver Notes

## Formula Notes

- The family is Profitable Robust Production (PRP), generated by Picat's SAT backend.
- File names use `PRP_D_u`; structural detection confirms there are `D` robust-minimum blocks, each with `u` candidate rows.
- The first clause introduces the first Tseitin variable. Variables below that point are Picat/log-encoding variables and reification variables; later variables are arithmetic Tseitin auxiliaries.
- The opening repeated block encodes `min(day_j_units)` with comparators `unit_value >= min_value`, equality reifiers for each unit, one positive selector clause requiring an arg-min, and XOR-style clauses that force every nonselected row to differ from the minimum.
- Picat's row variables have trailing domain clauses that make the six row bits move together. A canonical satisfying min-block assignment is: selected first row and minimum all false; every other row all true; all nonfirst selectors false.
- After the min blocks and unit clauses are propagated, the remaining hard choices are dominated by all-positive domain clauses. A shortest-unsatisfied-positive-clause search with chronological backtracking completes the primary and Tseitin layers on all train instances tested.
- The public benchmark description says the model contains profit, steady production, robust-minimum, and boundary constraints. The CNF itself is comment-free in evaluation, so the solver uses only structural properties.

## Techniques Used

- Parse sanitized DIMACS with a fast scanner and infer the primary/Tseitin split from the first generated comparator clause.
- Structurally match the 92-clause Picat min-row template and the following reversed selector clause; if this detector finds no blocks, return `UNKNOWN`.
- Seed each detected min block with the canonical model described above.
- Build watched literals over the full CNF and propagate units plus the min seed.
- Maintain all-positive clauses with a remaining-literal heap. Branch on the shortest unsatisfied positive clause, using occurrence-score ordering and chronological backtracking when a candidate conflicts.
- Complete any remaining variables with watched propagation, then verify every original clause before printing `SATISFIABLE`. No UNSAT claims are made.

## Experiments

- Primary-only formulas solve very quickly on sampled training instances; for example `PRP_30_35` solved in a few thousand flips.
- Completing the full Tseitin layer is the hard part. On `PRP_30_35`, full local search from a primary seed got close but did not reliably reach zero within short local runs.
- A bounded exact repair over the final violated clauses was prototyped. It reduced the problem to small neighborhoods in some runs but was not reliable enough to ship.
- A direct all-zero/all-max construction was tested against primary clauses and failed because Picat's optimized arithmetic/log encoding has additional bit-level consistency constraints.
- New deterministic min-block seeding plus positive-clause BCP solved every local training instance. Representative local times/memory: `PRP_30_35` 0.19s/49MB, `PRP_100_150` 3.08s/660MB, `PRP_100_600` 12.72s/2.64GB.

## Known Limitations

- This version is SAT-only and incomplete. It is designed for the detected PRP/Picat structure and returns `UNKNOWN` on unsupported structures, failed detections, or failed model completion.
- It assumes the robust-minimum row template and all-positive-domain completion pattern remain stable across target instances.
- It does not emit VeriPB proofs and therefore never claims UNSAT.

## Remaining Things To Try

- Reduce peak memory for the largest formulas by replacing full literal storage with streamed verification or compressed clause starts.
- Replace recursive chronological backtracking with an explicit stack. The current solver runs the search in a pthread with an explicit 256MB stack to avoid default-stack crashes on large instances.
- Further decode the high-level production/profit variables; a direct high-level assignment could remove most generic propagation state.

## Changelog

- Initial scaffold: placeholder solver returned `UNKNOWN`.
- Added analysis tools under `tools/` for primary-clause profiling, min-block detection, greedy propagation, SLS exploration, and repair experiments.
- Implemented C++ solver using primary projection seeding plus full weighted focused local search.
- Updated metadata and build notes for broker submission.
- Replaced SLS with deterministic min-block construction, watched-literal BCP, all-positive-clause chronological backtracking, complete model verification, and explicit-stack execution for large instances.
- Added `tools/greedy_semantic.py` and `tools/dpll_semantic.py` to document and reproduce the successful structure-driven prototype.
- Updated metadata for the new solver approach.
