-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindOptimalSolution.m
36 lines (32 loc) · 1.4 KB
/
findOptimalSolution.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function solution = findOptimalSolution(tableau, constraints_matrix)
% left-hand side of constraits matrix
constraints_number = size(constraints_matrix,1) - 1;
solution = [];
% tableau dimensions
[m,n] = size(tableau);
output = "";
for i = 1:n-1
if tableau(m,i) == 0
output = output + sprintf("x%d = %f, ",i,tableau(find(tableau(1:m-1,i) == 1),n));
else
output = output + sprintf("x%d = 0, ", i);
end
if length(solution) <= constraints_number
if isempty(tableau(find(tableau(1:m-1,i) == 1),n))
solution(i) = 0
else
solution(i) = (tableau(find(tableau(1:m-1,i) == 1),n))
end
end
end
% append optimum value to solution
solution = [solution, tableau(end,end)];
disp("=====================================================================================================================")
disp("F I N A L T A B L E A U:")
disp(" ")
disp(tableau)
disp("=====================================================================================================================")
output = sprintf("S O L U T I O N: ") + output + sprintf("Optimal value = %f",tableau(m,n));
disp(output);
disp("=====================================================================================================================")
end