Skip to content

Commit

Permalink
feat: Add support for bypass cost in RiverGaugeNode. (#228)
Browse files Browse the repository at this point in the history
This is functionality that is available in Pywr v1.x.
Includes conversion from Pywr v1.x "cost" field.
  • Loading branch information
jetuk authored Jul 26, 2024
1 parent 01df832 commit 6c07b6a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pywr-schema/src/nodes/river_gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct RiverGaugeNode {
pub meta: NodeMeta,
pub mrf: Option<Metric>,
pub mrf_cost: Option<Metric>,
pub bypass_cost: Option<Metric>,
}

impl RiverGaugeNode {
Expand Down Expand Up @@ -89,6 +90,11 @@ impl RiverGaugeNode {
network.set_node_max_flow(self.meta.name.as_str(), Self::mrf_sub_name(), value.into())?;
}

if let Some(cost) = &self.bypass_cost {
let value = cost.load(network, args)?;
network.set_node_cost(self.meta.name.as_str(), Self::bypass_sub_name(), value.into())?;
}

Ok(())
}
pub fn create_metric(
Expand Down Expand Up @@ -143,7 +149,17 @@ impl TryFrom<RiverGaugeNodeV1> for RiverGaugeNode {
.map(|v| v.try_into_v2_parameter(Some(&meta.name), &mut unnamed_count))
.transpose()?;

let n = Self { meta, mrf, mrf_cost };
let bypass_cost = v1
.cost
.map(|v| v.try_into_v2_parameter(Some(&meta.name), &mut unnamed_count))
.transpose()?;

let n = Self {
meta,
mrf,
mrf_cost,
bypass_cost,
};
Ok(n)
}
}
Expand Down

0 comments on commit 6c07b6a

Please sign in to comment.