0001 function t_scale_load(quiet)
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 if nargin < 1
0034 quiet = 0;
0035 end
0036
0037 n_tests = 407;
0038
0039 t_begin(n_tests, quiet);
0040
0041
0042 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0043 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0044 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0045 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0046 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0047 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0048
0049 mpc = loadcase('t_auction_case');
0050 mpc.gen(8, GEN_BUS) = 2;
0051 mpc.gen(8, [QG QMIN QMAX]) = [ 3 0 3 ];
0052 mpc.gencost(7, COST:end) = [-30 -600 -20 -300 -10 -100 0 0];
0053 mpc.gencost(8, COST:end) = [-30 -60 -20 -30 -10 -10 0 0];
0054 mpc.gencost(9, COST:end) = [-30 -850 -10 -250 -5 -50 0 0];
0055
0056 mpc.gen = [mpc.gen(8, :); mpc.gen(1:7, :); mpc.gen(9, :)];
0057 mpc.gencost = [mpc.gencost(8, :); mpc.gencost(1:7, :); mpc.gencost(9, :)];
0058 gg = find(~isload(mpc.gen));
0059 ld = find( isload(mpc.gen));
0060 for k = 1:3
0061 a{k} = find(mpc.bus(:, BUS_AREA) == k);
0062 [junk, tmp, junk2] = intersect(mpc.gen(ld, GEN_BUS), a{k});
0063 lda{k} = ld(tmp);
0064 end
0065 for k = 1:3
0066 area(k).fixed.p = sum(mpc.bus(a{k}, PD));
0067 area(k).fixed.q = sum(mpc.bus(a{k}, QD));
0068 area(k).disp.p = -sum(mpc.gen(lda{k}, PMIN));
0069 area(k).disp.qmin = -sum(mpc.gen(lda{k}, QMIN));
0070 area(k).disp.qmax = -sum(mpc.gen(lda{k}, QMAX));
0071 area(k).disp.q = area(k).disp.qmin + area(k).disp.qmax;
0072 area(k).both.p = area(k).fixed.p + area(k).disp.p;
0073 area(k).both.q = area(k).fixed.q + area(k).disp.q;
0074 end
0075 total.fixed.p = sum(mpc.bus(:, PD));
0076 total.fixed.q = sum(mpc.bus(:, QD));
0077 total.disp.p = -sum(mpc.gen(ld, PMIN));
0078 total.disp.qmin = -sum(mpc.gen(ld, QMIN));
0079 total.disp.qmax = -sum(mpc.gen(ld, QMAX));
0080 total.disp.q = total.disp.qmin + total.disp.qmax;
0081 total.both.p = total.fixed.p + total.disp.p;
0082 total.both.q = total.fixed.q + total.disp.q;
0083 orig_gc = mpc.gencost;
0084
0085
0086 load = 2;
0087 t = 'all fixed loads (PQ) * 2 : ';
0088 bus = scale_load(load, mpc.bus);
0089 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0090 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0091 opt = struct('which', 'FIXED');
0092 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0093 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0094 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0095 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0096 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0097 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0098
0099 t = 'all fixed loads (P) * 2 : ';
0100 opt = struct('pq', 'P');
0101 bus = scale_load(load, mpc.bus, [], [], opt);
0102 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0103 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0104 opt = struct('pq', 'P', 'which', 'FIXED');
0105 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0106 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0107 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0108 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0109 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0110 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0111
0112 t = 'all loads (PQ) * 2 : ';
0113 [bus, gen] = scale_load(load, mpc.bus, mpc.gen);
0114 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0115 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0116 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0117 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0118 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0119
0120 t = 'all loads/costs (PQ) * 2 : ';
0121 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], [], mpc.gencost);
0122 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0123 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0124 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0125 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0126 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0127 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0128 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0129
0130 t = 'all loads (P) * 2 : ';
0131 opt = struct('pq', 'P');
0132 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0133 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0134 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0135 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0136 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0137 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0138
0139 t = 'all loads/costs (P) * 2 : ';
0140 opt = struct('pq', 'P');
0141 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0142 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0143 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0144 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0145 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0146 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0147 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0148 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0149
0150 t = 'all disp loads (PQ) * 2 : ';
0151 opt = struct('which', 'DISPATCHABLE');
0152 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0153 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0154 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0155 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0156 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0157 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0158
0159 t = 'all disp loads/costs (PQ) * 2 : ';
0160 opt = struct('which', 'DISPATCHABLE');
0161 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0162 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0163 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0164 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0165 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0166 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0167 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0168 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0169
0170 t = 'all disp loads (P) * 2 : ';
0171 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0172 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0173 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0174 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0175 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0176 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0177 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0178
0179 t = 'all disp loads/costs (P) * 2 : ';
0180 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0181 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0182 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0183 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0184 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0185 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0186 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0187 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0188 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0189
0190
0191 load = 200;
0192 t = 'all fixed loads (PQ) => total = 200 : ';
0193 opt = struct('scale', 'QUANTITY');
0194 bus = scale_load(load, mpc.bus, [], [], opt);
0195 t_is(sum(bus(:, PD)), load, 8, [t 'total fixed P']);
0196 t_is(sum(bus(:, QD)), load/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0197 opt = struct('scale', 'QUANTITY', 'which', 'FIXED');
0198 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0199 t_is(sum(bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0200 t_is(sum(bus(:, QD)), (load-total.disp.p)/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0201 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0202 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0203 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0204
0205 t = 'all fixed loads (P) => total = 200 : ';
0206 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0207 bus = scale_load(load, mpc.bus, [], [], opt);
0208 t_is(sum(bus(:, PD)), load, 8, [t 'total fixed P']);
0209 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0210 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'FIXED');
0211 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0212 t_is(sum(bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0213 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0214 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0215 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0216 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0217
0218 t = 'all loads (PQ) => total = 200 : ';
0219 opt = struct('scale', 'QUANTITY');
0220 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0221 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0222 t_is(sum(bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0223 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0224 t_is(-sum(gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0225 t_is(-sum(gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0226
0227 t = 'all loads/costs (PQ) => total = 200 : ';
0228 opt = struct('scale', 'QUANTITY');
0229 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0230 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0231 t_is(sum(bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0232 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0233 t_is(-sum(gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0234 t_is(-sum(gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0235 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0236 t_is(gencost(ld, COST:end), load/total.both.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0237
0238 t = 'all loads (P) => total = 200 : ';
0239 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0240 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0241 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0242 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0243 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0244 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0245 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0246
0247 t = 'all loads/costs (P) => total = 200 : ';
0248 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0249 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0250 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0251 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0252 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0253 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0254 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0255 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0256 t_is(gencost(ld, COST:end), load/total.both.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0257
0258 t = 'all disp loads (PQ) => total = 200 : ';
0259 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0260 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0261 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0262 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0263 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0264 t_is(-sum(gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0265 t_is(-sum(gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0266
0267 t = 'all disp loads/costs (PQ) => total = 200 : ';
0268 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0269 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0270 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0271 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0272 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0273 t_is(-sum(gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0274 t_is(-sum(gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0275 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0276 t_is(gencost(ld, COST:end), (load-total.fixed.p)/total.disp.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0277
0278 t = 'all disp loads (P) => total = 200 : ';
0279 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0280 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0281 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0282 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0283 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0284 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0285 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0286
0287 t = 'all disp loads/costs (P) => total = 200 : ';
0288 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0289 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0290 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0291 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0292 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0293 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0294 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0295 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0296 t_is(gencost(ld, COST:end), (load-total.fixed.p)/total.disp.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0297
0298
0299 t = 'area fixed loads (PQ) * [3 2 1] : ';
0300 load = [3 2 1];
0301 bus = scale_load(load, mpc.bus);
0302 for k = 1:length(load)
0303 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0304 t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0305 end
0306 opt = struct('which', 'FIXED');
0307 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0308 for k = 1:length(load)
0309 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0310 t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0311 t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0312 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0313 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0314 end
0315
0316 t = 'area fixed loads (P) * [3 2 1] : ';
0317 load = [3 2 1];
0318 opt = struct('pq', 'P');
0319 bus = scale_load(load, mpc.bus, [], [], opt);
0320 for k = 1:length(load)
0321 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0322 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0323 end
0324 opt = struct('pq', 'P', 'which', 'FIXED');
0325 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0326 for k = 1:length(load)
0327 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0328 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0329 t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0330 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0331 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0332 end
0333
0334 t = 'all area loads (PQ) * [3 2 1] : ';
0335 [bus, gen] = scale_load(load, mpc.bus, mpc.gen);
0336 for k = 1:length(load)
0337 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0338 t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0339 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0340 t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0341 t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0342 end
0343
0344 t = 'all area loads/costs (PQ) * [3 2 1] : ';
0345 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], [], mpc.gencost);
0346 for k = 1:length(load)
0347 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0348 t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0349 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0350 t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0351 t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0352 t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0353 end
0354 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0355
0356 t = 'all area loads (P) * [3 2 1] : ';
0357 opt = struct('pq', 'P');
0358 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0359 for k = 1:length(load)
0360 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0361 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0362 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0363 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0364 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0365 end
0366
0367 t = 'all area loads/costs (P) * [3 2 1] : ';
0368 opt = struct('pq', 'P');
0369 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0370 for k = 1:length(load)
0371 t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0372 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0373 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0374 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0375 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0376 t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0377 end
0378 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0379
0380 t = 'area disp loads (PQ) * [3 2 1] : ';
0381 opt = struct('which', 'DISPATCHABLE');
0382 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0383 for k = 1:length(load)
0384 t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0385 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0386 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0387 t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0388 t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0389 end
0390
0391 t = 'area disp loads/costs (PQ) * [3 2 1] : ';
0392 opt = struct('which', 'DISPATCHABLE');
0393 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0394 for k = 1:length(load)
0395 t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0396 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0397 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0398 t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0399 t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0400 t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0401 end
0402 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0403
0404 t = 'area disp loads (P) * [3 2 1] : ';
0405 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0406 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0407 for k = 1:length(load)
0408 t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0409 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0410 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0411 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0412 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0413 end
0414
0415 t = 'area disp loads/costs (P) * [3 2 1] : ';
0416 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0417 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0418 for k = 1:length(load)
0419 t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0420 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0421 t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0422 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0423 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0424 t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0425 end
0426 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0427
0428
0429 t = 'area fixed loads (PQ) => total = [100 80 60] : ';
0430 load = [100 80 60];
0431 opt = struct('scale', 'QUANTITY');
0432 bus = scale_load(load, mpc.bus, [], [], opt);
0433 for k = 1:length(load)
0434 t_is(sum(bus(a{k}, PD)), load(k), 8, sprintf('%s area %d fixed P', t, k));
0435 t_is(sum(bus(a{k}, QD)), load(k)/area(k).fixed.p*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0436 end
0437 opt = struct('scale', 'QUANTITY', 'which', 'FIXED');
0438 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0439 for k = 1:length(load)
0440 t_is(sum(bus(a{k}, PD)), load(k)-area(k).disp.p, 8, sprintf('%s area %d fixed P', t, k));
0441 t_is(sum(bus(a{k}, QD)), (load(k)-area(k).disp.p)/area(k).fixed.p*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0442 t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0443 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0444 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0445 end
0446
0447 t = 'area fixed loads (P) => total = [100 80 60] : ';
0448 load = [100 80 60];
0449 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0450 bus = scale_load(load, mpc.bus, [], [], opt);
0451 for k = 1:length(load)
0452 t_is(sum(bus(a{k}, PD)), load(k), 8, sprintf('%s area %d fixed P', t, k));
0453 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0454 end
0455 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'FIXED');
0456 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0457 for k = 1:length(load)
0458 t_is(sum(bus(a{k}, PD)), load(k)-area(k).disp.p, 8, sprintf('%s area %d fixed P', t, k));
0459 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0460 t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0461 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0462 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0463 end
0464
0465 t = 'all area loads (PQ) => total = [100 80 60] : ';
0466 opt = struct('scale', 'QUANTITY');
0467 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0468 for k = 1:length(load)
0469 t_is(sum(bus(a{k}, PD)), load(k)/area(k).both.p*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0470 t_is(sum(bus(a{k}, QD)), load(k)/area(k).both.p*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0471 t_is(-sum(gen(lda{k}, PMIN)), load(k)/area(k).both.p*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0472 t_is(-sum(gen(lda{k}, QMIN)), load(k)/area(k).both.p*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0473 t_is(-sum(gen(lda{k}, QMAX)), load(k)/area(k).both.p*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0474 end
0475
0476 t = 'all area loads (P) => total = [100 80 60] : ';
0477 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0478 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0479 for k = 1:length(load)
0480 t_is(sum(bus(a{k}, PD)), load(k)/area(k).both.p*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0481 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0482 t_is(-sum(gen(lda{k}, PMIN)), load(k)/area(k).both.p*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0483 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0484 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0485 end
0486
0487 t = 'area disp loads (PQ) => total = [100 80 60] : throws expected exception';
0488 load = [100 80 60];
0489 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0490 err = 0;
0491 try
0492 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0493 catch
0494 [msg, id] = lasterr;
0495 expected = 'scale_load: impossible to make zone 2 load equal 80 by scaling non-existent dispatchable load';
0496 if ~isempty(findstr(expected, msg))
0497 err = 1;
0498 end
0499 end
0500 t_ok(err, t);
0501
0502 t = 'area disp loads (PQ) => total = [100 74.3941 60] : ';
0503 load = [100 area(2).fixed.p 60];
0504 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0505 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0506 for k = 1:length(load)
0507 t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0508 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0509 t_is(-sum(gen(lda{k}, PMIN)), load(k)-area(k).fixed.p, 8, sprintf('%s area %d disp P', t, k));
0510 if k == 2
0511 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0512 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0513 else
0514 t_is(-sum(gen(lda{k}, QMIN)), (load(k)-area(k).fixed.p)/area(k).disp.p*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0515 t_is(-sum(gen(lda{k}, QMAX)), (load(k)-area(k).fixed.p)/area(k).disp.p*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0516 end
0517 end
0518
0519 t = 'area disp loads (P) => total = [100 74.3941 60] : ';
0520 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0521 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0522 for k = 1:length(load)
0523 t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0524 t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0525 t_is(-sum(gen(lda{k}, PMIN)), load(k)-area(k).fixed.p, 8, sprintf('%s area %d disp P', t, k));
0526 t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0527 t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0528 end
0529
0530
0531 t = 'explicit single load zone';
0532 load_zone = zeros(1, size(mpc.bus, 1));
0533 load_zone([3 4]) = 1;
0534 load = 2;
0535 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, load_zone);
0536 Pd = mpc.bus(:, PD);
0537 Pd([3 4]) = load * Pd([3 4]);
0538 t_is( bus(:, PD), Pd, 8, t);
0539
0540
0541 t = 'explicit multiple load zone';
0542 load_zone = zeros(1, size(mpc.bus, 1));
0543 load_zone([3 4]) = 1;
0544 load_zone([7 8]) = 2;
0545 load = [2 0.5];
0546 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, load_zone);
0547 Pd = mpc.bus(:, PD);
0548 Pd([3 4]) = load(1) * Pd([3 4]);
0549 Pd([7 8]) = load(2) * Pd([7 8]);
0550 t_is( bus(:, PD), Pd, 8, t);
0551
0552 t_end;