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

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005