% Solution to Section 3 exercise.

c = ones(21,1);
 
B = -1*ones(21,7);
  
d = [-9,-6,-3,0,12,15,18];
  
A = spdiags(B,d,21,21);

spy(A), title('A');

b = -1*[5,7,9;3,8,10;2,9,10;4,5,7;3,7,11;2,2,2;2,5,2]';

lb = zeros(21,1);
  
ub = 60*ones(21,1);
 
n = linprog(c,A,b,[],[],lb,ub);

disp(strvcat('Number of workers needed:','(optimization output)'))
number = sum(n)

N = reshape(n,3,7);

disp('Schedule using ceil:')
N = ceil(N)

N = reshape(n,3,7);

disp('Schedule using floor:')
N = floor(N)

N = reshape(n,3,7);
 
disp('Schedule using round:')
N = round(N)