Skip to main content

problemreductions/rules/
ilp_bounded_ilp.rs

1//! Forget the bounded-interval certificate while retaining the entire ILP.
2
3use crate::models::algebraic::{Bounded, ILP};
4use crate::reduction;
5use crate::rules::{ReduceTo, ReductionResult};
6
7/// Identity embedding of bounded integer ILP into general integer ILP.
8#[derive(Debug, Clone)]
9pub struct ReductionBoundedILPToILP {
10    target: ILP<i64>,
11}
12
13impl ReductionResult for ReductionBoundedILPToILP {
14    type Source = ILP<i64, i64, Bounded>;
15    type Target = ILP<i64>;
16
17    fn target_problem(&self) -> &Self::Target {
18        &self.target
19    }
20
21    fn extract_solution(&self, solution: &Vec<i64>) -> crate::rules::ExtractionResult<Vec<i64>> {
22        crate::rules::traits::validate_target_witness(
23            ReductionResult::target_problem(self),
24            solution,
25            |value| value.value.is_some(),
26            "target ILP assignment is infeasible",
27        )?;
28        Ok(solution.clone())
29    }
30}
31
32#[crate::aggregate_reduction(identity)]
33impl crate::rules::AggregateReductionResult for ReductionBoundedILPToILP {}
34
35#[reduction(transform = exact {
36    max_constraint_magnitude_bits = "max_constraint_magnitude_bits",
37    num_vars = "num_vars",
38    num_constraints = "num_constraints",
39    num_nonzeros = "num_nonzeros",
40})]
41impl ReduceTo<ILP<i64>> for ILP<i64, i64, Bounded> {
42    type Result = ReductionBoundedILPToILP;
43
44    fn reduce_to(&self) -> Result<Self::Result, crate::rules::ReductionError> {
45        Ok(ReductionBoundedILPToILP {
46            target: ILP::with_variables(
47                self.variables().to_vec(),
48                self.constraints().to_vec(),
49                self.objective().to_vec(),
50                self.sense(),
51            )
52            .map_err(<Self as ReduceTo<ILP<i64>>>::target_construction)?,
53        })
54    }
55}
56
57#[cfg(test)]
58#[path = "../unit_tests/rules/ilp_bounded_ilp.rs"]
59mod tests;