Skip to main content

quantrs2_sim/automatic_parallelization/
autoparallelengine_calculate_strategy_efficiency_group.rs

1//! # AutoParallelEngine - calculate_strategy_efficiency_group Methods
2//!
3//! This module contains method implementations for `AutoParallelEngine`.
4//!
5//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
6
7use super::types::ParallelTask;
8
9use super::autoparallelengine_type::AutoParallelEngine;
10
11impl AutoParallelEngine {
12    /// Calculate strategy efficiency
13    pub(super) fn calculate_strategy_efficiency(tasks: &[ParallelTask]) -> f64 {
14        if tasks.is_empty() {
15            return 0.0;
16        }
17        let total_cost: f64 = tasks.iter().map(|t| t.cost).sum();
18        let max_cost = tasks.iter().map(|t| t.cost).fold(0.0, f64::max);
19        if max_cost > 0.0 {
20            total_cost / (max_cost * tasks.len() as f64)
21        } else {
22            0.0
23        }
24    }
25}