cloudsim-plus-master/cloudsim-plus-master/cloudsim-plus/src/main/java/org/cloudbus/cloudsim/distributions/PoissonDistr.java
public static void main(String args[]){
        /*
         * Average number of customers that arrives per minute.
         * The value of 0.4 customers per minute means that 1 customer will arrive
         * at every 2.5 minutes.
         * It means that 1 minute / 0.4 customer per minute = 1 customer at every 2.5 minutes.
         * This is the interarrival time (in average).
         */
        final double MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE=0.4;

        /*
         * Time length of each simulation in minutes.
        */
        final int SIMULATION_TIME_LENGHT = 25;

        //If the arrival of each customers must be shown.
        final boolean showCustomerArrivals = true;

        /*
         * Number of simulations to run.
         */
        final int NUMBER_OF_SIMULATIONS = 100;

        BiConsumer<PoissonDistr, Integer> printArrivals = (poisson, minute) -> {
            if(showCustomerArrivals)
                System.out.printf("%d customers arrived at minute %d\n", poisson.getK(), minute);
        };

        /*
         * A {@link Function} to simulate the arrival of customers for a given time period.
         * This is just a method to test the implementation.
         *
         * @param poisson the PoissonDistr object that will compute the customer arrivals probabilities
         * @return the number of arrived customers
         */
        Function<PoissonDistr, Integer> runSimulation = poisson -> {
            /*We want to check the probability of 1 customer to arrive at each
            single minute. The default k value is 1, so we dont need to set it.*/
            final int totalArrivedCustomers =
                IntStream.range(0, SIMULATION_TIME_LENGHT)
                    .filter(i -> poisson.eventsHappened())
                    .peek(i -> printArrivals.accept(poisson, i))
                    .map(i -> poisson.getK())
                    .sum();

            System.out.printf(
                    "\t%d customers arrived in %d minutes\n", totalArrivedCustomers, SIMULATION_TIME_LENGHT);
            System.out.printf("\tArrival rate: %.2f customers per minute. Customers interarrival time: %.2f minutes in average\n",
                    poisson.getLambda(), poisson.getInterarrivalMeanTime());

            return totalArrivedCustomers;
        };

        double customersArrivedInAllSimulations = 0;
        PoissonDistr poisson = null;
        final long seed=System.currentTimeMillis();
        for(int i = 0; i < NUMBER_OF_SIMULATIONS; i++){
            poisson = new PoissonDistr(MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE, seed+i);
            System.out.printf("Simulation number %d\n", i);
            customersArrivedInAllSimulations += runSimulation.apply(poisson);
        }

        final double mean = customersArrivedInAllSimulations/NUMBER_OF_SIMULATIONS;
        System.out.printf("\nArrived customers average after %d simulations: %.2f\n",
                NUMBER_OF_SIMULATIONS, mean);
        if(poisson != null){
            System.out.printf(
                "%.2f customers expected by each %d minutes of simulation with interarrival time of %.2f minutes\n",
                 poisson.getLambda()*SIMULATION_TIME_LENGHT, SIMULATION_TIME_LENGHT,
                 poisson.getInterarrivalMeanTime());
        }
    }
/**
     * Tests the simulations of customers arrivals in a Poisson process.
     *
     * @param args
     */
