// // Discrete Time CA using rates and parameterised time // import java.util.*; import java.io.*; import java.awt.*; public class Rdb2 extends CARS { Integer[] siteOrder = new Integer[n*n]; // Integer array of site indices (as object so can use Collections.shuffle) public Rdb2(int n,int m,double tau,boolean draw){ super(n,m,tau,draw); } void doBirths(int[][]X,int[][]Y){ int species = -1; // shuffle array of indices so we can go through grid in random order Collections.shuffle(Arrays.asList(siteOrder)); // update each site for (int siteindex : siteOrder) { int i = siteindex/n; int j = siteindex%n; species = X[i][j]; if (species != empty && gen.nextDouble() <= pBirth[species]) { //System.out.println("giving birth"); birth(species,Y,i,j); } } } public void doGeneration(){ //fill arrays for ordering of events (local to the class) for (int i=0; i < siteOrder.length; i++) { siteOrder[i] = i; } /* // birth-death, newborns may not survive copy(A,B); doBirths(A,B); doDeaths(B,B); copy(B,A); */ /* // birth-death, newborns survive copy(A,B); doBirths(A,B); doDeaths(A,B); copy(B,A); */ /* // death-birth, newborns survive copy(A,B); doDeaths(A,B); doBirths(A,B); copy(B,A); */ // death-birth, newborns may not survive to reproduce copy(A,B); doDeaths(A,B); doBirths(B,B); copy(B,A); time = time + tau; if (draw){plot(); pause(100);} show(); } public static void main(String[] args) { int n = Integer.parseInt(args[0]); // size of grid int maxTime = Integer.parseInt(args[1]); // number of iterations double tau = Double.parseDouble(args[2]); // the click of the clock int m = (args.length/3) - 1; // n species boolean draw = args[args.length-1].equals("draw"); // do we draw? int reps = 1; if (args[args.length-1].equals("ten")) reps = 10; if (args[args.length-1].equals("hundred")) reps = 100; while (reps > 0){ Rdb2 rdb2 = new Rdb2(n,m,tau,draw); for (int i=1;i<=m;i++){ int species = i-1; int pop = Integer.parseInt(args[3*i]); rdb2.setBirthRate(species,Double.parseDouble(args[3*i+1])); rdb2.setDeathRate(species,Double.parseDouble(args[3*i+2])); for (int j=0;j