138 CHAPTER 9. OUTLINE OF THE MONTE-CARLO STRATEGY
< < endl ;
ex i t (1) ;
}
el se {
outfilename =argv [ 1 ] ;
}
o f i l e . open ( outfilename ) ;
/ / Read in data
i n i t i a l i s e ( i n i t i a l _ n _ p a r t i c l e s , max_time , number_cycles ,
decay_p robability ) ;
ncumulative = new int [ max_time +1];
/ / Do the mc sampling
mc_sampling ( i n i t i a l _ n _ p a r t i c l e s , max_time , number_cycles ,
decay_probabil it y , ncumulative ) ;
/ / Print out re s u l t s
output ( max_time , number_cycles , ncumulative ) ;
delete [ ] ncumulative ;
return 0 ;
} / / end of main fu nc ti on
the part which performs the Monte Carlo sampling
void mc_sampling ( int i n i t i a l _ n _ p a r t i c l e s , int max_time ,
int number_cycles , double decay_probability ,
int ncumulative )
{
int cycles , time , np , n_unstable , p a r t i c l e _ l i m i t ;
long idum ;
idum = 1; / / i n i t i a l i s e random number generator
/ / loop over monte carlo cycle s
/ / One monte carlo loop i s one sample
for ( cycles = 1 ; cycles <= number_cycles ; cycles ++){
n_unstable = i n i t i a l _ n _ p a r t i c l e s ;
/ / accumulate the number of p a r t i c l e s per time step per t r i a l
ncumulative [0 ] += i n i t i a l _ n_ p a r t i c l e s ;
/ / loop over each time step
for ( time =1; time <= max_time ; time ++){
/ / for each time step , we check each p a r t i c l e
p a r t i c l e _ l i mi t = n_unstable ;
for ( np = 1 ; np <= p a r t i c l e _ l im i t ; np++) {
i f ( ran0(&idum ) <= decay_probability ) {
n_unstable =n_unstable 1;
}
} / / end of loop over p a rt ic le s
ncumulative [ time ] += n_unstable ;