package WT;

/** This class generates n realizations of a homogeneous Poisson process in the intervall [0, T] with intensity lambda.
 *
 */
public class PoissonProcess {
        
    public static void main(String[] args) {
        
        //the intensity lambda
        double lambda = 0.2;
        //the number of iterations
        int n = 1000;
        //the border of the interval 
        int T = 100;
        //the number of random variables (Erneuerungszeitpunkte)
        int m = 0;
        
        for(int i=0;i<n;i++) //loop for the repetitions of the simulation
        {
            double sum = 0; //sum of the random variables 
            
            while(sum<T)
            {
                
                double u = java.lang.Math.random(); //generates a random number between 0 and 1
                double t = - Math.log(u)/lambda; //transforms u into an exponential distributed random variable with intensity lambda
                if(sum+t<T)
                {
                    sum = sum + t;
                    m++;
                    //export of the first realization
                    if(i==0)
                        System.out.println("Erneuerungszeitpunkt "+m+": "+sum);
                }
                else
                    break;
            }
  
        }
        //calculation of the mean intensity 
        System.out.println("Erwartete Anzahl an Erneuerungspunkten: "+lambda*T);
        System.out.println("Mittlere Anzahl an Erneuerungspunkten bei "+n+" Iterationen: "+m/(double)n);
    }
    
}
