void CruceBLXPW(chromosome& par1, chromosome& par2, chromosome& suc1, chromosome& suc2) { double temp, px, py, I, alfa; int ingressi=numVar; if (CLASSIFICATION) ingressi--; alfa = 0.5; //double space=(double)1/(numpieces+1); for (int j = 0; j < ingressi; j++) { for (int i = 0; i < numParts[j]-2; i++) { px = par1.pwLT[j][i]; py = par2.pwLT[j][i]; if (px > py) { temp = px; px = py; py = temp; } I = py - px; px = px - I * alfa; py = py + I * alfa; if (px < par1.pwLT_lim[0][j][i]) px = par1.pwLT_lim[0][j][i]; if (py >= par1.pwLT_lim[1][j][i]) py = par1.pwLT_lim[1][j][i]; suc1.pwLT[j][i] = px + Rand() * (py - px); suc2.pwLT[j][i] = px + Rand() * (py - px); } bool trovato = false; ordina(suc1.pwLT[j], numParts[j]-2); for (int i = 1; i < numParts[j]-2 && !trovato; i++) if (suc1.pwLT[j][i] - suc1.pwLT[j][i - 1] < (double) 1 / GrDig) trovato = true; if (trovato) for (int i = 0; i < numParts[j]-2; i++) suc1.pwLT[j][i] = par1.pwLT[j][i]; ordina(suc2.pwLT[j], numParts[j]-2); trovato = false; for (int i = 1; i < numParts[j]-2 && !trovato; i++) if (suc2.pwLT[j][i] - suc2.pwLT[j][i - 1] < (double) 1 / GrDig) trovato = true; if (trovato) for (int i = 0; i < numParts[j]-2; i++) suc2.pwLT[j][i] = par2.pwLT[j][i]; } }
quadri *carica_dati(quadri *db, int *n) { FILE *f; if((f=fopen(nomefile,"rb")) != NULL) { while(!feof(f)) { db=(quadri*)realloc(db,((*n)+1)*sizeof(quadri)); fread((db+(*n)),sizeof(quadri),1,f); (*n)++; }} else { printf("File impossibile da aprire!\n"); exit(1); } db=ordina(db,*n); stampa(db,*n); fclose(f); return db; }
/************************************************************* ************************************************************* Initializes a chromosome with random values without adding rule ************************************************************* **************************************************************/ void chromosome::inizializewithoutrule() { rank = 1; crowd_dist = 0; //unsigned maxpart; int ingressi=numVar; numFeat=0; if (CLASSIFICATION) ingressi--; allocateSpace(); float space; bool trovato; for (int i = 0; i < ingressi; i++) { if (TuningPW) { space = (double) 1 / (numParts[i]-2 + 1);// half of support of a fuzzy set in a uniform partition for (int j = 0; j < numParts[i]-2 ; j++) { if (vinc == true) //constrained version { pwLT_lim[0][i][j] = space * (j + 1) - space / 2; pwLT_lim[1][i][j] = space * (j + 1) + space / 2 - (double) 1 / GrDig; //pwLT[i][j] = Randint(pwLT_lim[0][i][j] * GrDig, pwLT_lim[1][i][j] * GrDig); pwLT[i][j]= space*(j+1)*GrDig; pwLT[i][j] /= (double) GrDig; } else { pwLT_lim[0][i][j] = 0.01; pwLT_lim[1][i][j] = 0.99; do { pwLT[i][j] = Randint(1, GrDig - 1); pwLT[i][j] /= (double) GrDig; trovato = false; for (int k = 0; k < j; k++) if (pwLT[i][j] == 0 || pwLT[i][j] == 1 || (j != 0 && abs(pwLT[i][j] - pwLT[i][k]) < (double) (1 / GrDig))) //to ensure that two genes cannot be equal and { trovato = true; break; } } while (trovato); } pwLT_lim[2][i][j] = space * (j + 1);// centroids of the uniform partition in [0,1] } if (!vinc) ordina(pwLT[i], numParts[i]-2 ); } for (int i=0;i<numVar;i++) realPart[i]=numParts[i]; } numRul = realNumRule = 0; for (int i = 0; i < maxRule; i++) for (int j = 0; j < numVar;j++) matR[i][j] = 0; for (int i = 0; i < sizeObjTot; i++) { objTot[i] = 56456465; objAlg[i]=56456465; } }