private void selectionSimulationStep(double[] previous, double[] next, SelectionStrengthModel[] ssm, double time) {

		boolean fixFlag =true;
		boolean zeroFlag =true;
		// lots of class v set from the calling function.

		for (int d =0; d < ndeme; d++) {
			if (sizes[d] == PopulationSizeModel.NULL_POPULATION)
				continue;
			double x =previous[d];
			// assumption
			double ax =1.0 - x;
			if (x > 0)
				zeroFlag =false;
			if (x < 1.0)
				fixFlag =false;
			double sAA =ssm[d].getStrength(1, 1, time);
			double sAa =ssm[d].getStrength(1, 0, time);
			double saa =ssm[d].getStrength(0, 0, time);
			//System.err.println("SAA @ time:"+time+"\t"+sAA+"\t"+sAa+"\t"+saa);
			//System.err.println("x's:"+x+"\t"+ax);
			afterSelectionA[d] =x * (1 + ax * sAa + x * sAA);
			afterSelectiona[d] =ax * (1 + x * sAa + ax * saa);
		}

		for (int d =0; d < ndeme; d++) {
			if (sizes[d] == PopulationSizeModel.NULL_POPULATION) {
				next[d] =0;// frequencys[d][1][nextGen] =0;
				// nextFreq[d][0]=0;//frequencys[d][0][nextGen] =0;
				continue;
			}
			// first self migration.
			double rate =1 - totalMRates[d];
			double nA =rate * afterSelectionA[d];
			double na =rate * afterSelectiona[d];
			//for(int[] dier:migrationDirections)
			//	System.out.println(Arrays.toString(dier));
			int[] directions =migrationDirections[d];
			double[] rates =migrationRates[d];
			for (int count =0; count < directions.length; count++) {
				int j =directions[count];
				rate =rates[count];
				//System.err.println("After!"+Arrays.toString(afterSelectionA)+"\t"+j+"\tD:"+Arrays.toString(directions));
				nA +=rate * afterSelectionA[j];
				na +=rate * afterSelectiona[j];
			}
			// now put it together for xp
			
			double xp =(nA * (1 - nu) + mu * na) / (nA + na);
			// we keep N in the sample for now...
			int N =(int)Math.ceil( sizes[d].populationSize(time) * 2);//
			//System.err.println("CallBin "+N+" "+xp+"\t"+sizes[d].populationSize(time)+"\t"+nA+"\t"+na);
			double f =(double) binomial.generateBinomial(N, xp) / N;
			//System.err.println("return bin "+f);
			//what if N is zero!
			if(N==0){
				f=0;//throw new RuntimeException("NaN, PopulationSize is probably zero! "+N);
			}
			// update
			next[d] =f;
		}

	}