Home > matpower6.0 > mpoption.m

mpoption

PURPOSE ^

MPOPTION Used to set and retrieve a MATPOWER options struct.

SYNOPSIS ^

function opt = mpoption(varargin)

DESCRIPTION ^

MPOPTION  Used to set and retrieve a MATPOWER options struct.

   OPT = MPOPTION
       Returns the default options struct.

   OPT = MPOPTION(OVERRIDES)
       Returns the default options struct, with some fields overridden
       by values from OVERRIDES, which can be a struct or the name of
       a function that returns a struct.

   OPT = MPOPTION(NAME1, VALUE1, NAME2, VALUE2, ...)
       Same as previous, except override options are specified by NAME,
       VALUE pairs. This can be used to set any part of the options
       struct. The names can be individual fields or multi-level field
       names with embedded periods. The values can be scalars or structs.

       For backward compatibility, the NAMES and VALUES may correspond
       to old-style MATPOWER option names (elements in the old-style
       options vector) as well.

   OPT = MPOPTION(OPT0)
       Converts an old-style options vector OPT0 into the corresponding
       options struct. If OPT0 is an options struct it does nothing.

   OPT = MPOPTION(OPT0, OVERRIDES)
       Applies overrides to an existing set of options, OPT0, which
       can be an old-style options vector or an options struct.

   OPT = MPOPTION(OPT0, NAME1, VALUE1, NAME2, VALUE2, ...)
       Same as above except it uses the old-style options vector OPT0
       as a base instead of the old default options vector.

   OPT_VECTOR = MPOPTION(OPT, [])
       Creates and returns an old-style options vector from an
       options struct OPT.

   Note: The use of old-style MATPOWER options vectors and their
         names and values has been deprecated and will be removed
         in a future version of MATPOWER. Until then, all uppercase
         option names are not permitted for new top-level options.

   Examples:
       mpopt = mpoption('pf.alg', 'FDXB', 'pf.tol', 1e-4);
       mpopt = mpoption(mpopt, 'opf.dc.solver', 'CPLEX', 'verbose', 2);

The currently defined options are as follows:

   name                    default     description [options]
----------------------    ---------   ----------------------------------
Model options:
   model                   'AC'        AC vs. DC power flow model
       [ 'AC' - use nonlinear AC model & corresponding algorithms/options  ]
       [ 'DC' - use linear DC model & corresponding algorithms/options     ]

