9.4 Conversion between External and Internal Numbering

9.4.1 ext2int, int2ext

  mpc_int = ext2int(mpc_ext)
  mpc_int = ext2int(mpc_ext, mpopt)
  mpc_ext = int2ext(mpc_int)
  mpc_ext = int2ext(mpc_int, mpopt)

These functions convert a Matpower case struct from external to internal, and from internal to external numbering, respectively. ext2int first removes all isolated buses, off-line generators and branches, and any generators or branches connected to isolated buses. Then the buses are renumbered consecutively, beginning at 1.56 Any 'ext2int' callback routines registered in the case are also invoked automatically. All of the related indexing information and the original data matrices are stored in an 'order' field in the struct to be used later by int2ext to perform the reverse conversions. If the case is already using internal numbering it is returned unchanged. The optional Matpower options struct (mpopt) input argument is only needed in conjunction with callback routines that depend on it, e.g. when toggle_softlims is on.

9.4.2 e2i_data, i2e_data

  val = e2i_data(mpc, val, ordering)
  val = e2i_data(mpc, val, ordering, dim)
  val = i2e_data(mpc, val, oldval, ordering)
  val = i2e_data(mpc, val, oldval, ordering, dim)

These functions can be used to convert other data structures from external to internal indexing and vice versa. When given a case struct (mpc) that has already been converted to internal indexing, e2i_data can be used to convert other data structures as well by passing in 2 or 3 extra parameters in addition to the case struct. If the value passed in the second argument (val) is a column vector or cell array, it will be converted according to the ordering specified by the third argument (described below). If val is an n  -dimensional matrix or cell array, then the optional fourth argument (dim, default = 1) can be used to specify which dimension to reorder. The return value in this case is the value passed in, converted to internal indexing.

The third argument, ordering, is used to indicate whether the data corresponds to bus-, gen- or branch-ordered data. It can be one of the following three strings: 'bus', 'gen' or 'branch'. For data structures with multiple blocks of data, ordered by bus, gen or branch, they can be converted with a single call by specifying ordering as a cell array of strings.

Any extra elements, rows, columns, etc. beyond those indicated in ordering, are not disturbed.

The function i2e_data performs the opposite conversion, from internal back to external indexing. It also assumes that mpc is using internal indexing, and the only difference is that it also includes an oldval argument used to initialize the return value before converting val to external indexing. In particular, any data corresponding to off-line gens or branches or isolated buses or any connected gens or branches will be taken from oldval, with val supplying the rest of the returned data.

9.4.3 e2i_field, i2e_field

  mpc = e2i_field(mpc, field, ordering)
  mpc = e2i_field(mpc, field, ordering, dim)
  mpc = i2e_field(mpc, field, ordering)
  mpc = i2e_field(mpc, field, ordering, dim)

These functions can be used to convert additional fields in mpc from external to internal indexing and vice versa. When given a case struct that has already been converted to internal indexing, e2i_field can be used to convert other fields as well by passing in 2 or 3 extra parameters in addition to the case struct.

The second argument (field) is a string or cell array of strings, specifying a field in the case struct whose value should be converted by a corresponding call to e2i_data. The field can contain either a numeric or a cell array. The converted value is stored back in the specified field, the original value is saved for later use and the updated case struct is returned. If field is a cell array of strings, they specify nested fields.

The third and optional fourth arguments (ordering and dim) are simply passed along to the call to e2i_data.

Similarly, i2e_field performs the opposite conversion, from internal back to external indexing. It also assumes that mpc is using internal indexing and utilizes the original data stored by e2i_field, calling i2e_data to do the conversion work.