Esempio n. 1
0
int main(void){

	char **m;
	int t,l;
	scanf("%d",&t);
	l=latoCristallo(t);
	printf("%d\n",l );
	m=creaMatrice(l);
	stampaMatrice(m,l);
	//crist(m,l,l,l);
	stampaMatrice(m,l);
	return 0;
}
Esempio n. 2
0
int main(void){

	int t,l;
	char **m;

	scanf("%d",&t);
	l=latoCristallo(t);
	
	m=creaMatrice(l);
	printf("%c\n",m[0][0]);
	printf("%d\n",l );
	crist(m,l/2,l/2,l);
	stampaMatrice(m,l);
	return 0;
}
Esempio n. 3
0
void chromosome::generateMatCL(frbs& fis)
{
	//da scommentare per generazione wm
	/*double* appopesi=fis.calcolaPesi((int**)matWM,dimMatWM,realPart,inOutTr,numPatterTr,pwLT,tun, scaling);
	eliminaConliffitto(appopesi,0, (int**)matWM, (int&)dimMatWM);
	delete[] appopesi;

	*/
	if (dimMatWM<maxRule)
		maxRule=dimMatWM;


	indiciCL=new int[numParts[numVar-1]];
	for (int i=0;i<numParts[numVar-1];i++)
		indiciCL[i]=0;
	ordinaxClasse((int**)matWM,dimMatWM,indiciCL);
	#ifdef stampa
		stampaMatrice((int**)matWM,dimMatWM,numVar);
	#endif
}
Esempio n. 4
0
int main()
{
    int matx[SIZER][SIZEC];
    int scelta,min,max,med;
    int uscita=0;
    float media;
    printf("Inserisci il vettore di 10cifre\n");
    for(int i=0;i<SIZER;i++){
        for(int j=0;j<SIZEC;j++){
            printf("Elemento  matrice[%d][%d]:",i,j);
            scanf("%d",&matx[i][j]);
        }
    }

    while(!uscita){
    printf("\nMENU:\n");
    printf("1-stampa matrice\n2-stampa matrice ruotata 90 gradi in senso antiorario\nscelta->");
    scanf("%d",&scelta);
    switch(scelta){
        case 1:
           // bubbleSort(matx,SIZER,SIZEC);
            printf("\n\nMATRICE:\n");
            stampaMatrice(matx,SIZER,SIZEC);
        break;
        case 2:
             printf("\n\nMATRICE:\n");
            stampaMatriceGirata(matx,SIZER,SIZEC);
        break;

        default:
            uscita=1;
            break;
    }

}

    return 0;
}
Esempio n. 5
0
void lavora(int n, int c, int d) {
    int row;
    numero_generazione_attuale = 0;
    do {//NUOVA GENERAZIONE
        //SCAMBIO VETTORI POPOLAZIONE
        numero_generazione_attuale++;
        int i_target;
        for (i_target = 0; i_target < num_pop_iniziale; i_target++) {
            if (POP_NEW[i_target] != POP_NOW[i_target]) {
                if (POP_NOW[i_target] != 0) {
                    for (row = 0; row < c; row++) {
                        free(POP_NOW[i_target] -> V_p[row]);
                        free(POP_NOW[i_target] -> U_p[row]);
                    }
                    free(POP_NOW[i_target]->V_p);
                    free(POP_NOW[i_target]->U_p);
                    free(POP_NOW[i_target]);
                }
                POP_NOW[i_target] = POP_NEW[i_target];
            }
        }
        /////////////////DE////////////////////
        for (i_target = 0; i_target < num_pop_iniziale; i_target++) {//PER OGNI COMPONENTE DELLA POP
            /*if(indice_base == i_target){
                printf("!");
                continue;
            }*/
                
            //SCELTA CANDIDATI
            //tre vettori devono essere scelti a caso nella popolazione
            //diversi dal target (indice i) e mutualmente
            
            int indice_1, indice_2, indice_base;
            do {
                indice_1 = random_at_most(((long) num_pop_iniziale) - 1);
            } while (indice_1 == i_target); // || indice_1 == indice_base

            do {
                indice_2 = random_at_most(((long) num_pop_iniziale) - 1);
            } while (indice_2 == i_target || indice_2 == indice_1); // || indice_2 == indice_base

            do {
                indice_base = random_at_most(((long) num_pop_iniziale) - 1);
            } while (indice_base == i_target || indice_base == indice_1 || indice_base == indice_2);

            //l'elemento mutante
            el_pop *mutant = malloc(sizeof (el_pop));
            //alloc V_p del mutante
            mutant -> V_p = malloc(c * sizeof (double*));
            for (row = 0; row < c; row++) {
                mutant -> V_p[row] = malloc(d * sizeof (double));
            }
            //alloc U_p mutante
            mutant -> U_p = malloc(c * sizeof (double*));
            for (row = 0; row < c; row++) {
                mutant -> U_p[row] = malloc(n * sizeof (double));
            }


            //MUTATION

            int i1, j1;
            for (i1 = 0; i1 < c; i1++) {
				double f;
                if (tipo_dw == 2)//dithering
                    f = dbl_rnd_inRange(dw_lowerbound, dw_upperbound);
                else if (tipo_dw == 3) //dither + jitter
                    f = dbl_rnd_inRange(dw_lowerbound, dw_upperbound) + 0.001 * (dbl_rnd_inRange(0, 1) - 0.5);
                else
                    f = dw_upperbound;
                for (j1 = 0; j1 < d; j1++) {
                    mutant->V_p[i1][j1] = POP_NOW[indice_base]->V_p[i1][j1] + f * (POP_NOW[indice_1]->V_p[i1][j1] - POP_NOW[indice_2]->V_p[i1][j1]);
                }
            }
            //CROSSOVER CON IL VETTORE TARGET (TIPO 1)
            for (i1 = 0; i1 < c; i1++) {
                double prob_crossover = dbl_rnd_inRange(0.0, 1.0);
                for (j1 = 0; j1 < d; j1++) {
                    if (prob_crossover < CR) {
                        //prendo il cromosoma del target
                        mutant->V_p[i1][j1] = POP_NOW[i_target]->V_p[i1][j1];
                    }
                }
            }

            //CROSSOVER CON IL VETTORE ATTUALE (TIPO 2) (BAD)
            /*for (i1 = 0; i1 < c; i1++) {
                for (j1 = 0; j1 < d; j1++) {
                    double prob_crossover = fRand(0.0, 1.0);
                    if (prob_crossover < CR) {
                        mutant->V_p[i1][j1] = POP_NOW[i_CPop]->V_p[i1][j1];
                    }
                }
            }*/

            //CROSSOVER CON IL VETTORE ATTUALE (TIPO 3)
            /*for (i1 = 0; i1 < c; i1++) {
                    double prob_crossover = fRand(0.0, 1.0);
                    if (prob_crossover < CR) {
                        //prendo tutto il vettore del compagno
                        copiaVettore(d,POP_NOW[i_CPop]->V_p[i1],mutant->V_p[i1]);
                    }
            }*/

            ///CALCOLO FITNESS DEL MUTANTE
            //calcolo U mutante
            for (i = 0; i < c; i++) {
                for (j = 0; j < n; j++) {
                    double denom = 0.0;
                    double dist_x_j__v_i = calcDistanza(X[j], mutant -> V_p[i]);
                    if (dist_x_j__v_i == 0) {
                        puts("calcolo U mutante, distanza nulla");
                        exit(-1);
                    }
                    int k;
                    for (k = 0; k < c; k++) {
                        double dist_xj_vk = calcDistanza(X[j], mutant -> V_p[k]);
                        if (dist_xj_vk == 0) {
                            puts("calcolo U mutante, distanza nulla");
                            exit(-1);
                        }
                        denom += pow((dist_x_j__v_i / dist_xj_vk), esponente_U);
                        if (denom == 0) {
                            puts("calcolo U mutante, denom nullo");
                            exit(-1);
                        }
                    }
                    mutant -> U_p[i][j] = 1.0 / denom;
                }
            }

            //calcolo fitness mutante            
            mutant->fitness = calcolaFitness(mutant->V_p, mutant->U_p, 1);

            //SELECTION
            //TIPO 2 (STANDARD)
            if (mutant->fitness < POP_NOW[i_target]->fitness) {
                xb_selezionato = mutant->fitness;
                POP_NEW[i_target] = mutant;
            } else {
                for (row = 0; row < c; row++) {
                    free(mutant -> V_p[row]);
                    free(mutant -> U_p[row]);
                }
                free(mutant->V_p);
                free(mutant->U_p);
                free(mutant);
                POP_NEW[i_target] = POP_NOW[i_target];
                xb_selezionato = POP_NOW[i_target]->fitness;
            }
        }//END DE
        numero_generazioni--;
    } while (numero_generazioni > 0);


    //computazione fitness della popolazione finale
    double best_fitness = DBL_MAX;
    int indice_best;
    for (pop_index = 0; pop_index < num_pop_iniziale; pop_index++) {
        POP_NEW[pop_index]->fitness = calcolaFitness(POP_NEW[pop_index]->V_p, POP_NEW[pop_index]->U_p, 0);
        if (POP_NEW[pop_index]->fitness < best_fitness) {
            best_fitness = POP_NEW[pop_index]->fitness;
            indice_best = pop_index;
        }
    }
    //calcolo xb del migliore
    best_xb = calcolaXB(POP_NEW[indice_best]->V_p, POP_NEW[indice_best]->U_p, 0);

    printf("miglior XB:%lf\n", best_xb);
    fprintf(out_LOG_RIS, "\nmiglior XB:%lf\n\n", best_xb);
    stampaMatriceSuFile(c, d, POP_NEW[indice_best]->V_p, out_LOG_RIS);
    puts("matrice V:");
    stampaMatrice(c, d, POP_NEW[indice_best]->V_p);
    stampaMatriceSuFile(c, d, POP_NEW[indice_best]->V_p, out_V);
    stampaMatriceSuFile(c, n, POP_NEW[indice_best]->U_p, out_U);
    puts("***********************************************");
}
Esempio n. 6
0
int main(int argc, char** argv) {
    //PUNTATORI A FILE DI OUTPUT
    FILE *out_V, *out_X, *out_U;
    out_V = fopen("v_fcm.out", "w");
    out_U = fopen("u_fcm.out", "w");
    out_X = fopen("dataset/aggregation.data", "r");

    //letture da utente
    puts("numero di punti in input");
    scanf("%d", &n);
    puts("numero di dimensioni");
    scanf("%d", &d);
    puts("numero di centroidi");
    scanf("%d", &c);

    double distanze[c]; //vettore con le dist fra centroidi dopo l'aggiornamento

    //allocazione X
    int row;
    X = malloc(n * sizeof (double*));
    for (row = 0; row < n; row++) {
        X[row] = malloc(d * sizeof (double));
    }

    //lettura X da file
    for (i = 0; i < n; i++) {
        for (j = 0; j < d; j++) {
            if (!fscanf(out_X, "%lf", &X[i][j]))
                break;
        }
    }
    fclose(out_X);

    //alloc V
    V = malloc(c * sizeof (double*));
    for (row = 0; row < c; row++) {
        V[row] = malloc(d * sizeof (double));
    }

    //INIT V
    srand48(rand());
    for (i = 0; i < c; i++)
        for (j = 0; j < d; j++)
            V[i][j] = 10 * drand48() - 5;

    //alloc U
    U = malloc(c * sizeof (double*));
    for (row = 0; row < c; row++) {
        U[row] = malloc(n * sizeof (double));
    }


    printf("########END INIT##########\n\n");
    max = 0.0;
    do {
        //CALCOLO PARTITION MATRIX
        for (i = 0; i < c; i++) {
            for (j = 0; j < n; j++) {
                double esponente = 2.0 / (m - 1.0);
                double denom = 0.0;
                double dist_x_j__v_i = calcDistanza(X[j], V[i]);

                int k; //SOMMATORIA 1
                for (k = 0; k < c; k++) {
                    double dist_xj_vk = calcDistanza(X[j], V[k]);
                    denom += pow((dist_x_j__v_i / dist_xj_vk), esponente);
                }
                U[i][j] = 1.0 / denom;
            }
        }


        //RICALCOLO POSIZIONE CENTROIDI
        int i, j, z, k;
        double old[d];
        double denom;
        for (i = 0; i < c; i++) {
            for (z = 0; z < d; z++)
                old[z] = V[i][z]; //per confronto diff
            denom = 0.0;
            for (j = 0; j < n; j++)//sommatoria denom (fatta una sola volta a centr.)
                denom += pow(U[i][j], m);
            for (k = 0; k < d; k++) {
                double num = 0.0;
                for (j = 0; j < n; j++) {//SOMMATORIA numeratore
                    num += X[j][k] * pow(U[i][j], m);
                }
                V[i][k] = num / denom;
            }
            distanze[i] = pow(calcDistanza(V[i], old), 2.0);
        }

    } while (maxDistCentroidi(distanze) > epsilon);

    puts("matrice V:");
    stampaMatrice(c, d, V);
    stampaMatriceSuFile(c, d, V, out_V);
    stampaMatriceSuFile(c, n, U, out_U);
    printf("MAXDISTCENTROIDI: %lf\n", maxDistCentroidi(distanze));
    puts("indice XB:");
    double xb = calcolaXB(V, U, 0);
    printf("%lf\n", xb);
    plot();
    return (0);
}
Esempio n. 7
0
void lavora(int n, int c, int d) {
    int row;
    numero_generazione_attuale = 0;
    do {//NUOVA GENERAZIONE
        //SCAMBIO VETTORI POPOLAZIONE
        conteggio_successi_generazione_attuale = 0;
        numero_generazione_attuale++;
        int i_target;
        for (i = 0; i < num_pop_iniziale; i++) {
            if (POP_NEW[i] != POP_NOW[i]) {
                if (POP_NOW[i] != 0) {//FREE
                    for (row = 0; row < c; row++) {
                        free(POP_NOW[i] -> V_p[row]);
                        free(POP_NOW[i] -> U_p[row]);
                    }
                    free(POP_NOW[i]->V_p);
                    free(POP_NOW[i]->U_p);
                    free(POP_NOW[i]);
                }
                POP_NOW[i] = POP_NEW[i]; //l'individuo era stato sostituito
            }
        }


        /////////////////DE////////////////////
        for (i_target = 0; i_target < num_pop_iniziale; i_target++) {//PER OGNI COMPONENTE DELLA POP
            //SCELTA CANDIDATI
            //tre vettori devono essere scelti a caso nella popolazione
            //diversi dal target (indice i) e mutualmente

            int indice_1, indice_2, indice_base;
            do {
                indice_1 = random_at_most(((long) num_pop_iniziale) - 1);
            } while (indice_1 == i_target); // || indice_1 == indice_base

            do {
                indice_2 = random_at_most(((long) num_pop_iniziale) - 1);
            } while (indice_2 == i_target || indice_2 == indice_1); // || indice_2 == indice_base

            do {
                indice_base = random_at_most(((long) num_pop_iniziale) - 1);
            } while (indice_base == i_target || indice_base == indice_1 || indice_base == indice_2);

            //l'elemento mutante
            el_pop *mutant = malloc(sizeof (el_pop));
            //alloc V_p del mutante
            mutant -> V_p = malloc(c * sizeof (double*));
            for (row = 0; row < c; row++) {
                mutant -> V_p[row] = malloc(d * sizeof (double));
            }
            //alloc U_p mutante
            mutant -> U_p = malloc(c * sizeof (double*));
            for (row = 0; row < c; row++) {
                mutant -> U_p[row] = malloc(n * sizeof (double));
            }


            int i1, j1;
            double f;
            ///MUTATION (TIPO 1 rand-rand-rand) singolo punto
            //scelta f
            if (tipo_dw == 2)//dithering
                f = dbl_rnd_inRange(dw_lowerbound, dw_upperbound);
            else if (tipo_dw == 3) //dither + jitter
                f = dbl_rnd_inRange(dw_lowerbound, dw_upperbound) + 0.001 * (dbl_rnd_inRange(0, 1) - 0.5);
            else
                f = dw_upperbound;

            for (i1 = 0; i1 < c; i1++) {//centroide
                for (j1 = 0; j1 < d; j1++) {
                    mutant->V_p[i1][j1] = POP_NOW[indice_base]->V_p[i1][j1] + f * (POP_NOW[indice_1]->V_p[i1][j1] - POP_NOW[indice_2]->V_p[i1][j1]);
                }
            }

            //MUTATION (TIPO 2 best-rand-rand) con f omogeneo per vettore dopo 3/4 delle gen., rand-rand-rand altrimenti
            /*aggiornaVettoreFitness(); //per il best
            for (i1 = 0; i1 < c; i1++) {
                if (tipo_dw == 2)//dithering
                    f = dbl_rnd_inRange(dw_lowerbound, dw_upperbound);
                else if (tipo_dw == 3) //dither + jitter
                    f = dbl_rnd_inRange(dw_lowerbound, dw_upperbound) + 0.001 * (dbl_rnd_inRange(0, 1) - 0.5);
                else
                    f = dw_upperbound;
                for (j1 = 0; j1 < d; j1++) {
                    if (numero_generazione_attuale > floor(numero_generazioni_iniziale * (7 / 8)))
                        mutant->V_p[i1][j1] = POP_NOW[bestFitIndex]->V_p[i1][j1] + f * (POP_NOW[indice_1]->V_p[i1][j1] - POP_NOW[indice_2]->V_p[i1][j1]);
                    else
                        mutant->V_p[i1][j1] = POP_NOW[indice_base]->V_p[i1][j1] + f * (POP_NOW[indice_1]->V_p[i1][j1] - POP_NOW[indice_2]->V_p[i1][j1]);
                }
            }*/


            //CROSSOVER CON IL VETTORE TARGET UNIFORME
            double prob_crossover;
            for (i1 = 0; i1 < c; i1++) {
                for (j1 = 0; j1 < d; j1++) {
                    prob_crossover = dbl_rnd_inRange(0.0, 1.0);
                    if (prob_crossover < CR) {
                        mutant->V_p[i1][j1] = POP_NOW[i_target]->V_p[i1][j1];
                    }
                }
            }

            //CROSSOVER SPLIT
            /*for (i1 = 0; i1 < c; i1++) {//centroide
                for (j1 = 0; j1 < d; j1++) {//coordinata centroide
                    if (i1 >= floor((double) c / 2)) {//prendo i cromosomi dal target so oltre il punto di CO
                        mutant->V_p[i1][j1] = POP_NOW[i_target]->V_p[i1][j1];
                    }
                }
            }*/

            //SORT MATRICE MUTANTE
            sortMatrice(mutant->V_p);

            ///CALCOLO FITNESS DEL MUTANTE
            //calcolo U mutante
            for (i = 0; i < c; i++) {
                for (j = 0; j < n; j++) {
                    double denom = 0.0;
                    double dist_x_j__v_i = calcDistanza(X[j], mutant -> V_p[i]);
                    if (dist_x_j__v_i == 0) {
                        puts("calcolo U mutante, distanza nulla");
                        exit(-1);
                    }
                    int k;
                    for (k = 0; k < c; k++) {
                        double dist_xj_vk = calcDistanza(X[j], mutant -> V_p[k]);
                        if (dist_xj_vk == 0) {
                            puts("calcolo U mutante, distanza nulla");
                            exit(-1);
                        }
                        denom += pow((dist_x_j__v_i / dist_xj_vk), esponente_U);
                        if (denom == 0) {
                            puts("calcolo U mutante, denom nullo");
                            exit(-1);
                        }
                    }
                    mutant -> U_p[i][j] = 1.0 / denom;
                }
            }

            //calcolo fitness mutante   
            mutant->fitness = calcolaFitness(mutant->V_p, mutant->U_p, 1);

            //impostazione timer età mutante
            mutant -> age = starting_age;

            //SELECTION
            //TIPO 2 (STANDARD)
            if (mutant->fitness < POP_NOW[i_target]->fitness) {//IL MUTANTE RIMPIAZZA IL TGT
                POP_NEW[i_target] = mutant;
                fitness_vector[i_target] = mutant->fitness;
                conteggio_successi_generazione_attuale++;
            } else {//IL MUTANTE è SCARTATO
                for (row = 0; row < c; row++) {
                    free(mutant -> V_p[row]);
                    free(mutant -> U_p[row]);
                }
                free(mutant->V_p);
                free(mutant->U_p);
                free(mutant);

                //INVECCHIAMENTO del sopravvissuto
                aggiornaVettoreFitness(); //MIGLIORE
                if (i_target != bestFitIndex) { //se non è il migliore invecchia
                    if (POP_NOW[i_target] -> age > 0)//non sono in modalità reset
                        POP_NOW[i_target] -> age--;
                    if (POP_NOW[i_target] -> age <= 0) {//morte
                        //RINASCITA
                        //REINIT V_p
                        for (i = 0; i < c; i++) {
                            for (j = 0; j < d; j++) {
                                POP_NOW[i_target]->V_p[i][j] = drand48();
                            }
                        }
                        //SORT MATRICE V
                        sortMatrice(POP_NOW[i_target]->V_p);

                        //calcola U
                        for (i = 0; i < c; i++) {
                            for (j = 0; j < n; j++) {
                                double denom = 0.0;
                                double dist_x_j__v_i = calcDistanza(X[j], POP_NOW[i_target] -> V_p[i]);

                                int k;
                                for (k = 0; k < c; k++) {
                                    double dist_xj_vk = calcDistanza(X[j], POP_NOW[i_target] -> V_p[k]);
                                    denom += pow((dist_x_j__v_i / dist_xj_vk), esponente_U);
                                }
                                POP_NOW[i_target] -> U_p[i][j] = 1.0 / denom;
                                if (POP_NOW[i_target] -> U_p[i][j] < 0) {
                                    printf("ERR: INIT POP:inizializzato U di un membro con negativo::");
                                    exit(-1);
                                }
                            }
                        }

                        //calcolo fitness
                        double fit = calcolaFitness(POP_NOW[i_target]->V_p, POP_NOW[i_target]->U_p, 0);
                        POP_NOW[i_target]->fitness = fit;
                        fitness_vector[i_target] = fit;

                        //impostazione età
                        POP_NOW[i_target] -> age = starting_age;
                    }
                }

                POP_NEW[i_target] = POP_NOW[i_target];
            }
            //END SELECTION
        }//END DE//END GENERATION
        numero_generazioni--;

        //ADATTAMENTO PARAMETRI
        if (conteggio_successi_generazione_attuale == 0 && ultimo_conteggio_successi == 0) {
            printf("DW!\n");
            dw_upperbound = dbl_rnd_inRange(dw_upperbound - 0.1, dw_upperbound + 0.1);
            conteggio_adattamenti++;
        }

        //RESET
        if (conteggio_adattamenti == reset_threshold) {
            puts("#RESET GLOBALE#");
            for (i = 0; i < num_pop; i++) {
                if (i != bestFitIndex)
                    POP_NOW[i] -> age = 0;
            }
            conteggio_adattamenti = 0; //reset contatore
        }
        //END RESET
        ultimo_conteggio_successi = conteggio_successi_generazione_attuale;
    } while (numero_generazioni > 0);
    //END GENERAZIONI

    puts("end lavora");

    //ULTIMO SCAMBIO POPOLAZIONI
    for (i = 0; i < num_pop_iniziale; i++) {
        if (POP_NEW[i] != POP_NOW[i]) {
            if (POP_NOW[i] != 0) {
                for (row = 0; row < c; row++) {
                    free(POP_NOW[i] -> V_p[row]);
                    free(POP_NOW[i] -> U_p[row]);
                }
                free(POP_NOW[i]->V_p);
                free(POP_NOW[i]->U_p);
                free(POP_NOW[i]);
            }
            POP_NOW[i] = POP_NEW[i];
        }
    }

    //computazione fitness della popolazione finale
    aggiornaVettoreFitness();

    //calcolo xb del migliore
    best_xb = calcolaXB(POP_NOW[bestFitIndex]->V_p, POP_NOW[bestFitIndex]->U_p, 0);

    printf("\nmiglior XB: \t%lf\n", best_xb);
    stampaMatrice(c, d, POP_NOW[bestFitIndex]->V_p);
    stampaMatriceSuFile(c, d, POP_NOW[bestFitIndex]->V_p, out_V);
    stampaMatriceSuFile(c, n, POP_NOW[bestFitIndex]->U_p, out_U);
    puts("###################################################################");
}
Esempio n. 8
0
//Genero il vettore delle regole selezionando dalla matrice matWM
void chromosome::generateIndiciCL(frbs& fis)
{
	int* reg;
	int numRegxClasse;
	int maxDim;
	int indmin;

	for (int i=0;i<maxRule;i++)
		vettR[i].index=dimMatWM;

	if (dimMatWM <= maxRule)  //Considero tutta la matrice matWM
	{	for (int i = 0; i < maxRule; i++)
		{	vettR[i].index = i;
			for (int j = 0; j < numVar-1; j++)
				if (matWM[i][j]!=0)
					vettR[i].vectAnt[j] = true;   //All'inizio tutti gli antecedenti della regola sono a 1
				else
					vettR[i].vectAnt[j] = false;
		}
		numRul=maxRule;
	}
	else
	{	//seleziono maxRule dalla matrice matWM
		numRegxClasse=maxRule/numParts[numVar-1];
		numRul=0;
		int numReg;
		for (int i=0;i<numParts[numVar-1];i++)
		{	if (i==0)
			{	numReg=indiciCL[i];
				indmin=0;
			}
			else
			{	numReg=indiciCL[i]-indiciCL[i-1];
				indmin=indiciCL[i-1];
			}
			if (numRegxClasse<=numReg)
				maxDim=numRegxClasse;
			else
				maxDim=numReg;
			reg=RandintDistinct(indmin, indiciCL[i] - 1, maxDim);
			for (int k = 0; k <maxDim ; k++)
			{	vettR[numRul].index = reg[k];
				for (int j = 0; j < numVar-1; j++)
					if (matWM[reg[k]][j]!=0)
						vettR[numRul].vectAnt[j] = true;   //All'inizio tutti gli antecedenti della regola sono a 1
					else
						vettR[numRul].vectAnt[j] = false;
				numRul++;
			}
			delete[] reg;
		}
	}

	ordinaIndex();
	faiMatdaVec();
	#ifdef stampa
		cout<<endl<<"Matrice Iniziale"<<endl;
		stampaMatrice((int**)matR,numRul,numVar);
	#endif

}