int main(){ Film *film; int n = 200, vTot, k; double alpha, *prt, *Ft, *Fexp; film = (Film*)allocArrayMemory(sizeof(Film), n); //citirea readInputFile("DateFilme.txt", film, n, &vTot); qsort(film, n, sizeof(Film), cmpFilm);//sortarea reRank(film, n, vTot);//calculul rangurilor writeDebug(film, n); scrierePuncte("NumeLeader2.txt", film, n); //partea de pana aici calculeaza alpha; alpha = 0.897675610478; prt = Zipf(alpha, n); writeOutputFiles(film, n, prt); calcVectRep(prt, film, n, &Ft, &Fexp); for(k=0;(k<n) && (Ft[k]<0.75);k++);// ";" nu e din greasala!!!!!!!!! printf("\nNumarul de file salvate in cache este k = %d\n", k); simulareVizualizari(Ft, n, k); simulareVizualizari(Fexp, n, k); if(prt) free(prt); if(Ft) free(prt); if(Fexp) free(prt); free(film); getch(); return 0; }
// funzione per creare una transazione ed accodarla transaction_descriptor *create_new_synthetic_transaction(state_type *state, int tx_id, double data_items_zipf_const) { // Get the client configuration from simulation state CLIENT_lp_state_type *pointer = &state->type.client_state; operation_descriptor *op = NULL; int number_of_operations = 0; int i, j; int tx_class_id = -1; double val; int local_access; transaction_descriptor *tx_descr = (transaction_descriptor *) malloc(sizeof(transaction_descriptor)); tx_descr->tx_id = tx_id; tx_descr->next = NULL; tx_descr->first_operation = NULL; tx_descr->last_operation = NULL; tx_descr->current_operation = NULL; if (pointer->configuration.tlm_verbose) { printf("creazione nuova transazione tx_id %i\n", tx_id); } //crea le operazioni // seleziona la classe transazionale double rand_number = Random(); float sum = 0; for (i = 0; i < pointer->configuration.number_of_tx_classes; i++) { sum += pointer->configuration.tx_class_probability[i]; if (rand_number < sum) { tx_class_id = i; break; } } tx_descr->tx_class_id = tx_class_id; // seleziona la lunghezza delle transazioni in operazioni switch (pointer->configuration.transaction_length_type) { case FIXED: number_of_operations = pointer->configuration.tx_class_length[tx_class_id]; //number_of_operations=5; //TODO rimettere la lungezza delle transazioni in modo corretto break; case UNIFORM: //number_of_operations=5; number_of_operations = RandomRange(0, pointer->configuration.tx_class_length[tx_class_id] - 1) + 1; break; case ZIPF: case SINGLE_BAR: default: fprintf(stderr, "Unsupported value %d at %s:%d\n", pointer->configuration.transaction_length_type, __FILE__, __LINE__); } for (j = 1; j <= number_of_operations; j++) { if (pointer->configuration.tlm_verbose) { printf("\tcreo operazione %i\n", j); } //crea l'operazione op = (operation_descriptor *) malloc(sizeof(operation_descriptor)); op->op_number = j; // seleziona il tipo di accesso double r; do { r = Random(); } while (r == 1); if (r <= pointer->configuration.tx_class_write_probability[tx_class_id]) { op->op_type = TX_PUT; } else { op->op_type = TX_GET; } operation_descriptor *l; //selezione distribuzione accesso ai data items //TODO switch (pointer->configuration.object_access_distribution_type[tx_class_id]) { //int dist=UNIFORM; //switch (dist) { case UNIFORM: // seleziona #pointer->cache_objects diversi do { op->object_key_id = RandomRange(0, state->cache_objects - 1); l = get_operation(tx_descr, op->object_key_id); } while (l); break; case LOCALITY: local_access=0; do { r = Random(); } while (r == 1); if (r <= 1) { local_access=1; } do { do { op->object_key_id = RandomRange(0, state->cache_objects - 1); l = get_operation(tx_descr, op->object_key_id); } while (l); } while ( local_access && !is_owner(op->object_key_id, get_server(state), state->num_servers, state->num_clients, state->object_replication_degree) || !local_access && is_owner(op->object_key_id, get_server(state), state->num_servers, state->num_clients, state->object_replication_degree) ); break; case TOPKEYS: rand_number = Random(); //printf("Random: %f\n", rand_number); float * objects_access_probability; op->object_key_id = -1; int id_item; int number_of_top_keys = 0; long double no_tk_probability; long double sum_tk = 0; bool top_key = false; //printf("%d - %d\n",op->op_type, TX_PUT); if (op->op_type == TX_GET) { objects_access_probability = pointer->configuration.topkeys_cache_objects_get_probability; number_of_top_keys = pointer->configuration.number_of_gets_topkeys; } else { objects_access_probability = pointer->configuration.topkeys_cache_objects_put_probability; number_of_top_keys = pointer->configuration.number_of_puts_topkeys; } for (id_item = 0; id_item < number_of_top_keys; id_item++) { sum_tk += objects_access_probability[id_item]; //printf("sum: %f\n",sum); if (rand_number < sum_tk) { top_key = true; op->object_key_id = id_item; break; } } if (!top_key) { no_tk_probability = (1 - sum_tk) / (state->cache_objects - number_of_top_keys); for (; id_item < state->cache_objects; id_item++) { sum_tk += no_tk_probability; //printf("sum-no_tk: %f\n",sum); if (rand_number < sum_tk) { op->object_key_id = id_item; break; } } } break; //printf("Scelto: %d\n",op->object_key_id); case ZIPF: op->object_key_id = Zipf(data_items_zipf_const, state->cache_objects); break; case SINGLE_BAR: val = Random(); if (val < 0.8) { // TODO: Alessandro: parametrizzare in una macro?! op->object_key_id = RandomRange(0, 10 - 1); //TODO va sul 20% dei data_item } else { op->object_key_id = RandomRange(0, state->cache_objects - 10 - 1) + 10; //restante 80% } break; } if (pointer->configuration.tlm_verbose) { printf("\t\ttipo %i\n", op->op_type); printf("\t\tdata_item %i\n", op->object_key_id); } op->next = NULL; enqueue_operation(tx_descr, op); } //resetta lo stato della transazione reset_transaction_state(tx_descr); return tx_descr; }