diff options
Diffstat (limited to 'demos')
-rw-r--r-- | demos/cbcintlinprog.dem.sce | 104 | ||||
-rw-r--r-- | demos/ecos.dem.sce | 56 | ||||
-rw-r--r-- | demos/intfminbnd.dem.sce | 55 | ||||
-rw-r--r-- | demos/intfmincon.dem.sce | 136 | ||||
-rw-r--r-- | demos/intfminimax.dem.sce | 57 | ||||
-rw-r--r-- | demos/intfminunc.dem.sce | 49 | ||||
-rw-r--r-- | demos/intqpipopt.dem.sce | 32 | ||||
-rw-r--r-- | demos/matrix_cbcintlinprog.sci | 296 | ||||
-rw-r--r-- | demos/mps_cbcintlinprog.sci | 79 | ||||
-rw-r--r-- | demos/sci_FOSSEE_Optimization_Toolbox.dem.gateway.sce | 4 |
10 files changed, 866 insertions, 2 deletions
diff --git a/demos/cbcintlinprog.dem.sce b/demos/cbcintlinprog.dem.sce new file mode 100644 index 0000000..e04946a --- /dev/null +++ b/demos/cbcintlinprog.dem.sce @@ -0,0 +1,104 @@ +mode(1) +// +// Demo of cbcintlinprog.sci +// + +// Objective function +// Reference: Westerberg, Carl-Henrik, Bengt Bjorklund, and Eskil Hultman. "An application of mixed integer programming in a Swedish steel mill." Interfaces 7, no. 2 (1977): 39-43. +c = [350*5,330*3,310*4,280*6,500,450,400,100]'; +// Lower Bound of variable +lb = repmat(0,1,8); +// Upper Bound of variables +ub = [repmat(1,1,4) repmat(%inf,1,4)]; +// Constraint Matrix +Aeq = [5,3,4,6,1,1,1,1; +5*0.05,3*0.04,4*0.05,6*0.03,0.08,0.07,0.06,0.03; +5*0.03,3*0.03,4*0.04,6*0.04,0.06,0.07,0.08,0.09;] +beq = [ 25, 1.25, 1.25] +intcon = [1 2 3 4]; +// Calling Symphony +[x,f,status,output] = cbcintlinprog(c,intcon,[],[],Aeq,beq,lb,ub) +// Press ENTER to continue +halt() // Press return to continue + +// An advanced case where we set some options in symphony +// This problem is taken from +// P.C.Chu and J.E.Beasley +// "A genetic algorithm for the multidimensional knapsack problem", +// Journal of Heuristics, vol. 4, 1998, pp63-86. +// The problem to be solved is: +// Max sum{j=1,...,n} p(j)x(j) +// st sum{j=1,...,n} r(i,j)x(j) <= b(i) i=1,...,m +// x(j)=0 or 1 +// The function to be maximize i.e. P(j) +c = -1*[ 504 803 667 1103 834 585 811 856 690 832 846 813 868 793 .. +825 1002 860 615 540 797 616 660 707 866 647 746 1006 608 .. +877 900 573 788 484 853 942 630 591 630 640 1169 932 1034 .. +957 798 669 625 467 1051 552 717 654 388 559 555 1104 783 .. +959 668 507 855 986 831 821 825 868 852 832 828 799 686 .. +510 671 575 740 510 675 996 636 826 1022 1140 654 909 799 .. +1162 653 814 625 599 476 767 954 906 904 649 873 565 853 1008 632]'; +// Constraint Matrix +A = [ //Constraint 1 +42 41 523 215 819 551 69 193 582 375 367 478 162 898 .. +550 553 298 577 493 183 260 224 852 394 958 282 402 604 .. +164 308 218 61 273 772 191 117 276 877 415 873 902 465 .. +320 870 244 781 86 622 665 155 680 101 665 227 597 354 .. +597 79 162 998 849 136 112 751 735 884 71 449 266 420 .. +797 945 746 46 44 545 882 72 383 714 987 183 731 301 .. +718 91 109 567 708 507 983 808 766 615 554 282 995 946 651 298; +//Constraint 2 +509 883 229 569 706 639 114 727 491 481 681 948 687 941 .. +350 253 573 40 124 384 660 951 739 329 146 593 658 816 .. +638 717 779 289 430 851 937 289 159 260 930 248 656 833 .. +892 60 278 741 297 967 86 249 354 614 836 290 893 857 .. +158 869 206 504 799 758 431 580 780 788 583 641 32 653 .. +252 709 129 368 440 314 287 854 460 594 512 239 719 751 .. +708 670 269 832 137 356 960 651 398 893 407 477 552 805 881 850; +//Constraint 3 +806 361 199 781 596 669 957 358 259 888 319 751 275 177 .. +883 749 229 265 282 694 819 77 190 551 140 442 867 283 .. +137 359 445 58 440 192 485 744 844 969 50 833 57 877 .. +482 732 968 113 486 710 439 747 174 260 877 474 841 422 .. +280 684 330 910 791 322 404 403 519 148 948 414 894 147 .. +73 297 97 651 380 67 582 973 143 732 624 518 847 113 .. +382 97 905 398 859 4 142 110 11 213 398 173 106 331 254 447 ; +//Constraint 4 +404 197 817 1000 44 307 39 659 46 334 448 599 931 776 .. +263 980 807 378 278 841 700 210 542 636 388 129 203 110 .. +817 502 657 804 662 989 585 645 113 436 610 948 919 115 .. +967 13 445 449 740 592 327 167 368 335 179 909 825 614 .. +987 350 179 415 821 525 774 283 427 275 659 392 73 896 .. +68 982 697 421 246 672 649 731 191 514 983 886 95 846 .. +689 206 417 14 735 267 822 977 302 687 118 990 323 993 525 322; +//Constraint 5 +475 36 287 577 45 700 803 654 196 844 657 387 518 143 .. +515 335 942 701 332 803 265 922 908 139 995 845 487 100 .. +447 653 649 738 424 475 425 926 795 47 136 801 904 740 .. +768 460 76 660 500 915 897 25 716 557 72 696 653 933 .. +420 582 810 861 758 647 237 631 271 91 75 756 409 440 .. +483 336 765 637 981 980 202 35 594 689 602 76 767 693 .. +893 160 785 311 417 748 375 362 617 553 474 915 457 261 350 635 ; +]; +nbVar = size(c,1); +b=[11927 13727 11551 13056 13460 ]; +// Lower Bound of variables +lb = repmat(0,1,nbVar); +// Upper Bound of variables +ub = repmat(1,1,nbVar); +// Lower Bound of constrains +intcon = []; +for i = 1:nbVar +intcon = [intcon i]; +end +options = list('MaxTime', 25); +// The expected solution : +// Output variables +xopt = [0 1 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 1 1 0 1 .. +0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 .. +0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 1 0]; +// Optimal value +fopt = [ 24381 ] +// Calling cbc +[x,f,status,output] = cbcintlinprog(c,intcon,A,b,[],[],lb,ub,options); +//========= E N D === O F === D E M O =========// diff --git a/demos/ecos.dem.sce b/demos/ecos.dem.sce new file mode 100644 index 0000000..7bf5621 --- /dev/null +++ b/demos/ecos.dem.sce @@ -0,0 +1,56 @@ +// +// Demo of cbcintlinprog.sci +// + + +// Objective function + c = [-750 -1000]; + // Constraint inequality matrix LHS + G = [ + 1 1; + 1 2; + 4 3; + ]; + // Constraint inequality matrix RHS + h = [10 15 25]'; + // Constraint equality matrix LHS + A = [ + 0.5 1 + ]; + // Constraint equality matrix RHS + b=[7.5]; + // Dimension of positive orthant + l = [3]; + q = []; + e = []; + dims=list("l",l,"q",q,"e",e) + //Calling ecos + [x,y,s,z,info,status] =ecos(c,G,h,dims,A,b); + + +halt() // Press return to continue + + // Objective function + c = [0 0 0 0 1]; + //Constraint inequality matrix LHS + G = [ + 0.4167578 0.0562668 0. 0. 0. + 2.1361961 -1.6402708 0. 0. 0. + 1.7934356 0.8417474 0. 0. 0. + 0. 0. 0.4167578 0.0562668 0. + 0. 0. 2.1361961 -1.6402708 0. + 0. 0. 1.7934356 0.8417474 0. + 0. 0. 0. 0. -1. + -1. 0. 0. 0. 0. + 0. -1. 0. 0. 0. + 0. 0. -1. 0. 0. + 0. 0. 0. -1. 0. + ]; + //Constraint inequality matrix RHS + h = [0 0 0 0 0 0 0 0 0 0 0]'; + // Dimension of positive orthant + l = [6]; + q = [5]; + e = [0] + dims=list("l",l,"q",q,"e",e) + [x,y,s,z,info,status] =ecos(c,G,h,dims);
\ No newline at end of file diff --git a/demos/intfminbnd.dem.sce b/demos/intfminbnd.dem.sce new file mode 100644 index 0000000..adbc9fa --- /dev/null +++ b/demos/intfminbnd.dem.sce @@ -0,0 +1,55 @@ +mode(1) +// +// Demo of intfminbnd.sci +// + +//Find x in R^6 such that it minimizes: +//f(x)= sin(x1) + sin(x2) + sin(x3) + sin(x4) + sin(x5) + sin(x6) +//-2 <= x1,x2,x3,x4,x5,x6 <= 2 +//Objective function to be minimised +function y=f(x) +y=0 +for i =1:6 +y=y+sin(x(i)); +end +endfunction +//Variable bounds +x1 = [-2, -2, -2, -2, -2, -2]; +x2 = [2, 2, 2, 2, 2, 2]; +intcon = [2 3 4] +//Options +options=list("MaxIter",[1500],"CpuTime", [100]) +[x,fval] =intfminbnd(f ,intcon, x1, x2, options) +// Press ENTER to continue +halt() // Press return to continue + +//Find x in R such that it minimizes: +//f(x)= 1/x^2 +//0 <= x <= 1000 +//Objective function to be minimised +function y=f(x) +y=1/x^2; +endfunction +//Variable bounds +x1 = [0]; +x2 = [1000]; +intcon = [1]; +[x,fval,exitflag,output,lambda] =intfminbnd(f,intcon , x1, x2) +// Press ENTER to continue +halt() // Press return to continue + +//The below problem is an unbounded problem: +//Find x in R^2 such that it minimizes: +//f(x)= -[(x1-1)^2 + (x2-1)^2] +//-inf <= x1,x2 <= inf +//Objective function to be minimised +function y=f(x) +y=-((x(1)-1)^2+(x(2)-1)^2); +endfunction +//Variable bounds +x1 = [-%inf , -%inf]; +x2 = [ %inf , %inf]; +//Options +options=list("MaxIter",[1500],"CpuTime", [100]) +[x,fval,exitflag,output,lambda] =intfminbnd(f,intcon, x1, x2, options) +//========= E N D === O F === D E M O =========// diff --git a/demos/intfmincon.dem.sce b/demos/intfmincon.dem.sce new file mode 100644 index 0000000..ef43b4b --- /dev/null +++ b/demos/intfmincon.dem.sce @@ -0,0 +1,136 @@ +mode(1) +// +// Demo of intfmincon.sci +// + +//Find x in R^2 such that it minimizes: +//f(x)= -x1 -x2/3 +//x0=[0,0] +//constraint-1 (c1): x1 + x2 <= 2 +//constraint-2 (c2): x1 + x2/4 <= 1 +//constraint-3 (c3): x1 - x2 <= 2 +//constraint-4 (c4): -x1/4 - x2 <= 1 +//constraint-5 (c5): -x1 - x2 <= -1 +//constraint-6 (c6): -x1 + x2 <= 2 +//constraint-7 (c7): x1 + x2 = 2 +//Objective function to be minimised +function [y,dy]=f(x) +y=-x(1)-x(2)/3; +dy= [-1,-1/3]; +endfunction +//Starting point, linear constraints and variable bounds +x0=[0 , 0]; +intcon = [1] +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq=[1,1]; +beq=[2]; +lb=[]; +ub=[]; +nlc=[]; +//Options +options=list("GradObj", "on"); +//Calling Ipopt +[x,fval,exitflag,grad,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// Press ENTER to continue +halt() // Press return to continue + +//Find x in R^3 such that it minimizes: +//f(x)= x1*x2 + x2*x3 +//x0=[0.1 , 0.1 , 0.1] +//constraint-1 (c1): x1^2 - x2^2 + x3^2 <= 2 +//constraint-2 (c2): x1^2 + x2^2 + x3^2 <= 10 +//Objective function to be minimised +function [y,dy]=f(x) +y=x(1)*x(2)+x(2)*x(3); +dy= [x(2),x(1)+x(3),x(2)]; +endfunction +//Starting point, linear constraints and variable bounds +x0=[0.1 , 0.1 , 0.1]; +intcon = [2] +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[]; +ub=[]; +//Nonlinear constraints +function [c,ceq,cg,cgeq]=nlc(x) +c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 , x(1)^2 + x(2)^2 + x(3)^2 - 10]; +ceq = []; +cg=[2*x(1) , -2*x(2) , 2*x(3) ; 2*x(1) , 2*x(2) , 2*x(3)]; +cgeq=[]; +endfunction +//Options +options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", "on","GradCon", "on"); +//Calling Ipopt +[x,fval,exitflag,output] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// Press ENTER to continue +halt() // Press return to continue + +//The below problem is an unbounded problem: +//Find x in R^3 such that it minimizes: +//f(x)= -(x1^2 + x2^2 + x3^2) +//x0=[0.1 , 0.1 , 0.1] +// x1 <= 0 +// x2 <= 0 +// x3 <= 0 +//Objective function to be minimised +function y=f(x) +y=-(x(1)^2+x(2)^2+x(3)^2); +endfunction +//Starting point, linear constraints and variable bounds +x0=[0.1 , 0.1 , 0.1]; +intcon = [3] +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[]; +ub=[0,0,0]; +//Options +options=list("MaxIter", [1500], "CpuTime", [500]); +//Calling Ipopt +[x,fval,exitflag,grad,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,[],options) +// Press ENTER to continue +halt() // Press return to continue + +//The below problem is an infeasible problem: +//Find x in R^3 such that in minimizes: +//f(x)=x1*x2 + x2*x3 +//x0=[1,1,1] +//constraint-1 (c1): x1^2 <= 1 +//constraint-2 (c2): x1^2 + x2^2 <= 1 +//constraint-3 (c3): x3^2 <= 1 +//constraint-4 (c4): x1^3 = 0.5 +//constraint-5 (c5): x2^2 + x3^2 = 0.75 +// 0 <= x1 <=0.6 +// 0.2 <= x2 <= inf +// -inf <= x3 <= 1 +//Objective function to be minimised +function [y,dy]=f(x) +y=x(1)*x(2)+x(2)*x(3); +dy= [x(2),x(1)+x(3),x(2)]; +endfunction +//Starting point, linear constraints and variable bounds +x0=[1,1,1]; +intcon = [2] +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; +//Nonlinear constraints +function [c,ceq,cg,cgeq]=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]; +cg = [2*x(1),0,0;2*x(1),2*x(2),0;0,0,2*x(3)]; +cgeq = [3*x(1)^2,0,0;0,2*x(2),2*x(3)]; +endfunction +//Options +options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", "on","GradCon", "on"); +//Calling Ipopt +[x,fval,exitflag,grad,hessian] =intfmincon(f, x0,intcon,A,b,Aeq,beq,lb,ub,nlc,options) +// Press ENTER to continue +//========= E N D === O F === D E M O =========// diff --git a/demos/intfminimax.dem.sce b/demos/intfminimax.dem.sce new file mode 100644 index 0000000..db74b92 --- /dev/null +++ b/demos/intfminimax.dem.sce @@ -0,0 +1,57 @@ +mode(1) +// +// Demo of intfminimax.sci +// + +// A basic case : +// we provide only the objective function and the nonlinear constraint +// function +function f = myfun(x) +f(1)= 2*x(1)^2 + x(2)^2 - 48*x(1) - 40*x(2) + 304; //Objectives +f(2)= -x(1)^2 - 3*x(2)^2; +f(3)= x(1) + 3*x(2) -18; +f(4)= -x(1) - x(2); +f(5)= x(1) + x(2) - 8; +endfunction +// The initial guess +x0 = [0.1,0.1]; +// The expected solution : only 4 digits are guaranteed +xopt = [4 4] +fopt = [0 -64 -2 -8 0] +intcon = [1] +maxfopt = 0 +// Run fminimax +[x,fval,maxfval,exitflag] = intfminimax(myfun, x0,intcon) +// Press ENTER to continue +halt() // Press return to continue + +// A case where we provide the gradient of the objective +// functions and the Jacobian matrix of the constraints. +// The objective function and its gradient +function [f,G] = myfun(x) +f(1)= 2*x(1)^2 + x(2)^2 - 48*x(1) - 40*x(2) + 304; +f(2)= -x(1)^2 - 3*x(2)^2; +f(3)= x(1) + 3*x(2) -18; +f(4)= -x(1) - x(2); +f(5)= x(1) + x(2) - 8; +G = [ 4*x(1) - 48, -2*x(1), 1, -1, 1; +2*x(2) - 40, -6*x(2), 3, -1, 1; ]' +endfunction +// The nonlinear constraints +function [c,ceq,DC,DCeq] = confun(x) +// Inequality constraints +c = [1.5 + x(1)*x(2) - x(1) - x(2), -x(1)*x(2) - 10] +// No nonlinear equality constraints +ceq=[] +DC= [x(2)-1, -x(2); +x(1)-1, -x(1)]' +DCeq = []' +endfunction +// Test with both gradient of objective and gradient of constraints +minimaxOptions = list("GradObj","on","GradCon","on"); +// The initial guess +x0 = [0,10]; +intcon = [2] +// Run intfminimax +[x,fval,maxfval,exitflag] = intfminimax(myfun,x0,intcon,[],[],[],[],[],[], confun, minimaxOptions) +//========= E N D === O F === D E M O =========// diff --git a/demos/intfminunc.dem.sce b/demos/intfminunc.dem.sce new file mode 100644 index 0000000..97cbb2d --- /dev/null +++ b/demos/intfminunc.dem.sce @@ -0,0 +1,49 @@ +mode(1) +// +// Demo of intfminunc.sci +// + +//Find x in R^2 such that it minimizes the Rosenbrock function +//f = 100*(x2 - x1^2)^2 + (1-x1)^2 +//Objective function to be minimised +function y= f(x) +y= 100*(x(2) - x(1)^2)^2 + (1-x(1))^2; +endfunction +//Starting point +x0=[-1,2]; +intcon = [2] +//Options +options=list("MaxIter", [1500], "CpuTime", [500]); +//Calling +[xopt,fopt,exitflag,gradient,hessian]=intfminunc(f,x0,intcon,options) +// Press ENTER to continue +halt() // Press return to continue + +//Find x in R^2 such that the below function is minimum +//f = x1^2 + x2^2 +//Objective function to be minimised +function y= f(x) +y= x(1)^2 + x(2)^2; +endfunction +//Starting point +x0=[2,1]; +intcon = [1]; +[xopt,fopt]=intfminunc(f,x0,intcon) +// Press ENTER to continue +halt() // Press return to continue + +//The below problem is an unbounded problem: +//Find x in R^2 such that the below function is minimum +//f = - x1^2 - x2^2 +//Objective function to be minimised +function [y,g,h] = f(x) +y = -x(1)^2 - x(2)^2; +g = [-2*x(1),-2*x(2)]; +h = [-2,0;0,-2]; +endfunction +//Starting point +x0=[2,1]; +intcon = [1] +options = list("gradobj","ON","hessian","on"); +[xopt,fopt,exitflag,gradient,hessian]=intfminunc(f,x0,intcon,options) +//========= E N D === O F === D E M O =========// diff --git a/demos/intqpipopt.dem.sce b/demos/intqpipopt.dem.sce new file mode 100644 index 0000000..5d8686c --- /dev/null +++ b/demos/intqpipopt.dem.sce @@ -0,0 +1,32 @@ +mode(1) +// +// Demo of intqpipopt.sci +// + +H = [1 -1; -1 2]; +f = [-2; -6]; +A = [1 1; -1 2; 2 1]; +b = [2; 2; 3]; +lb=[0,0]; +ub=[%inf, %inf]; +intcon = [1 2]; +[xopt,fopt,status,output]=intqpipopt(H,f,intcon,A,b,[],[],lb,ub) +halt() // Press return to continue + +//Find x in R^6 such that: +Aeq= [1,-1,1,0,3,1; +-1,0,-3,-4,5,6; +2,5,3,0,1,0]; +beq=[1; 2; 3]; +A= [0,1,0,1,2,-1; +-1,0,2,1,1,0]; +b = [-1; 2.5]; +lb=[-1000; -10000; 0; -1000; -1000; -1000]; +ub=[10000; 100; 1.5; 100; 100; 1000]; +x0 = repmat(0,6,1); +param = list("MaxIter", 300, "CpuTime", 100); +//and minimize 0.5*x'*H*x + f'*x with +f=[1; 2; 3; 4; 5; 6]; H=eye(6,6); +intcon = [2 4]; +[xopt,fopt,exitflag,output]=intqpipopt(H,f,intcon,A,b,Aeq,beq,lb,ub,x0,param) +//========= E N D === O F === D E M O =========// diff --git a/demos/matrix_cbcintlinprog.sci b/demos/matrix_cbcintlinprog.sci new file mode 100644 index 0000000..ff71700 --- /dev/null +++ b/demos/matrix_cbcintlinprog.sci @@ -0,0 +1,296 @@ +// Code Authors: Akshay Miterani and Pranav Deshpande +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [xopt,fopt,status,output] = cbcmatrixintlinprog (varargin) + // Sci file wrapper for the matrix_cbcintlinprog.cpp file + + // To check the number of input and output argument + [lhs , rhs] = argn(); + + // To check the number of argument given by user + if ( rhs < 4 | rhs == 5 | rhs == 7 | rhs > 9 ) then + errmsg = msprintf(gettext("%s: Unexpected number of input arguments : %d provided while should be in the set [4 6 8 9]"), "cbcintlinprog", rhs); + error(errmsg); + end + + c = []; + intcon = []; + A = []; + b = []; + Aeq = []; + beq = []; + lb = []; + ub = []; + options = list(); + + c = varargin(1) + intcon = varargin(2) + A = varargin(3) + b = varargin(4) + + if(size(c,2) == 0) then + errmsg = msprintf(gettext("%s: Cannot determine the number of variables because input objective coefficients is empty"),"cbcintlinprog"); + error(errmsg); + end + + if (size(c,2)~=1) then + errmsg = msprintf(gettext("%s: Objective Coefficients should be a column matrix"), "cbcintlinprog"); + error(errmsg); + end + + nbVar = size(c,1); + + if ( rhs<5 ) then + Aeq = [] + beq = [] + else + Aeq = varargin(5); + beq = varargin(6); + end + + if ( rhs<7 ) then + lb = repmat(-%inf,1,nbVar); + ub = repmat(%inf,1,nbVar); + else + lb = varargin(7); + ub = varargin(8); + end + + if (rhs<9|size(varargin(9))==0) then + options = list(); + else + options = varargin(9); + end + + //Check type of variables + Checktype("cbcintlinprog", c, "c", 1, "constant") + Checktype("cbcintlinprog", intcon, "intcon", 2, "constant") + Checktype("cbcintlinprog", A, "A", 3, "constant") + Checktype("cbcintlinprog", b, "b", 4, "constant") + Checktype("cbcintlinprog", Aeq, "Aeq", 5, "constant") + Checktype("cbcintlinprog", beq, "beq", 6, "constant") + Checktype("cbcintlinprog", lb, "lb", 7, "constant") + Checktype("cbcintlinprog", ub, "ub", 8, "constant") + + // Check if the user gives empty matrix + if (size(lb,2)==0) then + lb = repmat(-%inf,nbVar,1); + end + + if (size(intcon,2)==0) then + intcon = []; + end + + if (size(ub,2)==0) then + ub = repmat(%inf,nbVar,1); + end + + // Calculating the size of equality and inequality constraints + nbConInEq = size(A,1); + nbConEq = size(Aeq,1); + + // Check if the user gives row vector + // and Changing it to a column matrix + + if (size(lb,2)== [nbVar]) then + lb = lb'; + end + + if (size(ub,2)== [nbVar]) then + ub = ub'; + end + + if (size(b,2)== [nbConInEq]) then + b = b'; + end + + if (size(beq,2)== [nbConEq]) then + beq = beq'; + end + + for i=1:size(intcon,2) + if(intcon(i)>nbVar) then + errmsg = msprintf(gettext("%s: The values inside intcon should be less than the number of variables"), "cbcintlinprog"); + error(errmsg); + end + + if (intcon(i)<0) then + errmsg = msprintf(gettext("%s: The values inside intcon should be greater than 0 "), "cbcintlinprog"); + error(errmsg); + end + + if(modulo(intcon(i),1)) then + errmsg = msprintf(gettext("%s: The values inside intcon should be an integer "), "cbcintlinprog"); + error(errmsg); + end + end + + //Check the size of inequality constraint which should equal to the number of inequality constraints + if ( size(A,2) ~= nbVar & size(A,2) ~= 0) then + errmsg = msprintf(gettext("%s: The size of inequality constraint is not equal to the number of variables"), "cbcintlinprog"); + error(errmsg); + end + + + //Check the size of lower bound of inequality constraint which should equal to the number of constraints + if ( size(b,1) ~= size(A,1)) then + errmsg = msprintf(gettext("%s: The Lower Bound of inequality constraint is not equal to the number of constraint"), "cbcintlinprog"); + error(errmsg); + end + + //Check the size of equality constraint which should equal to the number of inequality constraints + if ( size(Aeq,2) ~= nbVar & size(Aeq,2) ~= 0) then + errmsg = msprintf(gettext("%s: The size of equality constraint is not equal to the number of variables"), "cbcintlinprog"); + error(errmsg); + end + + //Check the size of upper bound of equality constraint which should equal to the number of constraints + if ( size(beq,1) ~= size(Aeq,1)) then + errmsg = msprintf(gettext("%s: The equality constraint upper bound is not equal to the number of equality constraint"), "cbcintlinprog"); + error(errmsg); + end + + //Check the size of Lower Bound which should equal to the number of variables + if ( size(lb,1) ~= nbVar) then + errmsg = msprintf(gettext("%s: The Lower Bound is not equal to the number of variables"), "cbcintlinprog"); + error(errmsg); + end + + //Check the size of Upper Bound which should equal to the number of variables + if ( size(ub,1) ~= nbVar) then + errmsg = msprintf(gettext("%s: The Upper Bound is not equal to the number of variables"), "cbcintlinprog"); + error(errmsg); + end + + if (type(options) ~= 15) then + errmsg = msprintf(gettext("%s: Options should be a list "), "cbcintlinprog"); + error(errmsg); + end + + + if (modulo(size(options),2)) then + errmsg = msprintf(gettext("%s: Size of parameters should be even"), "cbcintlinprog"); + error(errmsg); + end + + //Check if the user gives a matrix instead of a vector + + if (((size(intcon,1)~=1)& (size(intcon,2)~=1))&(size(intcon,2)~=0)) then + errmsg = msprintf(gettext("%s: intcon should be a vector"), "cbcintlinprog"); + error(errmsg); + end + + if (size(lb,1)~=1)& (size(lb,2)~=1) then + errmsg = msprintf(gettext("%s: Lower Bound should be a vector"), "cbcintlinprog"); + error(errmsg); + end + + if (size(ub,1)~=1)& (size(ub,2)~=1) then + errmsg = msprintf(gettext("%s: Upper Bound should be a vector"), "cbcintlinprog"); + error(errmsg); + end + + if (nbConInEq) then + if ((size(b,1)~=1)& (size(b,2)~=1)) then + errmsg = msprintf(gettext("%s: Constraint Lower Bound should be a vector"), "cbcintlinprog"); + error(errmsg); + end + end + + if (nbConEq) then + if (size(beq,1)~=1)& (size(beq,2)~=1) then + errmsg = msprintf(gettext("%s: Constraint Upper Bound should be a vector"), "cbcintlinprog"); + error(errmsg); + end + end + + + //Changing the inputs in symphony's format + conMatrix = [A;Aeq] + nbCon = size(conMatrix,1); + conLB = [repmat(-%inf,size(A,1),1);beq]; + conUB = [b;beq] ; + + isInt = repmat(%f,1,nbVar); + // Changing intcon into column vector + intcon = intcon(:); + for i=1:size(intcon,1) + isInt(intcon(i)) = %t + end + + objSense = 1.0; + + //Changing into row vector + lb = lb'; + ub = ub'; + c = c'; + + //Pusing options as required to a double array + optval = []; + if length(options) == 0 then + optval = [0 0 0 0]; + else + optval = [0 0 0 0]; + for i=1:2:length(options) + select options(i) + case 'IntegerTolerance' then + optval(1) = options(i+1); + case 'MaxNodes' then + optval(2) = options(i+1); + case 'MaxTime' then + optval(3) = options(i+1); + case 'AllowableGap' then + optval(4) = options(i+1); + else + error(999, 'Unknown string argument passed.'); + end + end + end + + [xopt,fopt,status,nodes,nfpoints,L,U,niter] = sci_matrix_intlinprog(nbVar,nbCon,c,intcon,conMatrix,conLB,conUB,lb,ub,objSense,optval); + + //Debugging Prints + //disp(c);disp(intcon);disp(conMatrix);disp(conLB);disp(conUB);disp(lb);disp(ub);disp(Aeq);disp(beq);disp(xopt); + //disp(L);disp(U); + //disp(options); + + output = struct("relativegap" , [],.. + "absolutegap" , [],.. + "numnodes" , [],.. + "numfeaspoints" , [],.. + "numiterations" , [],.. + "constrviolation" , [],.. + "message" , ''); + + output.numnodes=[nodes]; + output.numfeaspoints=[nfpoints]; + output.numiterations=[niter]; + output.relativegap=(U-L)/(abs(U)+1); + output.absolutegap=(U-L); + output.constrviolation = max([0;norm(Aeq*xopt-beq, 'inf');(lb'-xopt);(xopt-ub');(A*xopt-b)]); + + select status + + case 0 then + output.message="Optimal Solution" + case 1 then + output.message="Primal Infeasible" + case 2 then + output.message="Solution Limit is reached" + case 3 then + output.message="Node Limit is reached" + case 4 then + output.message="Numerical Difficulties" + case 5 then + output.message="Time Limit Reached" + case 6 then + output.message="Continuous Solution Unbounded" + case 7 then + output.message="Dual Infeasible" + else + output.message="Invalid status returned. Notify the Toolbox authors" + break; + end + +endfunction diff --git a/demos/mps_cbcintlinprog.sci b/demos/mps_cbcintlinprog.sci new file mode 100644 index 0000000..eef8b68 --- /dev/null +++ b/demos/mps_cbcintlinprog.sci @@ -0,0 +1,79 @@ +// Code Authors: Akshay Miterani and Pranav Deshpande +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [xopt,fopt,status,output] = cbcmpsintlinprog(varargin) + // Sci File Wrapper for the mps_cbcintlinprog.cpp file + + // Number of input and output arguments + [nOutput, nInput] = argn(); + + // To check the number of arguments given by the user + if (nInput<1 | nInput>2) then + error(999, 'Check the number of input arguments!'); + end + + mpsFile = varargin(1); + optval = [0,0,0,0]; + if(nInput==2) then + options=varargin(2); + if length(options) == 0 then + optval = [0 0 0 0]; + else + optval = [0 0 0 0]; + for i=1:2:length(options) + select options(i) + case 'IntegerTolerance' then + optval(1) = options(i+1); + case 'MaxNodes' then + optval(2) = options(i+1); + case 'MaxTime' then + optval(3) = options(i+1); + case 'AllowableGap' then + optval(4) = options(i+1); + else + error(999, 'Unknown string argument passed.'); + end + end + end + end + + [xopt,fopt,status,nodes,nfpoints,L,U,niter] = sci_mps_intlinprog(mpsFile, optval) + + output = struct("relativegap" , [],.. + "absolutegap" , [],.. + "numnodes" , [],.. + "numfeaspoints" , [],.. + "numiterations" , [],.. + "message" , ''); + + output.numnodes = [nodes]; + output.numfeaspoints = [nfpoints]; + output.numiterations = [niter]; + output.relativegap = (U-L)/(abs(U)+1); + output.absolutegap = (U-L); + + select status + + case 0 then + output.message="Optimal Solution" + case 1 then + output.message="Primal Infeasible" + case 2 then + output.message="Solution Limit is reached" + case 3 then + output.message="Node Limit is reached" + case 4 then + output.message="Numerical Difficulties" + case 5 then + output.message="Time Limit Reached" + case 6 then + output.message="Continuous Solution Unbounded" + case 7 then + output.message="Dual Infeasible" + else + output.message="Invalid status returned. Notify the Toolbox authors" + break; + end + +endfunction diff --git a/demos/sci_FOSSEE_Optimization_Toolbox.dem.gateway.sce b/demos/sci_FOSSEE_Optimization_Toolbox.dem.gateway.sce index 739ad2c..14f95bb 100644 --- a/demos/sci_FOSSEE_Optimization_Toolbox.dem.gateway.sce +++ b/demos/sci_FOSSEE_Optimization_Toolbox.dem.gateway.sce @@ -5,12 +5,12 @@ // you should have received as part of this distribution. The terms // are also available at // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt -// Author: Harpreet Singh +// Author: Harpreet Singh and Georgey John // Organization: FOSSEE, IIT Bombay // Email: toolbox@scilab.in demopath = get_absolute_file_path("sci_FOSSEE_Optimization_Toolbox.dem.gateway.sce"); -subdemolist = ["Linprog","linprog.dem.sce";"Symphony", "symphony.dem.sce"; "SymphonyMat", "symphonymat.dem.sce"; "Qpipopt", "qpipopt.dem.sce"; "QpipoptMat", "qpipoptmat.dem.sce";"Lsqlin","lsqlin.dem.sce";"Lsqnonneg","lsqnonneg.dem.sce";"Fminunc","fminunc.dem.sce";"Fminbnd","fminbnd.dem.sce";"Fmincon","fmincon.dem.sce"]; +subdemolist = ["Linprog","linprog.dem.sce";"Cbcintlinprog","cbcintlinprog.dem.sce";"Symphony", "symphony.dem.sce"; "SymphonyMat", "symphonymat.dem.sce"; "Qpipopt", "qpipopt.dem.sce"; "QpipoptMat", "qpipoptmat.dem.sce";"Intqpipopt","intqpipopt.dem.sce";"Lsqlin","lsqlin.dem.sce";"Lsqnonneg","lsqnonneg.dem.sce";"Fminunc","fminunc.dem.sce";"Intfminunc","intfminunc.dem.sce";"Fminbnd","fminbnd.dem.sce";"Intfminbnd","intfminbnd.dem.sce";"Fmincon","fmincon.dem.sce";"Intfmincon","intfmincon.dem.sce"]; subdemolist(:,2) = demopath + subdemolist(:,2); |