|
144 | 144 | mo.IncludeFixedReserves = 0;
|
145 | 145 | end
|
146 | 146 | end
|
| 147 | +if mo.SecurityConstrained % check that at least some contingency is specified |
| 148 | + have_contingency = 0; |
| 149 | + for t = 1:nt |
| 150 | + for j = 1:mdi.idx.nj(t) |
| 151 | + if isfield(mdi, 'cont') && isfield(mdi.cont(t,j), 'contab') && ... |
| 152 | + ~isempty(mdi.cont(t,j).contab) |
| 153 | + have_contingency = 1; % found a contingency |
| 154 | + end |
| 155 | + end |
| 156 | + end |
| 157 | +end |
147 | 158 | if mo.SecurityConstrained == -1
|
148 |
| - if isfield(mdi, 'cont') && isfield(mdi.cont(1,1), 'contab') && ... |
149 |
| - ~isempty(mdi.cont(1,1).contab) |
| 159 | + if have_contingency |
150 | 160 | mo.SecurityConstrained = 1;
|
151 | 161 | else
|
152 | 162 | mo.SecurityConstrained = 0;
|
|
165 | 175 | isfield(mdi.FixedReserves(1,1,1), 'req'))
|
166 | 176 | error('most: MDI.FixedReserves(t,j,k) must be specified when MPOPT.most.fixed_res = 1');
|
167 | 177 | end
|
168 |
| -if mo.SecurityConstrained && ~(isfield(mdi, 'cont') && ... |
169 |
| - isfield(mdi.cont(1,1), 'contab') && ~isempty(mdi.cont(1,1).contab)) |
170 |
| - error('most: MDI.cont(t,j).contab cannot be empty when MPOPT.most.security_constraints = 1'); |
| 178 | +if mo.SecurityConstrained && ~have_contingency |
| 179 | + error('most: MDI.cont(t,j).contab cannot be empty for all t, j when MPOPT.most.security_constraints = 1'); |
171 | 180 | end
|
172 | 181 | if mo.IncludeFixedReserves && mo.SecurityConstrained
|
173 | 182 | warning('most: Using MPOPT.most.fixed_res = 1 and MPOPT.most.security_constraints = 1 together is not recommended.');
|
|
446 | 455 | mdi.StepProb(t) = sum(scenario_probs); % probability of making it to the t-th step
|
447 | 456 | if mdi.SecurityConstrained
|
448 | 457 | for j = 1:mdi.idx.nj(t)
|
449 |
| - [tmp, ii] = sort(mdi.cont(t,j).contab(:, CT_LABEL)); %sort in ascending contingency label |
450 |
| - contab = mdi.cont(t,j).contab(ii, :); |
451 |
| - rowdecomlist = ones(size(contab,1), 1); |
452 |
| - for l = 1:size(contab, 1) |
453 |
| - if contab(l, CT_TABLE) == CT_TGEN && contab(l, CT_COL) == GEN_STATUS ... |
454 |
| - && contab(l, CT_CHGTYPE) == CT_REP && contab(l, CT_NEWVAL) == 0 ... % gen turned off |
455 |
| - && mdi.flow(t,j,1).mpc.gen(contab(l, CT_ROW), GEN_STATUS) <= 0 % but it was off on input |
456 |
| - rowdecomlist(l) = 0; |
457 |
| - elseif contab(l, CT_TABLE) == CT_TBRCH && contab(l, CT_COL) == BR_STATUS ... |
458 |
| - && contab(l, CT_CHGTYPE) == CT_REP && contab(l, CT_NEWVAL) == 0 ... % branch taken out |
459 |
| - && mdi.flow(t,j,1).mpc.branch(contab(l, CT_ROW), BR_STATUS) <= 0 % but it was off on input |
460 |
| - rowdecomlist(l) = 0; |
| 458 | + if isempty(mdi.cont(t,j).contab) |
| 459 | + mdi.idx.nc(t, j) = 0; |
| 460 | + mdi.CostWeights(1, j, t) = 1; |
| 461 | + else |
| 462 | + [tmp, ii] = sort(mdi.cont(t,j).contab(:, CT_LABEL)); %sort in ascending contingency label |
| 463 | + contab = mdi.cont(t,j).contab(ii, :); |
| 464 | + rowdecomlist = ones(size(contab,1), 1); |
| 465 | + for l = 1:size(contab, 1) |
| 466 | + if contab(l, CT_TABLE) == CT_TGEN && contab(l, CT_COL) == GEN_STATUS ... |
| 467 | + && contab(l, CT_CHGTYPE) == CT_REP && contab(l, CT_NEWVAL) == 0 ... % gen turned off |
| 468 | + && mdi.flow(t,j,1).mpc.gen(contab(l, CT_ROW), GEN_STATUS) <= 0 % but it was off on input |
| 469 | + rowdecomlist(l) = 0; |
| 470 | + elseif contab(l, CT_TABLE) == CT_TBRCH && contab(l, CT_COL) == BR_STATUS ... |
| 471 | + && contab(l, CT_CHGTYPE) == CT_REP && contab(l, CT_NEWVAL) == 0 ... % branch taken out |
| 472 | + && mdi.flow(t,j,1).mpc.branch(contab(l, CT_ROW), BR_STATUS) <= 0 % but it was off on input |
| 473 | + rowdecomlist(l) = 0; |
| 474 | + end |
461 | 475 | end
|
| 476 | + contab = contab(rowdecomlist ~= 0, :); |
| 477 | + mdi.cont(t, j).contab = contab; |
| 478 | + clist = unique(contab(:, CT_LABEL)); |
| 479 | + mdi.idx.nc(t, j) = length(clist); |
| 480 | + k = 2; |
| 481 | + for label = clist' |
| 482 | + mdi.flow(t, j, k).mpc = apply_changes(label, mdi.flow(t, j, 1).mpc, contab); |
| 483 | + ii = find( label == contab(:, CT_LABEL) ); |
| 484 | + mdi.CostWeights(k, j, t) = contab(ii(1), CT_PROB); |
| 485 | + mdi.idx.nb(t, j, k) = size(mdi.flow(t, j, k).mpc.bus, 1); |
| 486 | + mdi.idx.ny(t, j, k) = length(find(mdi.flow(t, j, 1).mpc.gencost(:, MODEL) == PW_LINEAR)); |
| 487 | + k = k + 1; |
| 488 | + end |
| 489 | + mdi.CostWeights(1, j, t) = 1 - sum(mdi.CostWeights(2:mdi.idx.nc(t,j)+1, j, t)); |
| 490 | + mdi.CostWeights(1:mdi.idx.nc(t,j)+1, j, t) = scenario_probs(j) * mdi.CostWeights(1:mdi.idx.nc(t,j)+1, j, t); |
462 | 491 | end
|
463 |
| - contab = contab(rowdecomlist ~= 0, :); |
464 |
| - mdi.cont(t, j).contab = contab; |
465 |
| - clist = unique(contab(:, CT_LABEL)); |
466 |
| - mdi.idx.nc(t, j) = length(clist); |
467 |
| - k = 2; |
468 |
| - for label = clist' |
469 |
| - mdi.flow(t, j, k).mpc = apply_changes(label, mdi.flow(t, j, 1).mpc, contab); |
470 |
| - ii = find( label == contab(:, CT_LABEL) ); |
471 |
| - mdi.CostWeights(k, j, t) = contab(ii(1), CT_PROB); |
472 |
| - mdi.idx.nb(t, j, k) = size(mdi.flow(t, j, k).mpc.bus, 1); |
473 |
| - mdi.idx.ny(t, j, k) = length(find(mdi.flow(t, j, 1).mpc.gencost(:, MODEL) == PW_LINEAR)); |
474 |
| - k = k + 1; |
475 |
| - end |
476 |
| - mdi.CostWeights(1, j, t) = 1 - sum(mdi.CostWeights(2:mdi.idx.nc(t,j)+1, j, t)); |
477 |
| - mdi.CostWeights(1:mdi.idx.nc(t,j)+1, j, t) = scenario_probs(j) * mdi.CostWeights(1:mdi.idx.nc(t,j)+1, j, t); |
478 | 492 | end
|
479 | 493 | else
|
480 | 494 | for j = 1:mdi.idx.nj(t)
|
|
0 commit comments