Power Flow options:
   pf.alg                  'NR'        AC power flow algorithm
       [ 'NR'   - Newton's method                                          ]
       [ 'FDXB' - Fast-Decoupled (XB version)                              ]
       [ 'FDBX' - Fast-Decoupled (BX version)                              ]
       [ 'GS'   - Gauss-Seidel                                             ]
   pf.tol                  1e-8        termination tolerance on per unit
                                       P & Q mismatch
   pf.nr.max_it            10          maximum number of iterations for
                                       Newton's method
   pf.fd.max_it            30          maximum number of iterations for
                                       fast decoupled method
   pf.gs.max_it            1000        maximum number of iterations for
                                       Gauss-Seidel method
   pf.enforce_q_lims       0           enforce gen reactive power limits at
                                       expense of |V|
       [  0 - do NOT enforce limits                                        ]
       [  1 - enforce limits, simultaneous bus type conversion             ]
       [  2 - enforce limits, one-at-a-time bus type conversion            ]

Continuation Power Flow options:
   cpf.parameterization    3           choice of parameterization
       [  1 - natural                                                      ]
       [  2 - arc length                                                   ]
       [  3 - pseudo arc length                                            ]
   cpf.stop_at             'NOSE'      determins stopping criterion
       [ 'NOSE'     - stop when nose point is reached                      ]
       [ 'FULL'     - trace full nose curve                                ]
       [ <lam_stop> - stop upon reaching specified target lambda value     ]
   cpf.enforce_p_lims      0           enforce gen active power limits
       [  0 - do NOT enforce limits                                        ]
       [  1 - enforce limits, simultaneous bus type conversion             ]
   cpf.enforce_q_lims      0           enforce gen reactive power limits at
                                       expense of |V|
       [  0 - do NOT enforce limits                                        ]
       [  1 - enforce limits, simultaneous bus type conversion             ]
   cpf.step                0.05        continuation power flow step size
   cpf.adapt_step          0           toggle adaptive step size feature
       [  0 - adaptive step size disabled                                  ]
       [  1 - adaptive step size enabled                                   ]
   cpf.step_min            1e-4        minimum allowed step size
   cpf.step_max            0.2         maximum allowed step size
   cpf.adapt_step_damping  0.7         damping factor for adaptive step
                                       sizing
   cpf.adapt_step_tol      1e-3        tolerance for adaptive step sizing
   cpf.target_lam_tol      1e-5        tolerance for target lambda detection
   cpf.nose_tol            1e-5        tolerance for nose point detection (pu)
   cpf.p_lims_tol          0.01        tolerance for generator active
                                       power limit enforcement (MW)
   cpf.q_lims_tol          0.01        tolerance for generator reactive
                                       power limit enforcement (MVAR)
   cpf.plot.level          0           control plotting of noze curve
       [  0 - do not plot nose curve                                       ]
       [  1 - plot when completed                                          ]
       [  2 - plot incrementally at each iteration                         ]
       [  3 - same as 2, with 'pause' at each iteration                    ]
   cpf.plot.bus            <empty>     index of bus whose voltage is to be
                                       plotted
   cpf.user_callback       <empty>     string containing the name of a user
                                       callback function, or struct with
                                       function name, and optional priority
                                       and/or args, or cell array of such
                                       strings and/or structs, see
                                       'help cpf_default_callback' for details

Optimal Power Flow options:
   name                    default     description [options]
----------------------    ---------   ----------------------------------
   opf.ac.solver           'DEFAULT'   AC optimal power flow solver
       [ 'DEFAULT' - choose solver based on availability in the following  ]
       [             order: 'PDIPM', 'MIPS'                                ]
       [ 'MIPS'    - MIPS, MATPOWER Interior Point Solver, primal/dual     ]
       [             interior point method (pure Matlab)                   ]
       [ 'FMINCON' - MATLAB Optimization Toolbox, FMINCON                  ]
       [ 'IPOPT'   - IPOPT, requires MEX interface to IPOPT solver         ]
       [             available from:                                       ]
       [                 http://www.coin-or.org/projects/Ipopt.xml         ]
       [ 'KNITRO'  - KNITRO, requires MATLAB Optimization Toolbox and      ]
       [             KNITRO libraries available from: http://www.ziena.com/]
       [ 'MINOPF'  - MINOPF, MINOS-based solver, requires optional         ]
       [             MEX-based MINOPF package, available from:             ]
       [                   http://www.pserc.cornell.edu/minopf/            ]
       [ 'PDIPM'   - PDIPM, primal/dual interior point method, requires    ]
       [             optional MEX-based TSPOPF package, available from:    ]
       [                   http://www.pserc.cornell.edu/tspopf/            ]
       [ 'SDPOPF'  - SDPOPF, solver based on semidefinite relaxation of    ]
       [             OPF problem, requires optional packages:              ]
       [               SDP_PF, available in extras/sdp_pf                  ]
       [               YALMIP, available from:                             ]
       [                   http://users.isy.liu.se/johanl/yalmip/          ]
       [               SDP solver such as SeDuMi, available from:          ]
       [                   http://sedumi.ie.lehigh.edu/                    ]
       [ 'TRALM'   - TRALM, trust region based augmented Langrangian       ]
       [             method, requires TSPOPF (see 'PDIPM')                 ]
   opf.dc.solver           'DEFAULT'   DC optimal power flow solver
       [ 'DEFAULT' - choose solver based on availability in the following  ]
       [             order: 'GUROBI', 'CPLEX', 'MOSEK', 'OT',              ]
       [             'GLPK' (linear costs only), 'BPMPD', 'MIPS'           ]
       [ 'MIPS'    - MIPS, MATPOWER Interior Point Solver, primal/dual     ]
       [             interior point method (pure Matlab)                   ]
       [ 'BPMPD'   - BPMPD, requires optional MEX-based BPMPD_MEX package  ]
       [             available from: http://www.pserc.cornell.edu/bpmpd/   ]
       [ 'CLP'     - CLP, requires interface to COIN-OP LP solver          ]
       [             available from:http://www.coin-or.org/projects/Clp.xml]
       [ 'CPLEX'   - CPLEX, requires CPLEX solver available from:          ]
       [             http://www.ibm.com/software/integration/ ...          ]
       [                                 ... optimization/cplex-optimizer/ ]
       [ 'GLPK'    - GLPK, requires interface to GLPK solver               ]
       [             available from: http://www.gnu.org/software/glpk/     ]
       [             (GLPK does not work with quadratic cost functions)    ]
       [ 'GUROBI'  - GUROBI, requires Gurobi optimizer (v. 5+)             ]
       [             available from: http://www.gurobi.com/                ]
       [ 'IPOPT'   - IPOPT, requires MEX interface to IPOPT solver         ]
       [             available from:                                       ]
       [                 http://www.coin-or.org/projects/Ipopt.xml         ]
       [ 'MOSEK'   - MOSEK, requires Matlab interface to MOSEK solver      ]
       [             available from: http://www.mosek.com/                 ]
       [ 'OT'      - MATLAB Optimization Toolbox, QUADPROG, LINPROG        ]
   opf.violation           5e-6        constraint violation tolerance
   opf.use_vg              0           respect gen voltage setpt     [ 0-1 ]
       [ 0 - use specified bus Vmin & Vmax, and ignore gen Vg              ]
       [ 1 - replace specified bus Vmin & Vmax by corresponding gen Vg     ]
       [ between 0 and 1 - use a weighted average of the 2 options         ]
   opf.flow_lim            'S'         quantity limited by branch flow
                                       constraints
       [ 'S' - apparent power flow (limit in MVA)                          ]
       [ 'P' - active power flow (limit in MW)                             ]
       [ 'I' - current magnitude (limit in MVA at 1 p.u. voltage)          ]
   opf.ignore_angle_lim    0           angle diff limits for branches
       [ 0 - include angle difference limits, if specified                 ]
       [ 1 - ignore angle difference limits even if specified              ]
   opf.init_from_mpc       -1          specify whether to use current state
                                       in MATPOWER case to initialize OPF
                                       (currently supported only for Ipopt,
                                        Knitro and MIPS solvers)
       [  -1 - MATPOWER decides, based on solver/algorithm                 ]
       [   0 - ignore current state when initializing OPF                  ]
       [   1 - use current state to initialize OPF                         ]
   opf.return_raw_der      0           for AC OPF, return constraint and
                                       derivative info in results.raw
                                       (in fields g, dg, df, d2f) [ 0 or 1 ]

Output options:
   name                    default     description [options]
----------------------    ---------   ----------------------------------
   verbose                 1           amount of progress info printed
       [   0 - print no progress info                                      ]
       [   1 - print a little progress info                                ]
       [   2 - print a lot of progress info                                ]
       [   3 - print all progress info                                     ]
   out.all                 -1          controls pretty-printing of results
       [  -1 - individual flags control what prints                        ]
       [   0 - do not print anything (overrides individual flags, ignored  ]
       [       for files specified as FNAME arg to runpf(), runopf(), etc.)]
       [   1 - print everything (overrides individual flags)               ]
   out.sys_sum             1           print system summary       [ 0 or 1 ]
   out.area_sum            0           print area summaries       [ 0 or 1 ]
   out.bus                 1           print bus detail           [ 0 or 1 ]
   out.branch              1           print branch detail        [ 0 or 1 ]
   out.gen                 0           print generator detail     [ 0 or 1 ]
   out.lim.all             -1          controls constraint info output
       [  -1 - individual flags control what constraint info prints        ]
       [   0 - no constraint info (overrides individual flags)             ]
       [   1 - binding constraint info (overrides individual flags)        ]
       [   2 - all constraint info (overrides individual flags)            ]
   out.lim.v               1           control voltage limit info
       [   0 - do not print                                                ]
       [   1 - print binding constraints only                              ]
       [   2 - print all constraints                                       ]
       [   (same options for OUT_LINE_LIM, OUT_PG_LIM, OUT_QG_LIM)         ]
   out.lim.line            1           control line flow limit info
   out.lim.pg              1           control gen active power limit info
   out.lim.qg              1           control gen reactive pwr limit info
   out.force               0           print results even if success
                                       flag = 0                   [ 0 or 1 ]
   out.suppress_detail     -1          suppress all output but system summary
       [  -1 - suppress details for large systems (> 500 buses)            ]
       [   0 - do not suppress any output specified by other flags         ]
       [   1 - suppress all output except system summary section           ]
       [       (overrides individual flags, but not out.all = 1)           ]

Solver specific options:
       name                    default     description [options]
   -----------------------    ---------   ----------------------------------
   MIPS:
       mips.linsolver          ''          linear system solver
           [   '' or '\'   build-in backslash \ operator (e.g. x = A \ b)  ]
           [   'PARDISO'   PARDISO solver (if available)                   ]
       mips.feastol            0           feasibility (equality) tolerance
                                           (set to opf.violation by default)
       mips.gradtol            1e-6        gradient tolerance
       mips.comptol            1e-6        complementary condition
                                           (inequality) tolerance
       mips.costtol            1e-6        optimality tolerance
       mips.max_it             150         maximum number of iterations
       mips.step_control       0           enable step-size cntrl [ 0 or 1 ]
       mips.sc.red_it          20          maximum number of reductions per
                                           iteration with step control
       mips.xi                 0.99995     constant used in alpha updates*
       mips.sigma              0.1         centering parameter*
       mips.z0                 1           used to initialize slack variables*
       mips.alpha_min          1e-8        returns "Numerically Failed" if
                                           either alpha parameter becomes
                                           smaller than this value*
       mips.rho_min            0.95        lower bound on rho_t*
       mips.rho_max            1.05        upper bound on rho_t*
       mips.mu_threshold       1e-5        KT multipliers smaller than this
                                           value for non-binding constraints
                                           are forced to zero
       mips.max_stepsize       1e10        returns "Numerically Failed" if the
                                           2-norm of the reduced Newton step
                                           exceeds this value*
           * See the corresponding Appendix in the manual for details.

   CPLEX:
       cplex.lpmethod          0           solution algorithm for LP problems
           [   0 - automatic: let CPLEX choose                             ]
           [   1 - primal simplex                                          ]
           [   2 - dual simplex                                            ]
           [   3 - network simplex                                         ]
           [   4 - barrier                                                 ]
           [   5 - sifting                                                 ]
           [   6 - concurrent (dual, barrier, and primal)                  ]
       cplex.qpmethod          0           solution algorithm for QP problems
           [   0 - automatic: let CPLEX choose                             ]
           [   1 - primal simplex optimizer                                ]
           [   2 - dual simplex optimizer                                  ]
           [   3 - network optimizer                                       ]
           [   4 - barrier optimizer                                       ]
       cplex.opts              <empty>     see CPLEX_OPTIONS for details
       cplex.opt_fname         <empty>     see CPLEX_OPTIONS for details
       cplex.opt               0           see CPLEX_OPTIONS for details

   FMINCON:
       fmincon.alg             4           algorithm used by fmincon() for OPF
                                           for Opt Toolbox 4 and later
            [  1 - active-set (not suitable for large problems)            ]
            [  2 - interior-point, w/default 'bfgs' Hessian approx         ]
            [  3 - interior-point, w/ 'lbfgs' Hessian approx               ]
            [  4 - interior-point, w/exact user-supplied Hessian           ]
            [  5 - interior-point, w/Hessian via finite differences        ]
            [  6 - sqp (not suitable for large problems)                   ]
       fmincon.tol_x           1e-4        termination tol on x
       fmincon.tol_f           1e-4        termination tol on f
       fmincon.max_it          0           maximum number of iterations
                                                           [  0 => default ]

   GUROBI:
       gurobi.method           0           solution algorithm (Method)
           [  -1 - automatic, let Gurobi decide                            ]
           [   0 - primal simplex                                          ]
           [   1 - dual simplex                                            ]
           [   2 - barrier                                                 ]
           [   3 - concurrent (LP only)                                    ]
           [   4 - deterministic concurrent (LP only)                      ]
       gurobi.timelimit        Inf         maximum time allowed (TimeLimit)
       gurobi.threads          0           max number of threads (Threads)
       gurobi.opts             <empty>     see GUROBI_OPTIONS for details
       gurobi.opt_fname        <empty>     see GUROBI_OPTIONS for details
       gurobi.opt              0           see GUROBI_OPTIONS for details

   IPOPT:
       ipopt.opts              <empty>     see IPOPT_OPTIONS for details
       ipopt.opt_fname         <empty>     see IPOPT_OPTIONS for details
       ipopt.opt               0           see IPOPT_OPTIONS for details

   KNITRO:
       knitro.tol_x            1e-4        termination tol on x
       knitro.tol_f            1e-4        termination tol on f
       knitro.opt_fname        <empty>     name of user-supplied native
                                           KNITRO options file that overrides
                                           all other options
       knitro.opt              0           if knitro.opt_fname is empty and
                                           knitro.opt is a non-zero integer N
                                           then knitro.opt_fname is auto-
                                           generated as:
                                           'knitro_user_options_N.txt'

   LINPROG:
       linprog                 <empty>     LINPROG options passed to
                                           OPTIMOPTIONS or OPTIMSET.
                                           see LINPROG in the Optimization
                                           Toolbox for details

   MINOPF:
       minopf.feastol          0 (1e-3)    primal feasibility tolerance
                                           (set to opf.violation by default)
       minopf.rowtol           0 (1e-3)    row tolerance
       minopf.xtol             0 (1e-4)    x tolerance
       minopf.majdamp          0 (0.5)     major damping parameter
       minopf.mindamp          0 (2.0)     minor damping parameter
       minopf.penalty          0 (1.0)     penalty parameter
       minopf.major_it         0 (200)     major iterations
       minopf.minor_it         0 (2500)    minor iterations
       minopf.max_it           0 (2500)    iterations limit
       minopf.verbosity        -1          amount of progress info printed
           [  -1 - controlled by 'verbose' option                          ]
           [   0 - print nothing                                           ]
           [   1 - print only termination status message                   ]
           [   2 - print termination status and screen progress            ]
           [   3 - print screen progress, report file (usually fort.9)     ]
       minopf.core             0 (1200*nb + 2*(nb+ng)^2) memory allocation
       minopf.supbasic_lim     0 (2*nb + 2*ng) superbasics limit
       minopf.mult_price       0 (30)      multiple price

   MOSEK:
       mosek.lp_alg            0           solution algorithm
                                               (MSK_IPAR_OPTIMIZER)
           for MOSEK 8.x ...        (see MOSEK_SYMBCON for a "better way")
           [   0 - automatic: let MOSEK choose                             ]
           [   1 - dual simplex                                            ]
           [   2 - automatic: let MOSEK choose                             ]
           [   3 - automatic simplex (MOSEK chooses which simplex method)  ]
           [   4 - interior point                                          ]
           [   6 - primal simplex                                          ]
       mosek.max_it            0 (400)     interior point max iterations
                                               (MSK_IPAR_INTPNT_MAX_ITERATIONS)
       mosek.gap_tol           0 (1e-8)    interior point relative gap tol
                                               (MSK_DPAR_INTPNT_TOL_REL_GAP)
       mosek.max_time          0 (-1)      maximum time allowed
                                               (MSK_DPAR_OPTIMIZER_MAX_TIME)
       mosek.num_threads       0 (1)       max number of threads
                                               (MSK_IPAR_INTPNT_NUM_THREADS)
       mosek.opts              <empty>     see MOSEK_OPTIONS for details
       mosek.opt_fname         <empty>     see MOSEK_OPTIONS for details
       mosek.opt               0           see MOSEK_OPTIONS for details

   QUADPROG:
       quadprog                <empty>     QUADPROG options passed to
                                           OPTIMOPTIONS or OPTIMSET.
                                           see QUADPROG in the Optimization
                                           Toolbox for details

   TSPOPF:
       pdipm.feastol           0           feasibility (equality) tolerance
                                           (set to opf.violation by default)
       pdipm.gradtol           1e-6        gradient tolerance
       pdipm.comptol           1e-6        complementary condition
                                           (inequality) tolerance
       pdipm.costtol           1e-6        optimality tolerance
       pdipm.max_it            150         maximum number of iterations
       pdipm.step_control      0           enable step-size cntrl [ 0 or 1 ]
       pdipm.sc.red_it         20          maximum number of reductions per
                                           iteration with step control
       pdipm.sc.smooth_ratio   0.04        piecewise linear curve smoothing
                                           ratio

       tralm.feastol           0           feasibility tolerance
                                           (set to opf.violation by default)
       tralm.primaltol         5e-4        primal variable tolerance
       tralm.dualtol           5e-4        dual variable tolerance
       tralm.costtol           1e-5        optimality tolerance
       tralm.major_it          40          maximum number of major iterations
       tralm.minor_it          40          maximum number of minor iterations
       tralm.smooth_ratio      0.04        piecewise linear curve smoothing
                                           ratio

Experimental Options:
   exp.sys_wide_zip_loads.pw   <empty>     1 x 3 vector of active load fraction
                                           to be modeled as constant power,
                                           constant current and constant
                                           impedance, respectively, where
                                           <empty> means use [1 0 0]
   exp.sys_wide_zip_loads.qw   <empty>     same for reactive power, where
                                           <empty> means use same value as
                                           for 'pw'

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function opt = mpoption(varargin)
0002 %MPOPTION  Used to set and retrieve a MATPOWER options struct.
0003 %
0004 %   OPT = MPOPTION
0005 %       Returns the default options struct.
0006 %
0007 %   OPT = MPOPTION(OVERRIDES)
0008 %       Returns the default options struct, with some fields overridden
0009 %       by values from OVERRIDES, which can be a struct or the name of
0010 %       a function that returns a struct.
0011 %
0012 %   OPT = MPOPTION(NAME1, VALUE1, NAME2, VALUE2, ...)
0013 %       Same as previous, except override options are specified by NAME,
0014 %       VALUE pairs. This can be used to set any part of the options
0015 %       struct. The names can be individual fields or multi-level field
0016 %       names with embedded periods. The values can be scalars or structs.
0017 %
0018 %       For backward compatibility, the NAMES and VALUES may correspond
0019 %       to old-style MATPOWER option names (elements in the old-style
0020 %       options vector) as well.
0021 %
0022 %   OPT = MPOPTION(OPT0)
0023 %       Converts an old-style options vector OPT0 into the corresponding
0024 %       options struct. If OPT0 is an options struct it does nothing.
0025 %
0026 %   OPT = MPOPTION(OPT0, OVERRIDES)
0027 %       Applies overrides to an existing set of options, OPT0, which
0028 %       can be an old-style options vector or an options struct.
0029 %
0030 %   OPT = MPOPTION(OPT0, NAME1, VALUE1, NAME2, VALUE2, ...)
0031 %       Same as above except it uses the old-style options vector OPT0
0032 %       as a base instead of the old default options vector.
0033 %
0034 %   OPT_VECTOR = MPOPTION(OPT, [])
0035 %       Creates and returns an old-style options vector from an
0036 %       options struct OPT.
0037 %
0038 %   Note: The use of old-style MATPOWER options vectors and their
0039 %         names and values has been deprecated and will be removed
0040 %         in a future version of MATPOWER. Until then, all uppercase
0041 %         option names are not permitted for new top-level options.
0042 %
0043 %   Examples:
0044 %       mpopt = mpoption('pf.alg', 'FDXB', 'pf.tol', 1e-4);
0045 %       mpopt = mpoption(mpopt, 'opf.dc.solver', 'CPLEX', 'verbose', 2);
0046 %
0047 %The currently defined options are as follows:
0048 %
0049 %   name                    default     description [options]
0050 %----------------------    ---------   ----------------------------------
0051 %Model options:
0052 %   model                   'AC'        AC vs. DC power flow model
0053 %       [ 'AC' - use nonlinear AC model & corresponding algorithms/options  ]
0054 %       [ 'DC' - use linear DC model & corresponding algorithms/options     ]
0055 %
0056 %Power Flow options:
0057 %   pf.alg                  'NR'        AC power flow algorithm
0058 %       [ 'NR'   - Newton's method                                          ]
0059 %       [ 'FDXB' - Fast-Decoupled (XB version)                              ]
0060 %       [ 'FDBX' - Fast-Decoupled (BX version)                              ]
0061 %       [ 'GS'   - Gauss-Seidel                                             ]
0062 %   pf.tol                  1e-8        termination tolerance on per unit
0063 %                                       P & Q mismatch
0064 %   pf.nr.max_it            10          maximum number of iterations for
0065 %                                       Newton's method
0066 %   pf.fd.max_it            30          maximum number of iterations for
0067 %                                       fast decoupled method
0068 %   pf.gs.max_it            1000        maximum number of iterations for
0069 %                                       Gauss-Seidel method
0070 %   pf.enforce_q_lims       0           enforce gen reactive power limits at
0071 %                                       expense of |V|
0072 %       [  0 - do NOT enforce limits                                        ]
0073 %       [  1 - enforce limits, simultaneous bus type conversion             ]
0074 %       [  2 - enforce limits, one-at-a-time bus type conversion            ]
0075 %
0076 %Continuation Power Flow options:
0077 %   cpf.parameterization    3           choice of parameterization
0078 %       [  1 - natural                                                      ]
0079 %       [  2 - arc length                                                   ]
0080 %       [  3 - pseudo arc length                                            ]
0081 %   cpf.stop_at             'NOSE'      determins stopping criterion
0082 %       [ 'NOSE'     - stop when nose point is reached                      ]
0083 %       [ 'FULL'     - trace full nose curve                                ]
0084 %       [ <lam_stop> - stop upon reaching specified target lambda value     ]
0085 %   cpf.enforce_p_lims      0           enforce gen active power limits
0086 %       [  0 - do NOT enforce limits                                        ]
0087 %       [  1 - enforce limits, simultaneous bus type conversion             ]
0088 %   cpf.enforce_q_lims      0           enforce gen reactive power limits at
0089 %                                       expense of |V|
0090 %       [  0 - do NOT enforce limits                                        ]
0091 %       [  1 - enforce limits, simultaneous bus type conversion             ]
0092 %   cpf.step                0.05        continuation power flow step size
0093 %   cpf.adapt_step          0           toggle adaptive step size feature
0094 %       [  0 - adaptive step size disabled                                  ]
0095 %       [  1 - adaptive step size enabled                                   ]
0096 %   cpf.step_min            1e-4        minimum allowed step size
0097 %   cpf.step_max            0.2         maximum allowed step size
0098 %   cpf.adapt_step_damping  0.7         damping factor for adaptive step
0099 %                                       sizing
0100 %   cpf.adapt_step_tol      1e-3        tolerance for adaptive step sizing
0101 %   cpf.target_lam_tol      1e-5        tolerance for target lambda detection
0102 %   cpf.nose_tol            1e-5        tolerance for nose point detection (pu)
0103 %   cpf.p_lims_tol          0.01        tolerance for generator active
0104 %                                       power limit enforcement (MW)
0105 %   cpf.q_lims_tol          0.01        tolerance for generator reactive
0106 %                                       power limit enforcement (MVAR)
0107 %   cpf.plot.level          0           control plotting of noze curve
0108 %       [  0 - do not plot nose curve                                       ]
0109 %       [  1 - plot when completed                                          ]
0110 %       [  2 - plot incrementally at each iteration                         ]
0111 %       [  3 - same as 2, with 'pause' at each iteration                    ]
0112 %   cpf.plot.bus            <empty>     index of bus whose voltage is to be
0113 %                                       plotted
0114 %   cpf.user_callback       <empty>     string containing the name of a user
0115 %                                       callback function, or struct with
0116 %                                       function name, and optional priority
0117 %                                       and/or args, or cell array of such
0118 %                                       strings and/or structs, see
0119 %                                       'help cpf_default_callback' for details
0120 %
0121 %Optimal Power Flow options:
0122 %   name                    default     description [options]
0123 %----------------------    ---------   ----------------------------------
0124 %   opf.ac.solver           'DEFAULT'   AC optimal power flow solver
0125 %       [ 'DEFAULT' - choose solver based on availability in the following  ]
0126 %       [             order: 'PDIPM', 'MIPS'                                ]
0127 %       [ 'MIPS'    - MIPS, MATPOWER Interior Point Solver, primal/dual     ]
0128 %       [             interior point method (pure Matlab)                   ]
0129 %       [ 'FMINCON' - MATLAB Optimization Toolbox, FMINCON                  ]
0130 %       [ 'IPOPT'   - IPOPT, requires MEX interface to IPOPT solver         ]
0131 %       [             available from:                                       ]
0132 %       [                 http://www.coin-or.org/projects/Ipopt.xml         ]
0133 %       [ 'KNITRO'  - KNITRO, requires MATLAB Optimization Toolbox and      ]
0134 %       [             KNITRO libraries available from: http://www.ziena.com/]
0135 %       [ 'MINOPF'  - MINOPF, MINOS-based solver, requires optional         ]
0136 %       [             MEX-based MINOPF package, available from:             ]
0137 %       [                   http://www.pserc.cornell.edu/minopf/            ]
0138 %       [ 'PDIPM'   - PDIPM, primal/dual interior point method, requires    ]
0139 %       [             optional MEX-based TSPOPF package, available from:    ]
0140 %       [                   http://www.pserc.cornell.edu/tspopf/            ]
0141 %       [ 'SDPOPF'  - SDPOPF, solver based on semidefinite relaxation of    ]
0142 %       [             OPF problem, requires optional packages:              ]
0143 %       [               SDP_PF, available in extras/sdp_pf                  ]
0144 %       [               YALMIP, available from:                             ]
0145 %       [                   http://users.isy.liu.se/johanl/yalmip/          ]
0146 %       [               SDP solver such as SeDuMi, available from:          ]
0147 %       [                   http://sedumi.ie.lehigh.edu/                    ]
0148 %       [ 'TRALM'   - TRALM, trust region based augmented Langrangian       ]
0149 %       [             method, requires TSPOPF (see 'PDIPM')                 ]
0150 %   opf.dc.solver           'DEFAULT'   DC optimal power flow solver
0151 %       [ 'DEFAULT' - choose solver based on availability in the following  ]
0152 %       [             order: 'GUROBI', 'CPLEX', 'MOSEK', 'OT',              ]
0153 %       [             'GLPK' (linear costs only), 'BPMPD', 'MIPS'           ]
0154 %       [ 'MIPS'    - MIPS, MATPOWER Interior Point Solver, primal/dual     ]
0155 %       [             interior point method (pure Matlab)                   ]
0156 %       [ 'BPMPD'   - BPMPD, requires optional MEX-based BPMPD_MEX package  ]
0157 %       [             available from: http://www.pserc.cornell.edu/bpmpd/   ]
0158 %       [ 'CLP'     - CLP, requires interface to COIN-OP LP solver          ]
0159 %       [             available from:http://www.coin-or.org/projects/Clp.xml]
0160 %       [ 'CPLEX'   - CPLEX, requires CPLEX solver available from:          ]
0161 %       [             http://www.ibm.com/software/integration/ ...          ]
0162 %       [                                 ... optimization/cplex-optimizer/ ]
0163 %       [ 'GLPK'    - GLPK, requires interface to GLPK solver               ]
0164 %       [             available from: http://www.gnu.org/software/glpk/     ]
0165 %       [             (GLPK does not work with quadratic cost functions)    ]
0166 %       [ 'GUROBI'  - GUROBI, requires Gurobi optimizer (v. 5+)             ]
0167 %       [             available from: http://www.gurobi.com/                ]
0168 %       [ 'IPOPT'   - IPOPT, requires MEX interface to IPOPT solver         ]
0169 %       [             available from:                                       ]
0170 %       [                 http://www.coin-or.org/projects/Ipopt.xml         ]
0171 %       [ 'MOSEK'   - MOSEK, requires Matlab interface to MOSEK solver      ]
0172 %       [             available from: http://www.mosek.com/                 ]
0173 %       [ 'OT'      - MATLAB Optimization Toolbox, QUADPROG, LINPROG        ]
0174 %   opf.violation           5e-6        constraint violation tolerance
0175 %   opf.use_vg              0           respect gen voltage setpt     [ 0-1 ]
0176 %       [ 0 - use specified bus Vmin & Vmax, and ignore gen Vg              ]
0177 %       [ 1 - replace specified bus Vmin & Vmax by corresponding gen Vg     ]
0178 %       [ between 0 and 1 - use a weighted average of the 2 options         ]
0179 %   opf.flow_lim            'S'         quantity limited by branch flow
0180 %                                       constraints
0181 %       [ 'S' - apparent power flow (limit in MVA)                          ]
0182 %       [ 'P' - active power flow (limit in MW)                             ]
0183 %       [ 'I' - current magnitude (limit in MVA at 1 p.u. voltage)          ]
0184 %   opf.ignore_angle_lim    0           angle diff limits for branches
0185 %       [ 0 - include angle difference limits, if specified                 ]
0186 %       [ 1 - ignore angle difference limits even if specified              ]
0187 %   opf.init_from_mpc       -1          specify whether to use current state
0188 %                                       in MATPOWER case to initialize OPF
0189 %                                       (currently supported only for Ipopt,
0190 %                                        Knitro and MIPS solvers)
0191 %       [  -1 - MATPOWER decides, based on solver/algorithm                 ]
0192 %       [   0 - ignore current state when initializing OPF                  ]
0193 %       [   1 - use current state to initialize OPF                         ]
0194 %   opf.return_raw_der      0           for AC OPF, return constraint and
0195 %                                       derivative info in results.raw
0196 %                                       (in fields g, dg, df, d2f) [ 0 or 1 ]
0197 %
0198 %Output options:
0199 %   name                    default     description [options]
0200 %----------------------    ---------   ----------------------------------
0201 %   verbose                 1           amount of progress info printed
0202 %       [   0 - print no progress info                                      ]
0203 %       [   1 - print a little progress info                                ]
0204 %       [   2 - print a lot of progress info                                ]
0205 %       [   3 - print all progress info                                     ]
0206 %   out.all                 -1          controls pretty-printing of results
0207 %       [  -1 - individual flags control what prints                        ]
0208 %       [   0 - do not print anything (overrides individual flags, ignored  ]
0209 %       [       for files specified as FNAME arg to runpf(), runopf(), etc.)]
0210 %       [   1 - print everything (overrides individual flags)               ]
0211 %   out.sys_sum             1           print system summary       [ 0 or 1 ]
0212 %   out.area_sum            0           print area summaries       [ 0 or 1 ]
0213 %   out.bus                 1           print bus detail           [ 0 or 1 ]
0214 %   out.branch              1           print branch detail        [ 0 or 1 ]
0215 %   out.gen                 0           print generator detail     [ 0 or 1 ]
0216 %   out.lim.all             -1          controls constraint info output
0217 %       [  -1 - individual flags control what constraint info prints        ]
0218 %       [   0 - no constraint info (overrides individual flags)             ]
0219 %       [   1 - binding constraint info (overrides individual flags)        ]
0220 %       [   2 - all constraint info (overrides individual flags)            ]
0221 %   out.lim.v               1           control voltage limit info
0222 %       [   0 - do not print                                                ]
0223 %       [   1 - print binding constraints only                              ]
0224 %       [   2 - print all constraints                                       ]
0225 %       [   (same options for OUT_LINE_LIM, OUT_PG_LIM, OUT_QG_LIM)         ]
0226 %   out.lim.line            1           control line flow limit info
0227 %   out.lim.pg              1           control gen active power limit info
0228 %   out.lim.qg              1           control gen reactive pwr limit info
0229 %   out.force               0           print results even if success
0230 %                                       flag = 0                   [ 0 or 1 ]
0231 %   out.suppress_detail     -1          suppress all output but system summary
0232 %       [  -1 - suppress details for large systems (> 500 buses)            ]
0233 %       [   0 - do not suppress any output specified by other flags         ]
0234 %       [   1 - suppress all output except system summary section           ]
0235 %       [       (overrides individual flags, but not out.all = 1)           ]
0236 %
0237 %Solver specific options:
0238 %       name                    default     description [options]
0239 %   -----------------------    ---------   ----------------------------------
0240 %   MIPS:
0241 %       mips.linsolver          ''          linear system solver
0242 %           [   '' or '\'   build-in backslash \ operator (e.g. x = A \ b)  ]
0243 %           [   'PARDISO'   PARDISO solver (if available)                   ]
0244 %       mips.feastol            0           feasibility (equality) tolerance
0245 %                                           (set to opf.violation by default)
0246 %       mips.gradtol            1e-6        gradient tolerance
0247 %       mips.comptol            1e-6        complementary condition
0248 %                                           (inequality) tolerance
0249 %       mips.costtol            1e-6        optimality tolerance
0250 %       mips.max_it             150         maximum number of iterations
0251 %       mips.step_control       0           enable step-size cntrl [ 0 or 1 ]
0252 %       mips.sc.red_it          20          maximum number of reductions per
0253 %                                           iteration with step control
0254 %       mips.xi                 0.99995     constant used in alpha updates*
0255 %       mips.sigma              0.1         centering parameter*
0256 %       mips.z0                 1           used to initialize slack variables*
0257 %       mips.alpha_min          1e-8        returns "Numerically Failed" if
0258 %                                           either alpha parameter becomes
0259 %                                           smaller than this value*
0260 %       mips.rho_min            0.95        lower bound on rho_t*
0261 %       mips.rho_max            1.05        upper bound on rho_t*
0262 %       mips.mu_threshold       1e-5        KT multipliers smaller than this
0263 %                                           value for non-binding constraints
0264 %                                           are forced to zero
0265 %       mips.max_stepsize       1e10        returns "Numerically Failed" if the
0266 %                                           2-norm of the reduced Newton step
0267 %                                           exceeds this value*
0268 %           * See the corresponding Appendix in the manual for details.
0269 %
0270 %   CPLEX:
0271 %       cplex.lpmethod          0           solution algorithm for LP problems
0272 %           [   0 - automatic: let CPLEX choose                             ]
0273 %           [   1 - primal simplex                                          ]
0274 %           [   2 - dual simplex                                            ]
0275 %           [   3 - network simplex                                         ]
0276 %           [   4 - barrier                                                 ]
0277 %           [   5 - sifting                                                 ]
0278 %           [   6 - concurrent (dual, barrier, and primal)                  ]
0279 %       cplex.qpmethod          0           solution algorithm for QP problems
0280 %           [   0 - automatic: let CPLEX choose                             ]
0281 %           [   1 - primal simplex optimizer                                ]
0282 %           [   2 - dual simplex optimizer                                  ]
0283 %           [   3 - network optimizer                                       ]
0284 %           [   4 - barrier optimizer                                       ]
0285 %       cplex.opts              <empty>     see CPLEX_OPTIONS for details
0286 %       cplex.opt_fname         <empty>     see CPLEX_OPTIONS for details
0287 %       cplex.opt               0           see CPLEX_OPTIONS for details
0288 %
0289 %   FMINCON:
0290 %       fmincon.alg             4           algorithm used by fmincon() for OPF
0291 %                                           for Opt Toolbox 4 and later
0292 %            [  1 - active-set (not suitable for large problems)            ]
0293 %            [  2 - interior-point, w/default 'bfgs' Hessian approx         ]
0294 %            [  3 - interior-point, w/ 'lbfgs' Hessian approx               ]
0295 %            [  4 - interior-point, w/exact user-supplied Hessian           ]
0296 %            [  5 - interior-point, w/Hessian via finite differences        ]
0297 %            [  6 - sqp (not suitable for large problems)                   ]
0298 %       fmincon.tol_x           1e-4        termination tol on x
0299 %       fmincon.tol_f           1e-4        termination tol on f
0300 %       fmincon.max_it          0           maximum number of iterations
0301 %                                                           [  0 => default ]
0302 %
0303 %   GUROBI:
0304 %       gurobi.method           0           solution algorithm (Method)
0305 %           [  -1 - automatic, let Gurobi decide                            ]
0306 %           [   0 - primal simplex                                          ]
0307 %           [   1 - dual simplex                                            ]
0308 %           [   2 - barrier                                                 ]
0309 %           [   3 - concurrent (LP only)                                    ]
0310 %           [   4 - deterministic concurrent (LP only)                      ]
0311 %       gurobi.timelimit        Inf         maximum time allowed (TimeLimit)
0312 %       gurobi.threads          0           max number of threads (Threads)
0313 %       gurobi.opts             <empty>     see GUROBI_OPTIONS for details
0314 %       gurobi.opt_fname        <empty>     see GUROBI_OPTIONS for details
0315 %       gurobi.opt              0           see GUROBI_OPTIONS for details
0316 %
0317 %   IPOPT:
0318 %       ipopt.opts              <empty>     see IPOPT_OPTIONS for details
0319 %       ipopt.opt_fname         <empty>     see IPOPT_OPTIONS for details
0320 %       ipopt.opt               0           see IPOPT_OPTIONS for details
0321 %
0322 %   KNITRO:
0323 %       knitro.tol_x            1e-4        termination tol on x
0324 %       knitro.tol_f            1e-4        termination tol on f
0325 %       knitro.opt_fname        <empty>     name of user-supplied native
0326 %                                           KNITRO options file that overrides
0327 %                                           all other options
0328 %       knitro.opt              0           if knitro.opt_fname is empty and
0329 %                                           knitro.opt is a non-zero integer N
0330 %                                           then knitro.opt_fname is auto-
0331 %                                           generated as:
0332 %                                           'knitro_user_options_N.txt'
0333 %
0334 %   LINPROG:
0335 %       linprog                 <empty>     LINPROG options passed to
0336 %                                           OPTIMOPTIONS or OPTIMSET.
0337 %                                           see LINPROG in the Optimization
0338 %                                           Toolbox for details
0339 %
0340 %   MINOPF:
0341 %       minopf.feastol          0 (1e-3)    primal feasibility tolerance
0342 %                                           (set to opf.violation by default)
0343 %       minopf.rowtol           0 (1e-3)    row tolerance
0344 %       minopf.xtol             0 (1e-4)    x tolerance
0345 %       minopf.majdamp          0 (0.5)     major damping parameter
0346 %       minopf.mindamp          0 (2.0)     minor damping parameter
0347 %       minopf.penalty          0 (1.0)     penalty parameter
0348 %       minopf.major_it         0 (200)     major iterations
0349 %       minopf.minor_it         0 (2500)    minor iterations
0350 %       minopf.max_it           0 (2500)    iterations limit
0351 %       minopf.verbosity        -1          amount of progress info printed
0352 %           [  -1 - controlled by 'verbose' option                          ]
0353 %           [   0 - print nothing                                           ]
0354 %           [   1 - print only termination status message                   ]
0355 %           [   2 - print termination status and screen progress            ]
0356 %           [   3 - print screen progress, report file (usually fort.9)     ]
0357 %       minopf.core             0 (1200*nb + 2*(nb+ng)^2) memory allocation
0358 %       minopf.supbasic_lim     0 (2*nb + 2*ng) superbasics limit
0359 %       minopf.mult_price       0 (30)      multiple price
0360 %
0361 %   MOSEK:
0362 %       mosek.lp_alg            0           solution algorithm
0363 %                                               (MSK_IPAR_OPTIMIZER)
0364 %           for MOSEK 8.x ...        (see MOSEK_SYMBCON for a "better way")
0365 %           [   0 - automatic: let MOSEK choose                             ]
0366 %           [   1 - dual simplex                                            ]
0367 %           [   2 - automatic: let MOSEK choose                             ]
0368 %           [   3 - automatic simplex (MOSEK chooses which simplex method)  ]
0369 %           [   4 - interior point                                          ]
0370 %           [   6 - primal simplex                                          ]
0371 %       mosek.max_it            0 (400)     interior point max iterations
0372 %                                               (MSK_IPAR_INTPNT_MAX_ITERATIONS)
0373 %       mosek.gap_tol           0 (1e-8)    interior point relative gap tol
0374 %                                               (MSK_DPAR_INTPNT_TOL_REL_GAP)
0375 %       mosek.max_time          0 (-1)      maximum time allowed
0376 %                                               (MSK_DPAR_OPTIMIZER_MAX_TIME)
0377 %       mosek.num_threads       0 (1)       max number of threads
0378 %                                               (MSK_IPAR_INTPNT_NUM_THREADS)
0379 %       mosek.opts              <empty>     see MOSEK_OPTIONS for details
0380 %       mosek.opt_fname         <empty>     see MOSEK_OPTIONS for details
0381 %       mosek.opt               0           see MOSEK_OPTIONS for details
0382 %
0383 %   QUADPROG:
0384 %       quadprog                <empty>     QUADPROG options passed to
0385 %                                           OPTIMOPTIONS or OPTIMSET.
0386 %                                           see QUADPROG in the Optimization
0387 %                                           Toolbox for details
0388 %
0389 %   TSPOPF:
0390 %       pdipm.feastol           0           feasibility (equality) tolerance
0391 %                                           (set to opf.violation by default)
0392 %       pdipm.gradtol           1e-6        gradient tolerance
0393 %       pdipm.comptol           1e-6        complementary condition
0394 %                                           (inequality) tolerance
0395 %       pdipm.costtol           1e-6        optimality tolerance
0396 %       pdipm.max_it            150         maximum number of iterations
0397 %       pdipm.step_control      0           enable step-size cntrl [ 0 or 1 ]
0398 %       pdipm.sc.red_it         20          maximum number of reductions per
0399 %                                           iteration with step control
0400 %       pdipm.sc.smooth_ratio   0.04        piecewise linear curve smoothing
0401 %                                           ratio
0402 %
0403 %       tralm.feastol           0           feasibility tolerance
0404 %                                           (set to opf.violation by default)
0405 %       tralm.primaltol         5e-4        primal variable tolerance
0406 %       tralm.dualtol           5e-4        dual variable tolerance
0407 %       tralm.costtol           1e-5        optimality tolerance
0408 %       tralm.major_it          40          maximum number of major iterations
0409 %       tralm.minor_it          40          maximum number of minor iterations
0410 %       tralm.smooth_ratio      0.04        piecewise linear curve smoothing
0411 %                                           ratio
0412 %
0413 %Experimental Options:
0414 %   exp.sys_wide_zip_loads.pw   <empty>     1 x 3 vector of active load fraction
0415 %                                           to be modeled as constant power,
0416 %                                           constant current and constant
0417 %                                           impedance, respectively, where
0418 %                                           <empty> means use [1 0 0]
0419 %   exp.sys_wide_zip_loads.qw   <empty>     same for reactive power, where
0420 %                                           <empty> means use same value as
0421 %                                           for 'pw'
0422 
0423 %   MATPOWER
0424 %   Copyright (c) 2013-2016, Power Systems Engineering Research Center (PSERC)
0425 %   by Ray Zimmerman, PSERC Cornell
0426 %   and Shrirang Abhyankar, Argonne National Laboratory
0427 %
0428 %   This file is part of MATPOWER.
0429 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0430 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0431 
0432 %% some constants
0433 N = 124;                %% number of options in old-style vector (MATPOWER 4.1)
0434 N40 = 116;              %% dimension of MATPOWER 4.0 options vector
0435 N32 = 93;               %% dimension of MATPOWER 3.2 options vector
0436 v = mpoption_version;   %% version number of MATPOWER options struct
0437 
0438 %% initialize flags and arg counter
0439 have_opt0 = 0;          %% existing options struct or vector provided?
0440 have_old_style_ov = 0;  %% override options using old-style names?
0441 return_old_style = 0;   %% return value as old-style vector?
0442 k = 1;
0443 if nargin > 0
0444     opt0 = varargin{k};
0445     if isstruct(opt0) && isfield(opt0, 'v')         %% options struct
0446         have_opt0 = 1;
0447         k = k + 1;
0448     elseif isnumeric(opt0) && size(opt0, 2) == 1    %% options vector
0449         nn = size(opt0, 1);
0450         if ismember(nn, [N N40 N32])                %% of valid size
0451             %% expand smaller option vectors (from before MATPOWER 4.1)
0452             if nn < N
0453                 optv = mpoption_old();
0454                 opt0(nn+1:N) = optv(nn+1:N);
0455             end
0456             have_opt0 = 1;
0457             k = k + 1;
0458         end
0459     end
0460 end
0461 
0462 %% create base options vector to which overrides are made
0463 if have_opt0
0464     if isstruct(opt0)               %% it's already a valid options struct
0465         if DEBUG, fprintf('OPT0 is a valid options struct\n'); end
0466         if opt0.v < v
0467             %% convert older version to current version
0468             opt_d = mpoption_default();
0469             if opt0.v == 1          %% convert version 1 to 2
0470                 if isfield(opt_d, 'linprog')
0471                     opt0.lingprog = opt_d.linprog;
0472                 end
0473                 if isfield(opt_d, 'quadprog')
0474                     opt0.quadprog = opt_d.quadprog;
0475                 end
0476             end
0477             if opt0.v <= 2          %% convert version 2 to 3
0478                 opt0.out.suppress_detail = opt_d.out.suppress_detail;
0479             end
0480             %if opt0.v <= 3          %% convert version 3 to 4
0481                 %% new mips options were all optional, no conversion needed
0482             %end
0483             if opt0.v <= 4          %% convert version 4 to 5
0484                 opt0.opf.init_from_mpc = opt_d.opf.init_from_mpc;
0485             end
0486             if opt0.v <= 5          %% convert version 5 to 6
0487                 if isfield(opt_d, 'clp')
0488                     opt0.clp = opt_d.clp;
0489                 end
0490             end
0491             if opt0.v <= 6          %% convert version 6 to 7
0492                 if isfield(opt_d, 'intlinprog')
0493                     opt0.intlinprog = opt_d.intlinprog;
0494                 end
0495             end
0496             if opt0.v <= 7          %% convert version 7 to 8
0497                 opt0.mips.linsolver = opt_d.mips.linsolver;
0498             end
0499             if opt0.v <= 8          %% convert version 8 to 9
0500                 opt0.exp.sys_wide_zip_loads = opt_d.exp.sys_wide_zip_loads;
0501             end
0502             if opt0.v <= 9          %% convert version 9 to 10
0503                 opt0.most = opt_d.most;
0504             end
0505             if opt0.v <= 10         %% convert version 10 to 11
0506                 opt0.cpf.enforce_p_lims     = opt_d.cpf.enforce_p_lims;
0507                 opt0.cpf.enforce_q_lims     = opt_d.cpf.enforce_q_lims;
0508                 opt0.cpf.adapt_step_damping = opt_d.cpf.adapt_step_damping;
0509                 opt0.cpf.target_lam_tol     = opt_d.cpf.target_lam_tol;
0510                 opt0.cpf.nose_tol           = opt_d.cpf.nose_tol;
0511                 opt0.cpf.p_lims_tol         = opt_d.cpf.p_lims_tol;
0512                 opt0.cpf.q_lims_tol         = opt_d.cpf.q_lims_tol;
0513                 if (~isempty(opt0.cpf.user_callback_args) && ...
0514                         ~isstruct(opt0.cpf.user_callback_args)) || ...
0515                         (isstruct(opt0.cpf.user_callback_args) && ...
0516                          ~isempty(fields(opt0.cpf.user_callback_args)))
0517                     warning('The ''cpf.user_callback_args'' option has been removed. Please include the args in a struct in ''cpf.user_callback'' instead.')
0518                 end
0519                 opt0.cpf = rmfield(opt0.cpf, 'user_callback_args');
0520             end
0521             if opt0.v <= 11         %% convert version 11 to 12
0522                 opt0.cpf.use_vg = opt_d.cpf.use_vg;
0523             end
0524             opt0.v = v;
0525         end
0526         opt = opt0;
0527     else                            %% convert from old-style options vector
0528         if DEBUG, fprintf('OPT0 is a old-style options vector\n'); end
0529         opt = mpoption_v2s(opt0);
0530     end
0531 else                                %% use default options struct as base
0532     if DEBUG, fprintf('no OPT0, starting with default options struct\n'); end
0533     opt = mpoption_default();
0534 end
0535 
0536 
0537 %% do we have OVERRIDES or NAME/VALUE pairs
0538 ov = [];
0539 if nargin - k == 0          %% looking at last arg, must be OVERRIDES
0540     if isstruct(varargin{k})        %% OVERRIDES provided as struct
0541         if DEBUG, fprintf('OVERRIDES struct\n'); end
0542         ov = varargin{k};
0543     elseif ischar(varargin{k})      %% OVERRIDES provided as file/function name
0544         if DEBUG, fprintf('OVERRIDES file/function name\n'); end
0545         try
0546             ov = feval(varargin{k});
0547         catch
0548             error('mpoption: Unable to load MATPOWER options from ''%s''', varargin{k});
0549         end
0550         if ~isstruct(ov)
0551             error('mpoption: calling ''%s'' did not return a struct', varargin{k});
0552         end
0553     elseif isempty(varargin{k})
0554         return_old_style = 1;
0555     else
0556         error('mpoption: OVERRIDES must be a struct or the name of a function that returns a struct');
0557     end
0558 elseif nargin - k > 0 && mod(nargin-k, 2)   %% even number of remaining args
0559     if DEBUG, fprintf('NAME/VALUE pairs override defaults\n'); end
0560     %% process NAME/VALUE pairs
0561     if strcmp(varargin{k}, upper(varargin{k}))  %% old-style, all UPPERCASE option pairs
0562         %% NOTE: new top-level option fields cannot be all uppercase
0563         if ~have_opt0
0564             opt_v = mpoption_old(varargin{:});  %% create modified vector ...
0565             opt = mpoption_v2s(opt_v);          %% ... then convert
0566         else
0567             have_old_style_ov = 1;
0568             %% convert pairs to struct
0569             while k < nargin
0570                 name = varargin{k};
0571                 val  = varargin{k+1};
0572                 k = k + 2;
0573                 ov.(name) = val;
0574             end
0575         end
0576     else                                        %% new option pairs
0577         %% convert pairs to struct
0578         while k < nargin
0579             name = varargin{k};
0580             val  = varargin{k+1};
0581             k = k + 2;
0582             c = regexp(name, '([^\.]*)', 'tokens');
0583             s = struct();
0584             for i = 1:length(c)
0585                 s(i).type = '.';
0586                 s(i).subs = c{i}{1};
0587             end
0588             ov = subsasgn(ov, s, val);
0589         end
0590     end
0591 elseif nargin == 0 || nargin == 1
0592     if DEBUG, fprintf('no OVERRIDES, return default options struct or converted OPT0 vector\n'); end
0593 else
0594     error('mpoption: invalid calling syntax, see ''help mpoption'' to double-check the valid options');
0595 end
0596 
0597 %% apply overrides
0598 if ~isempty(ov)
0599     if have_old_style_ov
0600         opt = apply_old_mpoption_overrides(opt, ov);
0601     else
0602         persistent nsc_opt;     %% cache this to speed things up
0603         if ~isstruct(nsc_opt)
0604             vf = nested_struct_copy(mpoption_default(), mpoption_info_mips('V'));
0605             vf = nested_struct_copy(vf, mpoption_optional_fields());
0606             ex = struct(...
0607                 'name', {}, ...
0608                 'check', {}, ...
0609                 'copy_mode', {} ...
0610             );
0611             %% add exceptions for optional packages
0612             opt_pkgs = mpoption_optional_pkgs();
0613             n = length(ex);
0614             for k = 1:length(opt_pkgs)
0615                 fname = ['mpoption_info_' opt_pkgs{k}];
0616                 if exist(fname, 'file') == 2
0617                     opt_ex = feval(fname, 'E');
0618                     nex = length(opt_ex);
0619                     if ~isempty(opt_ex)
0620                         for j = 1:nex
0621                             ex(n+j).name = opt_ex(j).name;
0622                         end
0623                         if isfield(opt_ex, 'check')
0624                             for j = 1:nex
0625                                 ex(n+j).check = opt_ex(j).check;
0626                             end
0627                         end
0628                         if isfield(opt_ex, 'copy_mode')
0629                             for j = 1:nex
0630                                 ex(n+j).copy_mode = opt_ex(j).copy_mode;
0631                             end
0632                         end
0633                         if isfield(opt_ex, 'valid_fields')
0634                             for j = 1:nex
0635                                 ex(n+j).valid_fields = opt_ex(j).valid_fields;
0636                             end
0637                         end
0638                         n = n + nex;
0639                     end
0640                 end
0641             end
0642             nsc_opt = struct('check', 1, 'valid_fields', vf, 'exceptions', ex);
0643         end
0644 %         if have_fcn('catchme')
0645 %             try
0646 %                 opt = nested_struct_copy(opt, ov, nsc_opt);
0647 %             catch me
0648 %                 str = strrep(me.message, 'field', 'option');
0649 %                 str = strrep(str, 'nested_struct_copy', 'mpoption');
0650 %                 error(str);
0651 %             end
0652 %         else
0653             try
0654                 opt = nested_struct_copy(opt, ov, nsc_opt);
0655             catch
0656                 me = lasterr;
0657                 str = strrep(me, 'field', 'option');
0658                 str = strrep(str, 'nested_struct_copy', 'mpoption');
0659                 error(str);
0660             end
0661 %         end
0662     end
0663 end
0664 if return_old_style
0665     opt = mpoption_s2v(opt);
0666 end
0667 
0668 
0669 %%-------------------------------------------------------------------
0670 function opt = apply_old_mpoption_overrides(opt0, ov)
0671 %
0672 %   OPT0 is assumed to already have all of the fields and sub-fields found
0673 %   in the default options struct.
0674 
0675 %% initialize output
0676 opt = opt0;
0677 
0678 errstr = 'mpoption: %g is not a valid value for the old-style ''%s'' option';
0679 fields = fieldnames(ov);
0680 for f = 1:length(fields)
0681     ff = fields{f};
0682     switch ff
0683         case 'PF_ALG'
0684             switch ov.(ff)
0685                 case 1
0686                     opt.pf.alg = 'NR';      %% Newton's method
0687                 case 2
0688                     opt.pf.alg = 'FDXB';    %% fast-decoupled (XB version)
0689                 case 3
0690                     opt.pf.alg = 'FDBX';    %% fast-decoupled (BX version)
0691                 case 4
0692                     opt.pf.alg = 'GS';      %% Gauss-Seidel
0693                 otherwise
0694                     error(errstr, ov.(ff), ff);
0695             end
0696         case 'PF_TOL'
0697             opt.pf.tol = ov.(ff);
0698         case 'PF_MAX_IT'
0699             opt.pf.nr.max_it = ov.(ff);
0700         case 'PF_MAX_IT_FD'
0701             opt.pf.fd.max_it = ov.(ff);
0702         case 'PF_MAX_IT_GS'
0703             opt.pf.gs.max_it = ov.(ff);
0704         case 'ENFORCE_Q_LIMS'
0705             opt.pf.enforce_q_lims = ov.(ff);
0706         case 'PF_DC'
0707             switch ov.(ff)
0708                 case 0
0709                     opt.model = 'AC';
0710                 case 1
0711                     opt.model = 'DC';
0712                 otherwise
0713                     error(errstr, ov.(ff), ff);
0714             end
0715         case 'OPF_ALG'
0716             switch ov.(ff)
0717                 case 0
0718                     opt.opf.ac.solver = 'DEFAULT';
0719                 case 500
0720                     opt.opf.ac.solver = 'MINOPF';
0721                 case 520
0722                     opt.opf.ac.solver = 'FMINCON';
0723                 case {540, 545}
0724                     opt.opf.ac.solver = 'PDIPM';
0725                     if ov.(ff) == 545
0726                         opt.pdipm.step_control = 1;
0727                     else
0728                         opt.pdipm.step_control = 0;
0729                     end
0730                 case 550
0731                     opt.opf.ac.solver = 'TRALM';
0732                 case {560, 565}
0733                     opt.opf.ac.solver = 'MIPS';
0734                     if ov.(ff) == 565
0735                         opt.mips.step_control = 1;
0736                     else
0737                         opt.mips.step_control = 0;
0738                     end
0739                 case 580
0740                     opt.opf.ac.solver = 'IPOPT';
0741                 case 600
0742                     opt.opf.ac.solver = 'KNITRO';
0743                 otherwise
0744                     error(errstr, ov.(ff), ff);
0745             end
0746         case 'OPF_VIOLATION'
0747             opt.opf.violation = ov.(ff);
0748         case 'CONSTR_TOL_X'
0749             opt.fmincon.tol_x = ov.(ff);
0750             opt.knitro.tol_x = ov.(ff);
0751         case 'CONSTR_TOL_F'
0752             opt.fmincon.tol_f = ov.(ff);
0753             opt.knitro.tol_f = ov.(ff);
0754         case 'CONSTR_MAX_IT'
0755             opt.fmincon.max_it = ov.(ff);
0756         case 'OPF_FLOW_LIM'
0757             switch ov.(ff)
0758                 case 0
0759                     opt.opf.flow_lim = 'S';   %% apparent power (MVA)
0760                 case 1
0761                     opt.opf.flow_lim = 'P';   %% real power (MW)
0762                 case 2
0763                     opt.opf.flow_lim = 'I';   %% current magnitude (MVA @ 1 p.u. voltage)
0764                 otherwise
0765                     error(errstr, ov.(ff), ff);
0766             end
0767         case 'OPF_IGNORE_ANG_LIM'
0768             opt.opf.ignore_angle_lim = ov.(ff);
0769         case 'OPF_ALG_DC'
0770             switch ov.(ff)
0771                 case 0
0772                     opt.opf.dc.solver = 'DEFAULT';
0773                 case 100
0774                     opt.opf.dc.solver = 'BPMPD';
0775                 case {200, 250}
0776                     opt.opf.dc.solver = 'MIPS';
0777                     if ov.(ff) == 250
0778                         opt.mips.step_control = 1;
0779                     else
0780                         opt.mips.step_control = 0;
0781                     end
0782                 case 300
0783                     opt.opf.dc.solver = 'OT';     %% QUADPROG, LINPROG
0784                 case 400
0785                     opt.opf.dc.solver = 'IPOPT';
0786                 case 500
0787                     opt.opf.dc.solver = 'CPLEX';
0788                 case 600
0789                     opt.opf.dc.solver = 'MOSEK';
0790                 case 700
0791                     opt.opf.dc.solver = 'GUROBI';
0792                 otherwise
0793                     error(errstr, ov.(ff), ff);
0794             end
0795         case 'VERBOSE'
0796             opt.verbose = ov.(ff);
0797         case 'OUT_ALL'
0798             opt.out.all = ov.(ff);
0799         case 'OUT_SYS_SUM'
0800             opt.out.sys_sum = ov.(ff);
0801         case 'OUT_AREA_SUM'
0802             opt.out.area_sum = ov.(ff);
0803         case 'OUT_BUS'
0804             opt.out.bus = ov.(ff);
0805         case 'OUT_BRANCH'
0806             opt.out.branch = ov.(ff);
0807         case 'OUT_GEN'
0808             opt.out.gen = ov.(ff);
0809         case 'OUT_ALL_LIM'
0810             opt.out.lim.all = ov.(ff);
0811         case 'OUT_V_LIM'
0812             opt.out.lim.v = ov.(ff);
0813         case 'OUT_LINE_LIM'
0814             opt.out.lim.line = ov.(ff);
0815         case 'OUT_PG_LIM'
0816             opt.out.lim.pg = ov.(ff);
0817         case 'OUT_QG_LIM'
0818             opt.out.lim.qg = ov.(ff);
0819         case 'OUT_FORCE'
0820             opt.out.force = ov.(ff);
0821         case 'RETURN_RAW_DER'
0822             opt.opf.return_raw_der = ov.(ff);
0823         case 'FMC_ALG'
0824             opt.fmincon.alg = ov.(ff);
0825         case 'KNITRO_OPT'
0826             opt.knitro.opt = ov.(ff);
0827         case 'IPOPT_OPT'
0828             opt.ipopt.opt = ov.(ff);
0829         case 'MNS_FEASTOL'
0830             opt.minopf.feastol = ov.(ff);
0831         case 'MNS_ROWTOL'
0832             opt.minopf.rowtol = ov.(ff);
0833         case 'MNS_XTOL'
0834             opt.minopf.xtol = ov.(ff);
0835         case 'MNS_MAJDAMP'
0836             opt.minopf.majdamp = ov.(ff);
0837         case 'MNS_MINDAMP'
0838             opt.minopf.mindamp = ov.(ff);
0839         case 'MNS_PENALTY_PARM'
0840             opt.minopf.penalty = ov.(ff);
0841         case 'MNS_MAJOR_IT'
0842             opt.minopf.major_it = ov.(ff);
0843         case 'MNS_MINOR_IT'
0844             opt.minopf.minor_it = ov.(ff);
0845         case 'MNS_MAX_IT'
0846             opt.minopf.max_it = ov.(ff);
0847         case 'MNS_VERBOSITY'
0848             opt.minopf.verbosity = ov.(ff);
0849         case 'MNS_CORE'
0850             opt.minopf.core = ov.(ff);
0851         case 'MNS_SUPBASIC_LIM'
0852             opt.minopf.supbasic_lim = ov.(ff);
0853         case 'MNS_MULT_PRICE'
0854             opt.minopf.mult_price = ov.(ff);
0855         case 'FORCE_PC_EQ_P0'
0856             opt.sopf.force_Pc_eq_P0 = ov.(ff);
0857         case 'PDIPM_FEASTOL'
0858             opt.mips.feastol = ov.(ff);
0859             opt.pdipm.feastol = ov.(ff);
0860         case 'PDIPM_GRADTOL'
0861             opt.mips.gradtol = ov.(ff);
0862             opt.pdipm.gradtol = ov.(ff);
0863         case 'PDIPM_COMPTOL'
0864             opt.mips.comptol = ov.(ff);
0865             opt.pdipm.comptol = ov.(ff);
0866         case 'PDIPM_COSTTOL'
0867             opt.mips.costtol = ov.(ff);
0868             opt.pdipm.costtol = ov.(ff);
0869         case 'PDIPM_MAX_IT'
0870             opt.mips.max_it = ov.(ff);
0871             opt.pdipm.max_it = ov.(ff);
0872         case 'SCPDIPM_RED_IT'
0873             opt.mips.sc.red_it = ov.(ff);
0874             opt.pdipm.sc.red_it = ov.(ff);
0875         case 'TRALM_FEASTOL'
0876             opt.tralm.feastol = ov.(ff);
0877         case 'TRALM_PRIMETOL'
0878             opt.tralm.primaltol = ov.(ff);
0879         case 'TRALM_DUALTOL'
0880             opt.tralm.dualtol = ov.(ff);
0881         case 'TRALM_COSTTOL'
0882             opt.tralm.costtol = ov.(ff);
0883         case 'TRALM_MAJOR_IT'
0884             opt.tralm.major_it = ov.(ff);
0885         case 'TRALM_MINOR_IT'
0886             opt.tralm.minor_it = ov.(ff);
0887         case 'SMOOTHING_RATIO'
0888             opt.pdipm.sc.smooth_ratio = ov.(ff);
0889             opt.tralm.smooth_ratio = ov.(ff);
0890         case 'CPLEX_LPMETHOD'
0891             opt.cplex.lpmethod = ov.(ff);
0892         case 'CPLEX_QPMETHOD'
0893             opt.cplex.qpmethod = ov.(ff);
0894         case 'CPLEX_OPT'
0895             opt.cplex.opt = ov.(ff);
0896         case 'MOSEK_LP_ALG'
0897             opt.mosek.lp_alg = ov.(ff);
0898         case 'MOSEK_MAX_IT'
0899             opt.mosek.max_it = ov.(ff);
0900         case 'MOSEK_GAP_TOL'
0901             opt.mosek.gap_tol = ov.(ff);
0902         case 'MOSEK_MAX_TIME'
0903             opt.mosek.max_time = ov.(ff);
0904         case 'MOSEK_NUM_THREADS'
0905             opt.mosek.num_threads = ov.(ff);
0906         case 'MOSEK_OPT'
0907             opt.mosek.opt = ov.(ff);
0908         case 'GRB_METHOD'
0909             opt.gurobi.method = ov.(ff);
0910         case 'GRB_TIMELIMIT'
0911             opt.gurobi.timelimit = ov.(ff);
0912         case 'GRB_THREADS'
0913             opt.gurobi.threads = ov.(ff);
0914         case 'GRB_OPT'
0915             opt.gurobi.opt = ov.(ff);
0916         otherwise
0917             error('mpoption: ''%s'' is not a valid old-style option name', ff);
0918     end
0919 end
0920 % ov
0921 
0922 
0923 %%-------------------------------------------------------------------
0924 function opt_s = mpoption_v2s(opt_v)
0925 if DEBUG, fprintf('mpoption_v2s()\n'); end
0926 opt_s = mpoption_default();
0927 errstr = 'mpoption: %g is not a valid value for the old-style ''%s'' option';
0928 switch opt_v(1)                                 %% PF_ALG
0929     case 1
0930         opt_s.pf.alg = 'NR';        %% Newton's method
0931     case 2
0932         opt_s.pf.alg = 'FDXB';      %% fast-decoupled (XB version)
0933     case 3
0934         opt_s.pf.alg = 'FDBX';      %% fast-decoupled (BX version)
0935     case 4
0936         opt_s.pf.alg = 'GS';        %% Gauss-Seidel
0937     otherwise
0938         error(errstr, opt_v(1), 'PF_ALG');
0939 end
0940 opt_s.pf.tol                = opt_v(2);         %% PF_TOL
0941 opt_s.pf.nr.max_it          = opt_v(3);         %% PF_MAX_IT
0942 opt_s.pf.fd.max_it          = opt_v(4);         %% PF_MAX_IT_FD
0943 opt_s.pf.gs.max_it          = opt_v(5);         %% PF_MAX_IT_GS
0944 opt_s.pf.enforce_q_lims     = opt_v(6);         %% ENFORCE_Q_LIMS
0945 switch opt_v(10)                                %% PF_DC
0946     case 0
0947         opt_s.model = 'AC';
0948     case 1
0949         opt_s.model = 'DC';
0950     otherwise
0951         error(errstr, opt_v(10), 'PF_DC');
0952 end
0953 switch opt_v(11)                                %% OPF_ALG
0954     case 0
0955         opt_s.opf.ac.solver = 'DEFAULT';
0956     case 500
0957         opt_s.opf.ac.solver = 'MINOPF';
0958     case 520
0959         opt_s.opf.ac.solver = 'FMINCON';
0960     case {540, 545}
0961         opt_s.opf.ac.solver = 'PDIPM';
0962     case 550
0963         opt_s.opf.ac.solver = 'TRALM';
0964     case {560, 565}
0965         opt_s.opf.ac.solver = 'MIPS';
0966     case 580
0967         opt_s.opf.ac.solver = 'IPOPT';
0968     case 600
0969         opt_s.opf.ac.solver = 'KNITRO';
0970     otherwise
0971         error(errstr, opt_v(11), 'OPF_ALG');
0972 end
0973 opt_s.opf.violation         = opt_v(16);        %% OPF_VIOLATION
0974 
0975 opt_s.fmincon.tol_x         = opt_v(17);        %% CONSTR_TOL_X
0976 opt_s.fmincon.tol_f         = opt_v(18);        %% CONSTR_TOL_F
0977 opt_s.fmincon.max_it        = opt_v(19);        %% CONSTR_MAX_IT
0978 
0979 opt_s.knitro.tol_x          = opt_v(17);        %% CONSTR_TOL_X
0980 opt_s.knitro.tol_f          = opt_v(18);        %% CONSTR_TOL_F
0981 
0982 switch opt_v(24)                                %% OPF_FLOW_LIM
0983     case 0
0984         opt_s.opf.flow_lim = 'S';   %% apparent power (MVA)
0985     case 1
0986         opt_s.opf.flow_lim = 'P';   %% real power (MW)
0987     case 2
0988         opt_s.opf.flow_lim = 'I';   %% current magnitude (MVA @ 1 p.u. voltage)
0989     otherwise
0990         error(errstr, opt_v(10), 'PF_DC');
0991 end
0992 
0993 opt_s.opf.ignore_angle_lim  = opt_v(25);        %% OPF_IGNORE_ANG_LIM
0994 
0995 switch opt_v(26)                                %% OPF_ALG_DC
0996     case 0
0997         opt_s.opf.dc.solver = 'DEFAULT';
0998     case 100
0999         opt_s.opf.dc.solver = 'BPMPD';
1000     case {200, 250}
1001         opt_s.opf.dc.solver = 'MIPS';
1002     case 300
1003         opt_s.opf.dc.solver = 'OT';     %% QUADPROG, LINPROG
1004     case 400
1005         opt_s.opf.dc.solver = 'IPOPT';
1006     case 500
1007         opt_s.opf.dc.solver = 'CPLEX';
1008     case 600
1009         opt_s.opf.dc.solver = 'MOSEK';
1010     case 700
1011         opt_s.opf.dc.solver = 'GUROBI';
1012     otherwise
1013         error(errstr, opt_v(26), 'OPF_ALG_DC');
1014 end
1015 
1016 opt_s.verbose               = opt_v(31);        %% VERBOSE
1017 opt_s.out.all               = opt_v(32);        %% OUT_ALL
1018 opt_s.out.sys_sum           = opt_v(33);        %% OUT_SYS_SUM
1019 opt_s.out.area_sum          = opt_v(34);        %% OUT_AREA_SUM
1020 opt_s.out.bus               = opt_v(35);        %% OUT_BUS
1021 opt_s.out.branch            = opt_v(36);        %% OUT_BRANCH
1022 opt_s.out.gen               = opt_v(37);        %% OUT_GEN
1023 opt_s.out.lim.all           = opt_v(38);        %% OUT_ALL_LIM
1024 opt_s.out.lim.v             = opt_v(39);        %% OUT_V_LIM
1025 opt_s.out.lim.line          = opt_v(40);        %% OUT_LINE_LIM
1026 opt_s.out.lim.pg            = opt_v(41);        %% OUT_PG_LIM
1027 opt_s.out.lim.qg            = opt_v(42);        %% OUT_QG_LIM
1028 opt_s.out.force             = opt_v(44);        %% OUT_FORCE
1029 
1030 opt_s.opf.return_raw_der    = opt_v(52);        %% RETURN_RAW_DER
1031 
1032 opt_s.fmincon.alg           = opt_v(55);        %% FMC_ALG
1033 opt_s.knitro.opt            = opt_v(58);        %% KNITRO_OPT
1034 opt_s.ipopt.opt             = opt_v(60);        %% IPOPT_OPT
1035 
1036 opt_s.minopf.feastol        = opt_v(61);        %% MNS_FEASTOL
1037 opt_s.minopf.rowtol         = opt_v(62);        %% MNS_ROWTOL
1038 opt_s.minopf.xtol           = opt_v(63);        %% MNS_XTOL
1039 opt_s.minopf.majdamp        = opt_v(64);        %% MNS_MAJDAMP
1040 opt_s.minopf.mindamp        = opt_v(65);        %% MNS_MINDAMP
1041 opt_s.minopf.penalty        = opt_v(66);        %% MNS_PENALTY_PARM
1042 opt_s.minopf.major_it       = opt_v(67);        %% MNS_MAJOR_IT
1043 opt_s.minopf.minor_it       = opt_v(68);        %% MNS_MINOR_IT
1044 opt_s.minopf.max_it         = opt_v(69);        %% MNS_MAX_IT
1045 opt_s.minopf.verbosity      = opt_v(70);        %% MNS_VERBOSITY
1046 opt_s.minopf.core           = opt_v(71);        %% MNS_CORE
1047 opt_s.minopf.supbasic_lim   = opt_v(72);        %% MNS_SUPBASIC_LIM
1048 opt_s.minopf.mult_price     = opt_v(73);        %% MNS_MULT_PRICE
1049 
1050 opt_s.sopf.force_Pc_eq_P0   = opt_v(80);        %% FORCE_PC_EQ_P0, for c3sopf
1051 
1052 if (opt_v(11) == 565 && opt_v(10) == 0) || (opt_v(26) == 250 && opt_v(10) == 1)
1053     opt_s.mips.step_control = 1;
1054 end
1055 opt_s.mips.feastol          = opt_v(81);        %% PDIPM_FEASTOL
1056 opt_s.mips.gradtol          = opt_v(82);        %% PDIPM_GRADTOL
1057 opt_s.mips.comptol          = opt_v(83);        %% PDIPM_COMPTOL
1058 opt_s.mips.costtol          = opt_v(84);        %% PDIPM_COSTTOL
1059 opt_s.mips.max_it           = opt_v(85);        %% PDIPM_MAX_IT
1060 opt_s.mips.sc.red_it        = opt_v(86);        %% SCPDIPM_RED_IT
1061 
1062 opt_s.pdipm.feastol         = opt_v(81);        %% PDIPM_FEASTOL
1063 opt_s.pdipm.gradtol         = opt_v(82);        %% PDIPM_GRADTOL
1064 opt_s.pdipm.comptol         = opt_v(83);        %% PDIPM_COMPTOL
1065 opt_s.pdipm.costtol         = opt_v(84);        %% PDIPM_COSTTOL
1066 opt_s.pdipm.max_it          = opt_v(85);        %% PDIPM_MAX_IT
1067 opt_s.pdipm.sc.red_it       = opt_v(86);        %% SCPDIPM_RED_IT
1068 opt_s.pdipm.sc.smooth_ratio = opt_v(93);        %% SMOOTHING_RATIO
1069 if opt_v(11) == 545 && opt_v(10) == 0
1070     opt_s.pdipm.step_control = 1;
1071 end
1072 
1073 opt_s.tralm.feastol         = opt_v(87);        %% TRALM_FEASTOL
1074 opt_s.tralm.primaltol       = opt_v(88);        %% TRALM_PRIMETOL
1075 opt_s.tralm.dualtol         = opt_v(89);        %% TRALM_DUALTOL
1076 opt_s.tralm.costtol         = opt_v(90);        %% TRALM_COSTTOL
1077 opt_s.tralm.major_it        = opt_v(91);        %% TRALM_MAJOR_IT
1078 opt_s.tralm.minor_it        = opt_v(92);        %% TRALM_MINOR_IT
1079 opt_s.tralm.smooth_ratio    = opt_v(93);        %% SMOOTHING_RATIO
1080 
1081 opt_s.cplex.lpmethod        = opt_v(95);        %% CPLEX_LPMETHOD
1082 opt_s.cplex.qpmethod        = opt_v(96);        %% CPLEX_QPMETHOD
1083 opt_s.cplex.opt             = opt_v(97);        %% CPLEX_OPT
1084 
1085 opt_s.mosek.lp_alg          = opt_v(111);       %% MOSEK_LP_ALG
1086 opt_s.mosek.max_it          = opt_v(112);       %% MOSEK_MAX_IT
1087 opt_s.mosek.gap_tol         = opt_v(113);       %% MOSEK_GAP_TOL
1088 opt_s.mosek.max_time        = opt_v(114);       %% MOSEK_MAX_TIME
1089 opt_s.mosek.num_threads     = opt_v(115);       %% MOSEK_NUM_THREADS
1090 opt_s.mosek.opt             = opt_v(116);       %% MOSEK_OPT
1091 
1092 opt_s.gurobi.method         = opt_v(121);       %% GRB_METHOD
1093 opt_s.gurobi.timelimit      = opt_v(122);       %% GRB_TIMELIMIT
1094 opt_s.gurobi.threads        = opt_v(123);       %% GRB_THREADS
1095 opt_s.gurobi.opt            = opt_v(124);       %% GRB_OPT
1096 
1097 
1098 %%-------------------------------------------------------------------
1099 function opt_v = mpoption_s2v(opt_s)
1100 if DEBUG, fprintf('mpoption_s2v()\n'); end
1101 %% PF_ALG
1102 old = mpoption_old;
1103 switch upper(opt_s.pf.alg)
1104     case 'NR'
1105         PF_ALG = 1;
1106     case 'FDXB'
1107         PF_ALG = 2;
1108     case 'FDBX'
1109         PF_ALG = 3;
1110     case 'GS'
1111         PF_ALG = 4;
1112 end
1113 
1114 %% PF_DC
1115 if strcmp(upper(opt_s.model), 'DC')
1116     PF_DC = 1;
1117 else
1118     PF_DC = 0;
1119 end
1120 
1121 %% OPF_ALG
1122 switch upper(opt_s.opf.ac.solver)
1123     case 'DEFAULT'
1124         OPF_ALG = 0;
1125     case 'MINOPF'
1126         OPF_ALG = 500;
1127     case 'FMINCON'
1128         OPF_ALG = 520;
1129     case 'PDIPM'
1130         if isfield(opt_s, 'pdipm') && opt_s.pdipm.step_control
1131             OPF_ALG = 545;
1132         else
1133             OPF_ALG = 540;
1134         end
1135     case 'TRALM'
1136         OPF_ALG = 550;
1137     case 'MIPS'
1138         if opt_s.mips.step_control
1139             OPF_ALG = 565;
1140         else
1141             OPF_ALG = 560;
1142         end
1143     case 'IPOPT'
1144         OPF_ALG = 580;
1145     case 'KNITRO'
1146         OPF_ALG = 600;
1147 end
1148 
1149 %% FMINCON, Knitro tol_x, tol_f, max_it
1150 if strcmp(upper(opt_s.opf.ac.solver), 'KNITRO') && isfield(opt_s, 'knitro')
1151     CONSTR_TOL_X = opt_s.knitro.tol_x;
1152     CONSTR_TOL_F = opt_s.knitro.tol_f;
1153 elseif isfield(opt_s, 'fmincon')
1154     CONSTR_TOL_X  = opt_s.fmincon.tol_x;
1155     CONSTR_TOL_F  = opt_s.fmincon.tol_f;
1156 else
1157     CONSTR_TOL_X = old(17);
1158     CONSTR_TOL_F = old(18);
1159 end
1160 if isfield(opt_s, 'fmincon')
1161     CONSTR_MAX_IT   = opt_s.fmincon.max_it;
1162     FMC_ALG         = opt_s.fmincon.alg;
1163 else
1164     CONSTR_MAX_IT   = old(19);
1165     FMC_ALG         = old(55);
1166 end
1167 
1168 %% OPF_FLOW_LIM
1169 switch upper(opt_s.opf.flow_lim)
1170     case 'S'
1171         OPF_FLOW_LIM = 0;
1172     case 'P'
1173         OPF_FLOW_LIM = 1;
1174     case 'I'
1175         OPF_FLOW_LIM = 2;
1176 end
1177 
1178 %% OPF_ALG_DC
1179 switch upper(opt_s.opf.dc.solver)
1180     case 'DEFAULT'
1181         OPF_ALG_DC = 0;
1182     case 'BPMPD'
1183         OPF_ALG_DC = 100;
1184     case 'MIPS'
1185         if opt_s.mips.step_control
1186             OPF_ALG_DC = 250;
1187         else
1188             OPF_ALG_DC = 200;
1189         end
1190     case 'OT'
1191         OPF_ALG_DC = 300;
1192     case 'IPOPT'
1193         OPF_ALG_DC = 400;
1194     case 'CPLEX'
1195         OPF_ALG_DC = 500;
1196     case 'MOSEK'
1197         OPF_ALG_DC = 600;
1198     case 'GUROBI'
1199         OPF_ALG_DC = 700;
1200 end
1201 
1202 %% KNITRO_OPT
1203 if isfield(opt_s, 'knitro')
1204     KNITRO_OPT  = opt_s.knitro.opt;
1205 else
1206     KNITRO_OPT  = old(58);
1207 end
1208 
1209 %% IPOPT_OPT
1210 if isfield(opt_s, 'ipopt')
1211     IPOPT_OPT  = opt_s.ipopt.opt;
1212 else
1213     IPOPT_OPT  = old(58);
1214 end
1215 
1216 %% MINOPF options
1217 if isfield(opt_s, 'minopf')
1218     MINOPF_OPTS = [
1219         opt_s.minopf.feastol;   %% 61 - MNS_FEASTOL
1220         opt_s.minopf.rowtol;    %% 62 - MNS_ROWTOL
1221         opt_s.minopf.xtol;      %% 63 - MNS_XTOL
1222         opt_s.minopf.majdamp;   %% 64 - MNS_MAJDAMP
1223         opt_s.minopf.mindamp;   %% 65 - MNS_MINDAMP
1224         opt_s.minopf.penalty;   %% 66 - MNS_PENALTY_PARM
1225         opt_s.minopf.major_it;  %% 67 - MNS_MAJOR_IT
1226         opt_s.minopf.minor_it;  %% 68 - MNS_MINOR_IT
1227         opt_s.minopf.max_it;    %% 69 - MNS_MAX_IT
1228         opt_s.minopf.verbosity; %% 70 - MNS_VERBOSITY
1229         opt_s.minopf.core;      %% 71 - MNS_CORE
1230         opt_s.minopf.supbasic_lim;  %% 72 - MNS_SUPBASIC_LIM
1231         opt_s.minopf.mult_price;%% 73 - MNS_MULT_PRICE
1232     ];
1233 else
1234     MINOPF_OPTS = old(61:73);
1235 end
1236 
1237 %% FORCE_PC_EQ_P0
1238 if isfield(opt_s, 'sopf') && isfield(opt_s.sopf, 'force_Pc_eq_P0')
1239     FORCE_PC_EQ_P0 = opt_s.sopf.force_Pc_eq_P0;
1240 else
1241     FORCE_PC_EQ_P0 = 0;
1242 end
1243 
1244 %% PDIPM options
1245 if isfield(opt_s, 'pdipm')
1246     PDIPM_OPTS = [
1247         opt_s.pdipm.feastol;    %% 81 - PDIPM_FEASTOL
1248         opt_s.pdipm.gradtol;    %% 82 - PDIPM_GRADTOL
1249         opt_s.pdipm.comptol;    %% 83 - PDIPM_COMPTOL
1250         opt_s.pdipm.costtol;    %% 84 - PDIPM_COSTTOL
1251         opt_s.pdipm.max_it;     %% 85 - PDIPM_MAX_IT
1252         opt_s.pdipm.sc.red_it;  %% 86 - SCPDIPM_RED_IT
1253     ];
1254 else
1255     PDIPM_OPTS = old(81:86);
1256 end
1257 
1258 %% TRALM options
1259 if isfield(opt_s, 'tralm')
1260     TRALM_OPTS = [
1261         opt_s.tralm.feastol;    %% 87 - TRALM_FEASTOL
1262         opt_s.tralm.primaltol;  %% 88 - TRALM_PRIMETOL
1263         opt_s.tralm.dualtol;    %% 89 - TRALM_DUALTOL
1264         opt_s.tralm.costtol;    %% 90 - TRALM_COSTTOL
1265         opt_s.tralm.major_it;   %% 91 - TRALM_MAJOR_IT
1266         opt_s.tralm.minor_it;   %% 92 - TRALM_MINOR_IT
1267     ];
1268 else
1269     TRALM_OPTS = old(87:92);
1270 end
1271 
1272 %% SMOOTHING_RATIO
1273 if strcmp(upper(opt_s.opf.ac.solver), 'TRALM') && isfield(opt_s, 'tralm')
1274     SMOOTHING_RATIO = opt_s.tralm.smooth_ratio;
1275 elseif isfield(opt_s, 'pdipm')
1276     SMOOTHING_RATIO = opt_s.pdipm.sc.smooth_ratio;
1277 else
1278     SMOOTHING_RATIO = old(93);
1279 end
1280 
1281 %% CPLEX options
1282 if isfield(opt_s, 'cplex')
1283     CPLEX_OPTS = [
1284         opt_s.cplex.lpmethod;   %% 95 - CPLEX_LPMETHOD
1285         opt_s.cplex.qpmethod;   %% 96 - CPLEX_QPMETHOD
1286         opt_s.cplex.opt;        %% 97 - CPLEX_OPT
1287     ];
1288 else
1289     CPLEX_OPTS = old(95:97);
1290 end
1291 
1292 %% MOSEK options
1293 if isfield(opt_s, 'mosek')
1294     MOSEK_OPTS = [
1295         opt_s.mosek.lp_alg;     %% 111 - MOSEK_LP_ALG
1296         opt_s.mosek.max_it;     %% 112 - MOSEK_MAX_IT
1297         opt_s.mosek.gap_tol;    %% 113 - MOSEK_GAP_TOL
1298         opt_s.mosek.max_time;   %% 114 - MOSEK_MAX_TIME
1299         opt_s.mosek.num_threads;%% 115 - MOSEK_NUM_THREADS
1300         opt_s.mosek.opt;        %% 116 - MOSEK_OPT
1301     ];
1302 else
1303     MOSEK_OPTS = old(111:116);
1304 end
1305 
1306 %% Gurobi options
1307 if isfield(opt_s, 'gurobi')
1308     GUROBI_OPTS = [
1309         opt_s.gurobi.method;    %% 121 - GRB_METHOD
1310         opt_s.gurobi.timelimit; %% 122 - GRB_TIMELIMIT
1311         opt_s.gurobi.threads;   %% 123 - GRB_THREADS
1312         opt_s.gurobi.opt;       %% 124 - GRB_OPT
1313     ];
1314 else
1315     GUROBI_OPTS = old(121:124);
1316 end
1317 
1318 opt_v = [
1319         %% power flow options
1320         PF_ALG;                 %% 1  - PF_ALG
1321         opt_s.pf.tol;           %% 2  - PF_TOL
1322         opt_s.pf.nr.max_it;     %% 3  - PF_MAX_IT
1323         opt_s.pf.fd.max_it;     %% 4  - PF_MAX_IT_FD
1324         opt_s.pf.gs.max_it;     %% 5  - PF_MAX_IT_GS
1325         opt_s.pf.enforce_q_lims;%% 6  - ENFORCE_Q_LIMS
1326         0;                      %% 7  - RESERVED7
1327         0;                      %% 8  - RESERVED8
1328         0;                      %% 9  - RESERVED9
1329         PF_DC;                  %% 10 - PF_DC
1330         
1331         %% OPF options
1332         OPF_ALG;                %% 11 - OPF_ALG
1333         0;                      %% 12 - RESERVED12 (was OPF_ALG_POLY = 100)
1334         0;                      %% 13 - RESERVED13 (was OPF_ALG_PWL = 200)
1335         0;                      %% 14 - RESERVED14 (was OPF_POLY2PWL_PTS = 10)
1336         0;                      %% 15 - OPF_NEQ (removed)
1337         opt_s.opf.violation;    %% 16 - OPF_VIOLATION
1338         CONSTR_TOL_X;           %% 17 - CONSTR_TOL_X
1339         CONSTR_TOL_F;           %% 18 - CONSTR_TOL_F
1340         CONSTR_MAX_IT;          %% 19 - CONSTR_MAX_IT
1341         old(20);                %% 20 - LPC_TOL_GRAD (removed)
1342         old(21);                %% 21 - LPC_TOL_X (removed)
1343         old(22);                %% 22 - LPC_MAX_IT (removed)
1344         old(23);                %% 23 - LPC_MAX_RESTART (removed)
1345         OPF_FLOW_LIM;           %% 24 - OPF_FLOW_LIM
1346         opt_s.opf.ignore_angle_lim; %% 25 - OPF_IGNORE_ANG_LIM
1347         OPF_ALG_DC;             %% 26 - OPF_ALG_DC
1348         0;                      %% 27 - RESERVED27
1349         0;                      %% 28 - RESERVED28
1350         0;                      %% 29 - RESERVED29
1351         0;                      %% 30 - RESERVED30
1352         
1353         %% output options
1354         opt_s.verbose;          %% 31 - VERBOSE
1355         opt_s.out.all;          %% 32 - OUT_ALL
1356         opt_s.out.sys_sum;      %% 33 - OUT_SYS_SUM
1357         opt_s.out.area_sum;     %% 34 - OUT_AREA_SUM
1358         opt_s.out.bus;          %% 35 - OUT_BUS
1359         opt_s.out.branch;       %% 36 - OUT_BRANCH
1360         opt_s.out.gen;          %% 37 - OUT_GEN
1361         opt_s.out.lim.all;      %% 38 - OUT_ALL_LIM
1362         opt_s.out.lim.v;        %% 39 - OUT_V_LIM
1363         opt_s.out.lim.line;     %% 40 - OUT_LINE_LIM
1364         opt_s.out.lim.pg;       %% 41 - OUT_PG_LIM
1365         opt_s.out.lim.qg;       %% 42 - OUT_QG_LIM
1366         0;                      %% 43 - RESERVED43 (was OUT_RAW)
1367         opt_s.out.force;        %% 44 - OUT_FORCE
1368         0;                      %% 45 - RESERVED45
1369         0;                      %% 46 - RESERVED46
1370         0;                      %% 47 - RESERVED47
1371         0;                      %% 48 - RESERVED48
1372         0;                      %% 49 - RESERVED49
1373         0;                      %% 50 - RESERVED50
1374         
1375         %% other options
1376         old(51);                %% 51 - SPARSE_QP (removed)
1377         opt_s.opf.return_raw_der;   %% 52 - RETURN_RAW_DER
1378         0;                      %% 53 - RESERVED53
1379         0;                      %% 54 - RESERVED54
1380         FMC_ALG;                %% 55 - FMC_ALG
1381         0;                      %% 56 - RESERVED56
1382         0;                      %% 57 - RESERVED57
1383         KNITRO_OPT;             %% 58 - KNITRO_OPT
1384         0;                      %% 59 - RESERVED59
1385         IPOPT_OPT;              %% 60 - IPOPT_OPT
1386         
1387         %% MINOPF options
1388         MINOPF_OPTS;            %% 61-73 - MNS_FEASTOL-MNS_MULT_PRICE
1389         0;                      %% 74 - RESERVED74
1390         0;                      %% 75 - RESERVED75
1391         0;                      %% 76 - RESERVED76
1392         0;                      %% 77 - RESERVED77
1393         0;                      %% 78 - RESERVED78
1394         0;                      %% 79 - RESERVED79
1395         FORCE_PC_EQ_P0;         %% 80 - FORCE_PC_EQ_P0, for c3sopf
1396         
1397         %% MIPS, PDIPM, SC-PDIPM, and TRALM options
1398         PDIPM_OPTS;             %% 81-86 - PDIPM_FEASTOL-SCPDIPM_RED_IT
1399         TRALM_OPTS;             %% 87-92 - TRALM_FEASTOL-TRALM_MINOR_IT
1400         SMOOTHING_RATIO;        %% 93 - SMOOTHING_RATIO
1401         0;                      %% 94 - RESERVED94
1402         
1403         %% CPLEX options
1404         CPLEX_OPTS;             %% 95-97 - CPLEX_LPMETHOD-CPLEX_OPT
1405         0;                      %% 98 - RESERVED98
1406         0;                      %% 99 - RESERVED99
1407         0;                      %% 100 - RESERVED100
1408         0;                      %% 101 - RESERVED101
1409         0;                      %% 102 - RESERVED102
1410         0;                      %% 103 - RESERVED103
1411         0;                      %% 104 - RESERVED104
1412         0;                      %% 105 - RESERVED105
1413         0;                      %% 106 - RESERVED106
1414         0;                      %% 107 - RESERVED107
1415         0;                      %% 108 - RESERVED108
1416         0;                      %% 109 - RESERVED109
1417         0;                      %% 110 - RESERVED110
1418 
1419         %% MOSEK options
1420         MOSEK_OPTS;             %% 111-116 - MOSEK_LP_ALG-MOSEK_OPT
1421         0;                      %% 117 - RESERVED117
1422         0;                      %% 118 - RESERVED118
1423         0;                      %% 119 - RESERVED119
1424         0;                      %% 120 - RESERVED120
1425 
1426         %% Gurobi options
1427         GUROBI_OPTS;            %% 121-124 - GRB_METHOD-GRB_OPT
1428     ];
1429 
1430 
1431 %%-------------------------------------------------------------------
1432 function optt = mpoption_default()
1433 if DEBUG, fprintf('mpoption_default()\n'); end
1434 persistent opt;             %% cache this for speed
1435 if ~isstruct(opt)
1436     opt = struct(...
1437         'v',                    mpoption_version, ...   %% version
1438         'model',                'AC', ...
1439         'pf',                   struct(...
1440             'alg',                  'NR', ...
1441             'tol',                  1e-8, ...
1442             'nr',                   struct(...
1443                 'max_it',               10  ), ...
1444             'fd',                   struct(...
1445                 'max_it',               30  ), ...
1446             'gs',                   struct(...
1447                 'max_it',               1000  ), ...
1448             'enforce_q_lims',       0   ), ...
1449         'cpf',                  struct(...
1450             'parameterization',     3, ...
1451             'stop_at',              'NOSE', ...     %% 'NOSE', <lam val>, 'FULL'
1452             'enforce_p_lims',       0, ...
1453             'enforce_q_lims',       0, ...
1454             'step',                 0.05, ...
1455             'step_min',             1e-4, ...
1456             'step_max',             0.2, ...
1457             'adapt_step',           0, ...
1458             'adapt_step_damping',   0.7, ...
1459             'adapt_step_tol',       1e-3, ...
1460             'target_lam_tol',       1e-5, ...
1461             'nose_tol',             1e-5, ...
1462             'p_lims_tol',           0.01, ...
1463             'q_lims_tol',           0.01, ...
1464             'plot',                 struct(...
1465                 'level',                0, ...
1466                 'bus',                  []  ), ...
1467             'user_callback',        ''  ), ...
1468         'opf',                  struct(...
1469             'ac',                   struct(...
1470                 'solver',               'DEFAULT'   ), ...
1471             'dc',                   struct(...
1472                 'solver',               'DEFAULT'   ), ...
1473             'violation',            5e-6, ...
1474             'use_vg',               0, ...
1475             'flow_lim',             'S', ...
1476             'ignore_angle_lim',     0, ...
1477             'init_from_mpc',        -1, ...
1478             'return_raw_der',       0   ), ...
1479         'verbose',              1, ...
1480         'out',                  struct(...
1481             'all',                  -1, ...
1482             'sys_sum',              1, ...
1483             'area_sum',             0, ...
1484             'bus',                  1, ...
1485             'branch',               1, ...
1486             'gen',                  0, ...
1487             'lim',                  struct(...
1488                 'all',                  -1, ...
1489                 'v',                    1, ...
1490                 'line',                 1, ...
1491                 'pg',                   1, ...
1492                 'qg',                   1   ), ...
1493             'force',                0, ...
1494             'suppress_detail',      -1  ), ...
1495         'mips',                 struct(...  %% see mpoption_info_mips() for optional fields
1496             'step_control',         0, ...
1497             'linsolver',            '', ...
1498             'feastol',              0, ...
1499             'gradtol',              1e-6, ...
1500             'comptol',              1e-6, ...
1501             'costtol',              1e-6, ...
1502             'max_it',               150, ...
1503             'sc',                   struct(...
1504                 'red_it',               20  )), ...
1505         'exp',                  struct(... %% experimental options
1506             'sys_wide_zip_loads',   struct(...
1507                 'pw',                   [], ...
1508                 'qw',                   []  )) ...
1509     );
1510     opt_pkgs = mpoption_optional_pkgs();
1511     for k = 1:length(opt_pkgs)
1512         fname = ['mpoption_info_' opt_pkgs{k}];
1513         if exist(fname, 'file') == 2
1514             opt = nested_struct_copy(opt, feval(fname, 'D'));
1515         end
1516     end
1517 end
1518 optt = opt;
1519 
1520 %%-------------------------------------------------------------------
1521 function optt = mpoption_optional_fields()
1522 if DEBUG, fprintf('mpoption_optional_fields()\n'); end
1523 persistent opt;         %% cache this for speed
1524 if ~isstruct(opt)
1525     opt_pkgs = mpoption_optional_pkgs();
1526     opt = struct;
1527     for k = 1:length(opt_pkgs)
1528         fname = ['mpoption_info_' opt_pkgs{k}];
1529         if exist(fname, 'file') == 2
1530             opt = nested_struct_copy(opt, feval(fname, 'V'));
1531         end
1532     end
1533 end
1534 optt = opt;
1535 
1536 %% globals
1537 %%-------------------------------------------------------------------
1538 function v = mpoption_version
1539 v = 12;     %% version number of MATPOWER options struct
1540             %% (must be incremented every time structure is updated)
1541             %% v1   - first version based on struct (MATPOWER 5.0b1)
1542             %% v2   - added 'linprog' and 'quadprog' fields
1543             %% v3   - (forgot to increment v) added 'out.suppress_detail'
1544             %%        field
1545             %% v4   - (forgot to increment v) MIPS 1.1, added optional
1546             %%        fields to 'mips' options: xi, sigma, z0, alpha_min,
1547             %%        rho_min, rho_max, mu_threshold and max_stepsize
1548             %% v5   - (forgot to increment v) added 'opf.init_from_mpc'
1549             %%        field (MATPOWER 5.0)
1550             %% v6   - added 'clp' field
1551             %% v7   - added 'intlinprog' field
1552             %% v8   - MIPS 1.2, added 'linsolver' field to
1553             %%        'mips' options
1554             %% v9   - added 'exp' for experimental fields, specifically
1555             %%        'sys_wide_zip_loads.pw', 'sys_wide_zip_loads.qw'
1556             %% v10  - added 'most' field
1557             %% v11  - added 'cpf' options 'adapt_step_damping',
1558             %%        'enforce_p_lims', 'enforce_q_lims', 'target_lam_tol'
1559             %%        'nose_tol', 'p_lims_tol' and 'q_lims_tol',
1560             %%        removed option 'cpf.user_callback_args'
1561             %% v12  - added option 'opf.use_vg'
1562 
1563 %%-------------------------------------------------------------------
1564 function db_level = DEBUG
1565 db_level = 0;
1566 
1567 %%-------------------------------------------------------------------
1568 function pkgs = mpoption_optional_pkgs()
1569 pkgs = {...
1570     'clp', 'cplex', 'fmincon', 'gurobi', 'glpk', 'intlinprog', 'ipopt', ...
1571     'knitro', 'linprog', 'minopf', 'most', 'mosek', 'quadprog', 'sdp_pf', ...
1572     'sopf', 'tspopf', 'yalmip' ...
1573 };

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