Skip to content

Commit f9b0ed6

Browse files
committed
Warm start updates for sqsolve and snsolve. Minor updates to examples
1 parent c4b3199 commit f9b0ed6

File tree

9 files changed

+144
-44
lines changed

9 files changed

+144
-44
lines changed

matlab/README

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
Using the SNOPT mex Files in $SNOPT/matlab
3+
==========================================
4+
5+
Run Matlab in the directory $SNOPT/matlab.
6+
7+
Typing
8+
>> more on
9+
>> help Contents
10+
from Matlab provides an overview of the package.
11+
12+
At the Matlab prompt, type
13+
14+
>> runQPExamples % for qpopt
15+
>> runNPExamples % for snopt
16+
17+
This script sets the matlab path appropriately.
18+
19+
The subdirectory ./examples contains various sample problems
20+
that demonstrate how to use the snOpt Matlab interfaces. Read
21+
the in-line help information for each m-file for more
22+
information. To run the individual m-files type
23+
24+
>> setpath % if you haven't already called run**Examples script
25+
>> addpath examples
26+
>> addpath examples/snmain
27+
>> snoptmain
28+
29+
SNOPT can be called via the Matlab m-file functions "snopt" and "snsolve".
30+
snopt is similar to the Fortran version of SNOPTA. snsolve is based off
31+
Matlab's "fmincon".
32+
33+
34+
If you provide the derivatives of your problem functions be sure to check them
35+
first using the command:
36+
>> snseti('Verify level', 3);
37+
38+
39+
BOTTOM LINE: The more information you give, the FASTER and MORE RELIABLE the solve.
40+
(the LONGER THE ARGUMENT LIST, the FASTER and MORE RELIABLE the solve)

matlab/examples/fmincon/toymin.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
options.name = 'toyprob';
3333
options.stop = @toySTOP;
3434

35-
[x,fval,INFO,lambda] = snsolve( @toyObj, x0, A, b, Aeq, beq, lb, ub, @toyCon, options);
35+
[x,fval,INFO,output,lambda,states] = snsolve( @toyObj, x0, A, b, Aeq, beq, lb, ub, ...
36+
@toyCon, options);
3637

3738
snprint off;
3839
snend;

matlab/examples/hs116/hs116.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
options.name = 'hs116';
1616

17-
[x,F,info,xmul,Fmul]= snopt( x, xlow, xupp, xmul, xstate, ...
18-
Flow, Fupp, Fmul, Fstate, ...
19-
@hs116userfun, ObjAdd, ObjRow, ...
20-
A, iAfun, jAvar, iGfun, jGvar, ...
21-
options );
17+
[x,F,info]= snopt( x, xlow, xupp, xmul, xstate, ...
18+
Flow, Fupp, Fmul, Fstate, ...
19+
@hs116userfun, ObjAdd, ObjRow, ...
20+
A, iAfun, jAvar, iGfun, jGvar, ...
21+
options );
2222

2323
snprint off; % Closes the file and empties the print buffer
2424
snend;

matlab/examples/hsmain/hs13.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
ObjAdd,ObjRow, ...
2020
A,iAfun,jAvar,iGfun,jGvar] = hs13data;
2121

22-
[x,F,INFO,xmul,Fmul]= snopt( x, xlow, xupp, xmul, xstate, ...
23-
Flow, Fupp, Fmul, Fstate, ...
24-
'hs13userfun', ObjAdd, ObjRow, ...
25-
A, iAfun, jAvar, iGfun, jGvar );
22+
[x,F,INFO]= snopt( x, xlow, xupp, xmul, xstate, ...
23+
Flow, Fupp, Fmul, Fstate, ...
24+
'hs13userfun', ObjAdd, ObjRow, ...
25+
A, iAfun, jAvar, iGfun, jGvar );
2626

2727
snprint off;
2828
snend;

matlab/examples/hsmain/hsmain.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@
1111
Flow,Fupp,Fmul,Fstate, ...
1212
ObjAdd,ObjRow,A,iAfun,jAvar,iGfun,jGvar] = hs47data;
1313

