Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/simple/commodity_constraints.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commodity_id,region_id,balance_type,years,time_slice,limits
GASPRD,GBR,prod,2020,winter.day,12.34..56.78
ELCTRI,GBR,cons,2020,summer,3.14..
CO2EMT,GBR,prod,2030,annual,..1.618034
29 changes: 29 additions & 0 deletions schemas/input/commodity_constraints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$schema: https://specs.frictionlessdata.io/schemas/table-schema.json
description: Specifies constraints on commodities.

fields:
- name: commodity_id
type: string
description: The commodity to which this constraint applies
- name: region_id
type: string
description: The region in which this constraint applies
- name: balance_type
type: string
description: The type of balance to which this is applied
notes:
The "net" option is not valid here, as net production is already constrained by
the commodity balance constraints.
- name: years
type: string
description: The year(s) to which this entry applies
- name: time_slice
type: string
description: The time slice(s) to which this entry applies
- name: limits
type: string
description: Lower and upper limits on the value of the commodity
notes:
A string in the format `min..max`, where `min` and `max` are decimal numbers
(e.g. "0.12..78.9"). Either `min` or `max` can be omitted (e.g "0.12.." or
"..78.9"), which will set the corresponding limit to 0 or infinite, respectively.
17 changes: 17 additions & 0 deletions src/commodity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::units::{Flow, MoneyPerFlow};
use indexmap::IndexMap;
use serde::Deserialize;
use std::collections::HashMap;
use std::ops::RangeInclusive;
use std::sync::Arc;

define_id_type! {CommodityID, "commodity ID"}
Expand All @@ -16,6 +17,9 @@ pub type CommodityMap = IndexMap<CommodityID, Arc<Commodity>>;
/// A map of [`MoneyPerFlow`]s, keyed by region ID, year and time slice ID for a specific levy
pub type CommodityLevyMap = HashMap<(RegionID, u32, TimeSliceID), MoneyPerFlow>;

/// A map of vectors of [`CommodityConstraint`]s, keyed by region ID and year
pub type CommodityConstraintsMap = HashMap<(RegionID, u32), Vec<CommodityConstraint>>;

/// A map of demand values, keyed by region ID, year and time slice selection
pub type DemandMap = HashMap<(RegionID, u32, TimeSliceSelection), Flow>;

Expand Down Expand Up @@ -115,6 +119,19 @@ pub enum PricingStrategy {
Unpriced,
}

/// A constraint imposed on commodity values
#[derive(PartialEq, Debug, Clone)]
pub struct CommodityConstraint {
/// The balance type for the commodity constraint
pub balance_type: BalanceType,
/// The time slice selection for the commodity constraint
pub ts_selection: TimeSliceSelection,
/// The range of values the commodity is constrained to lie between
pub limits: RangeInclusive<Flow>,
}

impl CommodityConstraint {}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
11 changes: 11 additions & 0 deletions src/input/commodity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use std::path::Path;

mod levy;
use levy::read_commodity_levies;
mod constraints;
use constraints::read_commodity_constraints;
mod demand;
use demand::read_demand;
mod demand_slicing;
Expand Down Expand Up @@ -55,6 +57,15 @@ pub fn read_commodities(
let commodities = read_commodities_file(model_dir)?;
let commodity_ids = commodities.keys().cloned().collect();

// Read constraints table
let _commodity_constraints = read_commodity_constraints(
model_dir,
&commodity_ids,
region_ids,
time_slice_info,
milestone_years,
);

// Read costs table
let mut costs = read_commodity_levies(
model_dir,
Expand Down
Loading
Loading