UOPF Solves combined unit decommitment / optimal power flow. [RESULTS, SUCCESS] = UOPF(MPC, MPOPT) Returns either a RESULTS struct and an optional SUCCESS flag, or individual data matrices, the objective function value and a SUCCESS flag. In the latter case, there are additional optional return values. See Examples below for the possible calling syntax options. Examples: Output argument options: results = uopf(...) [results, success] = uopf(...) [bus, gen, branch, f, success] = uopf(...) [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = uopf(...) Input arguments options: uopf(mpc) uopf(mpc, mpopt) uopf(mpc, userfcn, mpopt) uopf(mpc, A, l, u) uopf(mpc, A, l, u, mpopt) uopf(mpc, A, l, u, mpopt, N, fparm, H, Cw) uopf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu) uopf(baseMVA, bus, gen, branch, areas, gencost) uopf(baseMVA, bus, gen, branch, areas, gencost, mpopt) uopf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt) uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u) uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt) uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ... mpopt, N, fparm, H, Cw) uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ... mpopt, N, fparm, H, Cw, z0, zl, zu) See OPF for more information on input and output arguments. Solves a combined unit decommitment and optimal power flow for a single time period. Uses an algorithm similar to dynamic programming. It proceeds through a sequence of stages, where stage N has N generators shut down, starting with N=0. In each stage, it forms a list of candidates (gens at their Pmin limits) and computes the cost with each one of them shut down. It selects the least cost case as the starting point for the next stage, continuing until there are no more candidates to be shut down or no more improvement can be gained by shutting something down. If MPOPT.verbose (see MPOPTION) is true, it prints progress info, if it is > 1 it prints the output of each individual opf. See also OPF, RUNUOPF.
0001 function [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = ... 0002 uopf(varargin) 0003 %UOPF Solves combined unit decommitment / optimal power flow. 0004 % [RESULTS, SUCCESS] = UOPF(MPC, MPOPT) 0005 % 0006 % Returns either a RESULTS struct and an optional SUCCESS flag, or individual 0007 % data matrices, the objective function value and a SUCCESS flag. In the 0008 % latter case, there are additional optional return values. See Examples 0009 % below for the possible calling syntax options. 0010 % 0011 % Examples: 0012 % Output argument options: 0013 % 0014 % results = uopf(...) 0015 % [results, success] = uopf(...) 0016 % [bus, gen, branch, f, success] = uopf(...) 0017 % [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = uopf(...) 0018 % 0019 % Input arguments options: 0020 % 0021 % uopf(mpc) 0022 % uopf(mpc, mpopt) 0023 % uopf(mpc, userfcn, mpopt) 0024 % uopf(mpc, A, l, u) 0025 % uopf(mpc, A, l, u, mpopt) 0026 % uopf(mpc, A, l, u, mpopt, N, fparm, H, Cw) 0027 % uopf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu) 0028 % 0029 % uopf(baseMVA, bus, gen, branch, areas, gencost) 0030 % uopf(baseMVA, bus, gen, branch, areas, gencost, mpopt) 0031 % uopf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt) 0032 % uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u) 0033 % uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt) 0034 % uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ... 0035 % mpopt, N, fparm, H, Cw) 0036 % uopf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ... 0037 % mpopt, N, fparm, H, Cw, z0, zl, zu) 0038 % 0039 % See OPF for more information on input and output arguments. 0040 % 0041 % Solves a combined unit decommitment and optimal power flow for a single 0042 % time period. Uses an algorithm similar to dynamic programming. It proceeds 0043 % through a sequence of stages, where stage N has N generators shut down, 0044 % starting with N=0. In each stage, it forms a list of candidates (gens at 0045 % their Pmin limits) and computes the cost with each one of them shut down. 0046 % It selects the least cost case as the starting point for the next stage, 0047 % continuing until there are no more candidates to be shut down or no 0048 % more improvement can be gained by shutting something down. 0049 % If MPOPT.verbose (see MPOPTION) is true, it prints progress 0050 % info, if it is > 1 it prints the output of each individual opf. 0051 % 0052 % See also OPF, RUNUOPF. 0053 0054 % MATPOWER 0055 % $Id: uopf.m 2366 2014-07-24 18:45:51Z ray $ 0056 % by Ray Zimmerman, PSERC Cornell 0057 % Copyright (c) 1996-2013 by Power System Engineering Research Center (PSERC) 0058 % 0059 % This file is part of MATPOWER. 0060 % See http://www.pserc.cornell.edu/matpower/ for more info. 0061 % 0062 % MATPOWER is free software: you can redistribute it and/or modify 0063 % it under the terms of the GNU General Public License as published 0064 % by the Free Software Foundation, either version 3 of the License, 0065 % or (at your option) any later version. 0066 % 0067 % MATPOWER is distributed in the hope that it will be useful, 0068 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0069 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0070 % GNU General Public License for more details. 0071 % 0072 % You should have received a copy of the GNU General Public License 0073 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0074 % 0075 % Additional permission under GNU GPL version 3 section 7 0076 % 0077 % If you modify MATPOWER, or any covered work, to interface with 0078 % other modules (such as MATLAB code and MEX-files) available in a 0079 % MATLAB(R) or comparable environment containing parts covered 0080 % under other licensing terms, the licensors of MATPOWER grant 0081 % you additional permission to convey the resulting work. 0082 0083 %%----- initialization ----- 0084 t0 = clock; %% start timer 0085 0086 %% process input arguments 0087 [mpc, mpopt] = opf_args(varargin{:}); 0088 0089 %% options 0090 if mpopt.verbose %% turn down verbosity one level for calls to opf 0091 mpopt = mpoption(mpopt, 'verbose', mpopt.verbose-1); 0092 end 0093 0094 %% define named indices into bus, gen, branch matrices 0095 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 0096 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 0097 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0098 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0099 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0100 0101 %%----- do combined unit commitment/optimal power flow ----- 0102 0103 %% check for sum(Pmin) > total load, decommit as necessary 0104 on = find( mpc.gen(:, GEN_STATUS) > 0 & ~isload(mpc.gen) ); %% gens in service 0105 onld = find( mpc.gen(:, GEN_STATUS) > 0 & isload(mpc.gen) ); %% disp loads in serv 0106 load_capacity = sum(mpc.bus(:, PD)) - sum(mpc.gen(onld, PMIN)); %% total load capacity 0107 Pmin = mpc.gen(on, PMIN); 0108 while sum(Pmin) > load_capacity 0109 %% shut down most expensive unit 0110 avgPmincost = totcost(mpc.gencost(on, :), Pmin) ./ Pmin; 0111 [junk, i] = fairmax(avgPmincost); %% pick one with max avg cost at Pmin 0112 i = on(i); %% convert to generator index 0113 0114 if mpopt.verbose 0115 fprintf('Shutting down generator %d so all Pmin limits can be satisfied.\n', i); 0116 end 0117 0118 %% set generation to zero 0119 mpc.gen(i, [ PG QG GEN_STATUS ]) = 0; 0120 0121 %% update minimum gen capacity 0122 on = find( mpc.gen(:, GEN_STATUS) > 0 & ~isload(mpc.gen) ); %% gens in service 0123 Pmin = mpc.gen(on, PMIN); 0124 end 0125 if ~any(mpc.gen(:, GEN_STATUS) > 0) %% don't bother to run anything if 0126 success = 0; %% everything has been shut down 0127 results0 = mpc; 0128 results0.success = success; 0129 results0.f = NaN; 0130 results0.et = 0; 0131 if mpopt.verbose 0132 fprintf('Infeasible problem, Pmin limits cannot be satisfied without shutting down all generators.\n'); 0133 end 0134 else 0135 %% run initial opf 0136 [results, success] = opf(mpc, mpopt); 0137 0138 %% best case so far 0139 results1 = results; 0140 0141 %% best case for this stage (ie. with n gens shut down, n=0,1,2 ...) 0142 results0 = results1; 0143 mpc.bus = results0.bus; %% use these V as starting point for OPF 0144 0145 while 1 0146 %% get candidates for shutdown 0147 candidates = find(results0.gen(:, MU_PMIN) > 0 & results0.gen(:, PMIN) > 0); 0148 if isempty(candidates) 0149 break; 0150 end 0151 done = 1; %% do not check for further decommitment unless we 0152 %% see something better during this stage 0153 for i = 1:length(candidates) 0154 k = candidates(i); 0155 %% start with best for this stage 0156 mpc.gen = results0.gen; 0157 0158 %% shut down gen k 0159 mpc.gen(k, [ PG QG GEN_STATUS ]) = 0; 0160 0161 %% run opf 0162 if any(mpc.gen(:, GEN_STATUS) > 0) 0163 [results, success] = opf(mpc, mpopt); 0164 else 0165 success = 0; 0166 end 0167 0168 %% something better? 0169 if success && results.f < results1.f 0170 results1 = results; 0171 k1 = k; 0172 done = 0; %% make sure we check for further decommitment 0173 end 0174 end 0175 0176 if done 0177 %% decommits at this stage did not help, so let's quit 0178 break; 0179 else 0180 %% shutting something else down helps, so let's keep going 0181 if mpopt.verbose 0182 fprintf('Shutting down generator %d.\n', k1); 0183 end 0184 0185 results0 = results1; 0186 mpc.bus = results0.bus; %% use these V as starting point for OPF 0187 end 0188 end 0189 end 0190 0191 %% compute elapsed time 0192 et = etime(clock, t0); 0193 0194 %% finish preparing output 0195 if nargout > 0 0196 success = results0.success; 0197 if nargout <= 2 0198 results0.et = et; 0199 bus = results0; 0200 gen = success; 0201 else 0202 [bus, gen, branch, f, info, xr, pimul] = deal(results0.bus, results0.gen, ... 0203 results0.branch, results0.f, results0.raw.info, ... 0204 results0.raw.xr, results0.raw.pimul); 0205 if isfield(results0, 'g') 0206 g = results0.g; 0207 end 0208 if isfield(results0, 'dg') 0209 jac = results0.dg; 0210 end 0211 end 0212 elseif results0.success 0213 results0.et = et; 0214 printpf(results0, 1, mpopt); 0215 end