14-
[x,F,INFO,xmul,Fmul]= snopt( x, xlow, xupp, xmul, xstate, ...
15-
Flow, Fupp, Fmul, Fstate, ...
16-
@hsmainusrfun, ObjAdd, ObjRow, ...
17-
A, iAfun, jAvar, iGfun, jGvar );
14+
[x,F,INFO,xmul,Fmul,xstate,Fstate,output]= snopt( x, xlow, xupp, xmul, xstate, ...
15+
Flow, Fupp, Fmul, Fstate, ...
16+
@hsmainusrfun, ObjAdd, ObjRow, ...
17+
A, iAfun, jAvar, iGfun, jGvar );
18+
19+
options.start = 'warm';
20+
[x,F,INFO,xmul,Fmul,xstate,Fstate,output]= snopt( x, xlow, xupp, xmul, xstate, ...
21+
Flow, Fupp, Fmul, Fstate, ...
22+
@hsmainusrfun, ObjAdd, ObjRow, ...
23+
A, iAfun, jAvar, iGfun, ...
24+
jGvar, options );
1825

1926
snprint off; % Closes the file and empties the print buffer
2027
snend;

matlab/examples/sntoy/sntoy.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
Flow,Fupp,Fmul,Fstate, ...
2121
ObjAdd,ObjRow,A,iAfun,jAvar,iGfun,jGvar] = toydata;
2222

23-
[x,F,INFO,xmul,Fmul]= snopt( x, xlow, xupp, xmul, xstate, ...
24-
Flow, Fupp, Fmul, Fstate, ...
25-
@toyusrfun, ObjAdd, ObjRow, ...
26-
A, iAfun, jAvar, iGfun, jGvar );
23+
[x,F,INFO]= snopt( x, xlow, xupp, xmul, xstate, ...
24+
Flow, Fupp, Fmul, Fstate, ...
25+
@toyusrfun, ObjAdd, ObjRow, ...
26+
A, iAfun, jAvar, iGfun, jGvar );
2727

2828
snprint off;
2929
snend;

matlab/snsolve.m

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
% [...] = snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon)
1414
% [...] = snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon,options)
1515
%
16+
% [...] = snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon,lambda,states)
17+
% [...] = snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon,lambda,states,options)
18+
%
19+
%
1620
% Output from snsolve:
1721
% [x,fval,exitflag,output,lambda,states] = snsolve(...)
1822
%
@@ -38,16 +42,14 @@
3842
% output.majors the total number of major iterations
3943
%
4044
% lambda are the final multipliers
41-
% lambda.lower lower bounds
42-
% lambda.upper upper bounds
45+
% lambda.x variables
4346
% lambda.ineqnonlin nonlinear inequalities
4447
% lambda.eqnonlin nonlinear equalities
4548
% lambda.ineqlin linear inequalities
4649
% lambda.eqlin linear equalities
4750
%
4851
% states are the final states
49-
% states.lower lower bounds
50-
% states.upper upper bounds
52+
% states.x variables
5153
% states.ineqnonlin nonlinear inequalities
5254
% states.eqnonlin nonlinear equalities
5355
% states.ineqlin linear inequalities
@@ -65,7 +67,8 @@
6567
myobj = checkFun(obj,'SNOPT',[1]);
6668

6769
% Deal with options
68-
if nargin == 5 || nargin == 7 || nargin == 9 || nargin == 10,
70+
if nargin == 5 || nargin == 7 || nargin == 9 || ...
71+
nargin == 10 || nargin == 12,
6972
optionsLoc = nargin - 4;
7073
if isstruct(varargin{optionsLoc}),
7174
options = varargin{optionsLoc};
@@ -109,13 +112,17 @@
109112
nonlin_eq = 0;
110113
nonlcon = 0;
111114

115+
112116
if nargin == 4 || nargin == 5,
113117
% snsolve(obj,x0,A,b)
114118
% snsolve(obj,x0,A,b,options)
115119

116120
Aeq = []; beq = [];
117121
xlow = []; xupp = [];
118122
c = []; ceq = [];
123+
xmul = []; xstate = [];
124+
Fmul = []; Fstate = [];
125+
119126

