Home > matpower5.0 > printpf.m

printpf

PURPOSE ^

PRINTPF Prints power flow results.

SYNOPSIS ^

function printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt)

DESCRIPTION ^

PRINTPF   Prints power flow results.
   PRINTPF(RESULTS, FD, MPOPT)
   PRINTPF(BASEMVA, BUS, GEN, BRANCH, F, SUCCESS, ET, FD, MPOPT)

   Prints power flow and optimal power flow results to FD (a file
   descriptor which defaults to STDOUT), with the details of what
   gets printed controlled by the optional MPOPT argument, which is a
   MATPOWER options struct (see MPOPTION for details).

   The data can either be supplied in a single RESULTS struct, or
   in the individual arguments: BASEMVA, BUS, GEN, BRANCH, F, SUCCESS
   and ET, where F is the OPF objective function value, SUCCESS is
   true if the solution converged and false otherwise, and ET is the
   elapsed time for the computation in seconds. If F is given, it is
   assumed that the output is from an OPF run, otherwise it is assumed
   to be a simple power flow run.

   Examples:
       mpopt = mpoptions('out.gen', 1, 'out.bus', 0, 'out.branch', 0);
       [fd, msg] = fopen(fname, 'at');
       results = runopf(mpc);
       printpf(results);
       printpf(results, fd);
       printpf(results, fd, mpopt);
       printpf(baseMVA, bus, gen, branch, f, success, et);
       printpf(baseMVA, bus, gen, branch, f, success, et, fd);
       printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt);
       fclose(fd);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt)
