RUNMARKET Runs PowerWeb-style smart market. [RESULTS, CO, CB, F, DISPATCH, SUCCESS, ET] = ... RUNMARKET(MPC, OFFERS, BIDS, MKT, MPOPT, FNAME, SOLVEDCASE) Computes the new generation and price schedules (cleared offers and bids) based on the OFFERS and BIDS submitted. See OFF2CASE for a description of the OFFERS and BIDS arguments. MKT is a struct with the following fields: auction_type - market used for dispatch and pricing t - time duration of the dispatch period in hours u0 - vector of gen commitment status from prev period lim - offer/bid/price limits (see 'help pricelimits') OPF - 'AC' or 'DC', default is 'AC' MPOPT is an optional MATPOWER options struct (see MPOPTION for details). The values for the auction_type field are defined as follows: 0 - discriminative pricing (price equal to offer or bid) 1 - last accepted offer auction 2 - first rejected offer auction 3 - last accepted bid auction 4 - first rejected bid auction 5 - first price auction (marginal unit, offer or bid, sets the price) 6 - second price auction (if offer is marginal, then price is set by min(FRO,LAB), if bid, then max(FRB,LAO) 7 - split the difference pricing (price set by last accepted offer & bid) 8 - LAO sets seller price, LAB sets buyer price The default auction_type is 5, where the marginal block (offer or bid) sets the price. The default lim sets no offer/bid or price limits. The default previous commitment status u0 is all ones (assume everything was running) and the default duration t is 1 hour. The results may optionally be printed to a file (appended if the file exists) whose name is given in FNAME (in addition to printing to STDOUT). Optionally returns the final values of the solved case in results, the cleared offers and bids in CO and CB, the objective function value F, the old style DISPATCH matrix, the convergence status of the OPF in SUCCESS, and the elapsed time ET. If a name is given in SOLVEDCASE, the solved case will be written to a case file in MATPOWER format with the specified name. See also OFF2CASE.
0001 function [r, co, cb, f, dispatch, success, et] = ... 0002 runmarket(mpc, offers, bids, mkt, mpopt, fname, solvedcase) 0003 %RUNMARKET Runs PowerWeb-style smart market. 0004 % [RESULTS, CO, CB, F, DISPATCH, SUCCESS, ET] = ... 0005 % RUNMARKET(MPC, OFFERS, BIDS, MKT, MPOPT, FNAME, SOLVEDCASE) 0006 % 0007 % Computes the new generation and price schedules (cleared offers and bids) 0008 % based on the OFFERS and BIDS submitted. See OFF2CASE for a 0009 % description of the OFFERS and BIDS arguments. MKT is a struct with the 0010 % following fields: 0011 % auction_type - market used for dispatch and pricing 0012 % t - time duration of the dispatch period in hours 0013 % u0 - vector of gen commitment status from prev period 0014 % lim - offer/bid/price limits (see 'help pricelimits') 0015 % OPF - 'AC' or 'DC', default is 'AC' 0016 % 0017 % MPOPT is an optional MATPOWER options struct (see MPOPTION for 0018 % details). The values for the auction_type field are defined as follows: 0019 % 0020 % 0 - discriminative pricing (price equal to offer or bid) 0021 % 1 - last accepted offer auction 0022 % 2 - first rejected offer auction 0023 % 3 - last accepted bid auction 0024 % 4 - first rejected bid auction 0025 % 5 - first price auction (marginal unit, offer or bid, sets the price) 0026 % 6 - second price auction (if offer is marginal, then price is set 0027 % by min(FRO,LAB), if bid, then max(FRB,LAO) 0028 % 7 - split the difference pricing (price set by last accepted offer & bid) 0029 % 8 - LAO sets seller price, LAB sets buyer price 0030 % 0031 % The default auction_type is 5, where the marginal block (offer or bid) 0032 % sets the price. The default lim sets no offer/bid or price limits. The 0033 % default previous commitment status u0 is all ones (assume everything was 0034 % running) and the default duration t is 1 hour. The results may 0035 % optionally be printed to a file (appended if the file exists) whose name 0036 % is given in FNAME (in addition to printing to STDOUT). Optionally 0037 % returns the final values of the solved case in results, the cleared 0038 % offers and bids in CO and CB, the objective function value F, the old 0039 % style DISPATCH matrix, the convergence status of the OPF in SUCCESS, and 0040 % the elapsed time ET. If a name is given in SOLVEDCASE, the solved case 0041 % will be written to a case file in MATPOWER format with the specified 0042 % name. 0043 % 0044 % See also OFF2CASE. 0045 0046 % MATPOWER 0047 % $Id: runmarket.m 2229 2013-12-11 01:28:09Z ray $ 0048 % by Ray Zimmerman, PSERC Cornell 0049 % Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC) 0050 % 0051 % This file is part of MATPOWER. 0052 % See http://www.pserc.cornell.edu/matpower/ for more info. 0053 % 0054 % MATPOWER is free software: you can redistribute it and/or modify 0055 % it under the terms of the GNU General Public License as published 0056 % by the Free Software Foundation, either version 3 of the License, 0057 % or (at your option) any later version. 0058 % 0059 % MATPOWER is distributed in the hope that it will be useful, 0060 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0061 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0062 % GNU General Public License for more details. 0063 % 0064 % You should have received a copy of the GNU General Public License 0065 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0066 % 0067 % Additional permission under GNU GPL version 3 section 7 0068 % 0069 % If you modify MATPOWER, or any covered work, to interface with 0070 % other modules (such as MATLAB code and MEX-files) available in a 0071 % MATLAB(R) or comparable environment containing parts covered 0072 % under other licensing terms, the licensors of MATPOWER grant 0073 % you additional permission to convey the resulting work. 0074 0075 %%----- initialize ----- 0076 %% default arguments 0077 if nargin < 7 0078 solvedcase = ''; %% don't save solved case 0079 if nargin < 6 0080 fname = ''; %% don't print results to a file 0081 if nargin < 5 0082 mpopt = mpoption; %% use default options 0083 if nargin < 4 0084 mkt = []; %% use default market 0085 if nargin < 3 0086 bids = struct([]); 0087 if nargin < 2 0088 offers = struct([]); 0089 if nargin < 1 0090 mpc = 'case9'; %% default data file is 'case9.m' 0091 end 0092 end 0093 end 0094 end 0095 end 0096 end 0097 end 0098 0099 %% read data & convert to internal bus numbering 0100 mpc = loadcase(mpc); 0101 0102 %% assign default arguments 0103 if isempty(mkt) 0104 mkt = struct( 'OPF', [], 'auction_type', [], 'lim', [], 'u0', [], 't', []); 0105 end 0106 if ~isfield(mkt, 'OPF') || isempty(mkt.OPF) 0107 mkt.OPF = 'AC'; %% default OPF is AC 0108 end 0109 if ~isfield(mkt, 'auction_type') || isempty(mkt.auction_type) 0110 mkt.auction_type = 5; %% default auction type is first price 0111 end 0112 if ~isfield(mkt, 'lim') || isempty(mkt.lim) 0113 mkt.lim = pricelimits([], isfield(offers, 'Q') || isfield(bids, 'Q')); 0114 end 0115 if ~isfield(mkt, 'u0') || isempty(mkt.u0) 0116 mkt.u0 = ones(size(mpc.gen, 1), 1); %% default for previous gen commitment, all on 0117 end 0118 if ~isfield(mkt, 't') || isempty(mkt.t) 0119 mkt.t = 1; %% default dispatch duration in hours 0120 end 0121 0122 %% if offers not defined, use gencost 0123 if isempty(offers) || isempty(offers.P.qty) 0124 [q, p] = case2off(mpc.gen, mpc.gencost); 0125 0126 %% find indices for gens and variable loads 0127 G = find( ~isload(mpc.gen) ); %% real generators 0128 L = find( isload(mpc.gen) ); %% variable loads 0129 offers = struct( 'P', struct( 'qty', q(G, :), 'prc', p(G, :) ) ); 0130 bids = struct( 'P', struct( 'qty', q(L, :), 'prc', p(L, :) ) ); 0131 end 0132 if isempty(bids) 0133 np = size(offers.P.qty, 2); 0134 bids = struct( 'P', struct('qty', zeros(0,np), 'prc', zeros(0,np))); 0135 end 0136 0137 %% start the clock 0138 t0 = clock; 0139 0140 %% run the market 0141 [co, cb, r, dispatch, success] = smartmkt(mpc, offers, bids, mkt, mpopt); 0142 0143 %% compute elapsed time 0144 et = etime(clock, t0); 0145 0146 %% print results 0147 if fname 0148 [fd, msg] = fopen(fname, 'at'); 0149 if fd == -1 0150 error(msg); 0151 else 0152 printmkt(r, mkt.t, dispatch, success, fd, mpopt); 0153 fclose(fd); 0154 end 0155 end 0156 printmkt(r, mkt.t, dispatch, success, 1, mpopt); 0157 0158 %% save solved case 0159 if solvedcase 0160 savecase(solvedcase, r); 0161 end 0162 0163 if nargout > 3 0164 f = r.f; 0165 end