From e6b4f6add3a5c8b3edb7eab1eae9c2be844cbeef Mon Sep 17 00:00:00 2001 From: Jun He Date: Thu, 17 Aug 2023 18:29:25 -0400 Subject: [PATCH] replace for loops with matrices --- src/solution/solution.jl | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/solution/solution.jl b/src/solution/solution.jl index c21a1b7..a400e4a 100644 --- a/src/solution/solution.jl +++ b/src/solution/solution.jl @@ -85,28 +85,25 @@ function solution(model::JuMP.Model)::OrderedDict sol[sc.name]["Load curtail (MW)"] = timeseries(model[:curtail], sc.buses, sc = sc) end + # get matrix of bus net injection (BxT) + bus_net_injection = [ + value(model[:net_injection][sc.name, bus.name, t]) for + bus in sc.buses, t in 1:T + ] if !isempty(sc.lines) sol[sc.name]["Line overflow (MW)"] = timeseries(model[:overflow], sc.lines, sc = sc) - sol[sc.name]["Transmission line flow (MW)"] = OrderedDict( - l.name => [ - ( - sc.isf[l.offset, :]' * [ - value(model[:net_injection][sc.name, bus.name, t]) for bus in sc.buses - ][2:end] - ) for t in 1:T - ] for l in sc.lines - ) + # get the matrix of line flows (Lx(B-1))x((B-1)xT)=(LxT) + line_flows = sc.isf * bus_net_injection[2:end, :] + sol[sc.name]["Transmission line flow (MW)"] = + OrderedDict(l.name => line_flows[l.offset, :] for l in sc.lines) end if !isempty(sc.interfaces) + # get the matrix of interface flows (Ix(B-1))x((B-1)xT)=(IxT) + interface_flows = sc.interface_isf * bus_net_injection[2:end, :] sol[sc.name]["Interface flow (MW)"] = OrderedDict( - ifc.name => [ - ( - sc.interface_isf[ifc.offset, :]' * [ - value(model[:net_injection][sc.name, bus.name, t]) for bus in sc.buses - ][2:end] - ) for t in 1:T - ] for ifc in sc.interfaces + ifc.name => interface_flows[ifc.offset, :] for + ifc in sc.interfaces ) end if !isempty(sc.price_sensitive_loads)