ModelGuts.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

package locusmodel;

/**

 *

 * @author Mike

 */

public class ModelGuts {

 double tc1, tc2, tc3, tnc1, tnc2, tnc3;

 double tsumbt=0, tsumref=0, tsumnc = 0, tsumnr = 0;

 Double temp;

 String resulttxt;

 double[][][] Refuge = new double[3][3][3];

 double[][][] Bt = new double[3][3][3];

 double[][][] Btnc = new double[3][3][3];

 double[][][] Migrants = new double[3][3][3];

 double[][][] nrMate = new double[3][3][3];

 double[][][] Survivorships = new double[3][3][3];

 double[][][] DailySurv = new double[3][3][3];

 double[] locus1 = new double[3];

 double[] locus2 = new double[3];

 double[] locus3 = new double[3];

 double[] locus1nc = new double[3];

 double[] locus2nc = new double[3];

 double[] locus3nc = new double[3];

 double[] locus1nr = new double[3];

 double[] locus2nr = new double[3];

 double[] locus3nr = new double[3];

 double[] olocus1 = new double[3];

 double[] olocus2 = new double[3];

 double[] olocus3 = new double[3];

 double[] olocus1nc = new double[3];

 double[] olocus2nc = new double[3];

 double[] olocus3nc = new double[3];

 double[] locus1mix = new double[3];

 double[] locus2mix = new double[3];

 double[] locus3mix = new double[3];

 double[] l1A = new double[2]; //Allele frequencies

 double[] l2A = new double[2]; //Allele frequencies

 double[] l3A = new double[2]; //Allele frequencies

 double[] l1Anc = new double[2]; //Allele frequencies

 double[] l2Anc = new double[2]; //Allele frequencies

 double[] l3Anc = new double[2]; //Allele frequencies

 double[] l1Amix = new double[2]; //Allele frequencies

 double[] l2Amix = new double[2]; //Allele frequencies

 double[] l3Amix = new double[2]; //Allele frequencies

 double[] l1Anr = new double[2]; //Allele frequencies

 double[] l2Anr = new double[2]; //Allele frequencies

 double[] l3Anr = new double[2]; //Allele frequencies

 double[] fit1 = new double[3];

 double[] fit2 = new double[3];

 double[] fit3 = new double[3];

 double OverallSurvivorship;

 double hl1, hl2, hl3;

 double refugeProp = 0.05;

 double refugeMort, dailyRefugeSurv, nr_mating;

 double irf;

 double sum, sumnc, sumMix, sumnr;

 double isum, isumnc, isumMix, isumnr, pc, pnc, pMix, pnr;

Page 1
ModelGuts.java

 double baseLM = 0.05;

 double propNC;

 double proportionalMovement;

 double complianceMix;

 int j1, j2, j3;

 int days;

 int generation = 0;

 int MaxGenerations;

 boolean stop = false;

 boolean includeLM = true;

 boolean includeL2;

 boolean includeL3;

 boolean AsymmMove;

 double nonAdditiveInteraction;

 double nonAdditiveInteraction2L;

 boolean SysOut = false;

