0001 function [results, success, raw] = dcopf_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 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0046 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0047 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0048 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0049 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0050 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0051 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0052 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0053 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0054
0055
0056 mpc = om.get_mpc();
0057 [baseMVA, bus, gen, branch, gencost] = ...
0058 deal(mpc.baseMVA, mpc.bus, mpc.gen, mpc.branch, mpc.gencost);
0059 cp = om.get_cost_params();
0060 Bf = om.get_userdata('Bf');
0061 Pfinj = om.get_userdata('Pfinj');
0062 [vv, ll] = om.get_idx();
0063
0064
0065 nb = size(bus, 1);
0066 nl = size(branch, 1);
0067 ny = om.getN('var', 'y');
0068
0069
0070 model = om.problem_type();
0071 opt = mpopt2qpopt(mpopt, model);
0072 if strcmp(opt.alg, 'OSQP')
0073 opt.x0 = [];
0074 end
0075
0076
0077 if mpopt.opf.start < 2 && ...
0078 (strcmp(opt.alg, 'MIPS') || strcmp(opt.alg, 'IPOPT'))
0079 [x0, xmin, xmax] = om.params_var();
0080 s = 1;
0081 lb = xmin; ub = xmax;
0082 lb(xmin == -Inf) = -1e10;
0083 ub(xmax == Inf) = 1e10;
0084 x0 = (lb + ub) / 2;
0085 k = find(xmin == -Inf & xmax < Inf);
0086 x0(k) = xmax(k) - s;
0087 k = find(xmin > -Inf & xmax == Inf);
0088 x0(k) = xmin(k) + s;
0089 Varefs = bus(bus(:, BUS_TYPE) == REF, VA) * (pi/180);
0090 x0(vv.i1.Va:vv.iN.Va) = Varefs(1);
0091 if ny > 0
0092 ipwl = find(gencost(:, MODEL) == PW_LINEAR);
0093 c = gencost(sub2ind(size(gencost), ipwl, NCOST+2*gencost(ipwl, NCOST)));
0094 x0(vv.i1.y:vv.iN.y) = max(c) + 0.1 * abs(max(c));
0095 end
0096 opt.x0 = x0;
0097 end
0098
0099
0100 [x, f, eflag, output, lambda] = om.solve(opt);
0101 success = (eflag == 1);
0102
0103
0104 if ~any(isnan(x))
0105
0106 Va = x(vv.i1.Va:vv.iN.Va);
0107 Pg = x(vv.i1.Pg:vv.iN.Pg);
0108
0109
0110 bus(:, VM) = ones(nb, 1);
0111 bus(:, VA) = Va * 180/pi;
0112 gen(:, PG) = Pg * baseMVA;
0113
0114
0115 branch(:, [QF, QT]) = zeros(nl, 2);
0116 branch(:, PF) = (Bf * Va + Pfinj) * baseMVA;
0117 branch(:, PT) = -branch(:, PF);
0118 end
0119
0120
0121 mu_l = lambda.mu_l;
0122 mu_u = lambda.mu_u;
0123 muLB = lambda.lower;
0124 muUB = lambda.upper;
0125
0126
0127 il = find(branch(:, RATE_A) ~= 0 & branch(:, RATE_A) < 1e10);
0128 bus(:, [LAM_P, LAM_Q, MU_VMIN, MU_VMAX]) = zeros(nb, 4);
0129 gen(:, [MU_PMIN, MU_PMAX, MU_QMIN, MU_QMAX]) = zeros(size(gen, 1), 4);
0130 branch(:, [MU_SF, MU_ST]) = zeros(nl, 2);
0131 bus(:, LAM_P) = (mu_u(ll.i1.Pmis:ll.iN.Pmis) - mu_l(ll.i1.Pmis:ll.iN.Pmis)) / baseMVA;
0132 if ~isempty(il)
0133 branch(il, MU_SF) = mu_u(ll.i1.Pf:ll.iN.Pf) / baseMVA;
0134 branch(il, MU_ST) = mu_l(ll.i1.Pf:ll.iN.Pf) / baseMVA;
0135 end
0136 gen(:, MU_PMIN) = muLB(vv.i1.Pg:vv.iN.Pg) / baseMVA;
0137 gen(:, MU_PMAX) = muUB(vv.i1.Pg:vv.iN.Pg) / baseMVA;
0138 pimul = [
0139 mu_l - mu_u;
0140 -ones(ny>0, 1);
0141 muLB - muUB
0142 ];
0143
0144 mu = struct( ...
0145 'var', struct('l', muLB, 'u', muUB), ...
0146 'lin', struct('l', mu_l, 'u', mu_u) );
0147
0148 results = mpc;
0149 [results.bus, results.branch, results.gen, ...
0150 results.om, results.x, results.mu, results.f] = ...
0151 deal(bus, branch, gen, om, x, mu, f);
0152
0153 raw = struct('xr', x, 'pimul', pimul, 'info', eflag, 'output', output);