0001 function t_most_uc(quiet, create_plots, create_pdfs, savepath)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 if nargin < 4
0018 savepath = '.';
0019 if nargin < 3
0020 create_pdfs = 0;
0021 if nargin < 2
0022 create_plots = 0;
0023 if nargin < 1
0024 quiet = 0;
0025 end
0026 end
0027 end
0028 end
0029 if create_plots
0030 if create_pdfs
0031 fname = 'uc-ex';
0032 else
0033 fname = '';
0034 end
0035 pp = 0;
0036 end
0037
0038 solvers = {'CPLEX', 'GLPK', 'GUROBI', 'MOSEK', 'OT'};
0039 fcn = {'cplex', 'glpk', 'gurobi', 'mosek', 'intlinprog'};
0040
0041
0042
0043
0044 ntests = 52;
0045 t_begin(ntests*length(solvers), quiet);
0046
0047 if quiet
0048 verbose = 0;
0049 else
0050 verbose = 0;
0051 end
0052
0053
0054 if have_fcn('octave')
0055 if have_fcn('octave', 'vnum') >= 4
0056 file_in_path_warn_id = 'Octave:data-file-in-path';
0057 else
0058 file_in_path_warn_id = 'Octave:load-file-in-path';
0059 end
0060 s1 = warning('query', file_in_path_warn_id);
0061 warning('off', file_in_path_warn_id);
0062 end
0063
0064 casefile = 'ex_case3b';
0065 solnfile = 't_most_uc_soln';
0066 soln = load(solnfile);
0067 mpopt = mpoption;
0068 mpopt = mpoption(mpopt, 'out.gen', 1);
0069 mpopt = mpoption(mpopt, 'verbose', verbose);
0070
0071
0072 mpopt = mpoption(mpopt, 'model', 'DC');
0073 mpopt = mpoption(mpopt, 'most.price_stage_warn_tol', 1e1);
0074
0075
0076 if have_fcn('cplex')
0077
0078
0079 mpopt = mpoption(mpopt, 'cplex.lpmethod', 2);
0080
0081
0082 mpopt = mpoption(mpopt, 'cplex.opts.mip.tolerances.mipgap', 0);
0083 mpopt = mpoption(mpopt, 'cplex.opts.mip.tolerances.absmipgap', 0);
0084 mpopt = mpoption(mpopt, 'cplex.opts.threads', 2);
0085 end
0086 if have_fcn('glpk')
0087 mpopt = mpoption(mpopt, 'glpk.opts.mipgap', 0);
0088 mpopt = mpoption(mpopt, 'glpk.opts.tolint', 1e-10);
0089 mpopt = mpoption(mpopt, 'glpk.opts.tolobj', 1e-10);
0090 end
0091 if have_fcn('gurobi')
0092
0093
0094 mpopt = mpoption(mpopt, 'gurobi.method', 1);
0095
0096 mpopt = mpoption(mpopt, 'gurobi.threads', 2);
0097 mpopt = mpoption(mpopt, 'gurobi.opts.MIPGap', 0);
0098 mpopt = mpoption(mpopt, 'gurobi.opts.MIPGapAbs', 0);
0099 end
0100 if have_fcn('mosek')
0101 sc = mosek_symbcon;
0102
0103
0104
0105 mpopt = mpoption(mpopt, 'mosek.lp_alg', sc.MSK_OPTIMIZER_DUAL_SIMPLEX);
0106
0107
0108 mpopt = mpoption(mpopt, 'mosek.opts.MSK_IPAR_MIO_NODE_OPTIMIZER', sc.MSK_OPTIMIZER_DUAL_SIMPLEX);
0109 mpopt = mpoption(mpopt, 'mosek.opts.MSK_IPAR_MIO_ROOT_OPTIMIZER', sc.MSK_OPTIMIZER_DUAL_SIMPLEX);
0110 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_MIO_TOL_ABS_RELAX_INT', 1e-9);
0111
0112 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_MIO_TOL_REL_GAP', 0);
0113 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_MIO_TOL_ABS_GAP', 0);
0114 end
0115 if have_fcn('intlinprog')
0116
0117
0118
0119 mpopt = mpoption(mpopt, 'linprog.Algorithm', 'dual-simplex');
0120
0121 mpopt = mpoption(mpopt, 'intlinprog.RootLPAlgorithm', 'dual-simplex');
0122 mpopt = mpoption(mpopt, 'intlinprog.TolCon', 1e-9);
0123 mpopt = mpoption(mpopt, 'intlinprog.TolGapAbs', 0);
0124 mpopt = mpoption(mpopt, 'intlinprog.TolGapRel', 0);
0125 mpopt = mpoption(mpopt, 'intlinprog.TolInteger', 1e-6);
0126
0127
0128
0129
0130
0131 end
0132 if ~verbose
0133 mpopt = mpoption(mpopt, 'out.all', 0);
0134 end
0135
0136
0137
0138 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0139 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0140 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0141 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0142 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0143 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0144 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0145 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0146 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0147 [CT_LABEL, CT_PROB, CT_TABLE, CT_TBUS, CT_TGEN, CT_TBRCH, CT_TAREABUS, ...
0148 CT_TAREAGEN, CT_TAREABRCH, CT_ROW, CT_COL, CT_CHGTYPE, CT_REP, ...
0149 CT_REL, CT_ADD, CT_NEWVAL, CT_TLOAD, CT_TAREALOAD, CT_LOAD_ALL_PQ, ...
0150 CT_LOAD_FIX_PQ, CT_LOAD_DIS_PQ, CT_LOAD_ALL_P, CT_LOAD_FIX_P, ...
0151 CT_LOAD_DIS_P, CT_TGENCOST, CT_TAREAGENCOST, CT_MODCOST_F, ...
0152 CT_MODCOST_X] = idx_ct;
0153
0154
0155 mpc = loadcase(casefile);
0156
0157 nb = size(mpc.bus, 1);
0158 nl = size(mpc.branch, 1);
0159 ng = size(mpc.gen, 1);
0160
0161 xgd = loadxgendata('ex_xgd_uc', mpc);
0162 [iwind, mpc, xgd] = addwind('ex_wind_uc', mpc, xgd);
0163 profiles = getprofiles('ex_wind_profile_d', iwind);
0164 profiles = getprofiles('ex_load_profile', profiles);
0165 nt = size(profiles(1).values, 1);
0166
0167 mpc_full = mpc;
0168 xgd_full = xgd;
0169
0170 mpc.gencost(:, [STARTUP SHUTDOWN]) = 0;
0171 xgd.MinUp(2) = 1;
0172 xgd.PositiveLoadFollowReserveQuantity(3) = 250;
0173 xgd.PositiveLoadFollowReservePrice(3) = 1e-6;
0174 xgd.NegativeLoadFollowReservePrice(3) = 1e-6;
0175 mpc0 = mpc;
0176 xgd0 = xgd;
0177
0178 for s = 1:length(solvers)
0179 if ~have_fcn(fcn{s})
0180 t_skip(ntests, sprintf('%s not installed', solvers{s}));
0181 else
0182 mpopt = mpoption(mpopt, 'opf.dc.solver', solvers{s});
0183 mpopt = mpoption(mpopt, 'most.solver', mpopt.opf.dc.solver);
0184 mpopt = mpoption(mpopt, 'most.storage.cyclic', 1);
0185
0186 t = sprintf('%s : base (econ disp, no network) : ', solvers{s});
0187 mpc = mpc0;
0188 xgd = xgd0;
0189 mpopt = mpoption(mpopt, 'most.dc_model', 0);
0190 mdi = loadmd(mpc, nt, xgd, [], [], profiles);
0191 mdo = most(mdi, mpopt);
0192 ms = most_summary(mdo);
0193 t_ok(mdo.QP.exitflag > 0, [t 'success']);
0194 ex = soln.ed;
0195 t_is(ms.f, ex.f, 8, [t 'f']);
0196 t_is(ms.Pg, ex.Pg, 8, [t 'Pg']);
0197 t_is(ms.Rup, ex.Rup, 8, [t 'Rup']);
0198 t_is(ms.Rdn, ex.Rdn, 8, [t 'Rdn']);
0199 t_is(ms.Pf, ex.Pf, 8, [t 'Pf']);
0200 t_is(ms.u, ex.u, 8, [t 'u']);
0201 t_is(ms.lamP, ex.lamP, 5, [t 'lamP']);
0202 t_is(ms.muF, ex.muF, 8, [t 'muF']);
0203
0204 if create_plots
0205 pp = pp + 1;
0206 plot_case('Base : No Network', mdo, ms, 500, 100, savepath, pp, fname);
0207 end
0208
0209
0210 t = sprintf('%s : + DC OPF constraints : ', solvers{s});
0211 mpc = mpc0;
0212
0213 mpopt = mpoption(mpopt, 'most.dc_model', 1);
0214 mdi = loadmd(mpc, nt, xgd, [], [], profiles);
0215 mdo = most(mdi, mpopt);
0216 ms = most_summary(mdo);
0217 t_ok(mdo.QP.exitflag > 0, [t 'success']);
0218 ex = soln.dcopf;
0219 t_is(ms.f, ex.f, 8, [t 'f']);
0220 t_is(ms.Pg, ex.Pg, 8, [t 'Pg']);
0221 t_is(ms.Rup, ex.Rup, 8, [t 'Rup']);
0222 t_is(ms.Rdn, ex.Rdn, 8, [t 'Rdn']);
0223 t_is(ms.Pf, ex.Pf, 8, [t 'Pf']);
0224 t_is(ms.u, ex.u, 8, [t 'u']);
0225 t_is(ms.lamP, ex.lamP, 5, [t 'lamP']);
0226 t_is(ms.muF, ex.muF, 8, [t 'muF']);
0227
0228 if create_plots
0229 pp = pp + 1;
0230 plot_case('+ DC Network', mdo, ms, 500, 100, savepath, pp, fname);
0231 end
0232
0233
0234 t = sprintf('%s : + startup/shutdown costs : ', solvers{s});
0235 if mpopt.out.all
0236 fprintf('Add STARTUP and SHUTDOWN costs\n');
0237 end
0238 mpc = mpc_full;
0239
0240
0241
0242
0243
0244
0245 mdi = loadmd(mpc, nt, xgd, [], [], profiles);
0246 mdo = most(mdi, mpopt);
0247 ms = most_summary(mdo);
0248 t_ok(mdo.QP.exitflag > 0, [t 'success']);
0249 ex = soln.wstart;
0250 t_is(ms.f, ex.f, 8, [t 'f']);
0251 t_is(ms.Pg, ex.Pg, 8, [t 'Pg']);
0252 t_is(ms.Rup, ex.Rup, 8, [t 'Rup']);
0253 t_is(ms.Rdn, ex.Rdn, 8, [t 'Rdn']);
0254 t_is(ms.Pf, ex.Pf, 8, [t 'Pf']);
0255 t_is(ms.u, ex.u, 8, [t 'u']);
0256 t_is(ms.lamP, ex.lamP, 8, [t 'lamP']);
0257 t_is(ms.muF, ex.muF, 8, [t 'muF']);
0258
0259 if create_plots
0260 pp = pp + 1;
0261 plot_case('+ Startup/Shutdown Costs', mdo, ms, 500, 100, savepath, pp, fname);
0262 end
0263
0264
0265 t = sprintf('%s : + min up/down time constraints : ', solvers{s});
0266 if mpopt.out.all
0267 fprintf('Add MinUp time\n');
0268 end
0269 xgd.MinUp(2) = 3;
0270 mdi = loadmd(mpc, nt, xgd, [], [], profiles);
0271 mdo = most(mdi, mpopt);
0272 ms = most_summary(mdo);
0273 t_ok(mdo.QP.exitflag > 0, [t 'success']);
0274 ex = soln.wminup;
0275 t_is(ms.f, ex.f, 8, [t 'f']);
0276 t_is(ms.Pg, ex.Pg, 8, [t 'Pg']);
0277 t_is(ms.Rup, ex.Rup, 8, [t 'Rup']);
0278 t_is(ms.Rdn, ex.Rdn, 8, [t 'Rdn']);
0279 t_is(ms.Pf, ex.Pf, 8, [t 'Pf']);
0280 t_is(ms.u, ex.u, 8, [t 'u']);
0281 t_is(ms.lamP, ex.lamP, 8, [t 'lamP']);
0282 t_is(ms.muF, ex.muF, 8, [t 'muF']);
0283
0284 if create_plots
0285 pp = pp + 1;
0286 plot_case('+ Min Up/Down Time Constraints', mdo, ms, 500, 100, savepath, pp, fname);
0287 end
0288
0289
0290 t = sprintf('%s : + ramp constraint/ramp res cost : ', solvers{s});
0291 if mpopt.out.all
0292 fprintf('Restrict ramping and add ramp reserve costs\n');
0293 end
0294 xgd = xgd_full;
0295 mdi = loadmd(mpc, nt, xgd, [], [], profiles);
0296 mdo = most(mdi, mpopt);
0297 ms = most_summary(mdo);
0298 t_ok(mdo.QP.exitflag > 0, [t 'success']);
0299 ex = soln.wramp;
0300 t_is(ms.f, ex.f, 8, [t 'f']);
0301 t_is(ms.Pg, ex.Pg, 8, [t 'Pg']);
0302 t_is(ms.Rup, ex.Rup, 8, [t 'Rup']);
0303 t_is(ms.Rdn, ex.Rdn, 8, [t 'Rdn']);
0304 t_is(ms.Pf, ex.Pf, 8, [t 'Pf']);
0305 t_is(ms.u, ex.u, 8, [t 'u']);
0306 t_is(ms.lamP, ex.lamP, 8, [t 'lamP']);
0307 t_is(ms.muF, ex.muF, 8, [t 'muF']);
0308
0309 if create_plots
0310 pp = pp + 1;
0311 plot_case('+ Ramping Constraints/Ramp Reserve Costs', mdo, ms, 500, 100, savepath, pp, fname);
0312 end
0313
0314
0315 t = sprintf('%s : + storage : ', solvers{s});
0316 if mpopt.out.all
0317 fprintf('Add storage\n');
0318 end
0319 [iess, mpc, xgd, sd] = addstorage('ex_storage', mpc, xgd);
0320 mdi = loadmd(mpc, nt, xgd, sd, [], profiles);
0321 mdo = most(mdi, mpopt);
0322 ms = most_summary(mdo);
0323 t_ok(mdo.QP.exitflag > 0, [t 'success']);
0324 ex = soln.wstorage;
0325 t_is(ms.f, ex.f, 8, [t 'f']);
0326 t_is(ms.Pg, ex.Pg, 8, [t 'Pg']);
0327 t_is(ms.Rup, ex.Rup, 8, [t 'Rup']);
0328 t_is(ms.Rdn, ex.Rdn, 8, [t 'Rdn']);
0329 t_is(ms.Pf, ex.Pf, 8, [t 'Pf']);
0330 t_is(ms.u, ex.u, 8, [t 'u']);
0331
0332
0333
0334 if create_plots
0335 pp = pp + 1;
0336 plot_case('+ Storage', mdo, ms, 500, 100, savepath, pp, fname);
0337 create_plots = 0;
0338 end
0339
0340 end
0341 end
0342
0343 if have_fcn('octave')
0344 warning(s1.state, file_in_path_warn_id);
0345 end
0346
0347 t_end;
0348
0349
0350
0351 function h = plot_case(label, md, ms, maxq, maxp, mypath, pp, fname)
0352
0353 if nargin < 8
0354 fname = '';
0355 end
0356
0357
0358 cc = {[0 0.45 0.74], [0.85 0.33 0.1], [0.93 0.69 0.13], [0.49 0.18 0.56], [0.47 0.67 0.19]};
0359
0360 ig = (1:3)';
0361 id = 4;
0362 iw = 5;
0363 is = 6;
0364
0365 subplot(3, 1, 1);
0366 md.mpc = rmfield(md.mpc, 'genfuel');
0367 plot_uc(md, [], 'title', label);
0368 ylabel('Unit Commitment', 'FontSize', 16);
0369 ah = gca;
0370 ah.YAxisLocation = 'left';
0371
0372 subplot(3, 1, 2);
0373 x = (1:ms.nt)';
0374 y1 = ms.Pg(ig, :)';
0375 if ms.ng == 6
0376 y1 = [y1 max(-ms.Pg(is, :), 0)' max(ms.Pg(is, :), 0)'];
0377 end
0378 y2 = -sum(ms.Pg([id; iw], :), 1)';
0379 [ah1, h1, h2] = plotyy(x, y1, x, y2);
0380 axis(ah1(1), [0.5 12.5 0 maxq]);
0381 axis(ah1(2), [0.5 12.5 0 maxq]);
0382
0383
0384
0385
0386 ah1(1).YTickMode = 'auto';
0387 ah1(2).YTickMode = 'auto';
0388 ah1(1).XTick = 1:12;
0389 nn = 3;
0390 for j = 1:3
0391 h1(j).LineWidth = 2;
0392 h1(j).Color = cc{j};
0393 end
0394 if ms.ng == 6
0395 h1(4).LineWidth = 2;
0396 h1(4).Color = cc{5};
0397 h1(4).LineStyle = ':';
0398 h1(5).LineWidth = 2;
0399 h1(5).Color = cc{5};
0400 end
0401 h2.LineWidth = 2;
0402 h2.Color = cc{4};
0403 h2.LineStyle = ':';
0404 ah1(2).YColor = cc{4};
0405
0406 ylabel(ah1(1), 'Generation, MW', 'FontSize', 16);
0407 ylabel(ah1(2), 'Net Load, MW', 'FontSize', 16);
0408 xlabel('Period', 'FontSize', 16);
0409 set(ah1(1), 'FontSize', 14);
0410 set(ah1(2), 'FontSize', 14);
0411 if ms.ng == 6
0412 legend('Gen 1', 'Gen 2', 'Gen 3', 'Storage Charge', 'Storage Discharge', 'Location', [0.7 0.6 0 0]);
0413 else
0414 legend('Gen 1', 'Gen 2', 'Gen 3', 'Location', [0.7 0.58 0 0]);
0415 end
0416
0417 subplot(3, 1, 3);
0418 y1 = ms.lamP';
0419 plot(x, y1, 'LineWidth', 2);
0420
0421 ylabel('Nodal Price, $/MWh', 'FontSize', 16);
0422 xlabel('Period', 'FontSize', 16);
0423 axis([0.5 12.5 0 maxp]);
0424 ah = gca;
0425 set(ah, 'FontSize', 14);
0426 ah.XTick = 1:12;
0427 legend('Bus 1', 'Bus 2', 'Bus 3', 'Location', [0.7 0.28 0 0]);
0428
0429 if nargin > 7 && ~isempty(fname)
0430 h = gcf;
0431 set(h, 'PaperSize', [11 8.5]);
0432 set(h, 'PaperPosition', [0.25 0.25 10.5 8]);
0433 print('-dpdf', fullfile(mypath, sprintf('%s-%d', fname, pp)));
0434 end