Skip to content

Commit c6bfae6

Browse files
committed
Add binary decision ILP to SAT reduction
1 parent 3d3b020 commit c6bfae6

9 files changed

Lines changed: 609 additions & 4 deletions

File tree

‎docs/paper/reductions.typ‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
"SpinGlass": [Spin Glass],
270270
"QUBO": [QUBO],
271271
"ILP": [Integer Linear Programming],
272+
"DecisionILP": [Binary Decision Integer Linear Programming],
272273
"IntegerKnapsack": [Integer Knapsack],
273274
"Knapsack": [Knapsack],
274275
"PartiallyOrderedKnapsack": [Partially Ordered Knapsack],
@@ -5100,6 +5101,30 @@ In all graph problems below, $G = (V, E)$ denotes an undirected graph with $|V|
51005101
]
51015102
}
51025103

5104+
#problem-def("DecisionILP")[
5105+
Given a binary integer linear program with integer coefficients, a minimization
5106+
or maximization sense, and an integer bound $b$, find $x in {0,1}^n$ satisfying
5107+
all constraints and $c^top x <= b$ for minimization, or $c^top x >= b$ for maximization.
5108+
][
5109+
This is the objective-threshold form of binary ILP. Binary adders translate its
5110+
pseudo-Boolean constraints to SAT @een2006. Exhaustive enumeration takes
5111+
$O^*(2^n)$ time; this is the registered reference bound, not a claim of a tight
5112+
best-known SAT solving bound. The registered SAT reduction answers a fixed
5113+
objective-threshold query; no reverse ILP-to-DecisionILP edge is registered.
5114+
5115+
*Example.* #let x = load-model-example("DecisionILP")
5116+
Select exactly one of #x.instance.inner.variables.len() variables and minimize
5117+
the objective with coefficients
5118+
#x.instance.inner.objective.map(t => str(t.at(1))).join(", ").
5119+
At bound #x.instance.bound, the witness
5120+
$(#fmt-values(x.optimal_config))$ has objective #x.instance.bound and meets the bound.
5121+
#pred-commands(
5122+
"pred create --example " + problem-spec(x) + " -o x.json",
5123+
"pred solve x.json",
5124+
"pred evaluate x.json --config " + cli-config(x.optimal_config),
5125+
)
5126+
]
5127+
51035128
#{
51045129
let x = load-model-example("QuadraticAssignment")
51055130
let C = x.instance.cost_matrix
@@ -12603,6 +12628,78 @@ _Solution extraction and bounds._ Decode a string permutation, concatenate with
1260312628

1260412629
// Removed: SubsetSum → CapacityAssignment (unsound reduction, #1006)
1260512630

