Skip to content

Commit

Permalink
Use numerical sensitivities for fmincon correctly #84
Browse files Browse the repository at this point in the history
- modified termination criterion in `iterateAL()`
- verified sensitivities against casadi
  • Loading branch information
timueh committed Apr 7, 2020
1 parent 61b4357 commit 075888a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/core/createLocalSolvers.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@

function res = build_local_NLP(f, g, h, A, lambda, rho, z, Sigma, x0, lbx, ubx, dgdx)
opts = optimoptions('fmincon');
opts.Algorithm = 'trust-region-reflective';
opts.Algorithm = 'interior-point';
opts.CheckGradients = false;
opts.SpecifyConstraintGradient = true;
opts.SpecifyObjectiveGradient = true;
opts.MaxFunctionEvaluations = 5e3;
% opts.Display = 'iter';

cost = @(x)build_cost_function(x, f(x), lambda, A, rho, z, Sigma);
nonlcon = @(x)build_nonlcon(x, g, h, dgdx);
[xopt, fval, flag, out, multiplier] = fmincon(cost, x0, [], [], [], [], lbx, ubx, nonlcon);
[xopt, fval, flag, out, multiplier] = fmincon(cost, x0, [], [], [], [], lbx, ubx, nonlcon, opts);
res.x = xopt;
res.lam_g = [multiplier.eqnonlin; multiplier.ineqnonlin];
res.lam_x = max(multiplier.lower, multiplier.upper);
Expand All @@ -103,14 +105,14 @@
% end
fun = f + lambda'*A*x + 0.5*rho*(x - z)'*Sigma*(x - z);
if nargout > 1
grad = A'*lambda + 0.5*rho*Sigma*(x - z);
grad = A'*lambda + rho*Sigma*(x - z);
end
end

function [ineq, eq, jac_ineq, jac_eq] = build_nonlcon(x, g, h, dgdx)
ineq = h(x);
eq = g(x);
jac_ineq = [];
iac_eq = dgdx(x);
jac_eq = dgdx(x)';
end

3 changes: 1 addition & 2 deletions src/core/iterateAL.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
iterTimer = tic;
i = 1;
iter.i = 1;
while ((i <= opts.maxiter) && ( (strcmp(opts.term_eps,'false')) || ...
(iter.logg.consViol(i) >= opts.term_eps)))
while (i <= opts.maxiter) && ( (strcmp(opts.term_eps,'false')) || (iter.logg.consViol(i) >= opts.term_eps))

% solve local NLPs and evaluate sensitivities
if (strcmp( opts.parfor, 'true' ))
Expand Down
4 changes: 2 additions & 2 deletions src/core/loadDefOpts.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
optVariants.muUpdate = {2};
optVariants.muMax = {2*1e6};

optVariants.eps = {0};
optVariants.eps = {1e-10};
optVariants.maxiter = {30};
optVariants.actMargin = {-1e-6};
optVariants.solveQP = {'MA57','ipopt','pinv','linsolve','sparseBs','MOSEK','quadprog'};
Expand All @@ -20,7 +20,7 @@
optVariants.plot = {'true', 'false'};
optVariants.Sig = {'const','dyn'};
optVariants.lamInit = {'false','true'};
optVariants.term_eps = {0};
optVariants.term_eps = {1e-10};
optVariants.regParam = {1e-4};

% extensions
Expand Down
3 changes: 2 additions & 1 deletion src/core/parallelStepCentral.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
z = iter.yy{j};
rho = iter.stepSizes.rho;
lambda = iter.lam;
Sigma = opts.SSig{j};
Sigma = sparse(opts.SSig{j});

fprintf('Solving NLP in region %i\n', j);
problem = sProb.nnlp{j};
sol = problem.solve_nlp(x0, z, rho, lambda, Sigma, problem.pars);

Expand Down

0 comments on commit 075888a

Please sign in to comment.