//This class calculates general case Guarded Train Model. import java.awt.Dimension; import java.awt.Image; abstract public class GuardedTrain extends Content{ public GuardedTrain(Dimension dim, Image img, String problemName){ super(dim,img,problemName); } //protected void spawnParametersAfterUserApplied(){} //Extra parameters: protected int GT_DivideBy_rInf=1; protected int GT_Subtract_rInf=1; protected void prepareGTParameters( double[] r, double[] m, int A, int b, int g, int s, double p, double q, double[] parameters){ int rLimit=r.length; int L=b+g+s; double Laverage=b+g+s/2.0; double density=(p+(b-1)*q)/Laverage; double amean=(1+A)/2.0; double aaverage=amean*density; double a2mean=(A+1)*(2*A+1)/6.0; double rinf=aaverage*aaverage; double h=1.0/(s+1); //do1 DH-PIM alpha=1. double c0=p/b; double c1=q/b; double C = c0+c1*(b-1); c0=c0/C; c1=c1/C; //Prepare parameters for return: parameters[0]=rinf; parameters[1]=b; m[0]=p; r[0]=a2mean*density; con(" GT. L="+L+" Laverage="+Laverage+" A="+A+" aaverage="+aaverage+ " density="+density+" rinf="+rinf); con(" GT. a2mean="+a2mean + " c0="+c0+" c1="+c1+" C="+C); con(" GT. r[0]="+r[0]+ " p="+p+" h="+h); //Set jumps inside populated area: for(int d=1; d<b; d++){ m[d]=q; con("d="+d+" m="+m[d]); } int v=b+g; //Set jumps to guard area: for(int d=b; d<v; d++){ m[d]=0; con("d="+d+" m="+m[d]); } //Set jumps over filler area: m[v]=p*h; con("d="+v+" m="+m[v]); for(int d=v+1; d<=L; d++){ m[d]=m[d-1]+h*m[d-v]; con("d="+d+" m="+m[d]); } for(int d=L+1; d<rLimit; d++){ double sum=0.0; for(int i=v; i<=L; i++){ sum=sum+m[d-i]; } //Take average: m[d]=sum*h; con("d="+d+" m="+m[d]); } //Finally, find r: for(int d=1; d<rLimit; d++){ //--------------------------------------------- //For small tail drLimit-1-(b-1),...,drLimit-1. r[d]=rinf; //--------------------------------------------- if( d+b-1<rLimit ){ double sum=0; for(int i=1; i<b; i++){ int di=d+i; sum=sum+m[di]; } r[d]=rinf*(c0*m[d] + c1*sum)/density; } con("d="+d+" rGT="+r[d]); } for(int d=0; d<rLimit; d++){ if(1==GT_Subtract_rInf) r[d]=r[d]-rinf; if(1==GT_DivideBy_rInf) r[d]=r[d]/rinf; if(1==GT_DivideBy_rInf || 1==GT_Subtract_rInf){ con(" Normalized. d="+d+" r="+r[d]); } } } protected double functionGT(double g, double[] r, double[] parameters){ int rLimit=r.length; double q=Math.PI*g; double Pw=Math.sin(q)/q; double sumr=r[0]; //con("d="+0+" r="+r[0]); for(int d=1; d<rLimit; d++){ sumr=sumr+r[d]*2*Math.cos(2.0*q*d); //con("d="+d+" r="+r[d]); } sumr=Pw*Pw*sumr; //con("g="+g+" GT="+sumr); return sumr; } } Copyright (C) 2009 Konstantin Kirillov