 public int ModelRun(LocusmodelView lmv) {

 //Technically I should have used getters and setters

 //But I just made them public

 stop = false;

 baseLM = 0.05;

 refugeProp = 0.05;

 generation = 0;

 fit1[0] = Double.valueOf(lmv.l1wss.getText().trim()).doubleValue();

 hl1 = Double.valueOf(lmv.l1wrs.getText()).doubleValue();

 fit1[2] = Double.valueOf(lmv.l1wrr.getText());

 fit1[1] = (fit1[2] - fit1[0]) * hl1 + fit1[0];

 fit2[0] = Double.valueOf(lmv.l2wss.getText());

 hl2 = Double.valueOf(lmv.l2wrs.getText());

 fit2[2] = Double.valueOf(lmv.l2wrr.getText());

 fit2[1] = (fit2[2] - fit2[0]) * hl2 + fit2[0];

 fit3[0] = Double.valueOf(lmv.l3wss.getText());

 hl3 = Double.valueOf(lmv.l3wrs.getText());

 fit3[2] = Double.valueOf(lmv.l3wrr.getText());

 fit3[1] = (fit3[2] - fit3[0]) * hl3 + fit3[0];

 OverallSurvivorship = Double.valueOf(lmv.jTextField9.getText());

 refugeProp = Double.valueOf(lmv.jTextField11.getText());

 refugeMort = Double.valueOf(lmv.jTextField12.getText());

 irf = Double.valueOf(lmv.jTextField10.getText());

 baseLM = Double.valueOf(lmv.baseLMField.getText());

 days = Integer.valueOf(lmv.jTextField1.getText());

 MaxGenerations = Integer.valueOf(lmv.MaxGen.getText());

 //MaxGenerations = 10000;

 includeLM = lmv.jCheckBox1.isSelected();

 includeL2 = lmv.jCheckBox2.isSelected();

 includeL3 = lmv.jCheckBox3.isSelected();

 //includeL3 = false;

 //includeL2 = false;

 AsymmMove = lmv.jCheckBox4.isSelected();

 propNC = Double.valueOf(lmv.jTextField2.getText()); 

 proportionalMovement = Double.valueOf(lmv.jTextField6.getText());

 complianceMix = Double.valueOf(lmv.jTextField7.getText());

 nr_mating = Double.valueOf(lmv.jTextField8.getText());

 if (!includeL2 && !includeL3){

 for (j1 = 0; j1 < 3; j1++)

Page 2
ModelGuts.java

 fit2[j1] = 1.0;

 }

 //No third locus for non-additive dose calculations

 //includeL3 = false;

 if (!includeL3) {

 for (j1 = 0; j1 < 3; j1++) {

 fit3[j1] = 1.0;

 }

 }

 dailyRefugeSurv = Math.exp(Math.log(1.0 - refugeMort) / days);

 {

 double allMovement;

 allMovement = 1.0 - (1.0 - lmv.asymmMove) * (1.0 - baseLM);

 proportionalMovement = 1.0 - Math.exp(Math.log(1.0 - allMovement) / days);

 }

 baseLM = 1.0 - Math.exp(Math.log(1.0 - baseLM) / days);

 nonAdditiveInteraction = OverallSurvivorship/(fit1[0] * fit2[0] *fit3[0]);

 //nonAdditiveInteraction2L = Math.sqrt(nonAdditiveInteraction);

 nonAdditiveInteraction2L = Math.exp(Math.log(nonAdditiveInteraction)/3);

 Survivorships[0][0][0] = OverallSurvivorship;

 Survivorships[2][0][0] = fit2[0] * fit3[0] * nonAdditiveInteraction2L;

 if (Survivorships[2][0][0] > Math.min(fit2[0],fit3[0]))

 {

 Survivorships[2][0][0] = Math.min(fit2[0],fit3[0]);

 }

 if(Survivorships[2][0][0] < OverallSurvivorship) {

 Survivorships[2][0][0] = OverallSurvivorship;

 }

 Survivorships[0][2][0] = fit1[0]*fit3[0] * nonAdditiveInteraction2L;

 if (Survivorships[0][2][0] > Math.min(fit1[0],fit3[0]))

 {

 Survivorships[0][2][0] = Math.min(fit1[0],fit3[0]);

 }

 if(Survivorships[0][2][0] < OverallSurvivorship) {

 Survivorships[0][2][0] = OverallSurvivorship;

 }

 Survivorships[0][0][2] = fit1[0] * fit2[0] * nonAdditiveInteraction2L;

 if (Survivorships[0][0][2] > Math.min(fit1[0],fit2[0]))

 {

 Survivorships[0][0][2] = Math.min(fit1[0],fit2[0]);

 }

 if(Survivorships[0][0][2] < OverallSurvivorship) {

 Survivorships[0][0][2] = OverallSurvivorship;

 }

 Survivorships[0][2][2] = fit1[0];

 Survivorships[1][2][2] = (1.0 - fit1[0]) * hl1 + fit1[0];

 Survivorships[2][2][2] = 1.0;

 Survivorships[2][0][2] = fit2[0];

 Survivorships[2][1][2] = (1.0 - fit2[0]) * hl2 + fit2[0];

 Survivorships[2][2][0] = fit3[0];

 Survivorships[2][2][1] = (1.0 - fit3[0]) * hl3 + fit3[0];

Page 3
ModelGuts.java

 Survivorships[0][1][2] = (Survivorships[0][2][2] - Survivorships[0][0][2]) * hl2

+ Survivorships[0][0][2];

 Survivorships[1][0][2]= (Survivorships[2][0][2] - Survivorships[0][0][2]) * hl1 

+ Survivorships[0][0][2];

 //Survivorships[1][1][2] = ??

 Survivorships[2][1][0] = (Survivorships[2][2][0] - Survivorships[2][0][0]) * hl2

+ Survivorships[2][0][0];

 Survivorships[2][0][1] = (Survivorships[2][0][2] - Survivorships[2][0][0]) * hl3

+ Survivorships[2][0][0];

 Survivorships[0][1][0] = (Survivorships[0][2][0] - OverallSurvivorship) * hl2 + 

OverallSurvivorship;

 //Survivorships[2][1][1] = ??

 Survivorships[1][2][0] = (Survivorships[2][2][0] - Survivorships[0][2][0]) * hl1

+ Survivorships[0][2][0];

 Survivorships[1][0][0] = (Survivorships[2][0][0] - OverallSurvivorship) * hl1 + 

OverallSurvivorship;

 Survivorships[2][2][1] = (1.0 - Survivorships[2][2][0]) * hl3 + 

Survivorships[2][2][0];

 Survivorships[2][1][1] = (Survivorships[2][1][2] - Survivorships[2][1][0]) * hl3

+ Survivorships[2][1][0];

 Survivorships[1][0][1] = (Survivorships[1][0][2] - Survivorships[1][0][0]) * hl3

+ Survivorships[1][0][0];

 Survivorships[0][0][1] = (Survivorships[0][0][2] - OverallSurvivorship) * hl3 + 

OverallSurvivorship;

 Survivorships[0][2][1] = (Survivorships[0][2][2] - Survivorships[0][2][0]) * hl3

+ Survivorships[0][2][0];

 Survivorships[1][2][1] = (Survivorships[1][2][2] - Survivorships[1][2][0]) * hl3

+ Survivorships[1][2][0];

 Survivorships[0][1][0] = (Survivorships[0][2][0] - OverallSurvivorship) * hl2 + 

OverallSurvivorship;

 Survivorships[0][1][1] = (Survivorships[0][1][2] - Survivorships[0][1][0]) * hl3

+ Survivorships[0][1][0];

 Survivorships[1][1][0] = (Survivorships[2][1][0] - 

Survivorships[0][1][0])*(hl1+hl2)/2 + Survivorships[0][1][0];

 Survivorships[1][1][1] = (Survivorships[2][1][1] - 

Survivorships[0][1][1])*(hl1+hl2)/2 + Survivorships[0][1][1];

 Survivorships[1][1][2] = (Survivorships[2][1][2] - 

Survivorships[0][1][2])*(hl1+hl2)/2 + Survivorships[0][1][2];

 if(SysOut){

 System.out.println();

 resulttxt = String.format ("locus 1: %7.5f, %7.5f", fit1[0], hl1);

 System.out.println(resulttxt);

 resulttxt = String.format ("locus 2: %7.5f, %7.5f", fit2[0], hl2);

 System.out.println(resulttxt);

 resulttxt = String.format ("locus 3: %7.5f, %7.5f", fit3[0], hl3);

 System.out.println(resulttxt);

 resulttxt = String.format ("Overall: %7.5f", OverallSurvivorship);

 System.out.println(resulttxt);

 System.out.println();

 System.out.println();

 for (int jj3 = 0; jj3 < 3; jj3++){

 for (int jj2 = 0; jj2 < 3; jj2++){

 for( int jj1 = 0; jj1 < 3; jj1++){

 resulttxt = String.format ("%7.5f,", Survivorships[jj1][jj2][jj3]);

 System.out.print(resulttxt);

 //System.out.print();

 }

 System.out.println(" ");

Page 4
ModelGuts.java

 }

 System.out.println();

 System.out.println();

 }

 System.out.println();

 }

 /*

 for (j1 = 1; j1 < 3; j1++){

 for(j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++) {

 Survivorships[j2][j3][j1] = Survivorships[j2][j3][0];

 }

 }

 }

 *

 */

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 DailySurv[j1][j2][j3] = 

Math.exp(Math.log(Survivorships[j1][j2][j3])/days);

 //String result = String.format ("%d %d %d, %12.10f", j1,j2,j3, 1.0 

- (1.0 - (1.0 - DailySurv[j1][j2][j3]) * proportionalMovement) * (1.0 - baseLM));

