{"id":13748693,"url":"https://github.com/togatoga/screwsat","last_synced_at":"2025-05-09T11:31:13.606Z","repository":{"id":54818700,"uuid":"181381633","full_name":"togatoga/screwsat","owner":"togatoga","description":"A simple CDCL(Conflict-Driven-Clause-Learning) SAT solver in Rust.","archived":false,"fork":false,"pushed_at":"2024-06-27T17:48:30.000Z","size":220,"stargazers_count":38,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T10:17:26.729Z","etag":null,"topics":["competitive-programming","math","rust","sat","sat-solver"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/togatoga.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-14T23:36:21.000Z","updated_at":"2025-03-12T15:01:25.000Z","dependencies_parsed_at":"2024-01-13T01:40:02.191Z","dependency_job_id":"0c1bc56f-cf59-42f8-80dc-4941e5f7e8ce","html_url":"https://github.com/togatoga/screwsat","commit_stats":{"total_commits":112,"total_committers":3,"mean_commits":"37.333333333333336","dds":0.1607142857142857,"last_synced_commit":"9b3014c37405ba301ced16f26833893f7b2c3938"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/togatoga%2Fscrewsat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/togatoga%2Fscrewsat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/togatoga%2Fscrewsat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/togatoga%2Fscrewsat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/togatoga","download_url":"https://codeload.github.com/togatoga/screwsat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253240350,"owners_count":21876593,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["competitive-programming","math","rust","sat","sat-solver"],"created_at":"2024-08-03T07:00:47.576Z","updated_at":"2025-05-09T11:31:12.958Z","avatar_url":"https://github.com/togatoga.png","language":"Rust","funding_links":[],"categories":["Projects"],"sub_categories":["Provers and Solvers"],"readme":"# screwsat\n\n[![Crates.io](https://img.shields.io/crates/v/screwsat)](https://crates.io/crates/screwsat)\n\nA simple CDCL(Conflict-Driven-Clause-Learning) SAT Solver in `Rust`.  \nI wrote it very simple to help people(including me) understand the inside of SAT Solver.  \n\n\nI have implemented the core SAT Solver algorithms and techniques in `screwsat`.  \n#### Algorithms and Techniques\n- CDCL(Conflict-Driven-Clause-Learning)\n- Back Jump\n- Two-Literal-Watching\n- VSIDS\n\nThe performance of `screwsat` isn't as good as other modern sat solvers.  \nBut you can grasp some important points of SAT Solver from `screwsat`(I hope).  \n\n\n`screwsat` is written in only one file and `std` libraries. You can use it for competitive programming problems.  \n\n#### Accepted by `screwsat`\n- [AtCoder Beginner Contest 187 F - Close Group](https://atcoder.jp/contests/abc187/submissions/19235301)\n- [天下一プログラマーコンテスト2016本戦（オープンコンテスト） B - 今年の B 問題](https://atcoder.jp/contests/tenka1-2016-final-open/submissions/19375260)\n\n\n#### Testing\n\nYou need to pull all SAT problems under the `cnf` directory that are stored by [`git-lfs`](https://git-lfs.github.com/) to run `cargo test`.\n\n```\n% git lfs pull\n% cargo test -- --nocapture\n```\n\n## How to use\n\n`screwsat` can be used as a library and a command-line tool.\n\n## Command\n\n### Install\n\n```bash\n% cargo install --locked screwsat\n```\n\n### Usage(cmd)\n\n```bash\n% screwsat --help\nUSAGE: screwsat [options] \u003cinput-file\u003e [output-file]\n\n% cat examples/sat.cnf\nc Here is a comment.\nc SATISFIABLE\np cnf 5 3\n1 -5 4 0\n-1 5 3 4 0\n-3 -4 0\n\n% screwsat examples/sat.cnf\ns SATISFIABLE\n-1 -2 -3 -4 -5 0\n\n% screwsat cnf/unsat/unsat.cnf\ns UNSATISFIABLE\n\n% screwsat examples/sat.cnf sat_result.txt\n% cat sat_result.txt\nSAT\n-1 -2 -3 -4 -5 0\n\n```\n\n## Library\n\nYou need to add `screwsat` to `Cargo.toml`.\n\n```toml\nscrewsat=\"*\"\n```\n\nOR\n\nCopy `src/lib.rs` and Paste it. (Competitive Programming Style)\n\n### Usage(lib)\n\n```rust\nuse std::vec;\n\nuse screwsat::solver::*;\nuse screwsat::util;\nfn main() {\n    {\n        // Create a default Solver struct\n        let mut solver = Solver::default();\n        // A problem is (x1 v ¬x5 v x4) ∧ (¬x1 v x5 v x3 v x4) ∧ (x3 v x4)\n        let clauses = vec![\n            // (x1 v ¬x5 v x4)\n            vec![Lit::from(1), Lit::from(-5), Lit::from(4)],\n            // (¬x1 v x5 v x3 v x4)\n            vec![Lit::from(-1), Lit::from(5), Lit::from(3), Lit::from(4)],\n            // (x3 v x4)\n            vec![Lit::from(3), Lit::from(4)],\n        ];\n        // Add clauses to solver\n        clauses\n            .into_iter()\n            .for_each(|clause| solver.add_clause(\u0026clause));\n\n        let status = solver.solve(None);\n        // Sat: A problem is SATISFIABLE.\n        println!(\"{:?}\", status);\n        // print the assignments satisfy a given problem.\n        // x1 = false x2 = false x3 = false x4 = true x5 = false\n        solver.models.iter().enumerate().for_each(|(var, assign)| {\n            let b = match assign {\n                LitBool::True =\u003e true,\n                _ =\u003e false,\n            };\n            print!(\"x{} = {} \", var + 1, b);\n        });\n        println!(\"\");\n    }\n\n    {\n        // Parse a DIMACS CNF file\n        // c\n        // c This is a sample input file.\n        // c (unsatisfiable)\n        // c\n        // p cnf 3 5\n        // 1 -2 3 0\n        // -1 2 0\n        // -2 -3 0\n        // 1 2 -3 0\n        // 1 3 0\n        // -1 -2 3 0\n        let input = std::fs::File::open(\"example/unsat.cnf\").unwrap();\n        let cnf = util::parse_cnf(input).unwrap();\n        // 3\n        let variable_num = cnf.var_num.unwrap();\n        // 5\n        //let clause_num = cnf.cla_num.unwrap();\n\n        let clauses = cnf.clauses;\n        // Create a new Solver struct\n        let mut solver = Solver::new(variable_num, \u0026clauses);\n        let status = solver.solve(None);\n        // Unsat: A problem is UNSATISFIABLE\n        println!(\"{:?}\", status);\n    }\n\n    {\n        // Set the time limitation\n        // You might want to set the time limitation for very hard problem\n        let input = std::fs::File::open(\"example/hard.cnf\").unwrap();\n        let cnf = util::parse_cnf(input).unwrap();\n        let mut solver = Solver::default();\n        let clauses = cnf.clauses;\n        clauses\n            .into_iter()\n            .for_each(|clause| solver.add_clause(\u0026clause));\n        // 5 sec\n        let status = solver.solve(Some(std::time::Duration::from_secs(5)));\n        // Indeterminate\n        println!(\"{:?}\", status);\n    }\n}\n```\n\n### Appreciation\n\nThis code is really inspired by his good simple code [not522's SAT Solver](https://github.com/not522/CompetitiveProgramming/blob/master/include/math/sat.hpp)\n\n### Contribution\nContributions and feedbacks are welcome. (e.g., fix typo and tedious code and my English, report bugs/issues, **GIVE ME GITHUB STARS**)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftogatoga%2Fscrewsat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftogatoga%2Fscrewsat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftogatoga%2Fscrewsat/lists"}