Req = {'(12*p1^10 - 427*p1^9 + (T+2322*p1^8 - (6*T + 5972)*p1^7 + (16*T + 9815)*p1^6 - (24*T + 12027)*p1^5 + (22*T + 11102)*p1^4 - (14*T + 6277)*p1^3 + (8*T + 2455)*p1^2 - (4*T + 355)*p1 + T) / (2*T*p1^8 - 12*T*p1^7 + 34*T*p1^6 - 54*T*p1^5 + 52*T*p1^4 - 32*T*p1^3 + 18*T*p1^2 - 8*T*p1 + 2*T)'
    '(-1000*p1^3 + 1035*p1^2 - 355*p1 + T) / (p1^3)'};


% oneMinusBeta lowerBound, upperBound and step
oneMinusBeta = [0.95 0.95 0.01];

pm = [0.8 0.2];

N = [10 20];
n = 2;

keepLooping = true;

%for i = 1 : n

%itr = N(i);
itr = 60000;

 set(0,'RecursionLimit',itr*2)

Be_to_Rb = 0;
Be_to_Bb = 0;
Bb_to_Be = 0;
Rb_to_Be = 0;
Rb_to_Re = 0;
Re_to_Bb = 0;
Re_to_Sb = 0;
Sb_to_Se = 0;
Sb_to_M1e = 0;
M1e_to_M2b = 0;
M1e_to_Sb = 0;
M2b_to_Se = 0;
M2b_to_M3e = 0;
Se_to_M1b = 0;
Se_to_Sb = 0;
M1b_to_Se = 0;
M1b_to_M2e = 0;
M2e_to_Sb = 0;
M2e_to_M3b = 0;
M3e_to_Sb = 0;
M3e_to_Bb = 0;
M3b_to_Se = 0;
M3b_to_Be = 0;

counter = 0;


while(keepLooping)
    
    counter = counter + 1;
    
    state_from_Be = exe_State(pm);
    
    if(state_from_Be == 1)
        Be_to_Rb = Be_to_Rb + 1;
        
        state_from_Rb = exe_State(pm);
        if(state_from_Rb == 1)
            Rb_to_Re = Rb_to_Re + 1;
            
            state_from_Re = exe_State(pm);        
        else
            Rb_to_Be = Rb_to_Be + 1;
        end
        
    else
        Be_to_Bb = Be_to_Bb + 1;
        Bb_to_Be = Bb_to_Be + 1;
    end
    
    if(counter >= itr)
        keepLooping = false;
    end
    
end

disp(['Be_to_Rb for ', num2str(itr), ' iteration  :  ', num2str(Be_to_Rb)]);
disp(['Be_to_Bb for ', num2str(itr), ' iteration  :  ', num2str(Be_to_Bb)]);
disp(['Bb_to_Be for ', num2str(itr), ' iteration  :  ', num2str(Bb_to_Be)]);
disp(['Rb_to_Be for ', num2str(itr), ' iteration  :  ', num2str(Rb_to_Be)]);
disp(['Rb_to_Re for ', num2str(itr), ' iteration  :  ', num2str(Rb_to_Re)]);
disp(['Re_to_Bb for ', num2str(itr), ' iteration  :  ', num2str(Re_to_Bb)]);
disp(['Re_to_Sb for ', num2str(itr), ' iteration  :  ', num2str(Re_to_Sb)]);
disp(['Sb_to_Se for ', num2str(itr), ' iteration  :  ', num2str(Sb_to_Se)]);
disp(['Sb_to_M1e for ', num2str(itr), ' iteration  :  ', num2str(Sb_to_M1e)]);
disp(['M1e_to_M2b for ', num2str(itr), ' iteration  :  ', num2str(M1e_to_M2b)]);
disp(['M1e_to_Sb for ', num2str(itr), ' iteration  :  ', num2str(M1e_to_Sb)]);
disp(['M2b_to_Se for ', num2str(itr), ' iteration  :  ', num2str(M2b_to_Se)]);
disp(['M2b_to_M3e for ', num2str(itr), ' iteration  :  ', num2str(M2b_to_M3e)]);
disp(['Se_to_M1b for ', num2str(itr), ' iteration  :  ', num2str(Se_to_M1b)]);
disp(['Se_to_Sb for ', num2str(itr), ' iteration  :  ', num2str(Se_to_Sb)]);
disp(['M1b_to_Se for ', num2str(itr), ' iteration  :  ', num2str(M1b_to_Se)]);
disp(['M1b_to_M2e for ', num2str(itr), ' iteration  :  ', num2str(M1b_to_M2e)]);
disp(['M2e_to_Sb for ', num2str(itr), ' iteration  :  ', num2str(M2e_to_Sb)]);
disp(['M2e_to_M3b for ', num2str(itr), ' iteration  :  ', num2str(M2e_to_M3b)]);
disp(['M3e_to_Sb for ', num2str(itr), ' iteration  :  ', num2str(M3e_to_Sb)]);
disp(['M3e_to_Bb for ', num2str(itr), ' iteration  :  ', num2str(M3e_to_Bb)]);
disp(['M3b_to_Se for ', num2str(itr), ' iteration  :  ', num2str(M3b_to_Se)]);
disp(['M3b_to_Be for ', num2str(itr), ' iteration  :  ', num2str(M3b_to_Be)]);


fName = ['LWB-input-' num2str(itr) '.txt'];
fid = fopen(fName,'wt');

for m = 1:size(Req)
    
    fprintf(fid,'%s\n',Req{m,:});
    fprintf(fid,'%0.2f ',oneMinusBeta);
    fprintf(fid,'\n%s\n',['p 2 ',num2str(Be_to_Rb + Be_to_Bb)]);
    fprintf(fid,'%s\n',num2str(Be_to_Rb));
    fprintf(fid,'%s\n',num2str(Bb_to_Be));
    fprintf(fid,'%s\n','END');
    
end

fclose(fid);



keepLooping = true;