120127
elseif nargin == 6 || nargin == 7,
121128
% snsolve(obj,x0,A,b,Aeq,beq)
@@ -127,6 +134,8 @@
127134

128135
xlow = []; xupp = [];
129136
c = []; ceq = [];
137+
xmul = []; xstate = [];
138+
Fmul = []; Fstate = [];
130139

131140
elseif nargin == 8 || (nargin == 9 && optionsLoc ~=0),
132141
% snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp)
@@ -138,17 +147,35 @@
138147
xupp = varargin{4};
139148
linear_eq = size(Aeq,1);
140149
c = []; ceq = [];
150+
xmul = []; xstate = [];
151+
Fmul = []; Fstate = [];
141152

142-
elseif nargin == 9 || nargin == 10,
153+
elseif nargin >= 9 && nargin <= 12,
143154
% snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon)
144155
% snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon,options)
156+
% snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon,lambda,states)
157+
% snsolve(obj,x0,A,b,Aeq,beq,xlow,xupp,nonlcon,lambda,states,options)
145158

146159
Aeq = varargin{1};
147160
beq = varargin{2};
148161
xlow = varargin{3};
149162
xupp = varargin{4};
150163
nonlc = varargin{5};
151164
linear_eq = size(Aeq,1);
165+
xmul = []; xstate = [];
166+
Fmul = []; Fstate = [];
167+
168+
if nargin == 11 || nargin == 12,
169+
lambda = varargin{6};
170+
states = varargin{7};
171+
172+
xmul = lambda.x; xstate = states.x;
173+
Fmul = [ 0; lambda.ineqnonlin; lambda.eqnonlin;
174+
lambda.ineqlin; lambda.eqlin];
175+
Fstate = [ 0; states.ineqnonlin; states.eqnonlin;
176+
states.ineqlin; states.eqlin];
177+
178+
end
152179

153180
nonlcon = checkFun(nonlc,'SNOPT');
154181

@@ -228,8 +255,8 @@
228255
@(x,needF,needG)snfun(x,needF,needG,myobj, ...
229256
nonlcon,iGfun,jGvar), ...
230257
x0, ...
231-
xlow, xupp, [], [], ...
232-
Flow, Fupp, [], [], ...
258+
xlow, xupp, xmul, xstate, ...
259+
Flow, Fupp, Fmul, Fstate, ...
233260
ObjAdd, ObjRow, ...
234261
Aij, iAfun, jAvar, iGfun, jGvar);
235262
else
@@ -238,17 +265,16 @@
238265
istart, stopFun, probName, ...
239266
@(x,needF,needG)snfun(x,needF,needG,myobj), ...
240267
x0, ...
241-
xlow, xupp, [], [], ...
242-
Flow, Fupp, [], [], ...
268+
xlow, xupp, xmul, xstate, ...
269+
Flow, Fupp, Fmul, Fstate, ...
243270
ObjAdd, ObjRow, ...
244271
Aij, iAfun, jAvar, iGfun, jGvar);
245272
end
246273

247274
fval = F(1);
248275
zero = zeros(n,1);
249276
states.x = xstate(1:n);
250-
lambda.lower = max(xmul(1:n),zero);
251-
lambda.upper = min(xmul(1:n),zero);
277+
lambda.x = xmul(1:n);
252278

253279
if nonlin_ineq > 0,
254280
i1 = 1+1; i2 = i1-1 + nonlin_ineq;

matlab/sqopt.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
% lambda.linear are for the linear constraints
5757
%
5858
% states is a structure
59-
% states.x
60-
% states.linear
59+
% states.x are for the variables
60+
% states.linear are for the linear constraints
6161
%
6262

6363
solveOpt = 1;

