|
1 | 1 | //! Processes are used for converting between different commodities. The data structures in this |
2 | 2 | //! module are used to represent these conversions along with the associated costs. |
3 | | -use crate::commodity::{Commodity, CommodityID}; |
| 3 | +use crate::commodity::{BalanceType, Commodity, CommodityID}; |
4 | 4 | use crate::id::define_id_type; |
5 | 5 | use crate::region::RegionID; |
6 | 6 | use crate::time_slice::TimeSliceID; |
@@ -98,6 +98,41 @@ pub struct ProcessFlow { |
98 | 98 | pub is_pac: bool, |
99 | 99 | } |
100 | 100 |
|
| 101 | +impl ProcessFlow { |
| 102 | + /// Get the cost for this flow with the given parameters. |
| 103 | + /// |
| 104 | + /// This includes cost per unit flow and levies/incentives, if any. |
| 105 | + pub fn get_total_cost(&self, region_id: &RegionID, year: u32, time_slice: &TimeSliceID) -> f64 { |
| 106 | + let cost_per_unit = self.cost + self.get_levy(region_id, year, time_slice); |
| 107 | + |
| 108 | + self.coeff.abs() * cost_per_unit |
| 109 | + } |
| 110 | + |
| 111 | + /// Get the levy/incentive for this process flow with the given parameters, if any |
| 112 | + fn get_levy(&self, region_id: &RegionID, year: u32, time_slice: &TimeSliceID) -> f64 { |
| 113 | + if self.commodity.levies.is_empty() { |
| 114 | + return 0.0; |
| 115 | + } |
| 116 | + |
| 117 | + let levy = self |
| 118 | + .commodity |
| 119 | + .levies |
| 120 | + .get(&(region_id.clone(), year, time_slice.clone())) |
| 121 | + .unwrap(); |
| 122 | + let apply_levy = match levy.balance_type { |
| 123 | + BalanceType::Net => true, |
| 124 | + BalanceType::Consumption => self.coeff < 0.0, |
| 125 | + BalanceType::Production => self.coeff > 0.0, |
| 126 | + }; |
| 127 | + |
| 128 | + if apply_levy { |
| 129 | + levy.value |
| 130 | + } else { |
| 131 | + 0.0 |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
101 | 136 | /// Type of commodity flow (see [`ProcessFlow`]) |
102 | 137 | #[derive(PartialEq, Default, Debug, Clone, DeserializeLabeledStringEnum)] |
103 | 138 | pub enum FlowType { |
|
0 commit comments