12631+
#let decision-ilp-sat = load-example("DecisionILP", "Satisfiability")
12632+
#reduction-rule("DecisionILP", "Satisfiability", example: true,
12633+
example-caption: [Binary ILP threshold query encoded with adders and CNF gates.],
12634+
extra: [
12635+
#pred-commands(
12636+
"pred create --example " + rule-spec(decision-ilp-sat) + " -o x.json",
12637+
"pred path " + problem-spec(decision-ilp-sat.source) + " " + problem-spec(decision-ilp-sat.target) + " --limit 1 -o paths.json",
12638+
"jq '.paths[0]' paths.json > route.json",
12639+
"pred reduce x.json --via route.json -o bundle.json",
12640+
"pred solve bundle.json --solver ilp",
12641+
)
12642+
*Example.* The source selects exactly one of
12643+
#decision-ilp-sat.source.instance.inner.variables.len() variables, with objective
12644+
coefficients #decision-ilp-sat.source.instance.inner.objective.map(t => str(t.at(1))).join(", ")
12645+
and minimization bound #decision-ilp-sat.source.instance.bound.
12646+
The CNF has #decision-ilp-sat.target.instance.num_vars variables and
12647+
#decision-ilp-sat.target.instance.clauses.len() clauses. Its canonical witness
12648+
projects to $(#fmt-values(decision-ilp-sat.solutions.at(0).source_config))$;
12649+
both the selected-variable sum and the objective equal the bound.
12650+
Lowering the bound to zero makes the instance infeasible: exactly one variable
12651+
must be selected, and every objective coefficient is at least one.
12652+
],
12653+
)[
12654+
Binary decision ILP reduces to CNF satisfiability by binary addition and
12655+
Tseitin gate equivalences, following the adder-based pseudo-Boolean encoding
12656+
approach @een2006. The encoding preserves the objective threshold and both
12657+
optimization senses; it does not turn an arbitrary feasible assignment into an optimum.
12658+
][
12659+
_Construction._ Let $n$ be the number of binary variables and $m$ the number of
12660+
constraints. Append the objective comparison as one additional row. Reserve
12661+
the first $n$ SAT variables for the source assignment and one false constant $f$.
12662+
For a row $sum_i a_i x_i diamond b$, replace each negative term by
12663+
$a_i x_i = (-a_i)(1-x_i)+a_i$. The normalized weights are $w_i=abs(a_i)$,
12664+
literals are $x_i$ or $not x_i$, and the threshold is
12665+
$B=b-sum_(i:a_i<0) a_i$. Set $T=sum_i w_i$.
12666+
Rows constant over $[0,T]$ emit either no clauses or an empty clause.
12667+
12668+
Otherwise, sum the weighted literals using $W$ bits, where $W$ is the binary
12669+
length of $T$. Starting from zero, add each weighted literal with ripple
12670+
full-adders: for input bits $a,b$ and carry $d$, compute
12671+
$p=a xor b$, output $p xor d$, and carry $(a and b) or (p and d)$.
12672+
Every partial sum is at most $T<2^W$, so the last carry can be discarded.
12673+
Use equivalence clauses for each AND, OR, and XOR gate; constants may be folded.
12674+
Equality asserts each sum bit. For a less-than-or-equal comparison, start
12675+
$q="true"$ and scan from least to most significant bit: set
12676+
$q=(not s_j or q)$ when $B_j=1$, and $q=(not s_j and q)$ when $B_j=0$.
12677+
Assert the final $q$. Greater-than-or-equal complements both $W$-bit operands
12678+
before applying the same comparator.
12679+
12680+
_Correctness._ ($arrow.r.double$) A feasible source assignment meeting the bound
12681+
satisfies every normalized comparison by the signed-term identity. Extend it
12682+
with the deterministic gate outputs. Induction over adders gives exact sums;
12683+
at each comparator bit, a more significant unequal bit decides the comparison,
12684+
while equal bits retain the previous result. Every asserted output is therefore true.
12685+
($arrow.l.double$) A satisfying CNF assignment obeys every gate equivalence and
12686+
the false-constant clause, forcing the computed sums and comparisons. The output
12687+
assertions imply every source row and its objective bound after reversing normalization.
12688+
12689+
_Solution extraction._ Validate the full SAT witness, then convert its first
12690+
$n$ bits to integers zero or one. Completed Boolean values map identically.
12691+
12692+
_Arithmetic and overhead._ Before encoding, checked sums of positive and negative
12693+
coefficients must each fit signed 64-bit arithmetic, including the objective row.
12694+
Otherwise the reduction returns a typed overflow error: some binary assignments
12695+
would overflow the source evaluator. Normalization uses arbitrary-precision integers.
12696+
On the accepted domain $T<=2^64-1$, hence $W<=64$. Each row uses at most $5 n W$
12697+
adder gates, $W$ comparator gates, and $W+1$ assertion clauses; every gate uses
12698+
at most four clauses of at most three literals. Including the constant gives
12699+
$V<=n+1+64(m+1)(5n+1)$ variables,
12700+
$C<=1+(m+1)(1280n+321)$ clauses, and at most $3C$ literal occurrences.
12701+
]
12702+
1260612703
#reduction-rule("ILP", "QUBO")[
1260712704
Binary ILP constraints are encoded by squared integer residuals with binary slack variables, following the penalty construction discussed by Lucas @lucas2014[Section 3]. The rule retains the omitted constant and uses a certified energy interval to recover the original objective direction or report infeasibility. No assumption that the ILP is feasible is needed.
1260812705
][

‎docs/paper/references.bib‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,3 +2332,14 @@ @article{axler2019
23322332
year = {2019},
23332333
url = {https://www.maths.tcd.ie/EMIS/journals/JIS/VOL22/Axler/axler17.pdf}
23342334
}
2335+
2336+
@article{een2006,
2337+
author = {Niklas E{\'e}n and Niklas S{\"o}rensson},
2338+
title = {Translating Pseudo-Boolean Constraints into {SAT}},
2339+
journal = {Journal on Satisfiability, Boolean Modeling and Computation},
2340+
year = {2006},
2341+
volume = {2},
2342+
number = {1--4},
2343+
pages = {1--26},
2344+
doi = {10.3233/SAT190014},
2345+
}

‎src/models/algebraic/ilp.rs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,41 @@ crate::declare_variants! {
690690
ILP<i64, f64> => "num_vars^num_vars",
691691
}
692692

693+
impl crate::solvers::BruteForceProblem for ILP<bool> {
694+
fn dimensions(&self) -> Vec<usize> {
695+
vec![2; self.num_vars()]
696+
}
697+
}
698+
699+
crate::decision_problem_meta!(ILP<bool>, "DecisionILP");
700+
crate::register_decision_variant!(without_turing;
701+
ILP<bool>, "DecisionILP", "2^num_vars", &[],
702+
"Does a binary ILP have a feasible solution meeting its objective bound?",
703+
category: crate::registry::ProblemCategory::Algebraic,
704+
dims: [
705+
VariantDimension::new("variable", "bool", &["bool"]),
706+
VariantDimension::new("coefficient", "i64", &["i64"]),
707+
VariantDimension::new("bounds", "general", &["general"]),
708+
],
709+
fields: [
710+
FieldInfo { name: "variables", type_name: "Vec<IntegerVariable>", description: "Binary variable bounds [0, 1]" },
711+
FieldInfo { name: "constraints", type_name: "Vec<LinearConstraint<i64>>", description: "Sparse integer linear constraints" },
712+
FieldInfo { name: "objective", type_name: "Vec<(usize, i64)>", description: "Sparse integer objective coefficients" },
713+
FieldInfo { name: "sense", type_name: "ObjectiveSense", description: "Optimization direction" },
714+
FieldInfo { name: "bound", type_name: "i64", description: "Upper bound for minimization, lower bound for maximization" },
715+
],
716+
decode: |_, indices: Vec<usize>| indices.into_iter().map(|bit| i64::try_from(bit).expect("binary coordinate fits i64")).collect::<Vec<_>>()
717+
);
718+
693719
#[cfg(feature = "example-db")]
694720
pub(crate) fn canonical_model_example_specs() -> Vec<crate::example_db::specs::ModelExampleSpec> {
695721
vec![
722+
crate::example_db::specs::ModelExampleSpec {
723+
id: "decision_ilp",
724+
instance: Box::new(canonical_decision_example()),
725+
optimal_config: serde_json::json!([0, 0, 1]),
726+
optimal_value: serde_json::json!(true),
727+
},
696728
crate::example_db::specs::ModelExampleSpec {
697729
id: "ilp",
698730
instance: Box::new(
@@ -733,3 +765,17 @@ pub(crate) fn canonical_model_example_specs() -> Vec<crate::example_db::specs::M
733765
#[cfg(test)]
734766
#[path = "../../unit_tests/models/algebraic/ilp.rs"]
735767
mod tests;
768+
769+
#[cfg(feature = "example-db")]
770+
pub(crate) fn canonical_decision_example() -> crate::models::Decision<ILP<bool>> {
771+
crate::models::Decision::new(
772+
ILP::new(
773+
3,
774+
vec![LinearConstraint::eq(vec![(0, 1), (1, 1), (2, 1)], 1)],
775+
vec![(0, 3), (1, 2), (2, 1)],
776+
ObjectiveSense::Minimize,
777+
)
778+
.unwrap(),
779+
1,
780+
)
781+
}

‎src/models/decision.rs‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ macro_rules! decision_problem_meta {
3131
/// variant's construction fields and decoder without adding another schema or default.
3232
/// Both decision/optimization edges derive their identity parameter transforms directly
3333
/// from the inner problem's canonical parameter schema.
34+
/// Prefix with `without_turing;` to omit the reverse optimization-to-decision Turing edge.
3435
#[macro_export]
3536
macro_rules! register_decision_variant {
36-
(
37+
(without_turing; $($body:tt)*) => {
38+
$crate::register_decision_variant!(@register witness_edge; $($body)*);
39+
};
40+
($inner:ty, $($body:tt)*) => {
41+
$crate::register_decision_variant!(@register edges; $inner, $($body)*);
42+
};
43+
(@register $edges:ident;
3744
$inner:ty,
3845
$name:literal,
3946
$complexity:literal,
@@ -61,16 +68,16 @@ macro_rules! register_decision_variant {
6168
}
6269
}
6370

64-
$crate::register_decision_variant!(@edges $inner, $name);
71+
$crate::register_decision_variant!(@$edges $inner, $name);
6572
$($(
6673
$crate::register_brute_force! {
6774
$crate::models::decision::Decision<$additional> decode $decoder,
6875
}
69-
$crate::register_decision_variant!(@edges $additional, $name);
76+
$crate::register_decision_variant!(@$edges $additional, $name);
7077
)*)?
7178
};
7279

73-
(@edges $inner:ty, $name:literal) => {
80+
(@witness_edge $inner:ty, $name:literal) => {
7481
// Decision<P> → P: both witness (identity config) and aggregate (solve + compare)
7582
$crate::inventory::submit! {
7683
$crate::rules::ReductionEntry {
@@ -114,7 +121,10 @@ macro_rules! register_decision_variant {
114121
turing: false,
115122
}
116123
}
124+
};
117125

126+
(@edges $inner:ty, $name:literal) => {
127+
$crate::register_decision_variant!(@witness_edge $inner, $name);
118128
// Reverse edge: P → Decision<P> (Turing/multi-query reduction via binary search)
119129
$crate::inventory::submit! {
120130
$crate::rules::ReductionEntry {

0 commit comments

Comments
 (0)