Home > matpower6.0 > extras > smartmarket > runmarket.m

runmarket

PURPOSE ^

RUNMARKET Runs PowerWeb-style smart market.

SYNOPSIS ^

function [r, co, cb, f, dispatch, success, et] =runmarket(mpc, offers, bids, mkt, mpopt, fname, solvedcase)

DESCRIPTION ^

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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0048 %   by Ray Zimmerman, PSERC Cornell
0049 %
0050 %   This file is part of MATPOWER.
0051 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0052 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0053 
0054 %%-----  initialize  -----
0055 %% default arguments
0056 if nargin < 7
0057     solvedcase = '';                        %% don't save solved case
0058     if nargin < 6
0059         fname = '';                         %% don't print results to a file
0060         if nargin < 5
0061             mpopt = mpoption;               %% use default options
0062             if nargin < 4
0063                 mkt = [];      %% use default market
0064                 if nargin < 3
0065                     bids = struct([]);
0066                     if nargin < 2
0067                         offers = struct([]);
0068                         if nargin < 1
0069                             mpc = 'case9';  %% default data file is 'case9.m'
0070                         end
0071                     end
0072                 end
0073             end
0074         end
0075     end
0076 end
0077 
0078 %% read data & convert to internal bus numbering
0079 mpc = loadcase(mpc);
0080 
0081 %% assign default arguments
0082 if isempty(mkt)
0083     mkt = struct( 'OPF', [], 'auction_type', [], 'lim', [], 'u0', [], 't', []);
0084 end
0085 if ~isfield(mkt, 'OPF') || isempty(mkt.OPF)
0086     mkt.OPF = 'AC';         %% default OPF is AC
0087 end
0088 if ~isfield(mkt, 'auction_type') || isempty(mkt.auction_type)
0089     mkt.auction_type = 5;   %% default auction type is first price
0090 end
0091 if ~isfield(mkt, 'lim') || isempty(mkt.lim)
0092     mkt.lim = pricelimits([], isfield(offers, 'Q') || isfield(bids, 'Q'));
0093 end
0094 if ~isfield(mkt, 'u0') || isempty(mkt.u0)
0095     mkt.u0 = ones(size(mpc.gen, 1), 1); %% default for previous gen commitment, all on
0096 end
0097 if ~isfield(mkt, 't') || isempty(mkt.t)
0098     mkt.t = 1;              %% default dispatch duration in hours
0099 end
0100 
0101 %% if offers not defined, use gencost
0102 if isempty(offers) || isempty(offers.P.qty)
0103     [q, p] = case2off(mpc.gen, mpc.gencost);
0104 
0105     %% find indices for gens and variable loads
0106     G = find( ~isload(mpc.gen) );   %% real generators
0107     L = find(  isload(mpc.gen) );   %% variable loads
0108     offers = struct( 'P', struct( 'qty', q(G, :), 'prc', p(G, :) ) );
0109     bids   = struct( 'P', struct( 'qty', q(L, :), 'prc', p(L, :) ) );
0110 end
0111 if isempty(bids)
0112     np = size(offers.P.qty, 2);
0113     bids = struct( 'P', struct('qty', zeros(0,np), 'prc', zeros(0,np)));
0114 end
0115 
0116 %% start the clock
0117 t0 = clock;
0118 
0119 %% run the market
0120 [co, cb, r, dispatch, success] = smartmkt(mpc, offers, bids, mkt, mpopt);
0121 
0122 %% compute elapsed time
0123 et = etime(clock, t0);
0124 
0125 %% print results
0126 if fname
0127     [fd, msg] = fopen(fname, 'at');
0128     if fd == -1
0129         error(msg);
0130     else
0131         printmkt(r, mkt.t, dispatch, success, fd, mpopt);
0132         fclose(fd);
0133     end
0134 end
0135 printmkt(r, mkt.t, dispatch, success, 1, mpopt);
0136 
0137 %% save solved case
0138 if solvedcase
0139     savecase(solvedcase, r);
0140 end
0141 
0142 if nargout > 3
0143     f = r.f;
0144 end

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005