Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ant0in/Max3SATLasVegas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language Badge Version Badge License Badge School Badge

🔎 Max 3-SAT Las Vegas Solver

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.

📜 Description

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

⚙️ Installation

To install the project locally, clone the repository and move into its directory:

git clone [email protected]:Ant0in/Max3SATLasVegas.git
cd Max3SATLasVegas

🚀 Use the Solver

The project works from the command line and supports two modes:

  1. Single-file mode – run the Las Vegas MAX-3SAT solver on one .cnf instance.
  2. Batch mode – run the solver on every .cnf file inside a directory.

Both modes accept optional parameters such as the maximum number of iterations and verbosity.


📄 Single File

To run the solver on a single CNF file:

python main.py --file res/example.cnf --verbose

This 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.

📂 Directory of Instances

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.

📝 Example of Accepted CNF Format

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 c are 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.

📊 Benchmarks

Standard MAX-3SAT benchmark instances can be found at the SATLIB repository: https://www.cs.ubc.ca/~hoos/SATLIB/benchm.html

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.

🙏 Acknowledgements

This project was developed for the Randomized algorithms course INFO—F413. Special thanks to Jean Cardinal (ULB) for their guidance and support.

About

Max3SAT Solver using a LasVegas Algorithm

Topics

Resources

License

Stars

Watchers

Forks

Languages