 //System.out.println(result);

 }

 }

 }

 //System.out.println("Generation C-R1 C-R2 C-R3 NC-R1 NC-R2 NC-R3 PropInC 

PropInNc");

 //Initialize frequency arrays

 locus1[0] =(1.0 - irf) * (1.0 - irf) * (1 - propNC);

 locus1nc[0] =(1.0 - irf) * (1.0 - irf) * (propNC);

 locus1[1] = 2 * irf * (1.0 - irf) * (1 - propNC);

 locus1nc[1] = 2 * irf * (1.0 - irf) * (propNC);

 locus1[2] = irf * irf * (1 - propNC);

 locus1nc[2] = irf * irf * (propNC);

 for (j1 = 0; j1 < 3; j1++){

 locus2[j1] = locus1[j1];

 locus3[j1] = locus1[j1];

 locus2nc[j1] = locus1nc[j1];

 locus3nc[j1] = locus1nc[j1];

 }

 //if (propNC > 0.00001){

 // refugeProp -= refugeProp * propNC;

 //}

 while (!stop){

 //lmv.genOut.setText(Integer.toString(generation));

 //lmv.addPropertyChangeListener(null, null);

 tc1=0; tc2 = 0; tc3 = 0; tnc1=0; tnc2 = 0; tnc3=0;

 for (j1 = 0; j1 < 3; j1++){

 tc1 += locus1[j1];

 tc2 += locus2[j1];

Page 5
ModelGuts.java

 tc3 += locus3[j1];

 //Refuge[j1][j2][j3] = locus1[j1] * locus2[j2] * locus3[j3] * 

(refugeProp);

 tnc1 += locus1nc[j1];

 tnc2 += locus2nc[j1];

 tnc3 += locus3nc[j1];

 }

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 if (tc1 == 0 || tc2 == 0 || tc3 == 0)

 Bt[j1][j2][j3] = Refuge[j1][j2][j3] = 0.0;

 else

 {

 Bt[j1][j2][j3] = locus1[j1]/tc1 * locus2[j2]/tc2 * 

locus3[j3]/tc2;

 Refuge[j1][j2][j3] = locus1[j1]/tc1 * locus2[j2]/tc2 * 

locus3[j3]/tc3;

 }

 if (tnc1 == 0 || tnc2 == 0 || tnc3 == 0)

 Btnc[j1][j2][j3] = 0.0;

 else

 Btnc[j1][j2][j3] = locus1nc[j1]/tnc1 * locus2nc[j2]/tnc2 * 

locus3nc[j3]/tnc3;

 }

 }

 }

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 Bt[j1][j2][j3] *= (tc1+tc2+tc3)/(tc1+tc2+tc3+tnc1+tnc2+tnc3) * 

