problemreductions/rules/
ilp_bool_ilp_i64.rs1use crate::models::algebraic::ILP;
8use crate::reduction;
9use crate::rules::traits::{ReduceTo, ReductionResult};
10
11#[derive(Debug, Clone)]
12pub struct ReductionBinaryILPToIntILP {
13 target: ILP<i64>,
14}
15
16impl ReductionResult for ReductionBinaryILPToIntILP {
17 type Source = ILP<bool>;
18 type Target = ILP<i64>;
19
20 fn target_problem(&self) -> &ILP<i64> {
21 &self.target
22 }
23
24 fn extract_solution(
25 &self,
26 target_solution: &<Self::Target as crate::traits::Problem>::Solution,
27 ) -> crate::rules::ExtractionResult<<Self::Source as crate::traits::Problem>::Solution> {
28 crate::rules::traits::validate_target_solution(self.target_problem(), target_solution)?;
29
30 Ok(target_solution.to_vec())
31 }
32}
33
34#[reduction(
35 transform = exact {
36 num_vars = "num_vars",
37 num_constraints = "num_constraints",
38 num_nonzeros = "num_nonzeros",
39 },)]
40impl ReduceTo<ILP<i64>> for ILP<bool> {
41 type Result = ReductionBinaryILPToIntILP;
42
43 fn reduce_to(&self) -> Result<Self::Result, crate::rules::ReductionError> {
44 Ok(ReductionBinaryILPToIntILP {
45 target: ILP::<i64>::with_variables(
46 self.variables().to_vec(),
47 self.constraints().to_vec(),
48 self.objective().to_vec(),
49 self.sense(),
50 )
51 .map_err(<Self as ReduceTo<ILP<i64>>>::target_construction)?,
52 })
53 }
54}
55
56#[cfg(test)]
57#[path = "../unit_tests/rules/ilp_bool_ilp_i64.rs"]
58mod tests;