Tests the simulations of customers arrivals in a Poisson process.
@param args
Tests the simulations of customers arrivals in a Poisson process . @param args
public static void main(String args[]){
        /*
         * Average number of customers that arrives per minute.
         * The value of 0.4 customers per minute means that 1 customer will arrive
         * at every 2.5 minutes.
         * It means that 1 minute / 0.4 customer per minute = 1 customer at every 2.5 minutes.
         * This is the interarrival time (in average).
         */
        final double MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE=0.4;
        /*
         * Time length of each simulation in minutes.
        */
        final int SIMULATION_TIME_LENGHT = 25;
        final boolean showCustomerArrivals = true;
        /*
         * Number of simulations to run.
         */
        final int NUMBER_OF_SIMULATIONS = 100;
        BiConsumer<PoissonDistr, Integer> printArrivals = (poisson, minute) -> {
            if(showCustomerArrivals)
                System.out.printf("%d customers arrived at minute %d\n", poisson.getK(), minute);
        };
        /*
         * A {@link Function} to simulate the arrival of customers for a given time period.
         * This is just a method to test the implementation.
         *
         * @param poisson the PoissonDistr object that will compute the customer arrivals probabilities
         * @return the number of arrived customers
         */
        Function<PoissonDistr, Integer> runSimulation = poisson -> {
            /*We want to check the probability of 1 customer to arrive at each
            single minute. The default k value is 1, so we dont need to set it.*/
            final int totalArrivedCustomers =
                IntStream.range(0, SIMULATION_TIME_LENGHT)
                    .filter(i -> poisson.eventsHappened())
                    .peek(i -> printArrivals.accept(poisson, i))
                    .map(i -> poisson.getK())
                    .sum();
            System.out.printf(
                    "\t%d customers arrived in %d minutes\n", totalArrivedCustomers, SIMULATION_TIME_LENGHT);
            System.out.printf("\tArrival rate: %.2f customers per minute. Customers interarrival time: %.2f minutes in average\n",
                    poisson.getLambda(), poisson.getInterarrivalMeanTime());
            return totalArrivedCustomers;
        };
        double customersArrivedInAllSimulations = 0;
        PoissonDistr poisson = null;
        final long seed=System.currentTimeMillis();
        for(int i = 0; i < NUMBER_OF_SIMULATIONS; i++){
            poisson = new PoissonDistr(MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE, seed+i);
            System.out.printf("Simulation number %d\n", i);
            customersArrivedInAllSimulations += runSimulation.apply(poisson);
        }
        final double mean = customersArrivedInAllSimulations/NUMBER_OF_SIMULATIONS;
        System.out.printf("\nArrived customers average after %d simulations: %.2f\n",
                NUMBER_OF_SIMULATIONS, mean);
        if(poisson != null){
            System.out.printf(
                "%.2f customers expected by each %d minutes of simulation with interarrival time of %.2f minutes\n",
                 poisson.getLambda()*SIMULATION_TIME_LENGHT, SIMULATION_TIME_LENGHT,
                 poisson.getInterarrivalMeanTime());
        }
    }
public static void main ( String args [ ] ) { /*
         * Average number of customers that arrives per minute.
         * The value of 0.4 customers per minute means that 1 customer will arrive
         * at every 2.5 minutes.
         * It means that 1 minute / 0.4 customer per minute = 1 customer at every 2.5 minutes.
         * This is the interarrival time (in average).
         */ final double MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE = 0.4 ; /*
         * Time length of each simulation in minutes.
        */ final int SIMULATION_TIME_LENGHT = 25 ; final boolean showCustomerArrivals = true ; /*
         * Number of simulations to run.
         */ final int NUMBER_OF_SIMULATIONS = 100 ; BiConsumer < PoissonDistr , Integer > printArrivals = ( poisson , minute ) -> { if ( showCustomerArrivals ) System . out . printf ( "%d customers arrived at minute %d\n" , poisson . getK ( ) , minute ) ; } ; /*
         * A {@link Function} to simulate the arrival of customers for a given time period.
         * This is just a method to test the implementation.
         *
         * @param poisson the PoissonDistr object that will compute the customer arrivals probabilities
         * @return the number of arrived customers
         */ Function < PoissonDistr , Integer > runSimulation = poisson -> { /*We want to check the probability of 1 customer to arrive at each
            single minute. The default k value is 1, so we dont need to set it.*/ final int totalArrivedCustomers = IntStream . range ( 0 , SIMULATION_TIME_LENGHT ) . filter ( i -> poisson . eventsHappened ( ) ) . peek ( i -> printArrivals . accept ( poisson , i ) ) . map ( i -> poisson . getK ( ) ) . sum ( ) ; System . out . printf ( "\t%d customers arrived in %d minutes\n" , totalArrivedCustomers , SIMULATION_TIME_LENGHT ) ; System . out . printf ( "\tArrival rate: %.2f customers per minute. Customers interarrival time: %.2f minutes in average\n" , poisson . getLambda ( ) , poisson . getInterarrivalMeanTime ( ) ) ; return totalArrivedCustomers ; } ; double customersArrivedInAllSimulations = 0 ; PoissonDistr poisson = null ; final long seed = System . currentTimeMillis ( ) ; for ( int i = 0 ; i < NUMBER_OF_SIMULATIONS ; i ++ ) { poisson = new PoissonDistr ( MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE , seed + i ) ; System . out . printf ( "Simulation number %d\n" , i ) ; customersArrivedInAllSimulations += runSimulation . apply ( poisson ) ; } final double mean = customersArrivedInAllSimulations / NUMBER_OF_SIMULATIONS ; System . out . printf ( "\nArrived customers average after %d simulations: %.2f\n" , NUMBER_OF_SIMULATIONS , mean ) ; if ( poisson != null ) { System . out . printf ( "%.2f customers expected by each %d minutes of simulation with interarrival time of %.2f minutes\n" , poisson . getLambda ( ) * SIMULATION_TIME_LENGHT , SIMULATION_TIME_LENGHT , poisson . getInterarrivalMeanTime ( ) ) ; } }
Tests the simulations of customers arrivals in a Poisson process.
Tests the simulations of customers arrivals in a Poisson process .
//If the arrival of each customers must be shown.