(1.0 - refugeProp);

 Refuge[j1][j2][j3] *= (tc1+tc2+tc3)/(tc1+tc2+tc3+tnc1+tnc2+tnc3)

* (refugeProp);

 Btnc[j1][j2][j3] *= 

(tnc1+tnc2+tnc3)/(tc1+tc2+tc3+tnc1+tnc2+tnc3);

 }

 }

 } 

 if(includeLM) {

 for (int j4 = 0; j4 < days; j4++) {

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 double btMov;

 sum = 0;

 Bt[j1][j2][j3] *= DailySurv[j1][j2][j3];

 Refuge[j1][j2][j3] *= (dailyRefugeSurv);

 if (AsymmMove) 

 //btMov = 1.0 - (1.0 - (1.0 - DailySurv[j1][j2][j3]) * 

proportionalMovement) * (1.0 - baseLM);

 //btMov = 1.0 - (1.0 - proportionalMovement) * (1.0 - 

baseLM);

 btMov = proportionalMovement;

 else

 btMov = baseLM;

 sum += Bt[j1][j2][j3] * btMov;

 sum += Refuge[j1][j2][j3] * baseLM;

Page 6
ModelGuts.java

 Bt[j1][j2][j3] -= (Bt[j1][j2][j3] * btMov);

 Refuge[j1][j2][j3] -= Refuge[j1][j2][j3] * baseLM;

 Refuge[j1][j2][j3] += sum * refugeProp;

 Bt[j1][j2][j3] += sum * (1.0 - refugeProp);

 }

 }

 }

 }

 }

 else {

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 Bt[j1][j2][j3] *= Survivorships[j1][j2][j3];

 Refuge[j1][j2][j3] *= (1.0 - refugeMort);

 Btnc[j1][j2][j3] *= Survivorships[j1][j2][j3];

 /*

 double tempnc = Bt[j1][j2][j3] * (complianceMix) * propNC +

 Refuge[j1][j2][j3] * (complianceMix) * propNC +

 Btnc[j1][j2][j3] * (1 - complianceMix) +

 Btnc[j1][j2][j3] * complianceMix * propNC;

 double tempBt = Bt[j1][j2][j3] * (1 - complianceMix) +

 Bt[j1][j2][j3] * (complianceMix) * (1 - 

propNC) +

 Btnc[j1][j2][j3] * complianceMix * (1 - 

propNC) * ( 1 - refugeProp);

 double tempRef = Refuge[j1][j2][j3] * (1 - complianceMix) +

 Refuge[j1][j2][j3] * complianceMix * (1 - 

propNC) +

 Btnc[j1][j2][j3] * complianceMix * (1 - 

propNC) * refugeProp;

 */

/*

 Migrants[j1][j2][j3] = Bt[j1][j2][j3] * (complianceMix) +

 Refuge[j1][j2][j3] * complianceMix +

 Btnc[j1][j2][j3] * complianceMix;

 Btnc[j1][j2][j3] -= Btnc[j1][j2][j3] * complianceMix;

 Bt[j1][j2][j3] -= Bt[j1][j2][j3] * (complianceMix);

 Refuge[j1][j2][j3] -= Refuge[j1][j2][j3] * complianceMix;

 */

 nrMate[j1][j2][j3] = Bt[j1][j2][j3] * nr_mating;

 Bt[j1][j2][j3] -= nrMate[j1][j2][j3]; //Bt[j1][j2][j3] * 

nr_mating;

 }

 }

 }

 }

 sum = 0.0;

 sumnc = 0.0;

 sumMix = 0.0;

 sumnr = 0.0;

 for (j1 = 0; j1 < 3; j1++) {

 for (j2 = 0; j2 < 3; j2++) {

 for (j3 = 0; j3 < 3; j3++) {

Page 7
ModelGuts.java

 sum += Bt[j1][j2][j3] + Refuge[j1][j2][j3];

 sumnc += Btnc[j1][j2][j3];

 //sumMix += Migrants[j1][j2][j3];

 sumnr += nrMate[j1][j2][j3];

 }

 }

 }

 if (sum > 0.0)

 isum = 1.0/sum;

 else

 isum = 0.0;

 if (sumnc > 0.0)

 isumnc = 1.0/sumnc;

 else

 isumnc = 0.0;

 //if (sumMix > 0.0)

 // isumMix = 1.0/sumMix;

 //else

 // isumMix = 0.0;

 if (sumnr > 0.0)

 isumnr = 1.0/sumnr;

 else

 isumnr = 0.0;

 

 sumMix = 0.0; //We don't want mixing yet

 pMix = 0.0; //ditto

 pc = sum / (sum + sumnc + sumMix + sumnr);

 pnc = sumnc / (sum + sumnc + sumMix + sumnr);

 pnr = sumnr / (sum + sumnc + sumMix + sumnr);

 //pMix = sumMix / (sum + sumnc + sumMix);

 //Now we convert each group sum to 1 to do the mating

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 Bt[j1][j2][j3] *= isum;

 Refuge[j1][j2][j3] *= isum;

 Btnc[j1][j2][j3] *= isumnc;

 nrMate[j1][j2][j3] *= isumnr;

 //Migrants[j1][j2][j3] *= isumMix;

 }

 }

 }

 //double tsumbt=0, tsumref=0, tsumnc = 0, tsumnr = 0;

 tsumbt=0; tsumref=0; tsumnc = 0; tsumnr = 0;

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 tsumbt += Bt[j1][j2][j3];

 tsumref += Refuge[j1][j2][j3];

 tsumnc += Btnc[j1][j2][j3];

 tsumnr += nrMate[j1][j2][j3];

 //Migrants[j1][j2][j3] *= isumMix;

 }

 }

 }

