import java.util.Random; public class Gillespie { private static Random random = new Random(); public static double uniform() { return random.nextDouble(); } public static int poisson(double lambda) { // using algorithm given by Knuth // see http://en.wikipedia.org/wiki/Poisson_distribution int k = 0; double p = 1.0; double L = Math.exp(-lambda); do { k++; p *= uniform(); } while (p >= L); return k-1; } public static double exp(double lambda) { return -Math.log(1 - Math.random()) / lambda; } public static void main(String[] args) { int n = (args.length - 1)/3; // n species int[] N = new int[n]; // population size double[] avgBirthRate = new double[n]; // mean birth rate double[] avgDeathRate = new double[n]; // mean death rate int M = Integer.parseInt(args[n*3]); // number of iterations int totN = 0; // total population for (int i=0;i 0; iter++){ lambda = 0.0; for (int i=0;i