Welcome to my Max 3-SAT Las Vegas Solver project! This project is part of the Randomized Algorithms INFO-F413 course at ULB. It implements a Max 3-SAT solver using a randomized Las Vegas algorithm, providing an efficient probabilistic approach for finding assignments that maximize the number of satisfied clauses.
This Python project provides:
- A Max 3-SAT solver based on a randomized Las Vegas algorithm.
- A full implementation of literals, clauses, and Boolean assignments for 3-CNF formulas.
- Methods to evaluate, optimize, and search for assignments that guarantees the number of satisfied clauses is at least
7m/8.
For more detailed problem specifications and additional information, please refer to the project specification doc/SatisfactionAssignment-1.pdf or to the report doc/infof413_assignment_2.pdf
To install the project locally, clone the repository and move into its directory:
git clone [email protected]:Ant0in/Max3SATLasVegas.git
cd Max3SATLasVegasThe project works from the command line and supports two modes:
- Single-file mode – run the Las Vegas MAX-3SAT solver on one
.cnfinstance. - Batch mode – run the solver on every
.cnffile inside a directory.
Both modes accept optional parameters such as the maximum number of iterations and verbosity.
To run the solver on a single CNF file:
python main.py --file res/example.cnf --verboseThis loads the instance, applies the Las Vegas MAX-3SAT algorithm, and prints:
- The best number of satisfied clauses found,
- Its proportion relative to the total clause count,
- (with
--verbose) The Boolean assignment that achieved it.
To automatically process every .cnf file inside a folder:
python main.py --dir res/The solver iterates over all matching files and reports the best result for each.
The solver expects files in standard DIMACS CNF format (as commonly used in SAT competitions).
A typical 3-SAT instance looks like this:
c This Formular is generated by mcnf
c
c horn? no
c forced? no
c mixed sat? no
c clause length = 3
c
p cnf 20 91
-10 -16 5 0
16 -6 5 0
-17 -14 -18 0
...
3 -9 8 0
%
0- Lines beginning with
care comments. - The line
p cnf <num_vars> <num_clauses>declares the problem. - Each clause is a list of integers ending with
0. - Negative integers represent negated literals.
Any .cnf file placed in the res/ directory following this structure will be correctly parsed by the solver.
Standard MAX-3SAT benchmark instances can be found at the SATLIB repository: https://www.cs.ubc.ca/~hoos/SATLIB/benchm.html
This project is licensed under the MIT License. See the LICENSE file for more details.
This project was developed for the Randomized algorithms course INFO—F413. Special thanks to Jean Cardinal (ULB) for their guidance and support.