//double test = 0; //Just here for debugging

 //Zero out the arrays

Page 8
ModelGuts.java

 for (j1 = 0; j1 < 3; j1++){

 locus1[j1] = 0.0;

 locus2[j1] = 0.0;

 locus3[j1] = 0.0;

 locus1nc[j1] = 0.0;

 locus2nc[j1] = 0.0;

 locus3nc[j1] = 0.0;

 locus1nr[j1] = 0.0;

 locus2nr[j1] = 0.0;

 locus3nr[j1] = 0.0;

 //locus1mix[j1] = 0.0;

 //locus2mix[j1] = 0.0;

 //locus3mix[j1] = 0.0;

 }

 //Now we sum the frequencies of of the genotypes at each locus

 for (j1 = 0; j1 < 3; j1++){

 for (j2 = 0; j2 < 3; j2++){

 for (j3 = 0; j3 < 3; j3++){

 locus1[j1] += Bt[j1][j2][j3];

 locus1[j1] += Refuge[j1][j2][j3];

 locus1nc[j1] += Btnc[j1][j2][j3];

 locus2[j2] += Bt[j1][j2][j3];

 locus2[j2] += Refuge[j1][j2][j3];

 locus2nc[j2] += Btnc[j1][j2][j3];

 locus3[j3] += Bt[j1][j2][j3];

 locus3[j3] += Refuge[j1][j2][j3];

 locus3nc[j3] += Btnc[j1][j2][j3];

 locus1nr[j1] += nrMate[j1][j2][j3];

 locus2nr[j2] += nrMate[j1][j2][j3];

 locus3nr[j3] += nrMate[j1][j2][j3];

 //locus1mix[j1] += Migrants[j1][j2][j3];

 //locus2mix[j2] += Migrants[j1][j2][j3];

 //locus3mix[j3] += Migrants[j1][j2][j3];

 }

 }

 }

 //Now we calculate allele frequencies

 l1A[0] = locus1[0] + 0.5 * locus1[1];

 l1A[1] = 1.0 - l1A[0];

 l2A[0] = locus2[0] + 0.5 * locus2[1];

 l2A[1] = 1.0 - l2A[0];

 l3A[0] = locus3[0] + 0.5 * locus3[1];

 l3A[1] = 1.0 - l3A[0];

 l1Anc[0] = locus1nc[0] + 0.5 * locus1nc[1];

 l1Anc[1] = 1.0 - l1Anc[0];

 l2Anc[0] = locus2nc[0] + 0.5 * locus2nc[1];

 l2Anc[1] = 1.0 - l2Anc[0];

 l3Anc[0] = locus3nc[0] + 0.5 * locus3nc[1];

 l3Anc[1] = 1.0 - l3Anc[0];

 l1Anr[0] = locus1nr[0] + 0.5 * locus1nr[1];

 l1Anr[1] = 1.0 - l1Anr[0];

 l2Anr[0] = locus2nr[0] + 0.5 * locus2nr[1];

 l2Anr[1] = 1.0 - l2Anr[0];

 l3Anr[0] = locus3nr[0] + 0.5 * locus3nr[1];

 l3Anr[1] = 1.0 - l3Anr[0];

 //l1Amix[0] = locus1mix[0] + 0.5 * locus1mix[1];