0002 %PRINTPF   Prints power flow results.
0003 %   PRINTPF(RESULTS, FD, MPOPT)
0004 %   PRINTPF(BASEMVA, BUS, GEN, BRANCH, F, SUCCESS, ET, FD, MPOPT)
0005 %
0006 %   Prints power flow and optimal power flow results to FD (a file
0007 %   descriptor which defaults to STDOUT), with the details of what
0008 %   gets printed controlled by the optional MPOPT argument, which is a
0009 %   MATPOWER options struct (see MPOPTION for details).
0010 %
0011 %   The data can either be supplied in a single RESULTS struct, or
0012 %   in the individual arguments: BASEMVA, BUS, GEN, BRANCH, F, SUCCESS
0013 %   and ET, where F is the OPF objective function value, SUCCESS is
0014 %   true if the solution converged and false otherwise, and ET is the
0015 %   elapsed time for the computation in seconds. If F is given, it is
0016 %   assumed that the output is from an OPF run, otherwise it is assumed
0017 %   to be a simple power flow run.
0018 %
0019 %   Examples:
0020 %       mpopt = mpoptions('out.gen', 1, 'out.bus', 0, 'out.branch', 0);
0021 %       [fd, msg] = fopen(fname, 'at');
0022 %       results = runopf(mpc);
0023 %       printpf(results);
0024 %       printpf(results, fd);
0025 %       printpf(results, fd, mpopt);
0026 %       printpf(baseMVA, bus, gen, branch, f, success, et);
0027 %       printpf(baseMVA, bus, gen, branch, f, success, et, fd);
0028 %       printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt);
0029 %       fclose(fd);
0030 
0031 %   MATPOWER
0032 %   $Id: printpf.m 2447 2014-12-05 20:32:22Z ray $
0033 %   by Ray Zimmerman, PSERC Cornell
0034 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0035 %
0036 %   This file is part of MATPOWER.
0037 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0038 %
0039 %   MATPOWER is free software: you can redistribute it and/or modify
0040 %   it under the terms of the GNU General Public License as published
0041 %   by the Free Software Foundation, either version 3 of the License,
0042 %   or (at your option) any later version.
0043 %
0044 %   MATPOWER is distributed in the hope that it will be useful,
0045 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0046 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0047 %   GNU General Public License for more details.
0048 %
0049 %   You should have received a copy of the GNU General Public License
0050 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0051 %
0052 %   Additional permission under GNU GPL version 3 section 7
0053 %
0054 %   If you modify MATPOWER, or any covered work, to interface with
0055 %   other modules (such as MATLAB code and MEX-files) available in a
0056 %   MATLAB(R) or comparable environment containing parts covered
0057 %   under other licensing terms, the licensors of MATPOWER grant
0058 %   you additional permission to convey the resulting work.
0059 
0060 %%----- initialization -----
0061 %% define named indices into bus, gen, branch matrices
0062 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0063     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0064 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0065     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0066     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0067 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0068     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0069     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0070 
0071 %% default arguments
0072 if isstruct(baseMVA)
0073     have_results_struct = 1;
0074     results = baseMVA;
0075     if nargin < 3 || isempty(gen)
0076         mpopt = mpoption;   %% use default options
0077     else
0078         mpopt = gen;
0079     end
0080     if mpopt.out.all == 0
0081         return;         %% nothin' to see here, bail out now
0082     end
0083     if nargin < 2 || isempty(bus)
0084         fd = 1;         %% print to stdio by default
0085     else
0086         fd = bus;
0087     end
0088     [baseMVA, bus, gen, branch, success, et] = ...
0089         deal(results.baseMVA, results.bus, results.gen, results.branch, ...
0090             results.success, results.et);
0091     if isfield(results, 'f') && ~isempty(results.f)
0092         f = results.f;
0093     else
0094         f = [];
0095     end
0096 else
0097     have_results_struct = 0;
0098     if nargin < 9
0099         mpopt = mpoption;   %% use default options
0100         if nargin < 8
0101             fd = 1;         %% print to stdio by default
0102         end
0103     end
0104     if mpopt.out.all == 0
0105         return;         %% nothin' to see here, bail out now
0106     end
0107 end
0108 isOPF = ~isempty(f);    %% FALSE -> only simple PF data, TRUE -> OPF data
0109 
0110 %% options
0111 isDC            = strcmp(upper(mpopt.model), 'DC');
0112 
0113 SUPPRESS        = mpopt.out.suppress_detail;
0114 if SUPPRESS == -1
0115     if size(bus, 1) > 500
0116         SUPPRESS = 1;
0117     else
0118         SUPPRESS = 0;
0119     end
0120 end
0121 OUT_ALL         = mpopt.out.all;
0122 OUT_FORCE       = mpopt.out.force;
0123 OUT_ANY         = OUT_ALL == 1;     %% set to true if any pretty output is to be generated
0124 OUT_SYS_SUM     = OUT_ALL == 1 || (OUT_ALL == -1 && mpopt.out.sys_sum);
0125 OUT_AREA_SUM    = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.area_sum);
0126 OUT_BUS         = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.bus);
0127 OUT_BRANCH      = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.branch);
0128 OUT_GEN         = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.gen);
0129 OUT_ANY         = OUT_ANY || (OUT_ALL == -1 && ...
0130                     (OUT_SYS_SUM || OUT_AREA_SUM || OUT_BUS || ...
0131                     OUT_BRANCH || OUT_GEN));
0132 if OUT_ALL == -1
0133     OUT_ALL_LIM = ~SUPPRESS * mpopt.out.lim.all;
0134 elseif OUT_ALL == 1
0135     OUT_ALL_LIM = 2;
0136 else
0137     OUT_ALL_LIM = 0;
0138 end
0139 OUT_ANY         = OUT_ANY || OUT_ALL_LIM >= 1;
0140 if OUT_ALL_LIM == -1
0141     OUT_V_LIM       = ~SUPPRESS * mpopt.out.lim.v;
0142     OUT_LINE_LIM    = ~SUPPRESS * mpopt.out.lim.line;
0143     OUT_PG_LIM      = ~SUPPRESS * mpopt.out.lim.pg;
0144     OUT_QG_LIM      = ~SUPPRESS * mpopt.out.lim.qg;
0145 else
0146     OUT_V_LIM       = OUT_ALL_LIM;
0147     OUT_LINE_LIM    = OUT_ALL_LIM;
0148     OUT_PG_LIM      = OUT_ALL_LIM;
0149     OUT_QG_LIM      = OUT_ALL_LIM;
0150 end
0151 OUT_ANY         = OUT_ANY || (OUT_ALL_LIM == -1 && (OUT_V_LIM || OUT_LINE_LIM || OUT_PG_LIM || OUT_QG_LIM));
0152 
0153 %%----- print the stuff -----
0154 if OUT_ANY
0155     ptol = 1e-4;        %% tolerance for displaying shadow prices
0156     if isOPF && ~isDC && strcmp(upper(mpopt.opf.ac.solver), 'SDPOPF')
0157         isSDP = 1;
0158         ptol = 0.1;     %% tolerance for displaying shadow prices
0159         if have_results_struct && isfield(results, 'mineigratio') && ~isempty(results.mineigratio)
0160             mineigratio = results.mineigratio;
0161         else
0162             mineigratio = [];
0163         end
0164         if have_results_struct && isfield(results, 'zero_eval') && ~isempty(results.zero_eval)
0165             zero_eval = results.zero_eval;
0166         else
0167             zero_eval = [];
0168         end
0169     else
0170         isSDP = 0;
0171     end
0172 
0173     %% create map of external bus numbers to bus indices
0174     i2e = bus(:, BUS_I);
0175     e2i = sparse(max(i2e), 1);
0176     e2i(i2e) = (1:size(bus, 1))';
0177 
0178     %% sizes of things
0179     nb = size(bus, 1);      %% number of buses
0180     nl = size(branch, 1);   %% number of branches
0181     ng = size(gen, 1);      %% number of generators
0182 
0183     %% zero out some data to make printout consistent for DC case
0184     if isDC
0185         bus(:, [QD, BS])            = zeros(nb, 2);
0186         gen(:, [QG, QMAX, QMIN])    = zeros(ng, 3);
0187         branch(:, [BR_R, BR_B])     = zeros(nl, 2);
0188     end
0189 
0190     %% parameters
0191     ties = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= bus(e2i(branch(:, T_BUS)), BUS_AREA));
0192                             %% area inter-ties
0193     xfmr = find(branch(:, TAP));                    %% indices of transformers
0194     nzld = find((bus(:, PD) | bus(:, QD)) & bus(:, BUS_TYPE) ~= NONE);
0195     sorted_areas = sort(bus(:, BUS_AREA));
0196     s_areas = sorted_areas([1; find(diff(sorted_areas))+1]);    %% area numbers
0197     nzsh = find((bus(:, GS) | bus(:, BS)) & bus(:, BUS_TYPE) ~= NONE);
0198     allg = find( ~isload(gen) );
0199     ong  = find( gen(:, GEN_STATUS) > 0 & ~isload(gen) );
0200     onld = find( gen(:, GEN_STATUS) > 0 &  isload(gen) );
0201     V = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA));
0202     if isDC
0203         loss = zeros(nl, 1);
0204         fchg = loss;
0205         tchg = loss;
0206     else
0207         [loss, fchg, tchg] = get_losses(baseMVA, bus, branch);
0208     end
0209 
0210     %% convergence & elapsed time
0211     if success
0212         if isSDP
0213             fprintf(fd, '\nSolution satisfies rank and consistency conditions, %.2f seconds.\nmineigratio = %0.5g, zero_eval = %0.5g', et, mineigratio, zero_eval);
0214         else
0215             fprintf(fd, '\nConverged in %.2f seconds', et);
0216         end
0217     else
0218         if isSDP
0219             fprintf(fd, '\n>>>>>  Solution does NOT satisfy rank and/or consistency conditions (%.2f seconds).  <<<<<\nmineigratio = %0.5g, zero_eval = %0.5g\n', et, mineigratio, zero_eval);
0220         else
0221             fprintf(fd, '\n>>>>>  Did NOT converge (%.2f seconds)  <<<<<\n', et);
0222         end
0223     end
0224     
0225     %% objective function value
0226     if isOPF && (success || OUT_FORCE)
0227         fprintf(fd, '\nObjective Function Value = %.2f $/hr', f);
0228     end
0229 end
0230 if OUT_SYS_SUM && (success || OUT_FORCE)
0231     fprintf(fd, '\n================================================================================');
0232     fprintf(fd, '\n|     System Summary                                                           |');
0233     fprintf(fd, '\n================================================================================');
0234     fprintf(fd, '\n\nHow many?                How much?              P (MW)            Q (MVAr)');
0235     fprintf(fd, '\n---------------------    -------------------  -------------  -----------------');
0236     fprintf(fd, '\nBuses         %6d     Total Gen Capacity   %7.1f       %7.1f to %.1f', nb, sum(gen(allg, PMAX)), sum(gen(allg, QMIN)), sum(gen(allg, QMAX)));
0237     fprintf(fd, '\nGenerators     %5d     On-line Capacity     %7.1f       %7.1f to %.1f', length(allg), sum(gen(ong, PMAX)), sum(gen(ong, QMIN)), sum(gen(ong, QMAX)));
0238     fprintf(fd, '\nCommitted Gens %5d     Generation (actual)  %7.1f           %7.1f', length(ong), sum(gen(ong, PG)), sum(gen(ong, QG)));
0239     fprintf(fd, '\nLoads          %5d     Load                 %7.1f           %7.1f', length(nzld)+length(onld), sum(bus(nzld, PD))-sum(gen(onld, PG)), sum(bus(nzld, QD))-sum(gen(onld, QG)));
0240     fprintf(fd, '\n  Fixed        %5d       Fixed              %7.1f           %7.1f', length(nzld), sum(bus(nzld, PD)), sum(bus(nzld, QD)));
0241     fprintf(fd, '\n  Dispatchable %5d       Dispatchable       %7.1f of %-7.1f%7.1f', length(onld), -sum(gen(onld, PG)), -sum(gen(onld, PMIN)), -sum(gen(onld, QG)));
0242     fprintf(fd, '\nShunts         %5d     Shunt (inj)          %7.1f           %7.1f', length(nzsh), ...
0243         -sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, GS)), sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, BS)) );
0244     fprintf(fd, '\nBranches       %5d     Losses (I^2 * Z)     %8.2f          %8.2f', nl, sum(real(loss)), sum(imag(loss)) );
0245     fprintf(fd, '\nTransformers   %5d     Branch Charging (inj)     -            %7.1f', length(xfmr), sum(fchg) + sum(tchg) );
0246     fprintf(fd, '\nInter-ties     %5d     Total Inter-tie Flow %7.1f           %7.1f', length(ties), sum(abs(branch(ties, PF)-branch(ties, PT))) / 2, sum(abs(branch(ties, QF)-branch(ties, QT))) / 2);
0247     fprintf(fd, '\nAreas          %5d', length(s_areas));
0248     fprintf(fd, '\n');
0249     fprintf(fd, '\n                          Minimum                      Maximum');
0250     fprintf(fd, '\n                 -------------------------  --------------------------------');
0251     [minv, mini] = min(bus(:, VM));
0252     [maxv, maxi] = max(bus(:, VM));
0253     fprintf(fd, '\nVoltage Magnitude %7.3f p.u. @ bus %-4d     %7.3f p.u. @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0254     [minv, mini] = min(bus(:, VA));
0255     [maxv, maxi] = max(bus(:, VA));
0256     fprintf(fd, '\nVoltage Angle   %8.2f deg   @ bus %-4d   %8.2f deg   @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0257     if ~isDC
0258         [maxv, maxi] = max(real(loss));
0259         fprintf(fd, '\nP Losses (I^2*R)             -              %8.2f MW    @ line %d-%d', maxv, branch(maxi, F_BUS), branch(maxi, T_BUS));
0260         [maxv, maxi] = max(imag(loss));
0261         fprintf(fd, '\nQ Losses (I^2*X)             -              %8.2f MVAr  @ line %d-%d', maxv, branch(maxi, F_BUS), branch(maxi, T_BUS));
0262     end
0263     if isOPF
0264         [minv, mini] = min(bus(:, LAM_P));
0265         [maxv, maxi] = max(bus(:, LAM_P));
0266         fprintf(fd, '\nLambda P        %8.2f $/MWh @ bus %-4d   %8.2f $/MWh @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0267         [minv, mini] = min(bus(:, LAM_Q));
0268         [maxv, maxi] = max(bus(:, LAM_Q));
0269         fprintf(fd, '\nLambda Q        %8.2f $/MWh @ bus %-4d   %8.2f $/MWh @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0270     end
0271     fprintf(fd, '\n');
0272 end
0273 
0274 if OUT_AREA_SUM && (success || OUT_FORCE)
0275     fprintf(fd, '\n================================================================================');
0276     fprintf(fd, '\n|     Area Summary                                                             |');
0277     fprintf(fd, '\n================================================================================');
0278     fprintf(fd, '\nArea  # of      # of Gens        # of Loads         # of    # of   # of   # of');
0279     fprintf(fd, '\n Num  Buses   Total  Online   Total  Fixed  Disp    Shunt   Brchs  Xfmrs   Ties');
0280     fprintf(fd, '\n----  -----   -----  ------   -----  -----  -----   -----   -----  -----  -----');
0281     for i=1:length(s_areas)
0282         a = s_areas(i);
0283         ib = find(bus(:, BUS_AREA) == a);
0284         ig = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & ~isload(gen));
0285         igon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & ~isload(gen));
0286         ildon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & isload(gen));
0287         inzld = find(bus(:, BUS_AREA) == a & (bus(:, PD) | bus(:, QD)) & bus(:, BUS_TYPE) ~= NONE);
0288         inzsh = find(bus(:, BUS_AREA) == a & (bus(:, GS) | bus(:, BS)) & bus(:, BUS_TYPE) ~= NONE);
0289         ibrch = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a);
0290         in_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) ~= a);
0291         out_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a);
0292         if isempty(xfmr)
0293             nxfmr = 0;
0294         else
0295             nxfmr = length(find(bus(e2i(branch(xfmr, F_BUS)), BUS_AREA) == a & bus(e2i(branch(xfmr, T_BUS)), BUS_AREA) == a));
0296         end
0297         fprintf(fd, '\n%3d  %6d   %5d  %5d   %5d  %5d  %5d   %5d   %5d  %5d  %5d', ...
0298             a, length(ib), length(ig), length(igon), ...
0299             length(inzld)+length(ildon), length(inzld), length(ildon), ...
0300             length(inzsh), length(ibrch), nxfmr, length(in_tie)+length(out_tie));
0301     end
0302     fprintf(fd, '\n----  -----   -----  ------   -----  -----  -----   -----   -----  -----  -----');
0303     fprintf(fd, '\nTot: %6d   %5d  %5d   %5d  %5d  %5d   %5d   %5d  %5d  %5d', ...
0304         nb, length(allg), length(ong), length(nzld)+length(onld), ...
0305         length(nzld), length(onld), length(nzsh), nl, length(xfmr), length(ties));
0306     fprintf(fd, '\n');
0307     fprintf(fd, '\nArea      Total Gen Capacity           On-line Gen Capacity         Generation');
0308     fprintf(fd, '\n Num     MW           MVAr            MW           MVAr             MW    MVAr');
0309     fprintf(fd, '\n----   ------  ------------------   ------  ------------------    ------  ------');
0310     for i=1:length(s_areas)
0311         a = s_areas(i);
0312         ig = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & ~isload(gen));
0313         igon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & ~isload(gen));
0314         fprintf(fd, '\n%3d   %7.1f  %7.1f to %-7.1f  %7.1f  %7.1f to %-7.1f   %7.1f %7.1f', ...
0315             a, sum(gen(ig, PMAX)), sum(gen(ig, QMIN)), sum(gen(ig, QMAX)), ...
0316             sum(gen(igon, PMAX)), sum(gen(igon, QMIN)), sum(gen(igon, QMAX)), ...
0317             sum(gen(igon, PG)), sum(gen(igon, QG)) );
0318     end
0319     fprintf(fd, '\n----   ------  ------------------   ------  ------------------    ------  ------');
0320     fprintf(fd, '\nTot:  %7.1f  %7.1f to %-7.1f  %7.1f  %7.1f to %-7.1f   %7.1f %7.1f', ...
0321             sum(gen(allg, PMAX)), sum(gen(allg, QMIN)), sum(gen(allg, QMAX)), ...
0322             sum(gen(ong, PMAX)), sum(gen(ong, QMIN)), sum(gen(ong, QMAX)), ...
0323             sum(gen(ong, PG)), sum(gen(ong, QG)) );
0324     fprintf(fd, '\n');
0325     fprintf(fd, '\nArea    Disp Load Cap       Disp Load         Fixed Load        Total Load');
0326     fprintf(fd, '\n Num      MW     MVAr       MW     MVAr       MW     MVAr       MW     MVAr');
0327     fprintf(fd, '\n----    ------  ------    ------  ------    ------  ------    ------  ------');
0328     Qlim = (gen(:, QMIN) == 0) .* gen(:, QMAX) + (gen(:, QMAX) == 0) .* gen(:, QMIN);
0329     for i=1:length(s_areas)
0330         a = s_areas(i);
0331         ildon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & isload(gen));
0332         inzld = find(bus(:, BUS_AREA) == a & (bus(:, PD) | bus(:, QD)));
0333         fprintf(fd, '\n%3d    %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f', ...
0334             a, -sum(gen(ildon, PMIN)), ...
0335             -sum(Qlim(ildon)), ...
0336             -sum(gen(ildon, PG)), -sum(gen(ildon, QG)), ...
0337             sum(bus(inzld, PD)), sum(bus(inzld, QD)), ...
0338             -sum(gen(ildon, PG)) + sum(bus(inzld, PD)), ...
0339             -sum(gen(ildon, QG)) + sum(bus(inzld, QD)) );
0340     end
0341     fprintf(fd, '\n----    ------  ------    ------  ------    ------  ------    ------  ------');
0342     fprintf(fd, '\nTot:   %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f', ...
0343             -sum(gen(onld, PMIN)), ...
0344             -sum(Qlim(onld)), ...
0345             -sum(gen(onld, PG)), -sum(gen(onld, QG)), ...
0346             sum(bus(nzld, PD)), sum(bus(nzld, QD)), ...
0347             -sum(gen(onld, PG)) + sum(bus(nzld, PD)), ...
0348             -sum(gen(onld, QG)) + sum(bus(nzld, QD)) );
0349     fprintf(fd, '\n');
0350     fprintf(fd, '\nArea      Shunt Inj        Branch      Series Losses      Net Export');
0351     fprintf(fd, '\n Num      MW     MVAr     Charging      MW     MVAr       MW     MVAr');
0352     fprintf(fd, '\n----    ------  ------    --------    ------  ------    ------  ------');
0353     for i=1:length(s_areas)
0354         a = s_areas(i);
0355         inzsh = find(bus(:, BUS_AREA) == a & (bus(:, GS) | bus(:, BS)));
0356         ibrch = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a & branch(:, BR_STATUS));
0357         in_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a & branch(:, BR_STATUS));
0358         out_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) ~= a & branch(:, BR_STATUS));
0359         fprintf(fd, '\n%3d    %7.1f %7.1f    %7.1f    %7.2f %7.2f   %7.1f %7.1f', ...
0360             a, -sum(bus(inzsh, VM) .^ 2 .* bus(inzsh, GS)), ...
0361             sum(bus(inzsh, VM) .^ 2 .* bus(inzsh, BS)), ...
0362             sum(fchg(ibrch)) + sum(tchg(ibrch)) + sum(fchg(out_tie)) + sum(tchg(in_tie)), ...
0363             sum(real(loss(ibrch))) + sum(real(loss([in_tie; out_tie]))) / 2, ...
0364             sum(imag(loss(ibrch))) + sum(imag(loss([in_tie; out_tie]))) / 2, ...
0365             sum(branch(in_tie, PT))+sum(branch(out_tie, PF)) - sum(real(loss([in_tie; out_tie]))) / 2, ...
0366             sum(branch(in_tie, QT))+sum(branch(out_tie, QF)) - sum(imag(loss([in_tie; out_tie]))) / 2  );
0367     end
0368     fprintf(fd, '\n----    ------  ------    --------    ------  ------    ------  ------');
0369     fprintf(fd, '\nTot:   %7.1f %7.1f    %7.1f    %7.2f %7.2f       -       -', ...
0370         -sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, GS)), ...
0371         sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, BS)), ...
0372         sum(fchg) + sum(tchg), sum(real(loss)), sum(imag(loss)) );
0373     fprintf(fd, '\n');
0374 end
0375 
0376 %% generator data
0377 if OUT_GEN && (success || OUT_FORCE)
0378     if isOPF
0379         genlamP = bus(e2i(gen(:, GEN_BUS)), LAM_P);
0380         genlamQ = bus(e2i(gen(:, GEN_BUS)), LAM_Q);
0381     end
0382     fprintf(fd, '\n================================================================================');
0383     fprintf(fd, '\n|     Generator Data                                                           |');
0384     fprintf(fd, '\n================================================================================');
0385     fprintf(fd, '\n Gen   Bus   Status     Pg        Qg   ');
0386     if isOPF, fprintf(fd, '   Lambda ($/MVA-hr)'); end
0387     fprintf(fd, '\n  #     #              (MW)     (MVAr) ');
0388     if isOPF, fprintf(fd, '     P         Q    '); end
0389     fprintf(fd, '\n----  -----  ------  --------  --------');
0390     if isOPF, fprintf(fd, '  --------  --------'); end
0391     for k = 1:length(ong)
0392         i = ong(k);
0393         fprintf(fd, '\n%3d %6d     %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0394         if gen(i, GEN_STATUS) > 0 && (gen(i, PG) || gen(i, QG))
0395             fprintf(fd, '%10.2f%10.2f', gen(i, PG), gen(i, QG));
0396         else
0397             fprintf(fd, '       -         -  ');
0398         end
0399         if isOPF, fprintf(fd, '%10.2f%10.2f', genlamP(i), genlamQ(i)); end
0400     end
0401     fprintf(fd, '\n                     --------  --------');
0402     fprintf(fd, '\n            Total: %9.2f%10.2f', sum(gen(ong, PG)), sum(gen(ong, QG)));
0403     fprintf(fd, '\n');
0404     if ~isempty(onld)
0405         fprintf(fd, '\n================================================================================');
0406         fprintf(fd, '\n|     Dispatchable Load Data                                                   |');
0407         fprintf(fd, '\n================================================================================');
0408         fprintf(fd, '\n Gen   Bus   Status     Pd        Qd   ');
0409         if isOPF, fprintf(fd, '   Lambda ($/MVA-hr)'); end
0410         fprintf(fd, '\n  #     #              (MW)     (MVAr) ');
0411         if isOPF, fprintf(fd, '     P         Q    '); end
0412         fprintf(fd, '\n----  -----  ------  --------  --------');
0413         if isOPF, fprintf(fd, '  --------  --------'); end
0414         for k = 1:length(onld)
0415             i = onld(k);
0416             fprintf(fd, '\n%3d %6d     %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0417             if gen(i, GEN_STATUS) > 0 && (gen(i, PG) || gen(i, QG))
0418                 fprintf(fd, '%10.2f%10.2f', -gen(i, PG), -gen(i, QG));
0419             else
0420                 fprintf(fd, '       -         -  ');
0421             end
0422             if isOPF, fprintf(fd, '%10.2f%10.2f', genlamP(i), genlamQ(i)); end
0423         end
0424         fprintf(fd, '\n                     --------  --------');
0425         fprintf(fd, '\n            Total: %9.2f%10.2f', -sum(gen(onld, PG)), -sum(gen(onld, QG)));
0426         fprintf(fd, '\n');
0427     end
0428 end
0429         
0430 %% bus data
0431 if OUT_BUS && (success || OUT_FORCE)
0432     fprintf(fd, '\n================================================================================');
0433     fprintf(fd, '\n|     Bus Data                                                                 |');
0434     fprintf(fd, '\n================================================================================');
0435     fprintf(fd, '\n Bus      Voltage          Generation             Load        ');
0436     if isOPF, fprintf(fd, '  Lambda($/MVA-hr)'); end
0437     fprintf(fd, '\n  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0438     if isOPF, fprintf(fd, '     P        Q   '); end
0439     fprintf(fd, '\n----- ------- --------  --------  --------  --------  --------');
0440     if isOPF, fprintf(fd, '  -------  -------'); end
0441     for i = 1:nb
0442         fprintf(fd, '\n%5d%7.3f%9.3f', bus(i, [BUS_I, VM, VA]));
0443         if bus(i, BUS_TYPE) == REF
0444             fprintf(fd, '*');
0445         elseif bus(i, BUS_TYPE) == NONE
0446             fprintf(fd, 'x');
0447         else
0448             fprintf(fd, ' ');
0449         end
0450         g  = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I) & ...
0451                     ~isload(gen));
0452         ld = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I) & ...
0453                     isload(gen));
0454         if ~isempty(g)
0455             fprintf(fd, '%9.2f%10.2f', sum(gen(g, PG)), sum(gen(g, QG)));
0456         else
0457             fprintf(fd, '      -         -  ');
0458         end
0459         if bus(i, PD) || bus(i, QD) || ~isempty(ld)
0460             if ~isempty(ld)
0461                 fprintf(fd, '%10.2f*%9.2f*', bus(i, PD) - sum(gen(ld, PG)), ...
0462                                              bus(i, QD) - sum(gen(ld, QG)));
0463             else
0464                 fprintf(fd, '%10.2f%10.2f ', bus(i, [PD, QD]));
0465             end
0466         else
0467             fprintf(fd, '       -         -   ');
0468         end
0469         if isOPF
0470             fprintf(fd, '%9.3f', bus(i, LAM_P));
0471             if abs(bus(i, LAM_Q)) > ptol
0472                 fprintf(fd, '%8.3f', bus(i, LAM_Q));
0473             else
0474                 fprintf(fd, '     -');
0475             end
0476         end
0477     end
0478     fprintf(fd, '\n                        --------  --------  --------  --------');
0479     fprintf(fd, '\n               Total: %9.2f %9.2f %9.2f %9.2f', ...
0480         sum(gen(ong, PG)), sum(gen(ong, QG)), ...
0481         sum(bus(nzld, PD)) - sum(gen(onld, PG)), ...
0482         sum(bus(nzld, QD)) - sum(gen(onld, QG)));
0483     fprintf(fd, '\n');
0484 end
0485 
0486 %% branch data
0487 if OUT_BRANCH && (success || OUT_FORCE)
0488     fprintf(fd, '\n================================================================================');
0489     fprintf(fd, '\n|     Branch Data                                                              |');
0490     fprintf(fd, '\n================================================================================');
0491     fprintf(fd, '\nBrnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  ');
0492     fprintf(fd, '\n  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0493     fprintf(fd, '\n-----  -----  -----  --------  --------  --------  --------  --------  --------');
0494     fprintf(fd, '\n%4d%7d%7d%10.2f%10.2f%10.2f%10.2f%10.3f%10.2f', ...
0495             [   (1:nl)', branch(:, [F_BUS, T_BUS]), ...
0496                 branch(:, [PF, QF]), branch(:, [PT, QT]), ...
0497                 real(loss), imag(loss) ...
0498             ]');
0499     fprintf(fd, '\n                                                             --------  --------');
0500     fprintf(fd, '\n                                                    Total:%10.3f%10.2f', ...
0501             sum(real(loss)), sum(imag(loss)));
0502     fprintf(fd, '\n');
0503 end
0504     
0505 %%-----  constraint data  -----
0506 if isOPF && (success || OUT_FORCE)
0507     ctol = mpopt.opf.violation; %% constraint violation tolerance
0508     %% voltage constraints
0509     if ~isDC && (OUT_V_LIM == 2 || (OUT_V_LIM == 1 && ...
0510                          (any(bus(:, VM) < bus(:, VMIN) + ctol) || ...
0511                           any(bus(:, VM) > bus(:, VMAX) - ctol) || ...
0512                           any(bus(:, MU_VMIN) > ptol) || ...
0513                           any(bus(:, MU_VMAX) > ptol))))
0514         fprintf(fd, '\n================================================================================');
0515         fprintf(fd, '\n|     Voltage Constraints                                                      |');
0516         fprintf(fd, '\n================================================================================');
0517         fprintf(fd, '\nBus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu');
0518         fprintf(fd, '\n-----  --------   -----  -----  -----   --------');        
0519         for i = 1:nb
0520             if OUT_V_LIM == 2 || (OUT_V_LIM == 1 && ...
0521                          (bus(i, VM) < bus(i, VMIN) + ctol || ...
0522                           bus(i, VM) > bus(i, VMAX) - ctol || ...
0523                           bus(i, MU_VMIN) > ptol || bus(i, MU_VMAX) > ptol))
0524                 fprintf(fd, '\n%5d', bus(i, BUS_I));
0525                 if bus(i, VM) < bus(i, VMIN) + ctol || bus(i, MU_VMIN) > ptol
0526                     fprintf(fd, '%10.3f', bus(i, MU_VMIN));                    
0527                 else
0528                     fprintf(fd, '      -   ');
0529                 end
0530                 fprintf(fd, '%8.3f%7.3f%7.3f', bus(i, [VMIN, VM, VMAX]));
0531                 if bus(i, VM) > bus(i, VMAX) - ctol || bus(i, MU_VMAX) > ptol
0532                     fprintf(fd, '%10.3f', bus(i, MU_VMAX));
0533                 else
0534                     fprintf(fd, '      -    ');
0535                 end
0536             end
0537         end
0538         fprintf(fd, '\n');
0539     end
0540         
0541     %% generator P constraints
0542     if OUT_PG_LIM == 2 || ...
0543             (OUT_PG_LIM == 1 && (any(gen(ong, PG) < gen(ong, PMIN) + ctol) || ...
0544                                 any(gen(ong, PG) > gen(ong, PMAX) - ctol) || ...
0545                                 any(gen(ong, MU_PMIN) > ptol) || ...
0546                                 any(gen(ong, MU_PMAX) > ptol))) || ...
0547             (~isDC && (OUT_QG_LIM == 2 || ...
0548             (OUT_QG_LIM == 1 && (any(gen(ong, QG) < gen(ong, QMIN) + ctol) || ...
0549                                 any(gen(ong, QG) > gen(ong, QMAX) - ctol) || ...
0550                                 any(gen(ong, MU_QMIN) > ptol) || ...
0551                                 any(gen(ong, MU_QMAX) > ptol)))))
0552         fprintf(fd, '\n================================================================================');
0553         fprintf(fd, '\n|     Generation Constraints                                                   |');
0554         fprintf(fd, '\n================================================================================');
0555     end
0556     if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0557                              (any(gen(ong, PG) < gen(ong, PMIN) + ctol) || ...
0558                               any(gen(ong, PG) > gen(ong, PMAX) - ctol) || ...
0559                               any(gen(ong, MU_PMIN) > ptol) || ...
0560                               any(gen(ong, MU_PMAX) > ptol)))
0561         fprintf(fd, '\n Gen   Bus                Active Power Limits');
0562         fprintf(fd, '\n  #     #    Pmin mu    Pmin       Pg       Pmax    Pmax mu');
0563         fprintf(fd, '\n----  -----  -------  --------  --------  --------  -------');
0564         for k = 1:length(ong)
0565             i = ong(k);
0566             if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0567                         (gen(i, PG) < gen(i, PMIN) + ctol || ...
0568                          gen(i, PG) > gen(i, PMAX) - ctol || ...
0569                          gen(i, MU_PMIN) > ptol || gen(i, MU_PMAX) > ptol))
0570                 fprintf(fd, '\n%4d%6d ', i, gen(i, GEN_BUS));
0571                 if gen(i, PG) < gen(i, PMIN) + ctol || gen(i, MU_PMIN) > ptol
0572                     fprintf(fd, '%8.3f', gen(i, MU_PMIN));
0573                 else
0574                     fprintf(fd, '     -  ');
0575                 end
0576                 if gen(i, PG)
0577                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [PMIN, PG, PMAX]));
0578                 else
0579                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [PMIN, PMAX]));
0580                 end
0581                 if gen(i, PG) > gen(i, PMAX) - ctol || gen(i, MU_PMAX) > ptol
0582                     fprintf(fd, '%9.3f', gen(i, MU_PMAX));
0583                 else
0584                     fprintf(fd, '      -  ');
0585                 end
0586             end
0587         end
0588         fprintf(fd, '\n');
0589     end
0590         
0591     %% generator Q constraints
0592     if ~isDC && (OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0593                              (any(gen(ong, QG) < gen(ong, QMIN) + ctol) || ...
0594                               any(gen(ong, QG) > gen(ong, QMAX) - ctol) || ...
0595                               any(gen(ong, MU_QMIN) > ptol) || ...
0596                               any(gen(ong, MU_QMAX) > ptol))))
0597         fprintf(fd, '\nGen  Bus              Reactive Power Limits');
0598         fprintf(fd, '\n #    #   Qmin mu    Qmin       Qg       Qmax    Qmax mu');
0599         fprintf(fd, '\n---  ---  -------  --------  --------  --------  -------');
0600         for k = 1:length(ong)
0601             i = ong(k);
0602             if OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0603                         (gen(i, QG) < gen(i, QMIN) + ctol || ...
0604                          gen(i, QG) > gen(i, QMAX) - ctol || ...
0605                          gen(i, MU_QMIN) > ptol || gen(i, MU_QMAX) > ptol))
0606                 fprintf(fd, '\n%3d%5d', i, gen(i, GEN_BUS));
0607                 if gen(i, QG) < gen(i, QMIN) + ctol || gen(i, MU_QMIN) > ptol
0608                     fprintf(fd, '%8.3f', gen(i, MU_QMIN));
0609                 else
0610                     fprintf(fd, '     -  ');
0611                 end
0612                 if gen(i, QG)
0613                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [QMIN, QG, QMAX]));
0614                 else
0615                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [QMIN, QMAX]));
0616                 end
0617                 if gen(i, QG) > gen(i, QMAX) - ctol || gen(i, MU_QMAX) > ptol
0618                     fprintf(fd, '%9.3f', gen(i, MU_QMAX));
0619                 else
0620                     fprintf(fd, '      -  ');
0621                 end
0622             end
0623         end
0624         fprintf(fd, '\n');
0625     end
0626         
0627     %% dispatchable load P constraints
0628     if ~isempty(onld) && (OUT_PG_LIM == 2 || OUT_QG_LIM == 2 || ...
0629             (OUT_PG_LIM == 1 && (any(gen(onld, PG) < gen(onld, PMIN) + ctol) || ...
0630                                 any(gen(onld, PG) > gen(onld, PMAX) - ctol) || ...
0631                                 any(gen(onld, MU_PMIN) > ptol) || ...
0632                                 any(gen(onld, MU_PMAX) > ptol))) || ...
0633             (OUT_QG_LIM == 1 && (any(gen(onld, QG) < gen(onld, QMIN) + ctol) || ...
0634                                 any(gen(onld, QG) > gen(onld, QMAX) - ctol) || ...
0635                                 any(gen(onld, MU_QMIN) > ptol) || ...
0636                                 any(gen(onld, MU_QMAX) > ptol))))
0637         fprintf(fd, '\n================================================================================');
0638         fprintf(fd, '\n|     Dispatchable Load Constraints                                            |');
0639         fprintf(fd, '\n================================================================================');
0640     end
0641     if ~isempty(onld) && (OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0642                              (any(gen(onld, PG) < gen(onld, PMIN) + ctol) || ...
0643                               any(gen(onld, PG) > gen(onld, PMAX) - ctol) || ...
0644                               any(gen(onld, MU_PMIN) > ptol) || ...
0645                               any(gen(onld, MU_PMAX) > ptol))))
0646         fprintf(fd, '\nGen  Bus               Active Power Limits');
0647         fprintf(fd, '\n #    #   Pmin mu    Pmin       Pg       Pmax    Pmax mu');
0648         fprintf(fd, '\n---  ---  -------  --------  --------  --------  -------');
0649         for k = 1:length(onld)
0650             i = onld(k);
0651             if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0652                         (gen(i, PG) < gen(i, PMIN) + ctol || ...
0653                          gen(i, PG) > gen(i, PMAX) - ctol || ...
0654                          gen(i, MU_PMIN) > ptol || gen(i, MU_PMAX) > ptol))
0655                 fprintf(fd, '\n%3d%5d', i, gen(i, GEN_BUS));
0656                 if gen(i, PG) < gen(i, PMIN) + ctol || gen(i, MU_PMIN) > ptol
0657                     fprintf(fd, '%8.3f', gen(i, MU_PMIN));
0658                 else
0659                     fprintf(fd, '     -  ');
0660                 end
0661                 if gen(i, PG)
0662                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [PMIN, PG, PMAX]));
0663                 else
0664                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [PMIN, PMAX]));
0665                 end
0666                 if gen(i, PG) > gen(i, PMAX) - ctol || gen(i, MU_PMAX) > ptol
0667                     fprintf(fd, '%9.3f', gen(i, MU_PMAX));
0668                 else
0669                     fprintf(fd, '      -  ');
0670                 end
0671             end
0672         end
0673         fprintf(fd, '\n');
0674     end
0675         
0676     %% dispatchable load Q constraints
0677     if ~isDC && ~isempty(onld) && (OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0678                              (any(gen(onld, QG) < gen(onld, QMIN) + ctol) || ...
0679                               any(gen(onld, QG) > gen(onld, QMAX) - ctol) || ...
0680                               any(gen(onld, MU_QMIN) > ptol) || ...
0681                               any(gen(onld, MU_QMAX) > ptol))))
0682         fprintf(fd, '\nGen  Bus              Reactive Power Limits');
0683         fprintf(fd, '\n #    #   Qmin mu    Qmin       Qg       Qmax    Qmax mu');
0684         fprintf(fd, '\n---  ---  -------  --------  --------  --------  -------');
0685         for k = 1:length(onld)
0686             i = onld(k);
0687             if OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0688                         (gen(i, QG) < gen(i, QMIN) + ctol || ...
0689                          gen(i, QG) > gen(i, QMAX) - ctol || ...
0690                          gen(i, MU_QMIN) > ptol || gen(i, MU_QMAX) > ptol))
0691                 fprintf(fd, '\n%3d%5d', i, gen(i, GEN_BUS));
0692                 if gen(i, QG) < gen(i, QMIN) + ctol || gen(i, MU_QMIN) > ptol
0693                     fprintf(fd, '%8.3f', gen(i, MU_QMIN));
0694                 else
0695                     fprintf(fd, '     -  ');
0696                 end
0697                 if gen(i, QG)
0698                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [QMIN, QG, QMAX]));
0699                 else
0700                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [QMIN, QMAX]));
0701                 end
0702                 if gen(i, QG) > gen(i, QMAX) - ctol || gen(i, MU_QMAX) > ptol
0703                     fprintf(fd, '%9.3f', gen(i, MU_QMAX));
0704                 else
0705                     fprintf(fd, '      -  ');
0706                 end
0707             end
0708         end
0709         fprintf(fd, '\n');
0710     end
0711         
0712     %% line flow constraints
0713     if upper(mpopt.opf.flow_lim(1)) == 'P' || isDC  %% |P| limit
0714         Ff = branch(:, PF);
0715         Ft = branch(:, PT);
0716         str = '\n  #     Bus    Pf  mu     Pf      |Pmax|      Pt      Pt  mu   Bus';
0717     elseif upper(mpopt.opf.flow_lim(1)) == 'I'      %% |I| limit
0718         Ff = abs( (branch(:, PF) + 1j * branch(:, QF)) ./ V(e2i(branch(:, F_BUS))) );
0719         Ft = abs( (branch(:, PT) + 1j * branch(:, QT)) ./ V(e2i(branch(:, T_BUS))) );
0720         str = '\n  #     Bus   |If| mu    |If|     |Imax|     |It|    |It| mu   Bus';
0721     else                                            %% |S| limit
0722         Ff = abs(branch(:, PF) + 1j * branch(:, QF));
0723         Ft = abs(branch(:, PT) + 1j * branch(:, QT));
0724         str = '\n  #     Bus   |Sf| mu    |Sf|     |Smax|     |St|    |St| mu   Bus';
0725     end
0726     if any(branch(:, RATE_A) ~= 0) && (OUT_LINE_LIM == 2 || (OUT_LINE_LIM == 1 && ...
0727                         (any(abs(Ff) > branch(:, RATE_A) - ctol) || ...
0728                          any(abs(Ft) > branch(:, RATE_A) - ctol) || ...
0729                          any(branch(:, MU_SF) > ptol) || ...
0730                          any(branch(:, MU_ST) > ptol))))
0731         fprintf(fd, '\n================================================================================');
0732         fprintf(fd, '\n|     Branch Flow Constraints                                                  |');
0733         fprintf(fd, '\n================================================================================');
0734         fprintf(fd, '\nBrnch   From     "From" End        Limit       "To" End        To');
0735         fprintf(fd, str);
0736         fprintf(fd, '\n-----  -----  -------  --------  --------  --------  -------  -----');
0737         for i = 1:nl
0738             if branch(i, RATE_A) ~= 0 && (OUT_LINE_LIM == 2 || (OUT_LINE_LIM == 1 && ...
0739                    (abs(Ff(i)) > branch(i, RATE_A) - ctol || ...
0740                     abs(Ft(i)) > branch(i, RATE_A) - ctol || ...
0741                     branch(i, MU_SF) > ptol || branch(i, MU_ST) > ptol)))
0742                 fprintf(fd, '\n%4d%7d', i, branch(i, F_BUS));
0743                 if Ff(i) > branch(i, RATE_A) - ctol || branch(i, MU_SF) > ptol
0744                     fprintf(fd, '%10.3f', branch(i, MU_SF));
0745                 else
0746                     fprintf(fd, '      -   ');
0747                 end
0748                 fprintf(fd, '%9.2f%10.2f%10.2f', ...
0749                     [Ff(i), branch(i, RATE_A), Ft(i)]);
0750                 if Ft(i) > branch(i, RATE_A) - ctol || branch(i, MU_ST) > ptol
0751                     fprintf(fd, '%10.3f', branch(i, MU_ST));
0752                 else
0753                     fprintf(fd, '      -   ');
0754                 end
0755                 fprintf(fd, '%6d', branch(i, T_BUS));
0756             end
0757         end
0758         fprintf(fd, '\n');
0759     end
0760 end
0761 
0762 %% execute userfcn callbacks for 'printpf' stage
0763 if have_results_struct && isfield(results, 'userfcn') && (success || OUT_FORCE)
0764     if ~isOPF   %% turn off option for all constraints if it isn't an OPF
0765         mpopt = mpoption(mpopt, 'out.lim.all', 0);
0766     end
0767     run_userfcn(results.userfcn, 'printpf', results, fd, mpopt);
0768 end
0769 if OUT_ANY && ~success
0770     if OUT_FORCE
0771         if isSDP
0772             fprintf(fd, '\n>>>>>  Solution does NOT satisfy rank and/or consistency conditions (%.2f seconds).  <<<<<\nmineigratio = %0.5g, zero_eval = %0.5g\n', et, mineigratio, zero_eval);
0773         else
0774             fprintf(fd, '\n>>>>>  Did NOT converge (%.2f seconds)  <<<<<\n', et);
0775         end
0776     end
0777     fprintf('\n');
0778 end

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005