Public synchronized int incContador (int val)
Classified in Electronics
Written at on English with a size of 3.76 KB.
if(padres%2==1){
padres = padres -1;
arrCruce[ultimo][2] = "0";
arrCruce[ultimo][3] = arrCruce[ultimo][0];
}
String c[][] = new String[padres][3];
int f=0;
for(vc=0; vc<individuos; vc++){
if(Integer.ParseInt(arrCruce[vc][2])>0){
c[f][0]=String.ValueOf(vc);
c[f][1]=arrCruce[vc][0];
f++;
}
}
vc=0;
int punto = (int)(Math.Random()*genes);
System.Out.print("\nCRUCE\n");
System.Out.Print("EL PUNTO DE CRUCE ES: " + punto + "\n");
while(vc<padres){
c[vc][2] = c[vc][1].substring(0,punto) + c[vc+1][1].Substring(punto,genes);
c[vc+1][2] = c[vc+1][1].Substring(0,punto) + c[vc][1].Substring(punto,genes);
arrCruce[Integer.ParseInt(c[vc][0])][3] = c[vc][2];
arrCruce[Integer.ParseInt(c[vc+1][0])][3] = c[vc][2];
vc = vc+2;
}
int x,y;
for(x=0; x<padres; x++){
for(y=0; y<3; y++){
System.Out.Print(c[x][y] + "\t");
}
System.Out.Print("\n");
}
Mutacion();
}
public void Mutacion(){
double aleatorio;
int punto;
System.Out.Print("\nMUTACION\n");
for(vc=0; vc<individuos; vc++){
BigDecimal decimal = new BigDecimal( Math.Random() ).SetScale(7,BigDecimal.ROUND_DOWN );
arrCruce[vc][4] = String.ValueOf(decimal);
aleatorio = Double.ParseDouble(arrCruce[vc][4]);
if(aleatorio<=tasa){
String caracter;
arrCruce[vc][5] = "1";
punto = (int)(Math.Random()*genes);
System.Out.Print("EL PUNTO DE MUTACION ES: " + punto + "\t" + arrCruce[vc][3] + "\n");
caracter = arrCruce[vc][3].Substring(punto,punto+1);
if(caracter.EqualsIgnoreCase("0")){
caracter="1";
}else{
caracter = "0";
}
arrCruce[vc][6] = arrCruce[vc][3].Substring(0,punto) + caracter + arrCruce[vc][3].Substring(punto+1,genes);
}else {
arrCruce[vc][5] = "0";
arrCruce[vc][6] = arrCruce[vc][3];
}
}