Created
October 28, 2021 21:19
-
-
Save gnowzil/5857ad03aae12d57cbba6db7c4fe14d2 to your computer and use it in GitHub Desktop.
HS116 matrix structure, nonlinear objective
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,info]=hs116_matrix() | |
% HS Problem 116 with explicit linear constraints. | |
% The Jacobian structure and linear elements are defined as a matrix. | |
% Linear objective row is in the first row and defined as a "nonlinear" function. | |
options.name = 'hs116'; | |
options.printfile = 'hs116_mtx.out'; | |
options.specsfile = which('hs116.spc'); | |
options.system_information ='yes'; | |
[x, xlow, xupp, xmul, xstate, ... | |
Flow, Fupp, Fmul, Fstate, ... | |
ObjAdd, ObjRow, ... | |
A, G] = hs116data; | |
% A.val, A.row, A.col, ... | |
% G.row, G.col] = hs116data; | |
[x,F,info]= snopt(x, xlow, xupp, xmul, xstate, ... | |
Flow, Fupp, Fmul, Fstate, ... | |
@(x)hs116userfun_1(x), ObjAdd, ObjRow, ... | |
A, G, options); | |
end | |
function [x,xlow,xupp,xmul,xstate, ... | |
Flow,Fupp,Fmul,Fstate, ... | |
ObjAdd,ObjRow,A,G] = hs116data() | |
% hs116data defines problem HS116. | |
% | |
% Minimize x(11) + x(12) + x(13) | |
% subject to linear and nonlinear 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); | |
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); | |
%% Jacobian structure as matrix | |
A = zeros(neF, n); | |
%A(ObjRow,11) = 1; | |
%A(ObjRow,12) = 1; | |
%A(ObjRow,13) = 1; | |
A(2,1) = -1; | |
A(2,2) = 1; | |
A(3,7) = a; | |
A(3,8) = -a; | |
A(4,11) = 1; | |
A(4,12) = 1; | |
A(4,13) = 1; | |
A(5,2) = -1; | |
A(5,3) = 1; | |
A(6,13) = 1; | |
A(10,12) = 1; | |
A(11,11) = 1; | |
G = zeros(neF,n); | |
G(ObjRow,13) = 1; | |
G(ObjRow,12) = 1; | |
G(ObjRow,11) = 1; | |
G(6,3) = c*x(10); | |
G(6,10) = -b + c*x(3); | |
G(7,2) = -d - e*x(5) + 2*f*x(2); | |
G(7,5) = 1 - e*x(2); | |
G(8,3) = -d - e*x(6) + 2*f*x(3); | |
G(8,6) = 1 - e*x(3); | |
G(9,1) = -d - e*x(4) + 2*f*x(1); | |
G(9,4) = 1 - e*x(1); | |
G(10,2) = c*x(9); | |
G(10,9) = -b + c*x(2); | |
G(11,1) = c*x(8); | |
G(11,8) =-b + c*x(1); | |
G(12,1) =-x(8); | |
G(12,4) =-x(7) + x(8); | |
G(12,5) = x(7); | |
G(12,7) = x(5) - x(4); | |
G(12,8) =-x(1) + x(4); | |
G(13,1) =-a*x(8); | |
G(13,2) = a*x(9); | |
G(13,5) = 1 + a*x(8); | |
G(13,6) = 1 - a*x(9); | |
G(13,8) = a*(x(5) - x(1)); | |
G(13,9) = a*(x(2) - x(6)); | |
G(14,2) =-500 + x(9) + x(10); | |
G(14,3) =-x(10); | |
G(14,6) = 500 - x(9); | |
G(14,9) = x(2) - x(6); | |
G(14,10) =-x(3) + x(2); | |
G(15,2) = 1 - a*x(10); | |
G(15,3) = a*x(10); | |
G(15,10) = -a*(x(2) - x(3)); | |
end | |
function [F,G] = hs116userfun_1(x) | |
% Defines nonlinear terms of F and derivatives for HS 116. | |
% Linear constraints are explicit. | |
% Parameters | |
a = 2e-3; | |
b = 1.262626; | |
c = 1.231059; | |
d = 3.475e-2; | |
e = 9.75e-1; | |
f = 9.75e-3; | |
F = [ %1, 0; | |
1, x(11) + x(12) + x(13); | |
2, 0; | |
3, 0; | |
4, 0; | |
5, 0; | |
6, -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, -b*x(9) + c*x(2)*x(9); % | |
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); | |
if nargout > 1, | |
% Define the derivatives. | |
n = 13; | |
neF = 15; | |
G = zeros(neF,n); | |
G(1,13) = 1; | |
G(1,11) = 1; | |
G(1,12) = 1; | |
G(8,3) = -d - e*x(6) + 2*f*x(3); | |
G(8,6) = 1 - e*x(3); | |
G(9,1) = -d - e*x(4) + 2*f*x(1); | |
G(9,4) = 1 - e*x(1); | |
G(6,3) = c*x(10); | |
G(6,10) = -b + c*x(3); | |
G(7,2) = -d - e*x(5) + 2*f*x(2); | |
G(7,5) = 1 - e*x(2); | |
G(10,2) = c*x(9); | |
G(10,9) = -b + c*x(2); | |
G(11,1) = c*x(8); | |
G(11,8) = -b + c*x(1); | |
G(12,1) = -x(8); | |
G(12,4) = -x(7) + x(8); | |
G(12,5) = x(7); | |
G(12,7) = x(5) - x(4); | |
G(12,8) = -x(1) + x(4); | |
G(13,1) = -a*x(8); | |
G(13,2) = a*x(9); | |
G(13,5) = 1 + a*x(8); | |
G(13,6) = 1 - a*x(9); | |
G(13,8) = a*(x(5) - x(1)); | |
G(13,9) = a*(x(2) - x(6)); | |
G(14,2) = -500 + x(9) + x(10); | |
G(14,3) = -x(10); | |
G(14,6) = 500 - x(9); | |
G(14,9) = x(2) - x(6); | |
G(14,10) = -x(3) + x(2); | |
G(15,2) = 1 - a*x(10); | |
G(15,3) = a*x(10); | |
G(15,10) = -a*(x(2) - x(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