replace for loops with matrices

pull/44/head
Jun He 2 years ago
parent b609abe4bb
commit e6b4f6add3

@ -85,28 +85,25 @@ function solution(model::JuMP.Model)::OrderedDict
sol[sc.name]["Load curtail (MW)"] = sol[sc.name]["Load curtail (MW)"] =
timeseries(model[:curtail], sc.buses, sc = sc) timeseries(model[:curtail], sc.buses, sc = sc)
end 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) if !isempty(sc.lines)
sol[sc.name]["Line overflow (MW)"] = sol[sc.name]["Line overflow (MW)"] =
timeseries(model[:overflow], sc.lines, sc = sc) timeseries(model[:overflow], sc.lines, sc = sc)
sol[sc.name]["Transmission line flow (MW)"] = OrderedDict( # get the matrix of line flows (Lx(B-1))x((B-1)xT)=(LxT)
l.name => [ line_flows = sc.isf * bus_net_injection[2:end, :]
( sol[sc.name]["Transmission line flow (MW)"] =
sc.isf[l.offset, :]' * [ OrderedDict(l.name => line_flows[l.offset, :] for l in sc.lines)
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
)
end end
if !isempty(sc.interfaces) 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( sol[sc.name]["Interface flow (MW)"] = OrderedDict(
ifc.name => [ ifc.name => interface_flows[ifc.offset, :] for
( ifc in sc.interfaces
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
) )
end end
if !isempty(sc.price_sensitive_loads) if !isempty(sc.price_sensitive_loads)

Loading…
Cancel
Save