Skip to contents

This function implements a two-step, population-based, hybrid optimization algorithm, for solving problems of the form:

\[ \begin{array}{c} \max_{x, \tilde{x}} f(x, \tilde{x}) ~~s.t.~~ g(x, \tilde{x}) \geq 0, ~ \tilde{g}(\tilde{x}) \geq 0,\ x \in X,~ \tilde{x} \in \tilde{X} \end{array} \]

See the readme and vignettes for more details on this format of problems, and when a phy algorithm would be useful.

Usage

optimize_phy(
  f = function(x, xtil) NA,
  g = function(x, xtil) 0,
  gtil = function(xtil) 0,
  x_dom,
  xtil_dom,
  initializer,
  optimizer,
  updater,
  stopper = flow_stopper(),
  logger = flow_logger(),
  check_samples = NULL,
  check_op = c(1, 2)
)

Arguments

f

Objective function \(f(x, \tilde{x})\).

g, gtil

Constraint functions \(g(x, \tilde{x})\) and \(\tilde{g}(\tilde{x})\). By default, never-binding ones.

x_dom, xtil_dom

Domains \(X\) and \(\tilde{X}\). These will be used by optimizer (for \(X\)), and initializer/updater (for \(\tilde{X}\)). Should be a list with \(m\) and \(\tilde{m}\) entries.

initializer

Operator (function) to initialize the population, such that \(S_0 = \text{initializer}(\tilde{X}, \tilde{g})\) (see details).

optimizer

Operator (function) to solve the reduced problem, such that \(R_t = \text{optimizer}(X, g, t, S_t)\) (see details).

updater

Operator (function) to update the population, such that \(S_{t+1} = \text{updater}(\tilde{X}, \tilde{g}, t, S_t, R_t)\).

stopper

Stopping criteria for the algorithm, created via flow_stopper().

logger

Logger for tracking the process, created via flow_logger().

check_samples

Number of samples to be expected in \(S_t\). Set to NULL to not check (required if it changes with iterations \(t\)).

check_op

Integer vector with iterations to check if the operators are producing results with the needed format. Helps catching errors. Set to 0 to not check.

Value

A list containing:

results

Optimization results for each iteration.

metrics

Metrics calculated during the optimization process.

duration

Timing information for initialization, main loop, and total execution.

Details

This function is a wrapper for the operator functions, organizing them in the correct structure of a population-based, two-step, hybrid algorithm. But, it is the job of the user to implement the operators correctly. I highly recommend seeing vignette("example") to fully understand their use:

  • initializer:

    • Arguments: xtil_dom and gtil.

    • Returns: A \(N \times \tilde{m}\) matrix of initial guesses for \(\tilde{x}\), where \(N\) is the initial population size.

  • optimizer:

    • Arguments: f_s, g_s - the functions conditional on a sample \(\tilde{x}_s\) -, x_dom, t - the current iteration -, and xtil_s - the current sample.

    • Returns: A data.frame with four columns:

      • x: A \(1 \times m\) vector of optimal values \(x^*\), given \(\tilde{x}_s\). Hint: use I() to create matrix-columns.

      • xtil: A \(1 \times \tilde{m}\) matrix with xtil_s.

      • f: The value of \(f(x^*, \tilde{x}_s)\) (a single double).

      • i: Any meta-information you want to add, for use in the updater or metrics methods. If none, use a single NA.

  • updater:

    • Arguments: xtil_dom, gtil, r_t - the results of the last iteration's optimizer (a data frame) -, and t.

    • Returns: A new \(N \times \tilde{m}\) matrix of guesses, but note that \(N\) can change between iterations.