MATPOWER / most

MOST – MATPOWER Optimal Scheduling Tool, for steady-state power systems scheduling problems.
https://matpower.org/
Other
31 stars 12 forks source link

Contingencies defined independently for some periods and scenarios #45

Closed StefanoUnipd closed 5 months ago

StefanoUnipd commented 6 months ago

In chapter 5.1.5 of the manual, it says that a set of contingencies can be applied to all periods and scenarios via loadmd. Alternatively, to apply contingencies only to some periods and scenarios, I think it should be used mdi.cont(t,j).contab. I tried to apply this second method to the example most_ex4_dcopf_ss.m, in particular, the part of code relating to Secure Stochastic DC OPF (w/wind,cont,res,ramp). I tried to apply some contingencies only to the second scenario (in total there are 3 scenarios and only one period per scenario):

contab_matrix = [
    1   0.06    CT_TGEN     2   GEN_STATUS  CT_REP  0;      %% gen 2 at bus 1
    2   0.04    CT_TBRCH    2   BR_STATUS   CT_REP  0;      %% line 1-3
];
mdi = loadmd(mpc, transmat, xgd, [], [], profiles);
mdi.cont(1,2).contab = contab_matrix;
mdo = most(mdi, mpopt);

But nothing happens, as if the contingencies weren't there.

Instead, if I use mdi.cont(t,j).contab to apply these contingencies to all scenarios, as if I used loadmd, the program works correctly:

contab_matrix = [
    1   0.06    CT_TGEN     2   GEN_STATUS  CT_REP  0;      %% gen 2 at bus 1
    2   0.04    CT_TBRCH    2   BR_STATUS   CT_REP  0;      %% line 1-3
];
mdi = loadmd(mpc, transmat, xgd, [], [], profiles);
mdi.cont(1,1).contab = contab_matrix;
mdi.cont(1,2).contab = contab_matrix;
mdi.cont(1,3).contab = contab_matrix;
mdo = most(mdi, mpopt);

I can't understand where I'm wrong, and above all I don't know if I understood the theory correctly.

rdzman commented 6 months ago

I think I know what's going on. If the most.security_constraints option is set to the default –1, then most() decides whether to include contingencies by checking if contingencies are specified in the input. The issue is that it makes a faulty assumption and only checks to see whether mdi.cont(1,1).contab is present and not empty. If it doesn't find a contab there, it incorrectly assumes the problem is not security constrained and skips over any contingency handling.

I consider this a bug and plan to fix it to ensure that it doesn't disable contingency handling unless there are no contingencies specified in any period or scenario.

I was hoping you could set the most.security_constraints option to 1 and it would just work, but I just tried it and got the following error:

Error using most (line 170)
most: MDI.cont(t,j).contab cannot be empty when MPOPT.most.security_constraints = 1

And commenting out that check doesn't work either. So, it looks like this is yet another example of the wise adage ... "if you didn't test it, it doesn't work." 😞

StefanoUnipd commented 6 months ago

Thank you very much for helping! I agree with the adage, and if the discovery of a bug could lead to being "remembered" in Appendix B of the manual, even better 😄