problemreductions/rules/
partition_cosineproductintegration.rs1use crate::models::misc::{CosineProductIntegration, Partition};
14use crate::reduction;
15use crate::rules::traits::{ReduceTo, ReductionResult};
16
17#[derive(Debug, Clone)]
19pub struct ReductionPartitionToCPI {
20 target: CosineProductIntegration,
21}
22
23impl ReductionResult for ReductionPartitionToCPI {
24 type Source = Partition;
25 type Target = CosineProductIntegration;
26
27 fn target_problem(&self) -> &Self::Target {
28 &self.target
29 }
30
31 fn extract_solution(&self, target_solution: &[usize]) -> Vec<usize> {
32 target_solution.to_vec()
33 }
34}
35
36#[reduction(overhead = {
37 num_coefficients = "num_elements",
38})]
39impl ReduceTo<CosineProductIntegration> for Partition {
40 type Result = ReductionPartitionToCPI;
41
42 fn reduce_to(&self) -> Self::Result {
43 let coefficients: Vec<i64> = self.sizes().iter().map(|&s| s as i64).collect();
44 ReductionPartitionToCPI {
45 target: CosineProductIntegration::new(coefficients),
46 }
47 }
48}
49
50#[cfg(feature = "example-db")]
51pub(crate) fn canonical_rule_example_specs() -> Vec<crate::example_db::specs::RuleExampleSpec> {
52 use crate::export::SolutionPair;
53
54 vec![crate::example_db::specs::RuleExampleSpec {
55 id: "partition_to_cosineproductintegration",
56 build: || {
57 crate::example_db::specs::rule_example_with_witness::<_, CosineProductIntegration>(
64 Partition::new(vec![3, 1, 1, 2, 2, 1]),
65 SolutionPair {
66 source_config: vec![1, 0, 0, 1, 0, 0],
67 target_config: vec![1, 0, 0, 1, 0, 0],
68 },
69 )
70 },
71 }]
72}
73
74#[cfg(test)]
75#[path = "../unit_tests/rules/partition_cosineproductintegration.rs"]
76mod tests;