Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.13 KB

README.md

File metadata and controls

40 lines (30 loc) · 1.13 KB

sat-solver-js

Simple SAT solver for javascript

Usage

const SATInstance = require('sat-solver-js');

const sat = new SATInstance();
sat.parseClause('A B');
sat.parseClause('A ~C');
sat.parseClause('~A ~B');
sat.parseClause('B C');

let ret = sat.solutions(); // => array with the solutions
console.log(ret);
// [ '~A, B, ~C', 'A, ~B, C' ]

const partialSolution = sat.createSolution();
partialSolution.set('A', true);
ret = sat.solutions(partialSolution); // => solutions having A=true
console.log(ret);
// [ 'A, ~B, C' ]

The method solutions has two optional parameters:

  • partialSolution (default null): a partial assignment of the variables to which the solutions have to comply.
  • verboseLevel (default 0):
    • 0: prints nothing
    • 1: prints the number of solutions or satisfying assigments
    • 2: prints every solution found
    • 3: prints details of the process

To run the examples: node examples/{filename}.

Acknowledgements