Created
October 28, 2021 21:17
-
-
Save gnowzil/16bed4965da27a86133fbaec7f75658b to your computer and use it in GitHub Desktop.
HS116 with nonlinear constraints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [x,F,xmul,Fmul,INFO] = hs116_nonlin() | |
% HS116 | |
% Problem has both linear and nonlinear constraints but | |
% all constraints are defiend as nonlinear in this example. | |
% | |
% Jacobian defined in coordinate form | |
% Linear objective defined in row 1. | |
% | |
% | |
options.printfile = 'hs116_nonlin.out'; | |
options.specsfile = which('hs116.spc'); | |
options.screen = 'on'; | |
options.name = 'hs116'; | |
[x,xlow,xupp,xmul,xstate, ... | |
Flow,Fupp,Fmul,Fstate, ... | |
ObjAdd,ObjRow,A.val,A.row,A.col,G.row,G.col] = hs116data; | |
[x,F,INFO,xmul,Fmul]= snopt(x, xlow, xupp, xmul, xstate, ... | |
Flow, Fupp, Fmul, Fstate, ... | |
@hs116userfun, ObjAdd, ObjRow, ... | |
A, G, options); | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function [x,xlow,xupp,xmul,xstate, ... | |
Flow,Fupp,Fmul,Fstate, ... | |
ObjAdd,ObjRow,A,iAfun,jAvar,iGfun,jGvar] = hs116data() | |
% hs116data defines problem HS116. | |
% | |
% Minimize x(11) + x(12) + x(13) | |
% subject to many constraints | |
n = 13; | |
neF = 15; | |
ObjRow = 1; | |
%% parameters | |
a = 0.002; | |
b = 1.262626; | |
c = 1.231059; | |
d = 0.03475; | |
e = 0.975; | |
f = 0.00975; | |
% HS Solution | |
x = [ 0.80377 | |
0.89999 | |
0.97095 | |
0.10000 | |
0.19081 | |
0.46057 | |
574.07758 | |
74.07758 | |
500.01615 | |
0.10000 | |
20.23309 | |
77.34768 | |
0.00673]; | |
%% initial x | |
x = [ 0.5; | |
0.8; | |
0.9; | |
0.1; | |
0.14; | |
0.5; | |
489; | |
80; | |
650; | |
450; | |
150; | |
150; | |
150 ]; | |
%% lower bounds on x | |
xlow = [ 0.1; | |
0.1; | |
0.1; | |
1e-4; | |
0.1; | |
0.1; | |
0.1; | |
0.1; | |
500; | |
0.1; | |
1; | |
1e-4; | |
1e-4 ]; | |
%% upper bounds on x | |
xupp = [ 1 ; | |
1 ; | |
1 ; | |
0.1; | |
0.9; | |
0.9; | |
1000; | |
1000; | |
1000; | |
500; | |
150; | |
150; | |
150 ]; | |
xstate = zeros(n,1); | |
xmul = zeros(n,1); | |
iAfun = []; jAvar = []; A = []; | |
ObjAdd = 0; | |
%% Bounds on F | |
Flow = zeros(neF,1); Fupp = Inf*ones(neF,1); | |
Flow(ObjRow) = -Inf; Fupp(ObjRow) = Inf; | |
Flow(3) = -Inf; Fupp(3) = 1; | |
Flow(4) = 50; Fupp(4) = 250; | |
Flow(13) = -Inf; Fupp(13) = 1; | |
Flow(15) = 0.9; Fupp(15) = Inf; | |
Fmul = zeros(neF,1); | |
Fstate = zeros(neF,1); | |
G = [ 5, 2, -1; | |
5, 3, 1; | |
2, 1, -1; | |
2, 2, 1; | |
3, 7, a; | |
3, 8, -a; | |
4, 11, 1; | |
4, 12, 1; | |
4, 13, 1; | |
ObjRow, 11, 1; | |
ObjRow, 12, 1; | |
ObjRow, 13, 1; | |
6, 3, c*x(10); | |
6, 10, -b + c*x(3); | |
6, 13, 1; | |
7, 2, -d - e*x(5) + 2*f*x(2); | |
7, 5, 1 - e*x(2); | |
8, 3, -d - e*x(6) + 2*f*x(3); | |
8, 6, 1 - e*x(3); | |
9, 1, -d - e*x(4) + 2*f*x(1); | |
9, 4, 1 - e*x(1); | |
10, 2, c*x(9); | |
10, 9, -b + c*x(2); | |
10, 12, 1; | |
11, 1, c*x(8); | |
11, 8, -b + c*x(1); | |
11, 11, 1; | |
12, 1, -x(8); | |
12, 4, -x(7) + x(8); | |
12, 5, x(7); | |
12, 7, x(5) - x(4); | |
12, 8, -x(1) + x(4); | |
13, 1, -a*x(8); | |
13, 2, a*x(9); | |
13, 5, -1 + a*x(8); | |
13, 6, 1 - a*x(9); | |
13, 8, a*(x(5) - x(1)); | |
13, 9, a*(x(2) - x(6)); | |
14, 2, -500 + x(9) + x(10); | |
14, 3, -x(10); | |
14, 6, 500 - x(9); | |
14, 9, x(2) - x(6); | |
14, 10, -x(3) + x(2); | |
15, 2, 1 - a*x(10); | |
15, 3, a*x(10); | |
15, 10, -a*(x(2) - x(3)) ]; | |
iGfun = G(:,1); jGvar = G(:,2); | |
end | |
function [F,G] = hs116userfun(x) | |
% Defines nonlinear terms of F and derivatives for HS 116. | |
% Parameters | |
a = 2e-3; | |
b = 1.262626; | |
c = 1.231059; | |
d = 3.475e-2; | |
e = 9.75e-1; | |
f = 9.75e-3; | |
ObjRow = 1; | |
F = [ObjRow, x(11) + x(12) + x(13); | |
2, x(2) - x(1); | |
3, a*x(7) - a*x(8); | |
4, x(11) + x(12) + x(13); | |
5, x(3) - x(2); | |
6, x(13) - b*x(10) + c*x(3)*x(10); % | |
7, x(5) - d*x(2) - e*x(2)*x(5) + f*x(2)^2; % | |
8, x(6) - d*x(3) - e*x(3)*x(6) + f*x(3)^2; % | |
9, x(4) - d*x(1) - e*x(1)*x(4) + f*x(1)^2; % | |
10, x(12) - b*x(9) + c*x(2)*x(9); % | |
11, x(11) - b*x(8) + c*x(1)*x(8); % | |
12, x(5)*x(7) - x(1)*x(8) - x(4)*x(7) + x(4)*x(8); % | |
13, x(6) + x(5) + a*(x(2)*x(9) + x(5)*x(8) - x(1)*x(8) - x(6)*x(9)); % | |
14, -500*(x(2) - x(6)) + x(2)*x(9) - x(3)*x(10) - x(6)*x(9) + x(2)*x(10); % | |
15, x(2) - a*(x(2)*x(10) - x(3)*x(10)) ]; % | |
F = F(:,2); | |
% Define the derivatives. | |
if nargout > 1, | |
G = [ 5, 2, -1; | |
5, 3, 1; | |
2, 1, -1; | |
2, 2, 1; | |
3, 7, a; | |
3, 8, -a; | |
4, 11, 1; | |
4, 12, 1; | |
4, 13, 1; | |
ObjRow, 11, 1; | |
ObjRow, 12, 1; | |
ObjRow, 13, 1; | |
6, 3, c*x(10); | |
6, 10, -b + c*x(3); | |
6, 13, 1; | |
7, 2, -d - e*x(5) + 2*f*x(2); | |
7, 5, 1 - e*x(2); | |
8, 3, -d - e*x(6) + 2*f*x(3); | |
8, 6, 1 - e*x(3); | |
9, 1, -d - e*x(4) + 2*f*x(1); | |
9, 4, 1 - e*x(1); | |
10, 2, c*x(9); | |
10, 9, -b + c*x(2); | |
10, 12, 1; | |
11, 1, c*x(8); | |
11, 8, -b + c*x(1); | |
11, 11, 1; | |
12, 1, -x(8); | |
12, 4, -x(7) + x(8); | |
12, 5, x(7); | |
12, 7, x(5) - x(4); | |
12, 8, -x(1) + x(4); | |
13, 1, -a*x(8); | |
13, 2, a*x(9); | |
13, 5, 1 + a*x(8); | |
13, 6, 1 - a*x(9); | |
13, 8, a*(x(5) - x(1)); | |
13, 9, a*(x(2) - x(6)); | |
14, 2, -500 + x(9) + x(10); | |
14, 3, -x(10); | |
14, 6, 500 - x(9); | |
14, 9, x(2) - x(6); | |
14, 10, -x(3) + x(2); | |
15, 2, 1 - a*x(10); | |
15, 3, a*x(10); | |
15, 10, -a*(x(2) - x(3)) ]; | |
G = G(:,3); | |
end | |
end |
Author
gnowzil
commented
Oct 28, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment