9.6 Miscellaneous

9.6.1 define_constants

  define_constants

The define_constants script is a convenience script that defines a set of useful constants, mostly to be used as named column indices into the bus, branch, gen and gencost data matrices. The purpose is to avoid having to remember column numbers and to allow code to be more robust against potential future changes to the Matpower case data format. It also defines constants for the change tables used by apply_changes.

Specifically, it includes all of the constants defined by idx_bus, idx_brch, idx_gen, idx_cost and idx_ct.

9.6.2 feval_w_path

  [y1, ..., yn] = feval_w_path(fpath, f, x1, ..., xn)

The feval_w_path function is identical to Matlab’s own feval, except that the function f need not be in the Matlab path if it is defined in a file in the path specified by fpath. Assumes that the current working directory is always first in the Matlab path.

9.6.3 have_fcn

  TorF = have_fcn(tag)
  TorF = have_fcn(tag, toggle)
  ver_str = have_fcn(tag, 'vstr')
  ver_num = have_fcn(tag, 'vnum')
  rdate   = have_fcn(tag, 'date')
  info    = have_fcn(tag, 'all')

The have_fcn function provides a unified mechanism for testing for optional functionality, such as the presence of certain solvers, or to detect whether the code is running under Matlab or Octave. Since its results are cached they allow for a very quick way to check frequently for functionality that may initially be a bit more costly to determine. For installed functionality, have_fcn also determines the installed version and release date, if possible. The optional second argument, when it is a string, defines which value is returned, as follows:

Alternatively, the optional functionality specified by tag can be toggled OFF or ON by calling have_fcn with a numeric second argument toggle with one of the following values:

9.6.4 mpopt2qpopt

  qpopt = mpopt2qpopt(mpopt)
  qpopt = mpopt2qpopt(mpopt, model)
  qpopt = mpopt2qpopt(mpopt, model, alg)

The mpopt2qpopt function returns an options struct suitable for qps_matpower, miqps_matpower or one of the solver specific equivalents. It is constructed from the relevant portions of mpopt, a Matpower options struct. The model argument specifies whether the problem to be solved is an LP, QP, MILP or MIQP problem to allow for the selection of a suitable default solver. The final alg argument allows the solver to be set explicitly (in qpopt.alg). By default this value is taken from mpopt.opf.dc.solver.

When the solver is set to 'DEFAULT', this function also selects the best available solver that is applicable57 to the specific problem class, based on the following precedence: Gurobi, CPLEX, MOSEK, Optimization Toolbox, GLPK, BPMPD, MIPS.

9.6.5 mpver

  mpver
  v = mpver
  v = mpver('all')

The mpver function returns the current Matpower version number. With the optional 'all' argument, it returns a struct with the fields 'Name', 'Version', 'Release' and 'Date' (all strings). Calling mpver without assigning the return value prints the version and release date of the current installation of Matpower, Matlab (or Octave), the Optimization Toolbox, MIPS and any optional Matpower packages.

9.6.6 nested_struct_copy

  ds = nested_struct_copy(d, s)
  ds = nested_struct_copy(d, s, opt)

The nested_struct_copy function copies values from a source struct s to a destination struct d in a nested, recursive manner. That is, the value of each field in s is copied directly to the corresponding field in d, unless that value is itself a struct, in which case the copy is done via a recursive call to nested_struct_copy. Certain aspects of the copy behavior can be controled via the optional options struct opt, including the possible checking of valid field names.