Page 9
ModelGuts.java

 //l1Amix[1] = 1.0 - l1Amix[0];

 //l2Amix[0] = locus2mix[0] + 0.5 * locus2mix[1];

 //l2Amix[1] = 1.0 - l2Amix[0];

 //l3Amix[0] = locus3mix[0] + 0.5 * locus3mix[1];

 //l3Amix[1] = 1.0 - l3Amix[0];

/*

 locus1[0] = l1A[0] * l1A[0] * pc + l1Amix[0] * l1Amix[0] * pMix * (1 - 

propNC);

 locus1nc[0] = l1Anc[0] * l1Anc[0] * pnc + l1Amix[0] * l1Amix[0] * pMix * 

(propNC);

 locus1[1] = 2 * l1A[0] * l1A[1] * pc + 2 * l1Amix[0] * l1Amix[1] * pMix * 

(1-propNC);

 locus1nc[1] = 2 * l1Anc[0] * l1Anc[1] * pnc + 2 * l1Amix[0] * l1Amix[1] * 

pMix * (propNC);

 locus1[2] = l1A[1] * l1A[1] * pc + l1Amix[1] * l1Amix[1] * pMix * (1 - 

propNC);

 locus1nc[2] = l1Anc[1] * l1Anc[1] * pnc + l1Amix[1] * l1Amix[1] * pMix * 

(propNC);

 locus2[0] = l2A[0] * l2A[0] * pc + l2Amix[0] * l2Amix[0] * pMix * (1 - 

propNC);

 locus2nc[0] = l2Anc[0] * l2Anc[0] * pnc + l2Amix[0] * l2Amix[0] * pMix * 

(propNC);

 locus2[1] = 2 * l2A[0] * l2A[1] * pc + 2 * l2Amix[0] * l2Amix[1] * pMix * 

(1-propNC);

 locus2nc[1] = 2 * l2Anc[0] * l2Anc[1] * pnc + 2 * l2Amix[0] * l2Amix[1] * 

pMix * (propNC);

 locus2[2] = l2A[1] * l2A[1] * pc + l2Amix[1] * l2Amix[1] * pMix * (1 - 

propNC);

 locus2nc[2] = l2Anc[1] * l2Anc[1] * pnc + l2Amix[1] * l2Amix[1] * pMix * 

(propNC);

 locus3[0] = l3A[0] * l3A[0] * pc + l3Amix[0] * l3Amix[0] * pMix * (1 - 

propNC);

 locus3nc[0] = l3Anc[0] * l3Anc[0] * pnc + l3Amix[0] * l3Amix[0] * pMix * 

(propNC);

 locus3[1] = 2 * l3A[0] * l3A[1] * pc + 2 * l3Amix[0] * l3Amix[1] * pMix * 

(1-propNC);

 locus3nc[1] = 2 * l3Anc[0] * l3Anc[1] * pnc + 2 * l3Amix[0] * l3Amix[1] * 

pMix * (propNC);

 locus3[2] = l3A[1] * l3A[1] * pc + l3Amix[1] * l3Amix[1] * pMix * (1 - 

propNC);

 locus3nc[2] = l3Anc[1] * l3Anc[1] * pnc + l3Amix[1] * l3Amix[1] * pMix * 

(propNC);

 */

 locus1[0] = l1A[0] * l1A[0] * pc;

 locus1nc[0] = l1Anc[0] * l1Anc[0] * pnc;

 locus1nr[0] = l1Anr[0] * l1Anr[0] * pnr;

 locus1[1] = 2 * l1A[0] * l1A[1] * pc;

 locus1nc[1] = 2 * l1Anc[0] * l1Anc[1] * pnc;

 locus1nr[1] = 2 * l1Anr[0] * l1Anr[1] * pnr;

 locus1[2] = l1A[1] * l1A[1] * pc;

 locus1nc[2] = l1Anc[1] * l1Anc[1] * pnc;

 locus1nr[2] = l1Anr[1] * l1Anr[1] * pnr;

 locus2[0] = l2A[0] * l2A[0] * pc;

 locus2nc[0] = l2Anc[0] * l2Anc[0] * pnc;

 locus2nr[0] = l2Anr[0] * l2Anr[0] * pnr;

 locus2[1] = 2 * l2A[0] * l2A[1] * pc;

 locus2nc[1] = 2 * l2Anc[0] * l2Anc[1] * pnc;

 locus2nr[1] = 2 * l2Anr[0] * l2Anr[1] * pnr;

