diff options
Diffstat (limited to 'tests/general_tests/intfmincon')
42 files changed, 1450 insertions, 0 deletions
diff --git a/tests/general_tests/intfmincon/intfmincon_A.sce b/tests/general_tests/intfmincon/intfmincon_A.sce new file mode 100644 index 0000000..db67222 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_A.sce @@ -0,0 +1,21 @@ + +// Check if a user specifies coefficients of linear inequality contraints of the correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4,5,6]; +b = [7,9]; +intcon=[1,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Matrix of size (No of linear inequality constraints X No of Variables) or an Empty Matrix for Linear Inequality Constraint coefficient Matrix A +//at line 343 of function fmincon called by : +//[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); +//at line 20 of exec file called by : +//exec fmincon_A.sce + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon, A, b); diff --git a/tests/general_tests/intfmincon/intfmincon_Aeq.sce b/tests/general_tests/intfmincon/intfmincon_Aeq.sce new file mode 100644 index 0000000..b630ad1 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_Aeq.sce @@ -0,0 +1,23 @@ + +// Check if a user specifies coefficients of linear equality contraints of the correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = [1,4,9]; +beq = [2]; +intcon = [1,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//intfmincon: Expected Matrix of size (No of linear equality constraints X No of Variables) or an Empty Matrix for Linear Equality Constraint coefficient Matrix Aeq +//at line 380 of function fmincon called by : +//[x0pt,fopt,exitflag,output,gradient,hessian] = intfmincon(fun,x0,intcon, A, b, Aeq, beq); +//at line 22 of exec file called by : +//exec intfmincon_Aeq.sce + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon, A, b, Aeq, beq); diff --git a/tests/general_tests/intfmincon/intfmincon_b1.sce b/tests/general_tests/intfmincon/intfmincon_b1.sce new file mode 100644 index 0000000..febbc64 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_b1.sce @@ -0,0 +1,22 @@ + +// Check if a user specifies upper bounds of linear inequality contraints in accordance with starting point dimensions and coefficient matrix of linear inequality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7,9,10,20]; +intcon=[1,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); +// !--error 10000 +// intfmincon: Expected 1 entries for input argument b at input #5, but current dimensions are [1 4] instead. +// at line 54 of function Checkvector called by : +// at line 306 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); +// at line 20 of exec file called by : +// exec intfmincon_b1.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); diff --git a/tests/general_tests/intfmincon/intfmincon_b2.sce b/tests/general_tests/intfmincon/intfmincon_b2.sce new file mode 100644 index 0000000..8df011a --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_b2.sce @@ -0,0 +1,17 @@ + +// Check if a user specifies upper bounds of linear inequality contraints in accordance with starting point dimensions and coefficient matrix of linear inequality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = []; +b = [8,3]; +intcon=[1,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// Objective Function is Continuous Unbounded. + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); diff --git a/tests/general_tests/intfmincon/intfmincon_b3.sce b/tests/general_tests/intfmincon/intfmincon_b3.sce new file mode 100644 index 0000000..c1cef24 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_b3.sce @@ -0,0 +1,21 @@ + +// Check if a user specifies upper bounds of linear inequality contraints in accordance with starting point dimensions and coefficient matrix of linear inequality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [5,8]; +b = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// !--error 10000 +// intfmincon: Expected a vector matrix for input argument b at input #5, but got [0 0] instead. +// at line 49 of function Checkvector called by : +// at line 306 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); +// at line 20 of exec file called by : +// exec intfmincon_b3.sce + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); diff --git a/tests/general_tests/intfmincon/intfmincon_beq1.sce b/tests/general_tests/intfmincon/intfmincon_beq1.sce new file mode 100644 index 0000000..38619b3 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_beq1.sce @@ -0,0 +1,24 @@ + +// Check if a user specifies value of linear equality contraints in accordance with starting point dimensions and coefficient matrix of linear equality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = [1,4]; +beq = [2,6]; +intcon=[1,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// !--error 10000 +// intfmincon: Expected 1 entries for input argument beq at input #7, but current dimensions are [1 2] instead. +// at line 54 of function Checkvector called by : +// at line 310 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq); +// at line 22 of exec file called by : +// exec intfmincon_beq1.sce + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq); diff --git a/tests/general_tests/intfmincon/intfmincon_beq2.sce b/tests/general_tests/intfmincon/intfmincon_beq2.sce new file mode 100644 index 0000000..d8a34f2 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_beq2.sce @@ -0,0 +1,24 @@ + +// Check if a user specifies value of linear equality contraints in accordance with starting point dimensions and coefficient matrix of linear equality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = [2,6]; +intcon=[1,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// !--error 6 +// Inconsistent row/column dimensions. +// at line 430 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq); +// at line 22 of exec file called by : +// exec intfmincon_beq2.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq); diff --git a/tests/general_tests/intfmincon/intfmincon_beq3.sce b/tests/general_tests/intfmincon/intfmincon_beq3.sce new file mode 100644 index 0000000..18e0d2c --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_beq3.sce @@ -0,0 +1,24 @@ + +// Check if a user specifies value of linear equality contraints in accordance with starting point dimensions and coefficient matrix of linear equality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = [7,5]; +beq = []; +intcon=[1,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// !--error 10000 +// intfmincon: Expected a vector matrix for input argument beq at input #7, but got [0 0] instead. +// at line 49 of function Checkvector called by : +// at line 310 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq); +// at line 22 of exec file called by : +// exec intfmincon_beq3.sce + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq); diff --git a/tests/general_tests/intfmincon/intfmincon_cputime.sce b/tests/general_tests/intfmincon/intfmincon_cputime.sce new file mode 100644 index 0000000..34a5018 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_cputime.sce @@ -0,0 +1,49 @@ +//Example where cputime is exceeded + +function y=f(x) +y=x(1)*x(2)+x(2)*x(3); +endfunction +//Starting point, linear constraints and variable bounds +x0=[0.1 , 0.1 , 0.1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[]; +ub=[]; +intcon=[1,2]; +//Nonlinear constraints +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 ; x(1)^2 + x(2)^2 + x(3)^2 - 10]'; +ceq = []; +endfunction + +//Hessian of the Lagrange Function +function y= lHess(x,obj,lambda) +y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,-2,0;0,0,2] + lambda(2)*[2,0,0;0,2,0;0,0,2] +endfunction + +//Options +options=list("MaxIter", [100], "CpuTime", [5], "Hessian", lHess); + +//Calling fmincon +[xopt,fopt,exitflag,output,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) + +// Limit Exceeded. +// hessian = + +// 0. 1. 0. 1. 0. 1. 0. 1. 0. +// output = + +// - 2. 3.4142136 - 2. +// exitflag = + +// 3 +// fopt = + +// - 6.8284271 +// xopt = + +// 2. +// - 2. +// 1.4142136 diff --git a/tests/general_tests/intfmincon/intfmincon_f.sce b/tests/general_tests/intfmincon/intfmincon_f.sce new file mode 100644 index 0000000..cd9d0c6 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_f.sce @@ -0,0 +1,19 @@ + +// Check if a user specifies function or not + +fun = []; +x0 = [1,2,3,4,5,6]; +A = [2,4,8,9,3,5]; +b = [1,5,7,3,9,6]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); +intcon = [1,2]; +// !--error 10000 +// intfmincon: Expected type ["function"] for input argument fun at input #1, but got "constant" instead. +// at line 56 of function Checktype called by : +// at line 254 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon, A, b); +// at line 18 of exec file called by : +// exec intfmincon_f.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon, A, b); diff --git a/tests/general_tests/intfmincon/intfmincon_grad1.sce b/tests/general_tests/intfmincon/intfmincon_grad1.sce new file mode 100644 index 0000000..9bc9b64 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_grad1.sce @@ -0,0 +1,47 @@ + +//Incompatibility between user defined gradient function and dimensions of the starting point x0 + +function y=f(x) + y=x(1)*x(2)+x(2)*x(3); +endfunction + +x0=[1,1,1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; +intcon = [1,2] + + // !--error 10000 +// intfmincon_options: Expected type ["string"] for input argument GradObj at input #6, but got "function" instead. +// at line 56 of function Checktype called by : +// at line 359 of function intfmincon called by : +// [x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 44 of exec file called by : +// exec intfmincon_grad1.sce + + +function [c,ceq]=nlc(x) + c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1]; + ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75]; +endfunction + +//x(4) is invalid here +function y= fGrad(x) + y= [x(2),x(1)+x(3),x(4)]; +endfunction + +function y= lHess(x,obj,lambda) + y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,0,0;0,0,0] + lambda(2)*[2,0,0;0,2,0;0,0,0] +lambda(3)*[0,0,0;0,0,0;0,0,2] + lambda(4)*[6*x(1),0,0;0,0,0;0,0,0] + lambda(5)*[0,0,0;0,2,0;0,0,2]; +endfunction + +function [cg,ceqg] = cGrad(x) + cg = [2*x(1),0,0;2*x(1),2*x(2),0;0,0,2*x(3)]; + ceqg = [3*x(1)^2,0,0;0,2*x(2),2*x(3)]; +endfunction + +options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess,"GradCon",cGrad); + +[x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) diff --git a/tests/general_tests/intfmincon/intfmincon_grad2.sce b/tests/general_tests/intfmincon/intfmincon_grad2.sce new file mode 100644 index 0000000..dac2a82 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_grad2.sce @@ -0,0 +1,46 @@ + +//User defined gradient function does not return a vector + +function y=f(x) + y=x(1)*x(2)+x(2)*x(3); +endfunction + +x0=[1,1,1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; +intcon=[1,2]; + +// !--error 10000 +// intfmincon_options: Expected type ["string"] for input argument GradObj at input #6, but got "function" instead. +// at line 56 of function Checktype called by : +// at line 359 of function intfmincon called by : +// [x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 44 of exec file called by : +// exec intfmincon_grad2.sce + +function [c,ceq]=nlc(x) + c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1]; + ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75]; +endfunction + +function y= fGrad(x) + //y is not a vector here + y= [x(2),x(1)+x(3);x(2),x(1)]; +endfunction + +function y= lHess(x,obj,lambda) + y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,0,0;0,0,0] + lambda(2)*[2,0,0;0,2,0;0,0,0] +lambda(3)*[0,0,0;0,0,0;0,0,2] + lambda(4)*[6*x(1),0,0;0,0,0;0,0,0] + lambda(5)*[0,0,0;0,2,0;0,0,2]; +endfunction + +function [cg,ceqg] = cGrad(x) + cg = [2*x(1),0,0;2*x(1),2*x(2),0;0,0,2*x(3)]; + ceqg = [3*x(1)^2,0,0;0,2*x(2),2*x(3)]; +endfunction + +options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess,"GradCon",cGrad); + +[x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) diff --git a/tests/general_tests/intfmincon/intfmincon_hess1.sce b/tests/general_tests/intfmincon/intfmincon_hess1.sce new file mode 100644 index 0000000..89b30b3 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_hess1.sce @@ -0,0 +1,46 @@ + +//Incompatibility between user defined hessian function and dimensions of the starting point x0 + +function y=f(x) + y=x(1)*x(2)+x(2)*x(3); +endfunction + +x0=[1,1,1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; +intcon=[1,2]; + +// !--error 10000 +// intfmincon_options: Expected type ["string"] for input argument GradObj at input #6, but got "function" instead. +// at line 56 of function Checktype called by : +// at line 359 of function intfmincon called by : +// [x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 45 of exec file called by : +// exec intfmincon_hess1.sce + +function [c,ceq]=nlc(x) + c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1]; + ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75]; +endfunction + +function y= fGrad(x) + y= [x(2),x(1)+x(3),x(2)]; +endfunction + +//x(4) is invalid here +function y= lHess(x,obj,lambda) + y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,0,0;0,0,0] + lambda(2)*[2,0,0;0,2,0;0,0,0] +lambda(3)*[0,0,0;0,0,0;0,0,2] + lambda(4)*[6*x(4),0,0;0,0,0;0,0,0] + lambda(5)*[0,0,0;0,2,0;0,0,2]; +endfunction + +function [cg,ceqg] = cGrad(x) + cg = [2*x(1),0,0;2*x(1),2*x(2),0;0,0,2*x(3)]; + ceqg = [3*x(1)^2,0,0;0,2*x(2),2*x(3)]; +endfunction + +options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess); + +[x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) diff --git a/tests/general_tests/intfmincon/intfmincon_hess2.sce b/tests/general_tests/intfmincon/intfmincon_hess2.sce new file mode 100644 index 0000000..3585a12 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_hess2.sce @@ -0,0 +1,41 @@ + +//User defined hessian is of wrong dimensions + +function y=f(x) + y=x(1)*x(2)+x(2)*x(3); +endfunction + +x0=[1,1,1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; +intcon=[1,2]; + +// !--error 10000 +// intfmincon_options: Expected type ["string"] for input argument GradObj at input #6, but got "function" instead. +// at line 56 of function Checktype called by : +// at line 359 of function intfmincon called by : +// [x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 46 of exec file called by : +// exec intfmincon_hess2.sce + +function [c,ceq]=nlc(x) + c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1]; + ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75]; +endfunction + +function y= fGrad(x) + y= [x(2),x(1)+x(3),x(2)]; +endfunction + +//Wrong dimensions of Hessian here +function y= lHess(x,obj,lambda) + y= obj*[0,1;1,0;0,1] + lambda(1)*[2,0;0,0;0,0] + lambda(2)*[2,0;0,2;0,0] +lambda(3)*[0,0;0,0;0,0] + lambda(4)*[6*x(1),0;0,0;0,0] + lambda(5)*[0,0;0,2;0,0]; +endfunction + +options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess); + +[x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) diff --git a/tests/general_tests/intfmincon/intfmincon_lb1.sce b/tests/general_tests/intfmincon/intfmincon_lb1.sce new file mode 100644 index 0000000..2c5ae22 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_lb1.sce @@ -0,0 +1,27 @@ + +//Check if lower bound is a vector + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4;5,9]; +ub = []; +intcon=[1,2]; +options=list("MaxIter", [1500], "CpuTime", [500]); + +// !--error 10000 +// intfmincon: Expected a vector matrix for input argument lb at input #8, but got [2 2] instead. +// at line 49 of function Checkvector called by : +// at line 313 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); +// at line 25 of exec file called by : +// exec intfmincon_lb1.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_lb2.sce b/tests/general_tests/intfmincon/intfmincon_lb2.sce new file mode 100644 index 0000000..7979780 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_lb2.sce @@ -0,0 +1,25 @@ + +//Check if lower bound is row vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4,9]; +ub = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); +intcon=[1,2]; +// !--error 10000 +// intfmincon: Expected 2 entries for input argument lb at input #8, but current dimensions are [1 3] instead. +// at line 54 of function Checkvector called by : +// at line 313 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); +// at line 24 of exec file called by : +// exec intfmincon_lb2.sce + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_lb3.sce b/tests/general_tests/intfmincon/intfmincon_lb3.sce new file mode 100644 index 0000000..78f0306 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_lb3.sce @@ -0,0 +1,27 @@ + +//Check if lower bound is column vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2;4;9]; +ub = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); +intcon=[1,2]; + +// !--error 10000 +// intfmincon: Expected 2 entries for input argument lb at input #8, but current dimensions are [3 1] instead. +// at line 54 of function Checkvector called by : +// at line 313 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); +// at line 24 of exec file called by : +// exec intfmincon_lb3.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_lb4.sce b/tests/general_tests/intfmincon/intfmincon_lb4.sce new file mode 100644 index 0000000..1a46587 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_lb4.sce @@ -0,0 +1,21 @@ + +//Check if lower bound is not infinity + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [%inf,4]; +ub = []; +intcon=[1,2]; + +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// MINLP Error. + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_logical1.sce b/tests/general_tests/intfmincon/intfmincon_logical1.sce new file mode 100644 index 0000000..db04835 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical1.sce @@ -0,0 +1,45 @@ +// Example with objective function and inequality constraints + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; + +//Output +//Optimal Solution Found. +// hessian = +// +// 2. - 7.451D-09 +// - 7.451D-09 2. +// gradient = +// +// 1.0000000 1. +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [9.087D-09,2.424D-08,4.546D-09,5.596D-09,1,4.544D-09] +// eqlin: [0x0 constant] +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 8 +// Cpu_Time: 0.112 +// Objective_Evaluation: 9 +// Dual_Infeasibility: 1.299D-11 +// exitflag = +// +// 0 +// fopt = +// +// 0.5 +// x0pt = +// +// 0.5000000 +// 0.5000000 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b) diff --git a/tests/general_tests/intfmincon/intfmincon_logical10.sce b/tests/general_tests/intfmincon/intfmincon_logical10.sce new file mode 100644 index 0000000..2865092 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical10.sce @@ -0,0 +1,38 @@ +//Example where user provides hessian + +function y=f(x) +y=x(1)*x(2)+x(2)*x(3); +endfunction +//Starting point, linear constraints and variable bounds +x0=[0.1 , 0.1 , 0.1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[]; +ub=[]; +intcon=[1,2]; +//Nonlinear constraints +// function [c,ceq]=nlc(x) +// c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 ; x(1)^2 + x(2)^2 + x(3)^2 - 10]'; +// ceq = []; +// endfunction +nlc="Hello"; +//Hessian of the Lagrange Function +function y= lHess(x,obj,lambda) +y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,-2,0;0,0,2] + lambda(2)*[2,0,0;0,2,0;0,0,2] +endfunction + +//Options +options=list("MaxIter", [100], "CpuTime", [1500], "Hessian", lHess); + +//Calling fmincon +[xopt,fopt,exitflag,output,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) + +// !--error 10000 +// intfmincon: Expected type ["constant" or "function"] for input argument nlc at input #10, but got "string" instead. +// at line 56 of function Checktype called by : +// at line 263 of function intfmincon called by : +// [xopt,fopt,exitflag,output,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 30 of exec file called by : +// exec intfmincon_logical10.sce diff --git a/tests/general_tests/intfmincon/intfmincon_logical11.sce b/tests/general_tests/intfmincon/intfmincon_logical11.sce new file mode 100644 index 0000000..613b3ce --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical11.sce @@ -0,0 +1,31 @@ +// Example with objective function using log functions + +function y=fun(x) +y=log(x(1)+x(2)); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +intcon=[1,2]; + +//Output +// Optimal Solution Found. +// hessian = + +// - 1. - 1. - 1. - 1. +// gradient = + +// 1. 1. +// exitflag = + +// 0 +// fopt = + +// 0. +// x0pt = + +// 0. +// 1. + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon, A, b) diff --git a/tests/general_tests/intfmincon/intfmincon_logical12.sce b/tests/general_tests/intfmincon/intfmincon_logical12.sce new file mode 100644 index 0000000..f40e8ac --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical12.sce @@ -0,0 +1,32 @@ +// Example with Infeasible solution +function y=fun(x) + y=-sum(exp(x)) +endfunction + +x0 = [repmat(1,1,20)]; +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; +intcon=[1,2]; + +lb = repmat(0,1,20); +ub = repmat(10,1,20); + +// InFeasible Solution. +// hessian = + +// [] +// gradient = + +// [] +// exitflag = + +// 1 +// fopt = + +// 0. +// x0pt = + +// [] + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon,A,b,[],[],lb,ub) diff --git a/tests/general_tests/intfmincon/intfmincon_logical2.sce b/tests/general_tests/intfmincon/intfmincon_logical2.sce new file mode 100644 index 0000000..aa706c2 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical2.sce @@ -0,0 +1,47 @@ +// Example with objective function, equality and inequality constraints + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [1.5] + +//Output +//Optimal Solution Found. +// hessian = +// +// 2. 0. +// 0. 2. +// gradient = +// +// 1.5 0.5000000 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [9.089D-09,4.842D-08,6.059D-09,6.324D-09,2.0000001,3.637D-09] +// eqlin: 0.5000000 +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 8 +// Cpu_Time: 0.092 +// Objective_Evaluation: 9 +// Dual_Infeasibility: 1.869D-11 +// exitflag = +// +// 0 +// fopt = +// +// 0.6250000 +// x0pt = +// +// 0.7500000 +// 0.25 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b,Aeq,beq) diff --git a/tests/general_tests/intfmincon/intfmincon_logical23.sce b/tests/general_tests/intfmincon/intfmincon_logical23.sce new file mode 100644 index 0000000..d62fe03 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical23.sce @@ -0,0 +1,31 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum((sin(x)).^2 + (cos(x)).^2) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); +intcon=[1,2]; + +// Optimal Solution Found. +// hessian = + +// 0. 0. 0. 0. 0. 0. 0. 0. 0. +// gradient = + +// 0. 0. 0. +// exitflag = + +// 0 +// fopt = + +// 3. +// x0pt = + +// 7115. +// 10. +// 51309.553 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon,A,b,[],[],lb,[]) diff --git a/tests/general_tests/intfmincon/intfmincon_logical24.sce b/tests/general_tests/intfmincon/intfmincon_logical24.sce new file mode 100644 index 0000000..c6e6279 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical24.sce @@ -0,0 +1,35 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum((sin(x)).^2 + (cos(x)).^2) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); +intcon=[1,2]; +function [c,ceq]=nlc(x) + c = [ -sum((sin(x)).^2 + (cos(x)).^2) + 1.5]; + ceq = []; +endfunction + +// Optimal Solution Found. +// hessian = + +// 0. 0. 0. 0. 0. 0. 0. 0. 0. +// gradient = + +// 0. 0. 0. +// exitflag = + +// 0 +// fopt = + +// 3. +// x0pt = + +// 4115. +// 519. +// 52357.435 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/intfmincon/intfmincon_logical3.sce b/tests/general_tests/intfmincon/intfmincon_logical3.sce new file mode 100644 index 0000000..1aa9e1d --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical3.sce @@ -0,0 +1,49 @@ +// Example with objective function, equality, inequality constraints and variable bounds + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +//Output +//Optimal Solution Found. +// hessian = +// +// 2. 0. +// 0. 2. +// gradient = +// +// 0.9999999 3. +// lambda = +// +// lower: [1.820D-08,6.060D-09] +// upper: [6.059D-09,0.7267088] +// ineqlin: [0.3633544,7.251D-08,3.030D-09,3.463D-09,9.093D-09,9.096D-09] +// eqlin: -1.3633544 +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 21 +// Cpu_Time: 0.2 +// Objective_Evaluation: 26 +// Dual_Infeasibility: 9.075D-11 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// x0pt = +// +// 0.5000000 +// 1.5 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub) diff --git a/tests/general_tests/intfmincon/intfmincon_logical4.sce b/tests/general_tests/intfmincon/intfmincon_logical4.sce new file mode 100644 index 0000000..b4fc982 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical4.sce @@ -0,0 +1,54 @@ +// Example with objective function, equality, inequality constraints, variable bounds and non linear function + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 ; x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +//Output +//Optimal Solution Found. +// hessian = +// +// 3970695.7 3.311D-10 +// 3.311D-10 3970695.5 +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.7272728] +// ineqlin: [0.3636363,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2698905 +// ineqnonlin: [6.061D-09,0.9062541] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.4 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 5.171D-09 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// x0pt = +// +// 0.5000000 +// 1.5 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub,nlc) diff --git a/tests/general_tests/intfmincon/intfmincon_logical5.sce b/tests/general_tests/intfmincon/intfmincon_logical5.sce new file mode 100644 index 0000000..e8f4290 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical5.sce @@ -0,0 +1,56 @@ +// Example with objective function, equality, inequality constraints, variable bounds, non linear function and options + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +options = list("MaxIter", [1500], "CpuTime", [500]) + +//Output +//Optimal Solution Found. +// hessian = +// +// 3970695.7 3.311D-10 +// 3.311D-10 3970695.5 +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.7272728] +// ineqlin: [0.3636363,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2698905 +// ineqnonlin: [6.061D-09,0.9062541] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.4 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 5.171D-09 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// x0pt = +// +// 0.5000000 +// 1.5 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/intfmincon/intfmincon_logical6.sce b/tests/general_tests/intfmincon/intfmincon_logical6.sce new file mode 100644 index 0000000..5ae9c99 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical6.sce @@ -0,0 +1,45 @@ +// Example with objective function using sinusoidal functions + +function y=fun(x) +y=sin(x(1))+cos(x(2)); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; + +//Output +//Optimal Solution Found. +// hessian = +// +// 0.2129952 0. +// 0. 0.2129198 +// gradient = +// +// 0.9770613 - 0.9770613 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [2.270D-08,1.202D-08,2.272D-09,3.316D-09,1.571D-08,0.9770613] +// eqlin: [0x0 constant] +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 12 +// Cpu_Time: 0.132 +// Objective_Evaluation: 15 +// Dual_Infeasibility: 7.674D-10 +// exitflag = +// +// 0 +// fopt = +// +// - 0.4259168 +// x0pt = +// +// - 0.2146019 +// 1.7853981 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b) diff --git a/tests/general_tests/intfmincon/intfmincon_logical7.sce b/tests/general_tests/intfmincon/intfmincon_logical7.sce new file mode 100644 index 0000000..280e04b --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical7.sce @@ -0,0 +1,45 @@ +// Example with objective function using exponential input + +function y=fun(x) + y=exp(x(2)*x(1)); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4]; +b=[2;1]; + +//Output +//Optimal Solution Found. +// hessian = +// +// 0.0000010 - 0.0000007 +// - 0.0000007 0.0000005 +// gradient = +// +// 7.127D-08 - 5.690D-08 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [6.963D-09,2.501D-09] +// eqlin: [0x0 constant] +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 15 +// Cpu_Time: 0.132 +// Objective_Evaluation: 16 +// Dual_Infeasibility: 8.073D-08 +// exitflag = +// +// 0 +// fopt = +// +// 1.500D-08 +// x0pt = +// +// - 3.7925137 +// 4.7501487 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b) diff --git a/tests/general_tests/intfmincon/intfmincon_logical8.sce b/tests/general_tests/intfmincon/intfmincon_logical8.sce new file mode 100644 index 0000000..45b1a1f --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical8.sce @@ -0,0 +1,60 @@ +// Example where user provides gradient of the objective function + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +function y= fGrad(x) +y= [2*x(1),2*x(2)]; +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +options = list("MaxIter", [150], "CpuTime", [500], "GradObj", fGrad) + +//Output +//Optimal Solution Found. +// hessian = +// +// 3970695.6 3.311D-10 +// 3.311D-10 3970695.4 +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.7272728] +// ineqlin: [0.3636363,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2698905 +// ineqnonlin: [6.061D-09,0.9062542] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.852 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 1.884D-09 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// x0pt = +// +// 0.5000000 +// 1.5 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/intfmincon/intfmincon_logical9.sce b/tests/general_tests/intfmincon/intfmincon_logical9.sce new file mode 100644 index 0000000..d7630d7 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_logical9.sce @@ -0,0 +1,63 @@ +// Example where user provides gradient of the constraints + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +//Gradient of Non-Linear Constraints +function [cg,ceqg] = cGrad(x) +cg=[2*x(1) , -2*x(2); 2*x(1) , 2*x(2)]; +ceqg=[]; +endfunction + +options = list("MaxIter", [150], "CpuTime", [500], "GradCon", cGrad) + +//Output +//Optimal Solution Found. +// hessian = +// +// 3353468.3 3.95D-323 +// 0. 0. +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.6917463] +// ineqlin: [0.3458731,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2520096 +// ineqnonlin: [6.061D-09,0.9061364] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.34 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 2.793D-09 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// x0pt = +// +// 0.5000000 +// 1.5 + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/intfmincon/intfmincon_maxiter.sce b/tests/general_tests/intfmincon/intfmincon_maxiter.sce new file mode 100644 index 0000000..b610131 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_maxiter.sce @@ -0,0 +1,50 @@ +// Example where maxiter exceeds the preset value + +function y=f(x) +y=x(1)*x(2)+x(2)*x(3); +endfunction +//Starting point, linear constraints and variable bounds +x0=[0.1 , 0.1 , 0.1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[]; +ub=[]; +intcon=[1,2]; +//Nonlinear constraints +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 ; x(1)^2 + x(2)^2 + x(3)^2 - 10]'; +ceq = []; +endfunction + +//Hessian of the Lagrange Function +function y= lHess(x,obj,lambda) +y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,-2,0;0,0,2] + lambda(2)*[2,0,0;0,2,0;0,0,2] +endfunction + +//Options +options=list("MaxIter", [5], "CpuTime", [1500], "Hessian", lHess); + +//Calling fmincon +[xopt,fopt,exitflag,output,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) + +// Limit Exceeded. +// hessian = + +// 0. 1. 0. 1. 0. 1. 0. 1. 0. +// output = + +// - 2. 3.4142136 - 2. +// exitflag = + +// 3 +// fopt = + +// - 6.8284271 +// xopt = + +// 2. +// - 2. +// 1.4142136 + diff --git a/tests/general_tests/intfmincon/intfmincon_nlc.sce b/tests/general_tests/intfmincon/intfmincon_nlc.sce new file mode 100644 index 0000000..2ab07fb --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_nlc.sce @@ -0,0 +1,38 @@ +//nlc not a function + +function y=f(x) +y=x(1)*x(2)+x(2)*x(3); +endfunction +//Starting point, linear constraints and variable bounds +x0=[0.1 , 0.1 , 0.1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[]; +ub=[]; +intcon=[1,2]; +//Nonlinear constraints +// function [c,ceq]=nlc(x) +// c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 ; x(1)^2 + x(2)^2 + x(3)^2 - 10]'; +// ceq = []; +// endfunction +nlc="Hello"; +//Hessian of the Lagrange Function +function y= lHess(x,obj,lambda) +y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,-2,0;0,0,2] + lambda(2)*[2,0,0;0,2,0;0,0,2] +endfunction + +//Options +options=list("MaxIter", [100], "CpuTime", [1500], "Hessian", lHess); + +//Calling fmincon +[xopt,fopt,exitflag,output,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) + +// !--error 10000 +// intfmincon: Expected type ["constant" or "function"] for input argument nlc at input #10, but got "string" instead. +// at line 56 of function Checktype called by : +// at line 263 of function intfmincon called by : +// [xopt,fopt,exitflag,output,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 30 of exec file called by : +// exec intfmincon_logical10.sce diff --git a/tests/general_tests/intfmincon/intfmincon_options1.sce b/tests/general_tests/intfmincon/intfmincon_options1.sce new file mode 100644 index 0000000..29261e5 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_options1.sce @@ -0,0 +1,32 @@ + +//Unknown option + +function y=f(x) + y=x(1)*x(2)+x(2)*x(3); +endfunction + +x0=[1,1,1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; +intcon=[1,2] +// !--error 999 +// Unknown string argument passed. +// at line 380 of function intfmincon called by : +// [x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 31 of exec file called by : +// exec intfmincon_options1.sce + + +function [c,ceq]=nlc(x) + c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1]; + ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75]; +endfunction + + +options=list("Maximum", [1500], "CpuTime", [500]); + +[x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) diff --git a/tests/general_tests/intfmincon/intfmincon_options2.sce b/tests/general_tests/intfmincon/intfmincon_options2.sce new file mode 100644 index 0000000..e23ddd1 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_options2.sce @@ -0,0 +1,31 @@ + +//Typing error in arguments to options + +function y=f(x) + y=x(1)*x(2)+x(2)*x(3); +endfunction + +x0=[1,1,1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; +intcon=[1,2]; +// !--error 999 +// Unknown string argument passed. +// at line 380 of function intfmincon called by : +// [x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// at line 44 of exec file called by : +// exec intfmincon_options2.sce + +function [c,ceq]=nlc(x) + c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1]; + ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75]; +endfunction + +//Typing error: Expected "GradObj" instead of "GradientObj" +options=list("MaxIter", [1500], "CpuTime", [500]); + +[x,fval,exitflag,grad,hessian] =intfmincon(f,x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) diff --git a/tests/general_tests/intfmincon/intfmincon_ub1.sce b/tests/general_tests/intfmincon/intfmincon_ub1.sce new file mode 100644 index 0000000..14fdec1 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_ub1.sce @@ -0,0 +1,27 @@ + +//Check if upper bound is a vector + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4]; +ub = [3,4;7,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// !--error 10000 +// intfmincon: Expected a vector matrix for input argument ub at input #9, but got [2 2] instead. +// at line 49 of function Checkvector called by : +// at line 316 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); +// at line 24 of exec file called by : +// exec intfmincon_ub1.sce + + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_ub2.sce b/tests/general_tests/intfmincon/intfmincon_ub2.sce new file mode 100644 index 0000000..892d81e --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_ub2.sce @@ -0,0 +1,27 @@ + +//Check if upper bound is row vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4]; +ub = [3,4,7]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); +intcon=[1,2] + +// !--error 10000 +// intfmincon: Expected 2 entries for input argument ub at input #9, but current dimensions are [1 3] instead. +// at line 54 of function Checkvector called by : +// at line 316 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); +// at line 24 of exec file called by : +// exec intfmincon_ub2.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_ub3.sce b/tests/general_tests/intfmincon/intfmincon_ub3.sce new file mode 100644 index 0000000..f4a9d52 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_ub3.sce @@ -0,0 +1,27 @@ + +//Check if lower bound is column vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4]; +ub = [3;4;7]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); +intcon=[1,2]; + +// !--error 10000 +// intfmincon: Expected 2 entries for input argument ub at input #9, but current dimensions are [3 1] instead. +// at line 54 of function Checkvector called by : +// at line 316 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); +// at line 24 of exec file called by : +// exec intfmincon_ub3.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_ub4.sce b/tests/general_tests/intfmincon/intfmincon_ub4.sce new file mode 100644 index 0000000..3ceed48 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_ub4.sce @@ -0,0 +1,20 @@ + +//Check if upper bound is not -infinity + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = []; +ub = [-%inf,6]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// MINLP Error. + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(fun,x0,intcon, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/intfmincon/intfmincon_x0a.sce b/tests/general_tests/intfmincon/intfmincon_x0a.sce new file mode 100644 index 0000000..d1e328d --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_x0a.sce @@ -0,0 +1,21 @@ + +// Check if a user specifies a starting point or not + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = []; +A = [3,4]; +b = [7,9]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +// !--error 10000 +// intfmincon: x0 cannot be an empty +// at line 270 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); +// at line 20 of exec file called by : +// exec intfmincon_x0a.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); diff --git a/tests/general_tests/intfmincon/intfmincon_x0b.sce b/tests/general_tests/intfmincon/intfmincon_x0b.sce new file mode 100644 index 0000000..2bbeaa9 --- /dev/null +++ b/tests/general_tests/intfmincon/intfmincon_x0b.sce @@ -0,0 +1,22 @@ + +// Check if a user specifies a starting point of the correct dimensions with respect to the objective function + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1]; +A = [3,4]; +b = [7,9]; +options=list("MaxIter", [1500], "CpuTime", [500]); + +// // !--error 999 +// Expected Matrix of size (No of linear inequality constraints X No of Variables) or +// an Empty Matrix for Linear Inequality Constraint coefficient Matrix A +// at line 285 of function intfmincon called by : +// [x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); +// at line 20 of exec file called by : +// exec intfmincon_x0b.sce + + +[x0pt,fopt,exitflag,gradient,hessian] = intfmincon(f,x0,intcon, A, b); |