Skip to content

Commit

Permalink
Add initial Intel SAT interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed Oct 12, 2023
1 parent 2bbd7d9 commit 1301bf0
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "crates/pindakaas-cadical/vendor/cadical"]
path = crates/pindakaas-cadical/vendor/cadical
url = https://github.com/arminbiere/cadical.git
[submodule "crates/pindakaas-intel-sat/vendor/intel_sat"]
path = crates/pindakaas-intel-sat/vendor/intel_sat
url = https://github.com/alexander-nadel/intel_sat_solver.git
2 changes: 1 addition & 1 deletion crates/pindakaas-cadical/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pindakaas-cadical"
version = "0.1.0"
version = "1.8.0"
edition = "2021"
build = "build.rs"
links = "cadical"
Expand Down
14 changes: 14 additions & 0 deletions crates/pindakaas-intel-sat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "pindakaas-intel-sat"
version = "0.1.0"
edition = "2021"
build = "build.rs"
links = "intel_sat"
exclude = ["vendor/intel_sat"]
include = ["vendor/intel_sat/*.cc"]

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }

[dependencies]
pindakaas-build-macros = { path = "../pindakaas-build-macros" }
24 changes: 24 additions & 0 deletions crates/pindakaas-intel-sat/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
fn main() {
let src = [
"vendor/intel_sat/Topi.cc",
"vendor/intel_sat/TopiAsg.cc",
"vendor/intel_sat/TopiBacktrack.cc",
"vendor/intel_sat/TopiBcp.cc",
"vendor/intel_sat/TopiBitCompression.cc",
"vendor/intel_sat/TopiCompression.cc",
"vendor/intel_sat/TopiConflictAnalysis.cc",
"vendor/intel_sat/TopiDebugPrinting.cc",
"vendor/intel_sat/TopiDecision.cc",
"vendor/intel_sat/TopiRestart.cc",
"vendor/intel_sat/TopiWL.cc",
"vendor/intel_sat/Topor.cc",
"vendor/intel_sat/ToporIpasir.cc",
];

let mut builder = cc::Build::new();
let build = builder.cpp(true).flag_if_supported("-std=c++20");

build.files(src);

build.compile("intel_sat");
}
3 changes: 3 additions & 0 deletions crates/pindakaas-intel-sat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use pindakaas_build_macros::ipasir_definitions;

ipasir_definitions!();
1 change: 1 addition & 0 deletions crates/pindakaas-intel-sat/vendor/intel_sat
Submodule intel_sat added at 65e7e7
4 changes: 3 additions & 1 deletion crates/pindakaas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ libloading = "0.8"
tracing = { version = "0.1", optional = true }

# Optional Solver Interfaces
splr = { version = "0.17", optional = true }
pindakaas-cadical = { path = "../pindakaas-cadical", optional = true }
pindakaas-intel-sat = { path = "../pindakaas-intel-sat", optional = true }
splr = { version = "0.17", optional = true }

[dev-dependencies]
splr = { version = "0.17", features = ["incremental_solver"] }
Expand All @@ -32,4 +33,5 @@ traced_test = { path = "../traced_test" }
[features]
trace = ["tracing"]
cadical = ["pindakaas-cadical"]
intel-sat = ["pindakaas-intel-sat"]
default = []
7 changes: 4 additions & 3 deletions crates/pindakaas/src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::{ClauseDatabase, Lit, Valuation, Var};

pub mod libloading;

#[cfg(feature = "splr")]
pub mod splr;

#[cfg(feature = "cadical")]
pub mod cadical;
#[cfg(feature = "intel-sat")]
pub mod intel_sat;
#[cfg(feature = "splr")]
pub mod splr;

pub trait Solver: ClauseDatabase {
/// Return the name and the version of SAT solving library.
Expand Down
39 changes: 39 additions & 0 deletions crates/pindakaas/src/solver/cadical.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
use super::ipasir_solver;

ipasir_solver!(pindakaas_cadical, Cadical);

#[cfg(test)]
mod tests {
#[cfg(feature = "trace")]
use traced_test::test;

use super::*;
use crate::{
linear::LimitComp,
solver::{SolveResult, Solver},
CardinalityOne, ClauseDatabase, Encoder, PairwiseEncoder,
};

#[test]
fn test_cadical() {
let mut slv = Cadical::default();
let a = slv.new_var();
let b = slv.new_var();
PairwiseEncoder::default()
.encode(
&mut slv,
&CardinalityOne {
lits: vec![a, b],
cmp: LimitComp::Equal,
},
)
.unwrap();
let res = slv.solve(
|value| {
assert!(
(value(!a).unwrap() && value(b).unwrap())
|| (value(a).unwrap() && value(!b).unwrap()),
)
},
|_| {},
);
assert_eq!(res, SolveResult::Sat);
}
}
42 changes: 42 additions & 0 deletions crates/pindakaas/src/solver/intel_sat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use super::ipasir_solver;

ipasir_solver!(pindakaas_intel_sat, IntelSat);

#[cfg(test)]
mod tests {
#[cfg(feature = "trace")]
use traced_test::test;

use super::*;
use crate::{
linear::LimitComp,
solver::{SolveResult, Solver},
CardinalityOne, ClauseDatabase, Encoder, PairwiseEncoder,
};

#[test]
fn test_intel_sat() {
let mut slv = IntelSat::default();
let a = slv.new_var();
let b = slv.new_var();
PairwiseEncoder::default()
.encode(
&mut slv,
&CardinalityOne {
lits: vec![a, b],
cmp: LimitComp::Equal,
},
)
.unwrap();
let res = slv.solve(
|value| {
assert!(
(value(!a).unwrap() && value(b).unwrap())
|| (value(a).unwrap() && value(!b).unwrap()),
)
},
|_| {},
);
assert_eq!(res, SolveResult::Sat);
}
}

0 comments on commit 1301bf0

Please sign in to comment.