Opt.optimize

Optimize

Equivalent in C API: nlopt_optimize

Params:

x = the initial guess of the optimization

min_f = the value of the objective function when the optimization 
        finishes
struct Opt
void
optimize
(
T
)
(
ref T x
,
ref double minf
)
if (
isDoubleForeach!T
)

Examples

import core.stdc.math : HUGE_VAL;
import std.math : approxEqual;

auto opt = Opt(Algorithm.ldMMA, 2);

double[] lb = [-HUGE_VAL, 0];
double[] x = [1.234, 5.678];
double minf;
my_constraint_data[2] c_data = [{2.0, 0.0}, {-1.0, 1.0}];

opt.setLowerBounds(lb);

opt.setMinObjective(&myFuncC);

opt.addInequalityConstraint(&myConstraintC, c_data[0]);
opt.addInequalityConstraint(&myConstraintC, c_data[1]);

opt.optimize(x, minf);

assert(opt.getResult() > 0);
assert(approxEqual(x[0], 0.333333));
assert(approxEqual(x[1], 0.296296));
assert(approxEqual(minf, 0.5443310476));

Meta