Code Monkey home page Code Monkey logo

togasat's Introduction

togasat

togasat based on minisat is a header-only CDCL SAT Solver for programming contests.

Minimum requirement C++ version

  • C++11

How to use togasat as a library

At first, include the header (or do copy & paste):

#include "togasat.hpp"

Make a solver object.

   togasat::Solver solver;

If you want to add a (x1 v x2 v not x3) clause

    std::vector<int> clause;
    clause.push_back(1);  // x1
    clause.push_back(2);  // x2
    clause.push_back(-3);  // not x3

    solver.addClause(clause);  // add (x1 v x2 v not x3)

YOU MUST NOT ADD CLAUSES THAT CONTAIN 0, IT WILL CAUSE A SAT SOLVER ABORTION

After adding all clauses, call .solve() method.

    togasat::lbool status = solver.solve();

The return value:

  • status is 0, SATISFIABLE
  • status is 1, UNSATSFIABLE
  • status is 2, UNKNOWN

Also, you can get the assignments, e.g.

   solver.assigns[0] = 0;  // X_1 = True
   solver.assigns[1] = 1;  // X_2 = False
   solver.assigns[i] = 0;  // X_{i + 1} = True

You should take care that 0 denotes true and 1 denotes false.

How to solve cnf

$ ./togasat <cnf problem>
int main(int argc, char *argv[]) {
    togasat::Solver solver;
    std::string problem_name = argv[1];
    solver.parseDimacsProblem(problem_name);  // parse problem
    togasat::lbool status = solver.solve();  // solve sat problem
    solver.printAnswer();  // print answer
}

SATISFIABLE

If Sat Solver proves a given problem is SATISFIABLE(SAT), it prints SAT and a model for the problem.

SAT
-1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 13 -14 15 16 0

The model is separated by a space and ended with zero(0).

  • A positive integer represents True.
  • A negative integer represents False.

For example,-1 represents X1=False,13 represents X13=True.

UNSATISFIABLE

It only prints UNSAT.

UNSAT

Algorithms

  • DPLL
  • Clause learning
  • Two literal watching
  • Back jump
  • Phase saving
  • Luby restart
  • VSIDS

Problems solved by togasat

Contributors

Note

Welcome any pull requests, fix of typo, refactoring, correction of documents and so on. If you can solve a competitive programming problem by togasat, please let me know and you make a pull request. It's very helpful for me.

Your star makes me motivated

togasat's People

Contributors

claw88 avatar kmyk avatar koba-e964 avatar mugenen avatar togatoga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

togasat's Issues

Assertion `value(p) == l_Undef` failed

Code

// sat_solver.cpp
#include <iostream>
#include <vector>
#include "togasat.hpp"

int main() {
    togasat::Solver solver;
    std::vector<int> clause0 = {1};
    std::vector<int> clause1 = {1};
    solver.addClause(clause0);
    solver.addClause(clause1);
    std::cout << solver.solve() << std::endl;

    return 0;
}

Compilation

g++ -fPIC -O3 sat_solver.cpp -o sat_solver

Execution

./sat_solver
sat_solver: togasat.hpp:258: void togasat::Solver::uncheckedEnqueue(togasat::Solver::Lit, togasat::CRef): Assertion `value(p) == l_Undef' failed.
Aborted (core dumped)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.