snopt vs fmincon on a test problem

150 views
Skip to first unread message

michael...@gmx.de

unread,
Dec 4, 2018, 8:22:38 AM12/4/18
to SNOPT
Hello,

I'm a new snopt-user, who just got his trial licence and would like to compare the results of fmincon against the solutions provided by snopt. Here's my first test problem, where the results of snopt don't look too promising. Does anyone know how to get a better performance?

%% Code
clear all; close all; clc; rng(0);

usefeasible = true;
if usefeasible
x0 = [0.5; 0.5]; % feasible inital guess
else
x0 = [2; 2]; % infeasible inital guess
end

% - fmincon
options = optimoptions('fmincon', 'Display', 'none', 'Algorithm', 'sqp', 'SpecifyObjectiveGradient', true, 'SpecifyConstraintGradient', true);
tic;
x1 = fmincon(@(x) obj(x), x0,[],[],[],[],[],[], @(x) con(x), options);
toc;

% - snopt
tic;
x2 = snsolve(@(x) obj(x), x0,[],[],[],[],[],[], @(x) con(x));
toc;

% - compare solutions
[x1 x2]

% - visualization
figure(1);
fcontour(@(x1,x2) 3*(x1-2).^2+2*(x2-3).^2); hold on; grid on;
fimplicit(@(x1,x2) x1.^2-x2,'k');
fimplicit(@(x1,x2) x1.^2+x2.^2-1,'k');
plot(x0(1),x0(2),'m+');
plot(x1(1),x1(2),'g*');
plot(x2(1),x2(2),'c*');
xlabel('x_1'); ylabel('x_2');

% - subfunctions
function [J, dJdx] = obj(x)
J = 3*(x(1)-2).^2+2*(x(2)-3).^2;
if nargout > 1
dJdx = [6*x(1)-12; 4*x(2)-12];
end
end

function [c, ceq, dcdx, dceqdx] = con(x)
c = [x(1)^2-x(2); x(1)^2+x(2)^2-1];
ceq = [];
if nargout > 2
dcdx = [2*x(1) -1; 2*x(1) 2*x(2)]';
dceqdx = [];
end
end

SNOPT

unread,
Dec 4, 2018, 4:49:56 PM12/4/18
to SNOPT
Don't transpose dcdx in your "con" function for SNOPT.  If you run with option "verify level 3", you'll see that with the transpose, SNOPT thinks the derivatives are incorrectly defined.  Removing the transpose fixes the run for SNOPT.

--Elizabeth

michael...@gmx.de

unread,
Dec 5, 2018, 10:13:26 AM12/5/18
to SNOPT
Thank you very much for that hint, best regards, Michael
Reply all
Reply to author
Forward
0 new messages