Skip to content

Commit

Permalink
Merge pull request #7 from lixitrixi/main
Browse files Browse the repository at this point in the history
Kissat bindings
  • Loading branch information
ozgurakgun authored Oct 4, 2023
2 parents cda01a7 + 113b506 commit ec06c22
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 6 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/kissat-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# https://doc.rust-lang.org/cargo/guide/continuous-integration.html
# https://ectobit.com/blog/speed-up-github-actions-rust-pipelines/
name: 'solvers/kissat'
on:
push:
paths:
- 'solvers/kissat/**'
pull_request:
paths:
- 'solvers/kissat/**'
workflow_dispatch:

jobs:
ubuntu:
name: 'solvers/kissat: Ubuntu Build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- working-directory: ./solvers/kissat
run: rustup update stable && rustup default stable

- working-directory: ./solvers/kissat
run: cargo build -vv

mac:
name: 'solvers/kissat: Mac Build'
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

- name: Set up cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- working-directory: ./solvers/kissat
run: rustup update stable && rustup default stable

- working-directory: ./solvers/kissat
run: rustup target add aarch64-apple-darwin

- working-directory: ./solvers/kissat
run: cargo build -vv

tests:
name: 'solvers/kissat: Tests'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- working-directory: ./solvers/kissat
run: rustup update stable && rustup default stable

- working-directory: ./solvers/kissat
run: cargo test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target

solvers/**/vendor/build
106 changes: 101 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[workspace]

members = ["solvers/minion", "solvers/chuffed"]
members = ["solvers/*"]
exclude = []
10 changes: 10 additions & 0 deletions solvers/kissat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "kissat_rs"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
kissat-rs = { git = "https://github.com/firefighterduck/kissat-rs", branch = "main", version = "0.1" }
kissat-sys = { git = "https://github.com/firefighterduck/kissat-rs", branch = "main", version = "0.1" }
31 changes: 31 additions & 0 deletions solvers/kissat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#[cfg(test)]
fn test1() {
use kissat_rs::Solver;
use kissat_rs::Assignment;

// Define three literals used in both formulae.
let x = 1;
let y = 2;
let z = 3;

// Construct a formula from clauses (i.e. an iterator over literals).
// (~x || y) && (~y || z) && (x || ~z) && (x || y || z)
let formula1 = vec![vec![-x, y], vec![-y, z], vec![x, -z], vec![x, y, z]];
let satisfying_assignment = Solver::solve_formula(formula1).unwrap();

// The formula from above is satisfied by the assignment: x -> True, y -> True, z -> True
if let Some(assignments) = satisfying_assignment {
assert_eq!(assignments.get(&x).unwrap(), &Some(Assignment::True));
assert_eq!(assignments.get(&y).unwrap(), &Some(Assignment::True));
assert_eq!(assignments.get(&z).unwrap(), &Some(Assignment::True));
}

// (x || y || ~z) && ~x && (x || y || z) && (x || ~y)
let formula2 = vec![vec![x, y, -z], vec![-x], vec![x, y, z], vec![x, -y]];
let unsat_result = Solver::solve_formula(formula2).unwrap();

// The second formula is unsatisfiable.
// This can for example be proved by resolution.
assert_eq!(unsat_result, None);
}

0 comments on commit ec06c22

Please sign in to comment.