Home > matpower4.0 > extras > smartmarket > smartmkt.m

smartmkt

PURPOSE ^

SMARTMKT Runs the PowerWeb smart market.

SYNOPSIS ^

function [co, cb, r, dispatch, success] =smartmkt(mpc, offers, bids, mkt, mpopt)

DESCRIPTION ^

SMARTMKT  Runs the PowerWeb smart market.
   [CO, CB, RESULTS, DISPATCH, SUCCESS] = SMARTMKT(MPC, ...
       OFFERS, BIDS, MKT, MPOPT) runs the ISO smart market.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [co, cb, r, dispatch, success] = ...
0002             smartmkt(mpc, offers, bids, mkt, mpopt)
0003 %SMARTMKT  Runs the PowerWeb smart market.
0004 %   [CO, CB, RESULTS, DISPATCH, SUCCESS] = SMARTMKT(MPC, ...
0005 %       OFFERS, BIDS, MKT, MPOPT) runs the ISO smart market.
0006 
0007 %   MATPOWER
0008 %   $Id: smartmkt.m,v 1.33 2010/04/26 19:45:26 ray Exp $
0009 %   by Ray Zimmerman, PSERC Cornell
0010 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0011 %
0012 %   This file is part of MATPOWER.
0013 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0014 %
0015 %   MATPOWER is free software: you can redistribute it and/or modify
0016 %   it under the terms of the GNU General Public License as published
0017 %   by the Free Software Foundation, either version 3 of the License,
0018 %   or (at your option) any later version.
0019 %
0020 %   MATPOWER is distributed in the hope that it will be useful,
0021 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0022 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0023 %   GNU General Public License for more details.
0024 %
0025 %   You should have received a copy of the GNU General Public License
0026 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0027 %
0028 %   Additional permission under GNU GPL version 3 section 7
0029 %
0030 %   If you modify MATPOWER, or any covered work, to interface with
0031 %   other modules (such as MATLAB code and MEX-files) available in a
0032 %   MATLAB(R) or comparable environment containing parts covered
0033 %   under other licensing terms, the licensors of MATPOWER grant
0034 %   you additional permission to convey the resulting work.
0035 
0036 %%-----  initialization  -----
0037 %% default arguments
0038 if nargin < 5
0039     mpopt = mpoption;       %% use default options
0040 end
0041 
0042 %% options
0043 verbose = mpopt(31);
0044 
0045 %% initialize some stuff
0046 G = find( ~isload(mpc.gen) );       %% real generators
0047 L = find(  isload(mpc.gen) );       %% dispatchable loads
0048 nL = length(L);
0049 if isfield(offers, 'Q') || isfield(bids, 'Q')
0050     haveQ = 1;
0051 else
0052     haveQ = 0;
0053 end
0054 
0055 if haveQ && mkt.auction_type ~= 0 && mkt.auction_type ~= 5
0056     error(['smartmkt: Combined active/reactive power markets ', ...
0057             'are only implemented for auction types 0 and 5']);
0058 end
0059 
0060 %% set power flow formulation based on market
0061 mpopt = mpoption(mpopt, 'PF_DC', strcmp(mkt.OPF, 'DC'));
0062 
0063 %% define named indices into data matrices
0064 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0065     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0066 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0067     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0068     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0069 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0070 [QUANTITY, PRICE, FCOST, VCOST, SCOST, PENALTY] = idx_disp;
0071 
0072 %% set up cost info & generator limits
0073 mkt.lim = pricelimits(mkt.lim, isfield(offers, 'Q') || isfield(bids, 'Q'));
0074 [gen, genoffer] = off2case(mpc.gen, mpc.gencost, offers, bids, mkt.lim);
0075 
0076 %% move Pmin and Pmax limits out slightly to avoid problems
0077 %% with lambdas caused by rounding errors when corner point
0078 %% of cost function lies at exactly Pmin or Pmax
0079 if any(find(genoffer(:, MODEL) == PW_LINEAR))
0080     gg = find( ~isload(gen) );      %% skip dispatchable loads
0081     gen(gg, PMIN) = gen(gg, PMIN) - 100 * mpopt(16) * ones(size(gg));
0082     gen(gg, PMAX) = gen(gg, PMAX) + 100 * mpopt(16) * ones(size(gg));
0083 end
0084 
0085 %%-----  solve the optimization problem  -----
0086 %% attempt OPF
0087 mpc2 = mpc;
0088 mpc2.gen = gen;
0089 mpc2.gencost = genoffer;
0090 [r, success] = uopf(mpc2, mpopt);
0091 [bus, gen] = deal(r.bus, r.gen);
0092 if verbose && ~success
0093     fprintf('\nSMARTMARKET: non-convergent UOPF');
0094 end
0095 
0096 %%-----  compute quantities, prices & costs  -----
0097 %% compute quantities & prices
0098 ng = size(gen, 1);
0099 if success      %% OPF solved case fine
0100     %% create map of external bus numbers to bus indices
0101     i2e = bus(:, BUS_I);
0102     e2i = sparse(max(i2e), 1);
0103     e2i(i2e) = (1:size(bus, 1))';
0104 
0105     %% get nodal marginal prices from OPF
0106     gbus    = e2i(gen(:, GEN_BUS));                 %% indices of buses w/gens
0107     npP     = max([ size(offers.P.qty, 2) size(bids.P.qty, 2) ]);
0108     lamP    = sparse(1:ng, 1:ng, bus(gbus, LAM_P), ng, ng) * ones(ng, npP); %% real power prices
0109     lamQ    = sparse(1:ng, 1:ng, bus(gbus, LAM_Q), ng, ng) * ones(ng, npP); %% reactive power prices
0110     
0111     %% compute fudge factor for lamP to include price of bundled reactive power
0112     pf   = zeros(length(L), 1);                 %% for loads Q = pf * P
0113     Qlim =  (gen(L, QMIN) == 0) .* gen(L, QMAX) + ...
0114             (gen(L, QMAX) == 0) .* gen(L, QMIN);
0115     pf = Qlim ./ gen(L, PMIN);
0116 
0117     gtee_prc.offer = 1;         %% guarantee that cleared offers are >= offers
0118     Poffer = offers.P;
0119     Poffer.lam = lamP(G,:);
0120     Poffer.total_qty = gen(G, PG);
0121     
0122     Pbid = bids.P;
0123     Pbid.total_qty = -gen(L, PG);
0124     if haveQ
0125         Pbid.lam = lamP(L,:);   %% use unbundled lambdas
0126         gtee_prc.bid = 0;       %% allow cleared bids to be above bid price
0127     else
0128         Pbid.lam = lamP(L,:) + sparse(1:nL, 1:nL, pf, nL, nL) * lamQ(L,:);  %% bundled lambdas
0129         gtee_prc.bid = 1;       %% guarantee that cleared bids are <= bids
0130     end
0131 
0132     [co.P, cb.P] = auction(Poffer, Pbid, mkt.auction_type, mkt.lim.P, gtee_prc);
0133 
0134     if haveQ
0135         npQ = max([ size(offers.Q.qty, 2) size(bids.Q.qty, 2) ]);
0136         
0137         %% get nodal marginal prices from OPF
0138         lamQ    = sparse(1:ng, 1:ng, bus(gbus, LAM_Q), ng, ng) * ones(ng, npQ); %% reactive power prices
0139 
0140         Qoffer = offers.Q;
0141         Qoffer.lam = lamQ;      %% use unbundled lambdas
0142         Qoffer.total_qty = (gen(:, QG) > 0) .* gen(:, QG);
0143         
0144         Qbid = bids.Q;
0145         Qbid.lam = lamQ;        %% use unbundled lambdas
0146         Qbid.total_qty = (gen(:, QG) < 0) .* -gen(:, QG);
0147 
0148         %% too complicated to scale with mixed bids/offers
0149         %% (only auction_types 0 and 5 allowed)
0150         [co.Q, cb.Q] = auction(Qoffer, Qbid, mkt.auction_type, mkt.lim.Q, gtee_prc);
0151     end
0152 
0153     quantity    = gen(:, PG);
0154     price       = zeros(ng, 1);
0155     price(G)    = co.P.prc(:, 1);   %% need these for prices for
0156     price(L)    = cb.P.prc(:, 1);   %% gens that are shut down
0157     if npP == 1
0158         k = find( co.P.qty );
0159         price(G(k)) = co.P.prc(k, :);
0160         k = find( cb.P.qty );
0161         price(L(k)) = cb.P.prc(k, :);
0162     else
0163         k = find( sum( co.P.qty' )' );
0164         price(G(k)) = sum( co.P.qty(k, :)' .* co.P.prc(k, :)' )' ./ sum( co.P.qty(k, :)' )';
0165         k = find( sum( cb.P.qty' )' );
0166         price(L(k)) = sum( cb.P.qty(k, :)' .* cb.P.prc(k, :)' )' ./ sum( cb.P.qty(k, :)' )';
0167     end
0168 else        %% did not converge even with imports
0169     quantity    = zeros(ng, 1);
0170     price       = mkt.lim.P.max_offer * ones(ng, 1);
0171     co.P.qty = zeros(size(offers.P.qty));
0172     co.P.prc = zeros(size(offers.P.prc));
0173     cb.P.qty = zeros(size(bids.P.qty));
0174     cb.P.prc = zeros(size(bids.P.prc));
0175     if haveQ
0176         co.Q.qty = zeros(size(offers.Q.qty));
0177         co.Q.prc = zeros(size(offers.Q.prc));
0178         cb.Q.qty = zeros(size(bids.Q.qty));
0179         cb.Q.prc = zeros(size(bids.Q.prc));
0180     end
0181 end
0182 
0183 
0184 %% compute costs in $ (note, NOT $/hr)
0185 fcost   = mkt.t * totcost(mpc.gencost, zeros(ng, 1) );      %% fixed costs
0186 vcost   = mkt.t * totcost(mpc.gencost, quantity     ) - fcost;  %% variable costs
0187 scost   =   (~mkt.u0 & gen(:, GEN_STATUS) >  0) .* ...
0188                 mpc.gencost(:, STARTUP) + ...               %% startup costs
0189             ( mkt.u0 & gen(:, GEN_STATUS) <= 0) .* ...
0190                 mpc.gencost(:, SHUTDOWN);                   %% shutdown costs
0191 
0192 %% store in dispatch
0193 dispatch = zeros(ng, PENALTY);
0194 dispatch(:, [QUANTITY PRICE FCOST VCOST SCOST]) = [quantity price fcost vcost scost];

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005