diff --git a/src/asset.rs b/src/asset.rs index 489c29c0a..c115ee646 100644 --- a/src/asset.rs +++ b/src/asset.rs @@ -650,7 +650,7 @@ impl Asset { flow.coeff * prices .get(&flow.commodity.id, &self.region_id, time_slice) - .unwrap_or_default() + .unwrap_or(MoneyPerFlow(0.0)) }) .sum() } diff --git a/src/input/asset.rs b/src/input/asset.rs index 8f219b3f6..c29c7b962 100644 --- a/src/input/asset.rs +++ b/src/input/asset.rs @@ -17,7 +17,7 @@ use std::rc::Rc; const ASSETS_FILE_NAME: &str = "assets.csv"; -#[derive(Default, Deserialize, PartialEq)] +#[derive(Deserialize, PartialEq)] struct AssetRaw { process_id: String, region_id: String, diff --git a/src/simulation/investment/appraisal.rs b/src/simulation/investment/appraisal.rs index bf33739e7..906bff3cb 100644 --- a/src/simulation/investment/appraisal.rs +++ b/src/simulation/investment/appraisal.rs @@ -363,7 +363,7 @@ mod tests { use crate::fixture::{agent_id, asset, process, region_id}; use crate::process::Process; use crate::region::RegionID; - use crate::units::{Money, MoneyPerActivity}; + use crate::units::{Money, MoneyPerActivity, MoneyPerFlow}; use float_cmp::assert_approx_eq; use rstest::rstest; use std::rc::Rc; @@ -551,7 +551,11 @@ mod tests { .map(|(asset, metric)| AppraisalOutput { asset: AssetRef::from(asset), capacity: AssetCapacity::Continuous(Capacity(10.0)), - coefficients: ObjectiveCoefficients::default(), + coefficients: ObjectiveCoefficients { + capacity_coefficient: MoneyPerCapacity(0.0), + activity_coefficients: IndexMap::new(), + unmet_demand_coefficient: MoneyPerFlow(0.0), + }, activity: IndexMap::new(), demand: IndexMap::new(), unmet_demand: IndexMap::new(), @@ -877,7 +881,11 @@ mod tests { .map(|metric| AppraisalOutput { asset: AssetRef::from(asset.clone()), capacity: AssetCapacity::Continuous(Capacity(0.0)), - coefficients: ObjectiveCoefficients::default(), + coefficients: ObjectiveCoefficients { + capacity_coefficient: MoneyPerCapacity(0.0), + activity_coefficients: IndexMap::new(), + unmet_demand_coefficient: MoneyPerFlow(0.0), + }, activity: IndexMap::new(), demand: IndexMap::new(), unmet_demand: IndexMap::new(), diff --git a/src/simulation/investment/appraisal/coefficients.rs b/src/simulation/investment/appraisal/coefficients.rs index e09511e5d..0c17f2b74 100644 --- a/src/simulation/investment/appraisal/coefficients.rs +++ b/src/simulation/investment/appraisal/coefficients.rs @@ -15,7 +15,6 @@ use std::collections::HashMap; /// the investment appraisal routines. The map contains the per-capacity and per-activity cost /// coefficients used in the appraisal optimisation, together with the unmet-demand penalty. #[derive(Clone)] -#[cfg_attr(test, derive(Default))] pub struct ObjectiveCoefficients { /// Cost per unit of capacity pub capacity_coefficient: MoneyPerCapacity, diff --git a/src/simulation/optimisation.rs b/src/simulation/optimisation.rs index 0ddaf8be7..c86638224 100644 --- a/src/simulation/optimisation.rs +++ b/src/simulation/optimisation.rs @@ -795,10 +795,11 @@ fn calculate_activity_coefficient( input_prices: Option<&CommodityPrices>, ) -> MoneyPerActivity { let opex = asset.get_operating_cost(year, time_slice); - let input_cost = input_prices - .map(|prices| asset.get_input_cost_from_prices(prices, time_slice)) - .unwrap_or_default(); - opex + input_cost + if let Some(prices) = input_prices { + opex + asset.get_input_cost_from_prices(prices, time_slice) + } else { + opex + } } /// Calculate the cost coefficient for a capacity variable (for flexible capacity assets only). diff --git a/src/simulation/prices.rs b/src/simulation/prices.rs index dfb1b7e47..1242ef18d 100644 --- a/src/simulation/prices.rs +++ b/src/simulation/prices.rs @@ -180,7 +180,10 @@ impl CommodityPrices { // NB: Time slice fractions will sum to one let weight = time_slice_info.time_slices[time_slice_id] / Year(1.0); let key = (commodity_id.clone(), region_id.clone()); - *weighted_prices.entry(key).or_default() += *price * weight; + weighted_prices + .entry(key) + .and_modify(|v| *v += *price * weight) + .or_insert_with(|| *price * weight); } weighted_prices @@ -352,7 +355,7 @@ where /// /// Note: this should be similar to the "shadow price" strategy, which is also based on marginal /// costs of the most expensive producer, but may be more successful in cases where there are -// multiple SED/SVD outputs per asset. +/// multiple SED/SVD outputs per asset. /// /// # Arguments /// diff --git a/src/units.rs b/src/units.rs index 437db54c7..2c40554f6 100644 --- a/src/units.rs +++ b/src/units.rs @@ -22,7 +22,6 @@ pub trait UnitType: + Sum + ApproxEq + fmt::Display - + Default { /// Create from an f64 value fn new(value: f64) -> Self; @@ -51,7 +50,6 @@ macro_rules! base_unit_struct { Copy, PartialEq, PartialOrd, - Default, Serialize, derive_more::Add, derive_more::Sub,