%% Experiments for the non-probabilistic case


% Arr_Ex is the array containing the info of the experiments. The three rows
% indicate 1, 2 and 4 minutes of experiment time. The first three columns
% indicate the Heart mode (Normal, Tachycardia and Bradycardia). The next
% three columns are used to store the verification time of each mode.
% Finally, the last six columns are used to count the number of beats in
% each modes first and the number of beats produced by the pacemaker.

% n_exps = number of experiments to run
% time = running time of the experiment
% n_Vg_beats = number of Vgets
% n_VP_beats = number of VPs

n_exps=10;
time=0;

n_Vg_beats=0;
n_VP_beats=0;

Arr_Ex=zeros(n_exps,12);

%% Cycle for Normal mode
for i=1:n_exps,
     tic;
    [N_STATES_N AS_N VS_N PS_N QS_N z_N] = ecggen(80*i,80);
    % Create the transition matrix for the normal behavior of the HEART
    [TH_N, c_state_HEART]=transitions(0, N_STATES_N,AS_N,VS_N);

    c_state_HEART=TH_N(1,1);

    % Take the composition
    TH_COMPOSITION = composition(N_STATES_N, TH_N, TP, IM, c_state_PACEMAKER, c_state_HEART);
    Arr_Ex(i,1)=N_STATES_N;
    time=toc;
    Arr_Ex(i,4)=time;
    [n_Vg_beats n_VP_beats]=count_beats(TH_N);
    Arr_Ex(i,7)=n_Vg_beats;
    fprintf(1,'Running time of experiment %d in Normal mode: %d\n',i,time);
    [n_Vg_beats n_VP_beats]=count_beats(TH_COMPOSITION);
    Arr_Ex(i,8)=n_VP_beats;
end


%% Cycle for Tachycardia mode
for i=1:n_exps,
     tic;
    [N_STATES_T AS_T VS_T PS_T QS_T z_T] = ecggen(180*i,180);
    % Create the transition matrix for the tachycardia behavior of the HEART
    [TH_T, c_state_HEART]=transitions(0, N_STATES_T,AS_T,VS_T);

    c_state_HEART=TH_T(1,1);

    % Take the composition
    TH_COMPOSITION = composition(N_STATES_T, TH_T, TP, IM, c_state_PACEMAKER, c_state_HEART);
    Arr_Ex(i,2)=N_STATES_T;
    time=toc;
    Arr_Ex(i,5)=time;
    [n_Vg_beats n_VP_beats]=count_beats(TH_T);
    Arr_Ex(i,9)=n_Vg_beats;
    fprintf(1,'Running time of experiment %d in Tachycardia mode: %d\n',i, time);
    [n_Vg_beats n_VP_beats]=count_beats(TH_COMPOSITION);
    Arr_Ex(i,10)=n_VP_beats;
end

%% Cycle for Bradycardia mode
for i=1:1,
     tic;
    [N_STATES_B AS_B VS_B PS_B QS_B z_B] = ecggen(30*i,30);
    % Create the transition matrix for the bradycardia behavior of the HEART
    [TH_B, c_state_HEART]=transitions(0, N_STATES_B,AS_B,VS_B);

    c_state_HEART=TH_B(1,1);

    % Take the composition
    TH_COMPOSITION = composition(N_STATES_B, TH_B, TP, IM, c_state_PACEMAKER, c_state_HEART);
    Arr_Ex(i,3)=N_STATES_B;
    time=toc;
    Arr_Ex(i,6)=time;
    [n_Vg_beats n_VP_beats]=count_beats(TH_B);
    Arr_Ex(i,11)=n_Vg_beats;
    fprintf(1,'Running time of experiment %d in Bradycardia mode: %d\n',i,time);
    [n_Vg_beats n_VP_beats]=count_beats(TH_COMPOSITION);
    Arr_Ex(i,12)=n_VP_beats;
end