This repository has been archived on 2021-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
NC/mp6/Project_6_Maggioni_Claudio/testSimplex.m

115 lines
No EOL
3.1 KiB
Matlab

% This script has the purpose of testing your implementation of the Simplex Method. In case there should be any issue with your solution, you will
% get an error and the code will stop. If your proposed solution passes all the tests, you can happily move to the next part of the assignment.
close all;
clear;
clc;
runTests = [0 0 1 0 0 0];
%% Test 1 (example page 86)
if runTests(1)
type = 'max';
A = [2 1; 1 3; 1 1];
h = [360;480;220];
c = [14,18];
sign = [0,0,0];
[z,x_B,index_B] = simplex (type,A,h,c,sign);
if(z==3600 && sum(uint32(x_B)-uint32([90;130;50]))==0 && sum(index_B==[1,2,3])==3)
fprintf('Test 1 has given the expected results. Proceding with the next one.\n\n');
else
error('Test 1 has given a wrong result. Interrupting the testing phase.');
end
pause
end
%% Test 2 (example page 114)
if runTests(2)
type = 'min';
A = [2,1,3; 3,4,2];
h = [210;360];
c = [9,11,8];
sign = [0,0];
[z,x_B,index_B] = simplex (type,A,h,c,sign);
if(z==1062 && sum(uint32(x_B)-uint32([96;18]))==0 && sum(index_B==[1,2])==2)
fprintf('Test 2 has given the expected results. Proceding with the next one.\n\n');
else
error('Test 2 has given a wrong result. Interrupting the testing phase.');
end
pause
end
%% Test 3 (example page 126)
if runTests(3)
type = 'max';
A = [1,2,1; 2,1,0; 1,-2,-1];
h = [5;8;1];
c = [3,-2,5];
sign = [0,1,1];
[z,x_B,index_B] = simplex (type,A,h,c,sign);
if(z==17 && sum(uint32(x_B)-uint32([4;1;2]))==0 && sum(index_B==[1,3,6])==3)
fprintf('Test 3 has given the expected results. Proceding with the next one.\n\n');
else
error('Test 3 has given a wrong result. Interrupting the testing phase.');
end
pause
end
%% Test 4 (TED)
if runTests(4)
type = 'min';
A = [-10,-5,-8; -10,-2,-10; -5,-5,-4; 10,5,8; 10,2,10; 5,5,4];
h = [-110,-60,-90,78,43,70]';
c = [20000,30000,25000];
sign = [0,0,0,0,0,0];
[z,x_B,index_B] = simplex (type,A,h,c,sign);
if(z==380000 && sum(uint32(x_B)-uint32([4;10;20;20;12;17]))==0 && sum(index_B==[1,2,4,6,7,8])==6)
fprintf('Test 4 has given the expected results. Proceding with the next one.\n\n');
else
error('Test 4 has given a wrong result. Interrupting the testing phase.');
end
pause
end
%% Test 5 (LP Exercise 2)
if runTests(5)
type = 'max';
A = [1,1,2; 5,3,1; 2,1,0];
h = [1200;2000;600];
c = [5,20,28];
sign = [0,0,0];
[z,x_B,index_B] = simplex (type,A,h,c,sign);
if(z==20160 && sum(uint32(x_B)-uint32([560;320;40]))==0 && sum(index_B==[2,3,6])==3)
fprintf('Test 5 has given the expected results. Proceding with the next one.\n\n');
else
error('Test 5 has given a wrong result. Interrupting the testing phase.');
end
pause
end
%% Test 6 (Vinitaly page 171)
if runTests(6)
type = 'max';
A = [1,1,1,0,0,0,0,0,0; 0,0,0,1,1,1,0,0,0; 0,0,0,0,0,0,1,1,1; 0,1,0,0,1,0,0,1,0; 0,0,1,0,0,1,0,0,1];
h = [4800;4000;2300;2500;4200];
c = [2,3,4,4,7,12,4,9,13];
sign = [0,0,0,0,0];
[z,x_B,index_B] = simplex (type,A,h,c,sign);
if(z==79500 && sum(uint32(x_B)-uint32([4400;400;4000;2100;200]))==0 && sum(index_B==[1,2,6,8,9])==5)
fprintf('Test 6 has given the expected results. Congratulations!!!\n\n');
else
error('Test 6 has given a wrong result. Interrupting the testing phase.');
end
end