Page 10
ModelGuts.java

 locus2[2] = l2A[1] * l2A[1] * pc;

 locus2nc[2] = l2Anc[1] * l2Anc[1] * pnc;

 locus2nr[2] = l2Anr[1] * l2Anr[1] * pnr;

 locus3[0] = l3A[0] * l3A[0] * pc;

 locus3nc[0] = l3Anc[0] * l3Anc[0] * pnc;

 locus3nr[0] = l3Anr[0] * l3Anr[0] * pnr;

 locus3[1] = 2 * l3A[0] * l3A[1] * pc;

 locus3nc[1] = 2 * l3Anc[0] * l3Anc[1] * pnc;

 locus3nr[1] = 2 * l3Anr[0] * l3Anr[1] * pnr;

 locus3[2] = l3A[1] * l3A[1] * pc;

 locus3nc[2] = l3Anc[1] * l3Anc[1] * pnc;

 locus3nr[2] = l3Anr[1] * l3Anr[1] * pnr;

 //Now we need to combine the nrMate and refuge+Bt alleles for random 

oviposition

 for (j1 = 0; j1 < 3; j1++)

 {

 locus1[j1] += locus1nr[j1];

 locus2[j1] += locus2nr[j1];

 locus3[j1] += locus3nr[j1];

 }

 //Now move some of the eggs back and forth

 //This simulates mated adults moving and laying eggs in other habitats

 for (j1 = 0; j1 < 3; j1++){

 temp = locus1[j1] + locus1nc[j1] * complianceMix * (1 - propNC) -

 locus1[j1] * complianceMix * propNC;

 locus1nc[j1] += locus1[j1] * complianceMix * propNC -

 locus1nc[j1] * complianceMix * (1 - propNC);

 locus1[j1] = temp;

 temp = locus2[j1] + locus2nc[j1] * complianceMix * (1 - propNC) -

 locus2[j1] * complianceMix * propNC;

 locus2nc[j1] += locus2[j1] * complianceMix * propNC -

 locus2nc[j1] * complianceMix * (1 - propNC);

 locus2[j1] = temp;

 temp = locus3[j1] + locus3nc[j1] * complianceMix * (1 - propNC) -

 locus3[j1] * complianceMix * propNC;

 locus3nc[j1] += locus3[j1] * complianceMix * propNC -

 locus3nc[j1] * complianceMix * (1 - propNC);

 locus3[j1] = temp;

 }

