@@ -115,20 +115,20 @@ Power = ResourceCarrier("Power", 0.0)
115115CO2 = ResourceEmit (" CO2" , 1.0 )
116116
117117# Function for setting up the system
118- function link_graph (LinkType:: Vector{DataType} )
118+ function link_graph (LinkType:: Vector{DataType} ; res_in = Power, res_out = Power )
119119 # Used source, network, and sink
120120 source = RefSource (
121121 " source" ,
122122 FixedProfile (4 ),
123123 FixedProfile (10 ),
124124 FixedProfile (0 ),
125- Dict (Power => 1 ),
125+ Dict (res_in => 1 ),
126126 )
127127 sink = RefSink (
128128 " sink" ,
129129 FixedProfile (3 ),
130130 Dict (:surplus => FixedProfile (4 ), :deficit => FixedProfile (100 )),
131- Dict (Power => 1 ),
131+ Dict (res_out => 1 ),
132132 )
133133
134134 resources = [Power, CO2]
@@ -147,6 +147,37 @@ function link_graph(LinkType::Vector{DataType})
147147 return run_model (case, model, HiGHS. Optimizer), case, model
148148end
149149
150+ @testset " Link - different resources" begin
151+ # Creation of a new link type with associated emissions in each operational period
152+ struct ResourceLink <: Link
153+ id:: Any
154+ from:: EMB.Node
155+ to:: EMB.Node
156+ formulation:: EMB.Formulation
157+ end
158+ function EMB. create_link (m, 𝒯, 𝒫, l:: ResourceLink , modeltype:: EnergyModel , formulation:: EMB.Formulation )
159+ # Generic link in which each output corresponds to the input
160+ @constraint (m, [t ∈ 𝒯],
161+ sum (m[:link_out ][l, t, p_out] for p_out ∈ outputs (l)) ==
162+ sum (m[:link_in ][l, t, p_in] for p_in ∈ inputs (l))
163+ )
164+ end
165+ EMB. inputs (l:: ResourceLink ) = [Power]
166+ EMB. outputs (l:: ResourceLink ) = [CO2]
167+
168+ # Create and solve the system
169+ m, case, model = link_graph ([ResourceLink]; res_out= CO2)
170+ ℒ = case[:links ]
171+ 𝒩 = case[:nodes ]
172+ 𝒯 = case[:T ]
173+
174+ # Test that the coupling is working correctly and resources are transported
175+ @test all (value .(m[:flow_out ][𝒩[1 ], t, Power]) ≈ value .(m[:link_in ][ℒ[1 ], t, Power]) for t ∈ 𝒯)
176+ @test all (value .(m[:flow_in ][𝒩[2 ], t, CO2]) ≈ value .(m[:link_out ][ℒ[1 ], t, CO2]) for t ∈ 𝒯)
177+ @test all (value .(m[:flow_out ][𝒩[1 ], t, Power]) ≈ value .(m[:flow_in ][𝒩[2 ], t, CO2]) for t ∈ 𝒯)
178+ @test all (value .(m[:flow_out ][𝒩[1 ], t, Power]) ≈ 3 for t ∈ 𝒯)
179+ end
180+
150181@testset " Link - emissions" begin
151182 # Creation of a new link type with associated emissions in each operational period
152183 struct EmissionDirect <: Link
0 commit comments