0001 function [results, success, raw] = copf_solver(om, mpopt)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0072 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0073 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0074 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0075 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0076 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0077 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0078 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0079
0080
0081 verbose = mpopt(31);
0082
0083
0084 mpc = get_mpc(om);
0085 [baseMVA, bus, gen, branch] = ...
0086 deal(mpc.baseMVA, mpc.bus, mpc.gen, mpc.branch);
0087 vv = get_idx(om);
0088
0089
0090 nb = size(bus, 1);
0091 nl = size(branch, 1);
0092 ny = getN(om, 'var', 'y');
0093
0094
0095 [x0, LB, UB] = getv(om);
0096
0097
0098
0099 nxyz = length(x0);
0100 om2 = om;
0101 om2 = add_constraints(om2, 'varlims', speye(nxyz, nxyz), LB, UB);
0102 [vv, ll, nn] = get_idx(om2);
0103 [A, l, u] = linear_constraints(om2);
0104
0105
0106
0107 ieq = find( abs(u-l) <= eps );
0108 igt = find( u >= 1e10 & l > -1e10 );
0109 ilt = find( l <= -1e10 & u < 1e10 );
0110 ibx = find( (abs(u-l) > eps) & (u < 1e10) & (l > -1e10) );
0111 Af = [ A(ilt, :); -A(igt, :); A(ibx, :); -A(ibx, :) ];
0112 bf = [ u(ilt); -l(igt); u(ibx); -l(ibx)];
0113 Afeq = A(ieq, :);
0114 bfeq = u(ieq);
0115
0116
0117 [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch);
0118
0119
0120 il = find(branch(:, RATE_A) ~= 0 & branch(:, RATE_A) < 1e10);
0121 nl2 = length(il);
0122
0123
0124 mpopt(15) = 2 * nb + length(bfeq);
0125 if mpopt(19) == 0
0126 mpopt(19) = 150 + 2*nb;
0127 end
0128
0129
0130 otopt = foptions;
0131 otopt(1) = (verbose > 0);
0132
0133 otopt(2) = mpopt(17);
0134 otopt(3) = mpopt(18);
0135 otopt(4) = mpopt(16);
0136 otopt(13) = mpopt(15);
0137 otopt(14) = mpopt(19);
0138
0139
0140 [x, otopt, lambda] = constr('fun_copf', x0, otopt, [], [], 'grad_copf', ...
0141 om2, Ybus, Yf(il,:), Yt(il,:), Afeq, bfeq, Af, bf, mpopt, il);
0142
0143 [f, g] = feval('fun_copf', x, om2, Ybus, Yf(il,:), Yt(il,:), Afeq, bfeq, Af, bf, mpopt, il);
0144
0145
0146 if otopt(10) >= otopt(14) || max(abs(g(1:otopt(13)))) > otopt(4) ...
0147 || max(g((otopt(13)+1):length(g))) > otopt(4)
0148 success = 0;
0149 else
0150 success = 1;
0151 end
0152 info = success;
0153
0154
0155 Va = x(vv.i1.Va:vv.iN.Va);
0156 Vm = x(vv.i1.Vm:vv.iN.Vm);
0157 Pg = x(vv.i1.Pg:vv.iN.Pg);
0158 Qg = x(vv.i1.Qg:vv.iN.Qg);
0159 V = Vm .* exp(1j*Va);
0160
0161
0162
0163 bus(:, VA) = Va * 180/pi;
0164 bus(:, VM) = Vm;
0165 gen(:, PG) = Pg * baseMVA;
0166 gen(:, QG) = Qg * baseMVA;
0167 gen(:, VG) = Vm(gen(:, GEN_BUS));
0168
0169
0170 Sf = V(branch(:, F_BUS)) .* conj(Yf * V);
0171 St = V(branch(:, T_BUS)) .* conj(Yt * V);
0172 branch(:, PF) = real(Sf) * baseMVA;
0173 branch(:, QF) = imag(Sf) * baseMVA;
0174 branch(:, PT) = real(St) * baseMVA;
0175 branch(:, QT) = imag(St) * baseMVA;
0176
0177
0178 nA = length(u);
0179 neq = length(ieq);
0180 nlt = length(ilt);
0181 ngt = length(igt);
0182 nbx = length(ibx);
0183
0184
0185
0186 inln = [(1:2*nb), (1:2*nl2) + 2*nb+neq];
0187 kl = find(lambda(inln) < 0);
0188 ku = find(lambda(inln) > 0);
0189 nl_mu_l = zeros(2*(nb+nl2), 1);
0190 nl_mu_u = zeros(2*(nb+nl2), 1);
0191 nl_mu_l(kl) = -lambda(inln(kl));
0192 nl_mu_u(ku) = lambda(inln(ku));
0193
0194
0195 ilin = [(1:neq)+2*nb, (1:(nlt+ngt+2*nbx)) + 2*nb+neq+2*nl2];
0196 kl = find(lambda(ilin(1:neq)) < 0);
0197 ku = find(lambda(ilin(1:neq)) > 0);
0198
0199 mu_l = zeros(nA, 1);
0200 mu_l(ieq) = -lambda(ilin(1:neq));
0201 mu_l(ieq(ku)) = 0;
0202 mu_l(igt) = lambda(ilin(neq+nlt+(1:ngt)));
0203 mu_l(ibx) = lambda(ilin(neq+nlt+ngt+nbx+(1:nbx)));
0204
0205 mu_u = zeros(nA, 1);
0206 mu_u(ieq) = lambda(ilin(1:neq));
0207 mu_u(ieq(kl)) = 0;
0208 mu_u(ilt) = lambda(ilin(neq+(1:nlt)));
0209 mu_u(ibx) = lambda(ilin(neq+nlt+ngt+(1:nbx)));
0210
0211
0212 muLB = mu_l(ll.i1.varlims:ll.iN.varlims);
0213 muUB = mu_u(ll.i1.varlims:ll.iN.varlims);
0214 mu_l(ll.i1.varlims:ll.iN.varlims) = [];
0215 mu_u(ll.i1.varlims:ll.iN.varlims) = [];
0216
0217
0218
0219 muSf = zeros(nl, 1);
0220 muSt = zeros(nl, 1);
0221 muSf(il) = 2 * nl_mu_u((1:nl2)+2*nb ) .* branch(il, RATE_A) / baseMVA;
0222 muSt(il) = 2 * nl_mu_u((1:nl2)+2*nb+nl2) .* branch(il, RATE_A) / baseMVA;
0223
0224
0225 nl_mu_l = [nl_mu_l(1:2*nb); zeros(2*nl, 1)];
0226 nl_mu_u = [nl_mu_u(1:2*nb); muSf; muSt];
0227
0228
0229 bus(:, MU_VMAX) = muUB(vv.i1.Vm:vv.iN.Vm);
0230 bus(:, MU_VMIN) = muLB(vv.i1.Vm:vv.iN.Vm);
0231 gen(:, MU_PMAX) = muUB(vv.i1.Pg:vv.iN.Pg) / baseMVA;
0232 gen(:, MU_PMIN) = muLB(vv.i1.Pg:vv.iN.Pg) / baseMVA;
0233 gen(:, MU_QMAX) = muUB(vv.i1.Qg:vv.iN.Qg) / baseMVA;
0234 gen(:, MU_QMIN) = muLB(vv.i1.Qg:vv.iN.Qg) / baseMVA;
0235 bus(:, LAM_P) = (nl_mu_u(nn.i1.Pmis:nn.iN.Pmis) - nl_mu_l(nn.i1.Pmis:nn.iN.Pmis)) / baseMVA;
0236 bus(:, LAM_Q) = (nl_mu_u(nn.i1.Qmis:nn.iN.Qmis) - nl_mu_l(nn.i1.Qmis:nn.iN.Qmis)) / baseMVA;
0237 branch(:, MU_SF) = muSf / baseMVA;
0238 branch(:, MU_ST) = muSt / baseMVA;
0239
0240 mu = struct( ...
0241 'var', struct('l', muLB, 'u', muUB), ...
0242 'nln', struct('l', nl_mu_l, 'u', nl_mu_u), ...
0243 'lin', struct('l', mu_l, 'u', mu_u) );
0244
0245 results = mpc;
0246 [results.bus, results.branch, results.gen, ...
0247 results.om, results.x, results.mu, results.f] = ...
0248 deal(bus, branch, gen, om, x, mu, f);
0249
0250 pimul = [ ...
0251 results.mu.nln.l - results.mu.nln.u;
0252 results.mu.lin.l - results.mu.lin.u;
0253 -ones(ny>0, 1);
0254 results.mu.var.l - results.mu.var.u;
0255 ];
0256 raw = struct('xr', x, 'pimul', pimul, 'info', info);