summaryrefslogtreecommitdiff
path: root/macros/symphonymat.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/symphonymat.sci')
-rw-r--r--macros/symphonymat.sci215
1 files changed, 112 insertions, 103 deletions
diff --git a/macros/symphonymat.sci b/macros/symphonymat.sci
index 9226bd6..2c0c18d 100644
--- a/macros/symphonymat.sci
+++ b/macros/symphonymat.sci
@@ -13,47 +13,47 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
// Solves a mixed integer linear programming constrained optimization problem in intlinprog format.
//
// Calling Sequence
- // xopt = symphonymat(C,intcon,A,b)
- // xopt = symphonymat(C,intcon,A,b,Aeq,beq)
- // xopt = symphonymat(C,intcon,A,b,Aeq,beq,lb,ub)
- // xopt = symphonymat(C,intcon,A,b,Aeq,beq,lb,ub,options)
+ // xopt = symphonymat(c,intcon,A,b)
+ // xopt = symphonymat(c,intcon,A,b,Aeq,beq)
+ // xopt = symphonymat(c,intcon,A,b,Aeq,beq,lb,ub)
+ // xopt = symphonymat(c,intcon,A,b,Aeq,beq,lb,ub,options)
// [xopt,fopt,status,output] = symphonymat( ... )
//
// Parameters
- // f : a vector of double, contains coefficients of the variables in the objective
+ // c : a vector of double, contains coefficients of the variables in the objective
// intcon : Vector of integer constraints, specified as a vector of positive integers. The values in intcon indicate the components of the decision variable x that are integer-valued. intcon has values from 1 through number of variable.
- // A : Linear inequality constraint matrix, specified as a matrix of double. A represents the linear coefficients in the constraints A*x ≤ b. A has size M-by-N, where M is the number of constraints and N is number of variables
- // b : Linear inequality constraint vector, specified as a vector of double. b represents the constant vector in the constraints A*x ≤ b. b has length M, where A is M-by-N
- // Aeq : Linear equality constraint matrix, specified as a matrix of double. Aeq represents the linear coefficients in the constraints Aeq*x = beq. Aeq has size Meq-by-N, where Meq is the number of constraints and N is number of variables
- // beq : Linear equality constraint vector, specified as a vector of double. beq represents the constant vector in the constraints Aeq*x = beq. beq has length Meq, where Aeq is Meq-by-N.
+ // A : Linear inequality constraint matrix, specified as a matrix of double. A represents the linear coefficients in the constraints A*x ≤ b. A has the size where columns equals to the number of variables.
+ // b : Linear inequality constraint vector, specified as a vector of double. b represents the constant vector in the constraints A*x ≤ b. b has size equals to the number of rows in A.
+ // Aeq : Linear equality constraint matrix, specified as a matrix of double. Aeq represents the linear coefficients in the constraints Aeq*x = beq. Aeq has the size where columns equals to the number of variables.
+ // beq : Linear equality constraint vector, specified as a vector of double. beq represents the constant vector in the constraints Aeq*x = beq. beq has size equals to the number of rows in Aeq.
// lb : Lower bounds, specified as a vector or array of double. lb represents the lower bounds elementwise in lb ≤ x ≤ ub.
// ub : Upper bounds, specified as a vector or array of double. ub represents the upper bounds elementwise in lb ≤ x ≤ ub.
// options : a list containing the the parameters to be set.
- // xopt : a vector of double, the computed solution of the optimization problem
+ // xopt : a vector of double, the computed solution of the optimization problem.
// fopt : a double, the function value at x
- // status : status flag from symphony.
- // output : The output data structure contains detailed informations about the optimization process. Right now it contains number of iteration.
+ // status : status flag from symphony. 227 is optimal, 228 is Time limit exceeded, 230 is iteration limit exceeded.
+ // output : The output data structure contains detailed information about the optimization process. This version only contains number of iterations.
//
// Description
// Search the minimum or maximum of a constrained mixed integer linear programming optimization problem specified by :
- // find the minimum or maximum of f(x) such that
+ // find the minimum or maximum of C'⋅x such that
//
// <latex>
// \begin{eqnarray}
// &\mbox{min}_{x}
- // & C^T*x \\
- // & \text{subject to} & A*x \leq b \\
- // & & Aeq*x = beq \\
+ // & C^T⋅x \\
+ // & \text{subject to} & A⋅x \leq b \\
+ // & & Aeq⋅x = beq \\
// & & lb \leq x \leq ub \\
// & & x_i \in \!\, \mathbb{Z}, i \in \!\, I
// \end{eqnarray}
// </latex>
//
- // We are calling SYMPHONY written in C by gateway files for the actual computation.
+ // The routine calls SYMPHONY written in C by gateway files for the actual computation.
//
// Examples
// // Objective function
- // C = [350*5,330*3,310*4,280*6,500,450,400,100]';
+ // 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
@@ -79,7 +79,7 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
// // 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 ..
+ // 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 ..
@@ -88,47 +88,47 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
// 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;
- // //Constrain 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 ;
+ // 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;
+ // //Constrain 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(objCoef,1)
+ // nbVar = size(c,1)
// b=[11927 13727 11551 13056 13460 ];
// // Lower Bound of variables
// lb = repmat(0,1,nbVar)
@@ -148,7 +148,7 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
// // Optimal value
// fopt = [ 24381 ]
// // Calling Symphony
- // [x,f,status,output] = symphonymat(C,intcon,A,b,[],[],lb,ub,options);
+ // [x,f,status,output] = symphonymat(c,intcon,A,b,[],[],lb,ub,options);
// Authors
// Keyur Joshi, Saikiran, Iswarya, Harpreet Singh
@@ -157,24 +157,33 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
[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]"), "Symphony", rhs);
- error(errmsg)
- end
-
+ 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]"), "Symphony", rhs);
+ error(errmsg);
+ end
- objCoef = varargin(1)
- intcon = varargin(2)
- A = varargin(3)
- b = varargin(4)
+ c = [];
+ intcon = [];
+ A = [];
+ b = [];
+ Aeq = [];
+ beq = [];
+ lb = [];
+ ub = [];
+
+
+ c = varargin(1)
+ intcon = varargin(2)
+ A = varargin(3)
+ b = varargin(4)
- if (size(objCoef,2)~=1) then
+ if (size(c,2)~=1) then
errmsg = msprintf(gettext("%s: Objective Coefficients should be a column matrix"), "Symphonymat");
error(errmsg);
end
- nbVar = size(objCoef,1);
+ nbVar = size(c,1);
if ( rhs<5 ) then
Aeq = []
@@ -218,25 +227,25 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
// 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(lb,2)== [nbVar]) then
+ lb = lb';
+ end
- if (size(ub,2)== [nbVar]) then
- ub = ub';
- end
+ if (size(ub,2)== [nbVar]) then
+ ub = ub';
+ end
- if (size(b,2)== [nbConInEq]) then
- b = b';
- end
+ if (size(b,2)== [nbConInEq]) then
+ b = b';
+ end
- if (size(beq,2)== [nbConEq]) then
- beq = beq';
- 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 not exceed total number of variable "), "Symphonymat");
+ errmsg = msprintf(gettext("%s: The values inside intcon should be less than the number of variables"), "Symphonymat");
error(errmsg);
end
@@ -246,35 +255,35 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
end
if(modulo(intcon(i),1)) then
- errmsg = msprintf(gettext("%s: The values inside intcon should be integer "), "Symphonymat");
+ errmsg = msprintf(gettext("%s: The values inside intcon should be an integer "), "Symphonymat");
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"), "Symphonymat");
- error(errmsg);
- end
+ 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"), "Symphonymat");
+ 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"), "Symphonymat");
- error(errmsg);
- end
+ 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"), "Symphonymat");
+ 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"), "Symphonymat");
- error(errmsg);
- end
+ 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"), "Symphonymat");
+ 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"), "Symphonymat");
- error(errmsg);
- end
+ 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"), "Symphonymat");
+ error(errmsg);
+ end
//Check the size of Lower Bound which should equal to the number of variables
if ( size(lb,1) ~= nbVar) then
@@ -349,9 +358,9 @@ function [xopt,fopt,status,iter] = symphonymat (varargin)
//Changing into row vector
lb = lb';
ub = ub';
- objCoef = objCoef';
+ c = c';
- [xopt,fopt,status,iter] = symphony_call(nbVar,nbCon,objCoef,isInt,lb,ub,conMatrix,conLB,conUB,objSense,options);
+ [xopt,fopt,status,iter] = symphony_call(nbVar,nbCon,c,isInt,lb,ub,conMatrix,conLB,conUB,objSense,options);
endfunction