%%%%%%%% Testing different simple control rules %%%%%%%%%%%%%%%%%%%%%%%%%%
% runs main.m with different simple control structures. The control 
% structures all have two phases, the heating phase and the conservation
% phase. In the heating phase the temperature set point is maximized,
% in the conservation phase the temperature set point is minimized.
% The different control structures differ by when the heating phase starts
% and for how long it lasts.
%Key variables:
% t,        how many hours to have max tempemrature set point
% s-1,      which hour to start maximizing the temperature set point
% emlist,   the binary vector that contains 24-hour temp set points
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
bo=0;
rmat = [];                                            % the results matrix
for t=3:8                         % number of hours spent in heating phase
    for s=[23,24,1,2]                 % hour to start increasing T_s (+1!)
        emlist=zeros(1,24);                   % defining the emlist vector
        t_temp = t;            % counting var. hours left of heating phase
        if s>22           % if heating start is before midnight. (24-1=23)
            if s==23 
                emlist(23) = 1;     % modify list to reflect heating phase
                emlist(24) = 1;
                t_temp = t_temp-2;                          % update count
            else
                emlist(24) = 1;
                t_temp = t_temp -1
            end
        end
        if s>1 && s<22       % adjusting start and endpoints of while loop
            startp=s-1;
            t_temp=t_temp+(s-1);
        else
            startp= 0;
        end;
        while t_temp> startp   % If still hours left of phase: modify list
            emlist(t_temp) = 1;
            t_temp = t_temp-1;
        end
        emlist = [emlist(5:end),emlist(1:4)];    % start profile at 4.00AM
        [T_violation,J_end]=main(3,200,0,emlist,bo);%find T_viol and J_end
        rmat = [rmat;[T_violation,J_end,s-1,t,emlist]];%save result to mat
    end
end

% Naming of the saved file
if bo >0
    name = ['cstructures','BO',num2str(bo)];
else
    name = ['cstructures1'];
end
save(name,'rmat')                              % save restult to .mat file