diff options
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/lsqlin.dia.ref | 48 | ||||
-rw-r--r-- | tests/unit_tests/lsqlin.tst | 48 | ||||
-rw-r--r-- | tests/unit_tests/lsqnonneg.dia.ref | 26 | ||||
-rw-r--r-- | tests/unit_tests/lsqnonneg.tst | 26 | ||||
-rw-r--r-- | tests/unit_tests/qpipopt_base.dia.ref | 38 | ||||
-rw-r--r-- | tests/unit_tests/qpipopt_base.tst | 41 | ||||
-rw-r--r-- | tests/unit_tests/qpipoptmat_base.dia.ref | 32 | ||||
-rw-r--r-- | tests/unit_tests/qpipoptmat_base.tst | 35 | ||||
-rw-r--r-- | tests/unit_tests/symphony_base.dia.ref | 1 | ||||
-rw-r--r-- | tests/unit_tests/symphony_base.tst | 8 | ||||
-rw-r--r-- | tests/unit_tests/symphonymat_base.dia.ref | 1 | ||||
-rw-r--r-- | tests/unit_tests/symphonymat_base.tst | 1 |
12 files changed, 155 insertions, 150 deletions
diff --git a/tests/unit_tests/lsqlin.dia.ref b/tests/unit_tests/lsqlin.dia.ref index 9fbe23f..327598e 100644 --- a/tests/unit_tests/lsqlin.dia.ref +++ b/tests/unit_tests/lsqlin.dia.ref @@ -53,30 +53,30 @@ endfunction //endfunction //A simple linear least square example -C = [0.9501 0.7620 0.6153 0.4057 - 0.2311 0.4564 0.7919 0.9354 - 0.6068 0.0185 0.9218 0.9169 - 0.4859 0.8214 0.7382 0.4102 - 0.8912 0.4447 0.1762 0.8936]; - d = [0.0578 - 0.3528 - 0.8131 - 0.0098 - 0.1388]; - A =[0.2027 0.2721 0.7467 0.4659 - 0.1987 0.1988 0.4450 0.4186 - 0.6037 0.0152 0.9318 0.8462]; - b =[0.5251 - 0.2026 - 0.6721]; - Aeq = [3 5 7 9]; - beq = 4; - lb = -0.1*ones(4,1); - ub = 2*ones(4,1); - [xopt,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b,Aeq,beq,lb,ub) +C = [1 1 1; + 1 1 0; + 0 1 1; + 1 0 0; + 0 0 1] +d = [89; + 67; + 53; + 35; + 20;] +A = [3 2 1; + 2 3 4; + 1 2 3]; +b = [191 + 209 + 162]; +Aeq = [1 2 1]; +beq = 10; +lb = repmat(0.1,3,1); +ub = repmat(4,3,1); +[xopt,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b,Aeq,beq,lb,ub) -assert_close ( xopt , [ -0.1, -0.1, 0.1599089, 0.4089598 ]' , 0.0005 ); -assert_close ( residual , [-0.0352969 -0.0876228 0.3532508 -0.1452700 -0.1212324 ]' , 0.0005 ); -assert_close ( resnorm , [ 0.1695104] , 0.0005 ); +assert_close ( xopt , [ 4 1 4 ]' , 0.0005 ); +assert_close ( residual , [80 62 48 31 16]' , 0.0005 ); +assert_close ( resnorm , [ 13765] , 0.0005 ); assert_checkequal( exitflag , int32(0) ); printf("Test Successful"); diff --git a/tests/unit_tests/lsqlin.tst b/tests/unit_tests/lsqlin.tst index 9fbe23f..327598e 100644 --- a/tests/unit_tests/lsqlin.tst +++ b/tests/unit_tests/lsqlin.tst @@ -53,30 +53,30 @@ endfunction //endfunction //A simple linear least square example -C = [0.9501 0.7620 0.6153 0.4057 - 0.2311 0.4564 0.7919 0.9354 - 0.6068 0.0185 0.9218 0.9169 - 0.4859 0.8214 0.7382 0.4102 - 0.8912 0.4447 0.1762 0.8936]; - d = [0.0578 - 0.3528 - 0.8131 - 0.0098 - 0.1388]; - A =[0.2027 0.2721 0.7467 0.4659 - 0.1987 0.1988 0.4450 0.4186 - 0.6037 0.0152 0.9318 0.8462]; - b =[0.5251 - 0.2026 - 0.6721]; - Aeq = [3 5 7 9]; - beq = 4; - lb = -0.1*ones(4,1); - ub = 2*ones(4,1); - [xopt,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b,Aeq,beq,lb,ub) +C = [1 1 1; + 1 1 0; + 0 1 1; + 1 0 0; + 0 0 1] +d = [89; + 67; + 53; + 35; + 20;] +A = [3 2 1; + 2 3 4; + 1 2 3]; +b = [191 + 209 + 162]; +Aeq = [1 2 1]; +beq = 10; +lb = repmat(0.1,3,1); +ub = repmat(4,3,1); +[xopt,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b,Aeq,beq,lb,ub) -assert_close ( xopt , [ -0.1, -0.1, 0.1599089, 0.4089598 ]' , 0.0005 ); -assert_close ( residual , [-0.0352969 -0.0876228 0.3532508 -0.1452700 -0.1212324 ]' , 0.0005 ); -assert_close ( resnorm , [ 0.1695104] , 0.0005 ); +assert_close ( xopt , [ 4 1 4 ]' , 0.0005 ); +assert_close ( residual , [80 62 48 31 16]' , 0.0005 ); +assert_close ( resnorm , [ 13765] , 0.0005 ); assert_checkequal( exitflag , int32(0) ); printf("Test Successful"); diff --git a/tests/unit_tests/lsqnonneg.dia.ref b/tests/unit_tests/lsqnonneg.dia.ref index 2c7c7d2..af929ee 100644 --- a/tests/unit_tests/lsqnonneg.dia.ref +++ b/tests/unit_tests/lsqnonneg.dia.ref @@ -53,20 +53,20 @@ endfunction //endfunction // A basic lsqnonneg problem -C = [ - 0.0372 0.2869 - 0.6861 0.7071 - 0.6233 0.6245 - 0.6344 0.6170]; -d = [ - 0.8587 - 0.1781 - 0.0747 - 0.8405]; +C = [1 1 1; + 1 1 0; + 0 1 1; + 1 0 0; + 0 0 1] +d = [89; + 67; + 53; + 35; + 20] [xopt,resnorm,residual,exitflag,output,lambda] = lsqnonneg(C,d) -assert_close ( xopt , [ 0 0.6929344 ]' , 0.0005 ); -assert_close ( residual , [0.6598971 -0.3118739 -0.3580375 0.4129595]' , 0.0005 ); -assert_close ( resnorm , [ 0.8314560] , 0.0005 ); +assert_close ( xopt , [ 35.125 32.5 20.625 ]' , 0.0005 ); +assert_close ( residual , [0.75 -0.625 -0.125 -0.125 -0.625]' , 0.0005 ); +assert_close ( resnorm , [ 1.375] , 0.0005 ); assert_checkequal( exitflag , int32(0) ); printf("Test Successful"); diff --git a/tests/unit_tests/lsqnonneg.tst b/tests/unit_tests/lsqnonneg.tst index 2c7c7d2..af929ee 100644 --- a/tests/unit_tests/lsqnonneg.tst +++ b/tests/unit_tests/lsqnonneg.tst @@ -53,20 +53,20 @@ endfunction //endfunction // A basic lsqnonneg problem -C = [ - 0.0372 0.2869 - 0.6861 0.7071 - 0.6233 0.6245 - 0.6344 0.6170]; -d = [ - 0.8587 - 0.1781 - 0.0747 - 0.8405]; +C = [1 1 1; + 1 1 0; + 0 1 1; + 1 0 0; + 0 0 1] +d = [89; + 67; + 53; + 35; + 20] [xopt,resnorm,residual,exitflag,output,lambda] = lsqnonneg(C,d) -assert_close ( xopt , [ 0 0.6929344 ]' , 0.0005 ); -assert_close ( residual , [0.6598971 -0.3118739 -0.3580375 0.4129595]' , 0.0005 ); -assert_close ( resnorm , [ 0.8314560] , 0.0005 ); +assert_close ( xopt , [ 35.125 32.5 20.625 ]' , 0.0005 ); +assert_close ( residual , [0.75 -0.625 -0.125 -0.125 -0.625]' , 0.0005 ); +assert_close ( resnorm , [ 1.375] , 0.0005 ); assert_checkequal( exitflag , int32(0) ); printf("Test Successful"); diff --git a/tests/unit_tests/qpipopt_base.dia.ref b/tests/unit_tests/qpipopt_base.dia.ref index 0cc59f1..25b440f 100644 --- a/tests/unit_tests/qpipopt_base.dia.ref +++ b/tests/unit_tests/qpipopt_base.dia.ref @@ -52,25 +52,25 @@ endfunction // if flag <> 1 then pause,end //endfunction -//Find the value of x that minimize following function -// f(x) = 0.5*x1^2 + x2^2 - x1*x2 - 2*x1 - 6*x2 -// Subject to: -// x1 + x2 ≤ 2 -// –x1 + 2x2 ≤ 2 -// 2x1 + x2 ≤ 3 -// 0 ≤ x1, 0 ≤ x2. -Q = [1 -1; -1 2]; -p = [-2; -6]; -conMatrix = [1 1; -1 2; 2 1]; -conUB = [2; 2; 3]; -conLB = [-%inf; -%inf; -%inf]; -lb = [0; 0]; -ub = [%inf; %inf]; -nbVar = 2; -nbCon = 3; -[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB) +//Find x in R^6 such that: +A= [1,-1,1,0,3,1; +-1,0,-3,-4,5,6; +2,5,3,0,1,0 +0,1,0,1,2,-1; +-1,0,2,1,1,0]; +conLB=[1;2;3;-%inf;-%inf]; +conUB = [1;2;3;-1;2.5]; +lb=[-1000;-10000; 0; -1000; -1000; -1000]; +ub=[10000; 100; 1.5; 100; 100; 1000]; +//and minimize 0.5*x'*H*x + f'*x with +f=[1; 2; 3; 4; 5; 6]; H=eye(6,6); +nbVar = 6; +nbCon = 5; +x0 = repmat(0,nbVar,1); +param = list("MaxIter", 300, "CpuTime", 100); +[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB,x0,param) -assert_close ( xopt , [0.6666667 1.3333333]' , 1.e-7 ); -assert_close ( fopt , [ - 8.2222223] , 1.e-7 ); +assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 ); +assert_close ( fopt , [ -14.843248] , 1.e-7 ); assert_checkequal( exitflag , int32(0) ); printf("Test Successful"); diff --git a/tests/unit_tests/qpipopt_base.tst b/tests/unit_tests/qpipopt_base.tst index eee8b91..25b440f 100644 --- a/tests/unit_tests/qpipopt_base.tst +++ b/tests/unit_tests/qpipopt_base.tst @@ -52,26 +52,25 @@ endfunction // if flag <> 1 then pause,end //endfunction -//Find the value of x that minimize following function -// f(x) = 0.5*x1^2 + x2^2 - x1*x2 - 2*x1 - 6*x2 -// Subject to: -// x1 + x2 ≤ 2 -// –x1 + 2x2 ≤ 2 -// 2x1 + x2 ≤ 3 -// 0 ≤ x1, 0 ≤ x2. -Q = [1 -1; -1 2]; -p = [-2; -6]; -conMatrix = [1 1; -1 2; 2 1]; -conUB = [2; 2; 3]; -conLB = [-%inf; -%inf; -%inf]; -lb = [0; 0]; -ub = [%inf; %inf]; -nbVar = 2; -nbCon = 3; -[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB) - -assert_close ( xopt , [0.6666667 1.3333333]' , 1.e-7 ); -assert_close ( fopt , [ - 8.2222223] , 1.e-7 ); +//Find x in R^6 such that: +A= [1,-1,1,0,3,1; +-1,0,-3,-4,5,6; +2,5,3,0,1,0 +0,1,0,1,2,-1; +-1,0,2,1,1,0]; +conLB=[1;2;3;-%inf;-%inf]; +conUB = [1;2;3;-1;2.5]; +lb=[-1000;-10000; 0; -1000; -1000; -1000]; +ub=[10000; 100; 1.5; 100; 100; 1000]; +//and minimize 0.5*x'*H*x + f'*x with +f=[1; 2; 3; 4; 5; 6]; H=eye(6,6); +nbVar = 6; +nbCon = 5; +x0 = repmat(0,nbVar,1); +param = list("MaxIter", 300, "CpuTime", 100); +[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB,x0,param) +assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 ); +assert_close ( fopt , [ -14.843248] , 1.e-7 ); assert_checkequal( exitflag , int32(0) ); -printf("Test Successfull") +printf("Test Successful"); diff --git a/tests/unit_tests/qpipoptmat_base.dia.ref b/tests/unit_tests/qpipoptmat_base.dia.ref index e99255c..fbebe58 100644 --- a/tests/unit_tests/qpipoptmat_base.dia.ref +++ b/tests/unit_tests/qpipoptmat_base.dia.ref @@ -52,22 +52,22 @@ endfunction // if flag <> 1 then pause,end //endfunction -//Find the value of x that minimize following function -// f(x) = 0.5*x1^2 + x2^2 - x1*x2 - 2*x1 - 6*x2 -// Subject to: -// x1 + x2 ≤ 2 -// –x1 + 2x2 ≤ 2 -// 2x1 + x2 ≤ 3 -// 0 ≤ x1, 0 ≤ x2. -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]; -[xopt,fopt,exitflag,output,lambda] = qpipoptmat(H,f,A,b,[],[],lb,ub) +//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]; +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); +[xopt,fopt,exitflag,output,lambda]=qpipoptmat(H,f,A,b,Aeq,beq,lb,ub,[],param); -assert_close ( xopt , [0.6666667 1.3333333]' , 1.e-7 ); -assert_close ( fopt , [ - 8.2222223] , 1.e-7 ); +assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 ); +assert_close ( fopt , [ -14.843248] , 1.e-7 ); assert_checkequal( exitflag , int32(0) ); printf("Test Successful"); diff --git a/tests/unit_tests/qpipoptmat_base.tst b/tests/unit_tests/qpipoptmat_base.tst index 482457d..fbebe58 100644 --- a/tests/unit_tests/qpipoptmat_base.tst +++ b/tests/unit_tests/qpipoptmat_base.tst @@ -52,23 +52,22 @@ endfunction // if flag <> 1 then pause,end //endfunction -//Find the value of x that minimize following function -// f(x) = 0.5*x1^2 + x2^2 - x1*x2 - 2*x1 - 6*x2 -// Subject to: -// x1 + x2 ≤ 2 -// –x1 + 2x2 ≤ 2 -// 2x1 + x2 ≤ 3 -// 0 ≤ x1, 0 ≤ x2. -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]; -[xopt,fopt,exitflag,output,lambda] = qpipoptmat(H,f,A,b,[],[],lb,ub) +//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]; +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); +[xopt,fopt,exitflag,output,lambda]=qpipoptmat(H,f,A,b,Aeq,beq,lb,ub,[],param); -assert_close ( xopt , [0.6666667 1.3333333]' , 1.e-7 ); -assert_close ( fopt , [ - 8.2222223] , 1.e-7 ); +assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 ); +assert_close ( fopt , [ -14.843248] , 1.e-7 ); assert_checkequal( exitflag , int32(0) ); - -printf("Test Successfull") +printf("Test Successful"); diff --git a/tests/unit_tests/symphony_base.dia.ref b/tests/unit_tests/symphony_base.dia.ref index 4b653a8..2e96146 100644 --- a/tests/unit_tests/symphony_base.dia.ref +++ b/tests/unit_tests/symphony_base.dia.ref @@ -52,6 +52,7 @@ endfunction // if flag <> 1 then pause,end //endfunction +//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. // Objective function c = [350*5,330*3,310*4,280*6,500,450,400,100]'; diff --git a/tests/unit_tests/symphony_base.tst b/tests/unit_tests/symphony_base.tst index 31e7547..2e96146 100644 --- a/tests/unit_tests/symphony_base.tst +++ b/tests/unit_tests/symphony_base.tst @@ -52,6 +52,7 @@ endfunction // if flag <> 1 then pause,end //endfunction +//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. // Objective function c = [350*5,330*3,310*4,280*6,500,450,400,100]'; @@ -76,9 +77,12 @@ conub = [ 25; 1.25; 1.25] isInt = [repmat(%t,1,4) repmat(%f,1,4)]; // Calling Symphony -[x,f,status,output] = symphony(8,3,c,isInt,lb,ub,conMatrix,conlb,conub,1); +[x,f,iter] = symphony(8,3,c,isInt,lb,ub,conMatrix,conlb,conub,1); + +//In Symphony Library for optimal solution status = 227 +status = sym_getStatus(); assert_close ( x , [1 1 0 1 7.25 0 0.25 3.5]' , 1.e-7 ); assert_close ( f , [ 8495] , 1.e-7 ); assert_checkequal( status , 227 ); - +printf("Test Successful"); diff --git a/tests/unit_tests/symphonymat_base.dia.ref b/tests/unit_tests/symphonymat_base.dia.ref index d57851a..17a5566 100644 --- a/tests/unit_tests/symphonymat_base.dia.ref +++ b/tests/unit_tests/symphonymat_base.dia.ref @@ -52,6 +52,7 @@ endfunction // if flag <> 1 then pause,end //endfunction +// 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. // Objective function c = [350*5,330*3,310*4,280*6,500,450,400,100]'; diff --git a/tests/unit_tests/symphonymat_base.tst b/tests/unit_tests/symphonymat_base.tst index 37b4c3f..95a1fec 100644 --- a/tests/unit_tests/symphonymat_base.tst +++ b/tests/unit_tests/symphonymat_base.tst @@ -52,6 +52,7 @@ endfunction // if flag <> 1 then pause,end //endfunction +// 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. // Objective function c = [350*5,330*3,310*4,280*6,500,450,400,100]'; |