Skip to content
Merged
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: 2 additions & 2 deletions docs/model/commodity_graphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ The investment order is worked out from the commodity graph for each year as fol

Markets within a circularity cannot be put into an order that respects every dependency, as each
market in the loop depends on the others. MUSE2 chooses an order for them by solving a small
optimisation problem; see the [API documentation for `order_sccs`][order-sccs] for details. For how
optimisation problem; see the [API documentation for `order_scc`][order-scc] for details. For how
investment then proceeds within a circularity, see [Circularities][investment-circularities].

### Example investment order
Expand Down Expand Up @@ -218,7 +218,7 @@ When reading these graphs, note that:
[prices]: ./prices.md
[topological sort]: https://en.wikipedia.org/wiki/Topological_sorting
[partial-dispatch]: ./investment.md#partial-system-dispatch
[order-sccs]: ../api/muse2/graph/investment/fn.order_sccs.html
[order-scc]: ../api/muse2/graph/investment/fn.order_scc.html
[investment-circularities]: ./investment.md#circularities
[pricing-circularities]: ./prices.md#circularities
[log level]: ../user_guide.md#setting-the-log-level
Expand Down
12 changes: 8 additions & 4 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub type CommoditiesGraph = Graph<GraphNode, GraphEdge, Directed>;
pub enum GraphNode {
/// A node representing a commodity in a specific region
#[display("{_0} | {_1}")]
Commodity(CommodityID, RegionID),
CommodityMarket(CommodityID, RegionID),
/// A source node for processes that have no inputs
#[display("SOURCE")]
Source,
Expand Down Expand Up @@ -115,15 +115,19 @@ fn create_commodities_graph_for_year(
let mut outputs: Vec<_> = flows
.values()
.filter(|flow| flow.direction() == FlowDirection::Output)
.map(|flow| GraphNode::Commodity(flow.commodity.id.clone(), region_id.clone()))
.map(|flow| {
GraphNode::CommodityMarket(flow.commodity.id.clone(), region_id.clone())
})
.collect();

// Get input nodes for the process
// For now, we assume processes always input commodities in their own region
let mut inputs: Vec<_> = flows
.values()
.filter(|flow| flow.direction() == FlowDirection::Input)
.map(|flow| GraphNode::Commodity(flow.commodity.id.clone(), region_id.clone()))
.map(|flow| {
GraphNode::CommodityMarket(flow.commodity.id.clone(), region_id.clone())
})
.collect();

// Use `Source` node if no inputs, `Sink` node if no outputs
Expand All @@ -148,7 +152,7 @@ fn create_commodities_graph_for_year(
.entry(output.clone())
.or_insert_with(|| graph.add_node(output.clone()));
let is_primary = match &output {
GraphNode::Commodity(commodity_id, _) => {
GraphNode::CommodityMarket(commodity_id, _) => {
primary_output.as_ref() == Some(commodity_id)
}
_ => false,
Expand Down
Loading