matlab/sqsolve.m

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
% x = sqsolve(Hx, f, A, b, Aeq, beq, lb, ub)
1818
% x = sqsolve(Hx, f, A, b, Aeq, beq, lb, ub, x0)
1919
% x = sqsolve(Hx, f, A, b, Aeq, beq, lb, ub, x0, options)
20+
% x = sqsolve(Hx, f, A, b, Aeq, beq, lb, ub, x0, lambda, states, options)
2021
%
2122
% [x,fval] = sqsolve(Hx, f, ...)
2223
% [x,fval,exitflag] = sqsolve(Hx, f, ...)
@@ -61,11 +62,12 @@
6162
% output.funcCount is the total number of function evaluations
6263
%
6364
% lambda is a structure containing the multipliers
64-
% lambda.lb are for the lower bounds
65-
% lambda.ub are for the upper bounds
66-
% lambda.ineqlin are for the linear inequality constraints
67-
% lambda.eqlin are for the linear equality constraints
65+
% lambda.x are for the variables
66+
% lambda.linear are for the linear constraints
6867
%
68+
% states is a structure containing the states
69+
% states.x are for the variables
70+
% states.linear are for the linear constraints
6971
%
7072
solveOpt = 1;
7173

@@ -81,6 +83,9 @@
8183
lb = []; ub = [];
8284
x0 = [];
8385

86+
xstate = []; xmul = [];
87+
astate = []; amul = [];
88+
8489
elseif nargin == 4,
8590
% sqsolve(Hx, f, A, b)
8691
A = varargin{1};
@@ -89,6 +94,9 @@
8994
lb = []; ub = [];
9095
x0 = [];
9196

97+
xstate = []; xmul = [];
98+
astate = []; amul = [];
99+
92100

93101
elseif nargin == 6,
94102
% sqsolve(Hx, f, A, b, Aeq, beq)
@@ -99,6 +107,9 @@
99107
lb = []; ub = [];
100108
x0 = [];
101109

110+
xstate = []; xmul = [];
111+
astate = []; amul = [];
112+
102113
elseif nargin == 8,
103114
% sqsolve(Hx, f, A, b, Aeq, beq, lb, ub)
104115
A = varargin{1};
@@ -109,6 +120,9 @@
109120
ub = varargin{6};
110121
x0 = [];
111122

123+
xstate = []; xmul = [];
124+
astate = []; amul = [];
125+
112126
elseif nargin == 9,
113127
% sqsolve(Hx, f, A, b, Aeq, beq, lb, ub, x0)
114128
A = varargin{1};
@@ -119,8 +133,12 @@
119133
ub = varargin{6};
120134
x0 = varargin{7};
121135

122-
elseif nargin == 10,
136+
xstate = []; xmul = [];
137+
astate = []; amul = [];
138+
139+
elseif nargin == 10 || nargin == 12,
123140
% sqsolve(Hx, f, A, b, Aeq, beq, lb, ub, x0, options)
141+
% sqsolve(Hx, f, A, b, Aeq, beq, lb, ub, x0, lambda, states, options)
124142
A = varargin{1};
125143
b = varargin{2};
126144
Aeq = varargin{3};
@@ -129,6 +147,19 @@
129147
ub = varargin{6};
130148
x0 = varargin{7};
131149

150+
xstate = []; xmul = [];
151+
astate = []; amul = [];
152+
153+
if nargin == 12,
154+
lambda = varargin{8};
155+
states = varargin{9};
156+
157+
xstate = states.x;
158+
xmul = lambda.x;
159+
astate = states.linear;
160+
amul = lambda.linear;
161+
end
162+
132163
% Deal with options.
133164
optionsLoc = 10;
134165
if isstruct(varargin{optionsLoc}),
@@ -161,8 +192,8 @@
161192
au = [ b; beq ];
162193

163194
[x,fval,exitFlag,itn,y,state] = sqoptmex(solveOpt, start, probName, ...
164-
userHx, f, x0, lb, ub, [], [], ...
165-
AA, al, au, [], []);
195+
userHx, f, x0, lb, ub, xstate, xmul, ...
196+
AA, al, au, astate, amul);
166197

167198
% Set output
168199
output.iterations = itn;
@@ -177,8 +208,3 @@
177208
states.linear = state(n+1:n+m);
178209
lambda.linear = y(n+1:n+m);
179210
end
180-
181-
lambda.lb = max(y(1:n),zero);
182-
lambda.ub = min(y(1:n),zero);
183-
lambda.ineqlin = y(1+n:ineq+n);
184-
lambda.eqlin = y(1+ineq+n:n+m);

0 commit comments

Comments
 (0)