problemreductions/rules/
cost.rs1use crate::rules::registry::ReductionOverhead;
4use crate::types::ProblemSize;
5
6pub trait PathCostFn {
8 fn edge_cost(&self, overhead: &ReductionOverhead, current_size: &ProblemSize) -> f64;
10}
11
12pub struct Minimize(pub &'static str);
14
15impl PathCostFn for Minimize {
16 fn edge_cost(&self, overhead: &ReductionOverhead, size: &ProblemSize) -> f64 {
17 overhead.evaluate_output_size(size).get(self.0).unwrap_or(0) as f64
18 }
19}
20
21pub struct MinimizeSteps;
23
24impl PathCostFn for MinimizeSteps {
25 fn edge_cost(&self, _overhead: &ReductionOverhead, _size: &ProblemSize) -> f64 {
26 1.0
27 }
28}
29
30pub struct CustomCost<F>(pub F);
32
33impl<F: Fn(&ReductionOverhead, &ProblemSize) -> f64> PathCostFn for CustomCost<F> {
34 fn edge_cost(&self, overhead: &ReductionOverhead, size: &ProblemSize) -> f64 {
35 (self.0)(overhead, size)
36 }
37}
38
39#[cfg(test)]
40#[path = "../unit_tests/rules/cost.rs"]
41mod tests;