/*

 //Move the refuge now. It shouldn't make a difference if complianceMix is 1

 for (j1 = 0; j1 < 3; j1++){

 Double temp;

 temp = locus1[j1];

 //sum = locus1[j1]+locus1nc[j1];

 locus1[j1] = 0.125*locus1nc[j1];

 locus1nc[j1] = temp + 0.875*locus1nc[j1];

 //sum = locus1[j1]+locus1nc[j1];

 temp = locus2[j1];

 locus2[j1] = 0.25*locus2nc[j1];

 locus2nc[j1] = temp + 0.75*locus2nc[j1];

 temp = locus3[j1];

 locus3[j1] = 0.25*locus3nc[j1];

 locus3nc[j1] = temp + 0.75*locus3nc[j1];

Page 11
ModelGuts.java

 

 }

 * 

 */

 //if( l1A[1] > 0.5 && l2A[1] > 0.5 && l3A[1] > 0.5)

 stop = true;

 if (l1A[1] < 0.5 || l1Anc[1] < 0.5){

 stop = false;

 }

 else if (includeL2 && (l2A[1] < 0.5 || l2Anc[1] < 0.5)){

 stop = false;

 }

 else if (includeL3 && (l3A[1] < 0.5 || l3Anc[1] < 0.5)){

 stop = false;

 }

 if (generation >= MaxGenerations)

 stop = true;

 

 //String result = String.format ("%d %8.6f %8.6f %8.6f ", generation, 

l1A[1], l2A[1], l3A[1]);

 //System.out.print(result);

 //result = String.format ("%8.6f %8.6f %8.6f ", l1Amix[1], l2Amix[1], 

l3Amix[1]);

 //System.out.print(result);

 //result = String.format ("%8.6f %8.6f %8.6f ", l1Anc[1], l2Anc[1], 

l3Anc[1]);

 //System.out.print(result);

 //result = String.format ("%14.12f %14.12f", pc, pnc);

 //System.out.println(result);

 generation++;

 }

 resulttxt = String.format ("%12.10f", l1A[1]);

 lmv.jTextField3.setText(resulttxt);

 if(SysOut)

 System.out.println("l1: "+resulttxt);

 resulttxt = String.format ("%12.10f", l2A[1]);

 lmv.jTextField4.setText(resulttxt);

 lmv.genOut.setText(Integer.toString(generation));

 if(SysOut)

 System.out.println("l2: "+resulttxt);

 resulttxt = String.format ("%12.10f", l3A[1]);

 lmv.jTextField5.setText(resulttxt);

 if(SysOut)

 System.out.println("l3: "+resulttxt);

 resulttxt = String.format("%12.10f",irf);

 if(SysOut)

 System.out.println("IRF: "+resulttxt);

 

lmv.getComponent().paintImmediately(lmv.getComponent().getX(),lmv.getComponent().get

Y(),lmv.getComponent().getWidth(),lmv.getComponent().getHeight());

 //System.gc();

 return (generation);

 }

}

Page 12