# Úkol 6

```function [s, Cmax] = bratleyAlg(p, r, d)
clear global;
k = [];

[ss,Cmaxx] = bratleyAlg_(p,r,d,0,1:length(p),k);
s = ss;
Cmax = Cmaxx;
end

global Cmax_;
global s_;
%Initialize s, Cmax and estimate UB if it is empty (1st function call)

%Cmax = c;

%Condition 0
if (isempty(p) || isempty(r) || isempty(d))
disp('we are done');
if(isempty(Cmax_))
Cmax_ = c;
s_ = s;
else
if(c < Cmax_)
Cmax_ = c;
s_ = s;
end
end
return %We are done
end

UB = max(d);

%Condition 1
estimated_deadlines = max(c, r) + p;
if 0 ~= (sum(estimated_deadlines > d))
return          %This branching does not lead to feasible solution
end

%Condition 2
LB = max(min(r), c) + sum(p);
if LB > UB
return          %This branching does not lead to feasible solution
end

%Branch each node to the appropriate number of other nodes
for i = 1:length(p)
%Calculate c
c_upravene = max(c, r(i)) + p(i);
%If only one job remains
%OK that's good

%If branching is still needed
s_upravene = s; s_upravene(end+1) = task_list(i);
%Solve subproblem by recursive call with modified inputs (e.g with use of the length of the partial solution)
p_upravene = p;p_upravene(i)=[];
r_upravene = r;r_upravene(i)=[];
d_upravene = d;d_upravene(i)=[];
%s = bratleyAlg(p_upravene, r_upravene, d_upravene, c_upravene, ts_index, n);