Skip to content

Commit bae744e

Browse files
authored
Merge pull request #1040 from EnergySystemsModellingLab/use-indexmap-for-prices
Use `IndexMap` rather than `BTreeMap` for commodity prices
2 parents 0fe2b73 + 4f58710 commit bae744e

File tree

6 files changed

+987
-985
lines changed

6 files changed

+987
-985
lines changed

src/simulation/prices.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use crate::simulation::optimisation::Solution;
77
use crate::time_slice::{TimeSliceID, TimeSliceInfo, TimeSliceSelection};
88
use crate::units::{Activity, Dimensionless, MoneyPerActivity, MoneyPerFlow, Year};
99
use anyhow::Result;
10+
use indexmap::IndexMap;
1011
use itertools::iproduct;
11-
use std::collections::{BTreeMap, HashMap, HashSet, btree_map};
12+
use std::collections::{HashMap, HashSet};
1213

1314
/// Iterator item type for asset activity iterators
1415
type Item<'a> = (&'a AssetRef, &'a TimeSliceID, Activity);
@@ -98,7 +99,7 @@ pub fn calculate_prices(model: &Model, solution: &Solution, year: u32) -> Result
9899

99100
/// A map relating commodity ID + region + time slice to current price (endogenous)
100101
#[derive(Default, Clone)]
101-
pub struct CommodityPrices(BTreeMap<(CommodityID, RegionID, TimeSliceID), MoneyPerFlow>);
102+
pub struct CommodityPrices(IndexMap<(CommodityID, RegionID, TimeSliceID), MoneyPerFlow>);
102103

103104
impl CommodityPrices {
104105
/// Insert a price for the given commodity, region and time slice
@@ -150,7 +151,9 @@ impl CommodityPrices {
150151
}
151152

152153
/// Iterate over the price map's keys
153-
pub fn keys(&self) -> btree_map::Keys<'_, (CommodityID, RegionID, TimeSliceID), MoneyPerFlow> {
154+
pub fn keys(
155+
&self,
156+
) -> indexmap::map::Keys<'_, (CommodityID, RegionID, TimeSliceID), MoneyPerFlow> {
154157
self.0.keys()
155158
}
156159

@@ -236,8 +239,7 @@ impl<'a> FromIterator<(&'a CommodityID, &'a RegionID, &'a TimeSliceID, MoneyPerF
236239

237240
impl IntoIterator for CommodityPrices {
238241
type Item = ((CommodityID, RegionID, TimeSliceID), MoneyPerFlow);
239-
type IntoIter =
240-
std::collections::btree_map::IntoIter<(CommodityID, RegionID, TimeSliceID), MoneyPerFlow>;
242+
type IntoIter = indexmap::map::IntoIter<(CommodityID, RegionID, TimeSliceID), MoneyPerFlow>;
241243

242244
fn into_iter(self) -> Self::IntoIter {
243245
self.0.into_iter()

0 commit comments

Comments
 (0)