

Hi Wang Chen,
It looks like you are trying to calculate the total MWh of power moved across all transmission lines during each period. I think the main problem you are running into is that you are not correctly identifying the available transmission lines. The indexed set m.TX_CONNECTIONS_TO_ZONE[z] tells you all the other zones that can send power to zone z. If you access m.TX_CONNECTIONS_TO_ZONE without the index, you get a list of all the zones that have any connections to them, and if you cross it with itself. So your calculation tries to calculate power flow from every zone to all other zones, even if they are not connected.
I think for your purpose, something like this may work better:
mod.TotalTransmissionUsage = Expression(
mod.PERIODS,
rule = lambda m, p: sum(
m.DispatchTx[zone_from, zone_to, tp] * m.tp_weight[tp]
for (zone_from, zone_to) in m.DIRECTIONAL_TX
for tp in m.TPS_IN_PERIOD[p]
)
)
This calculates the total amount of power sent into all connections throughout the system. If you want to calculate the total coming out of all connections (net of losses), you should multiply by m.trans_efficiency[m.trans_d_line[zone_from, zone_to]] before m.tp_weight. Or you could split the difference by multiplying by (1 + m.trans_efficiency[m.trans_d_line[zone_from, zone_to]])/2.
There’s another issue that is trickier to deal with. If there is surplus power (e.g., during times of renewable curtailment), Switch may sometimes send power on loops throughout the system unnecessarily. This doesn’t have any effect except increasing transmission losses, but it can make it look like more transmission is being used than is really the case. You could use a different calculation to try to work around that, like this:
mod.NetTransmissionUsage = Expression(
mod.PERIODS,
rule = lambda m, p: 0.5 * sum(
abs(m.TXPowerNet[z, tp]) * m.tp_weight[tp]
for z in m.LOAD_ZONES
for tp in m.TPS_IN_PERIOD[p]
)
)
This version calculates the net flow into or out of each zone and sums the absolute value of that across all zones. Then it multiplies by 0.5, since net outflow from one zone is inflow to another zone (minus losses), and we don’t want to count it twice. This also ends up averaging between the injections to a line and withdrawals from a line, which are the same minus losses. This version uses the abs() function, which is non-linear, so you can’t use it in a constraint or cost function, but it should work OK for reporting.
This version may not be completely satisfactory either, because if 1 MWh is sent from zone 1 to zone 2 and then on to zone 3, it will only be counted as 1 MWh of flow, not 2 MWh (1 MWh from zone 1 to zone 2 and 1 MWh from zone 2 to zone 3).
Another option would be to use the first method I showed (summing DispatchTx across all paths), but add a post-optimization cleanup stage (similar to switch_model.hawaii.smooth_dispatch) that minimizes loop flows before doing the final calculations.
You may also want to consider reporting MWh-km flows instead of MWh (you could get that by multiplying by m.trans_length_km [m.trans_d_line[zone_from, zone_to]]).
Let me know if you have more questions or need help with any of these.
Also, by the way, it’s easier if you paste the code from your editor directly into the email, rather than pasting an image. Those can be hard to read, search or convert back into runnable code.
Matthias

Figure 1

Figure 2
--
You received this message because you are subscribed to the Google Groups "Switch Model" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
switch-model...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/switch-model/5f0dd5b6-c663-488a-bdd0-2291c305c404n%40googlegroups.com.