| 293 | int GetExperienceSize(int sockfd, int *num_rows, int *num_cols) |
| 294 | { |
| 295 | char buffer[256]; |
| 296 | |
| 297 | // number of rows |
| 298 | bzero(buffer,256); |
| 299 | ReadMessage(sockfd,buffer); |
| 300 | *num_rows = atoi(buffer); |
| 301 | // number of columns |
| 302 | bzero(buffer,256); |
| 303 | ReadMessage(sockfd,buffer); |
| 304 | *num_cols = atoi(buffer); |
| 305 | /*printf("number of rows: %d, number of columns: %d\n", |
| 306 | *num_rows, *num_cols); */ |
| 307 | return 1; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | int GetExperience(int sockfd, int num_rows, int num_cols, |
| 312 | float **past_exp) |
| 313 | { |
| 314 | char buffer[256]; |
| 315 | int i, j; |
| 316 | |
| 317 | // read experience |
| 318 | for (i = 0; i < num_rows; i++){ |
| 319 | for (j = 0; j < num_cols; j++){ |
| 320 | bzero(buffer,256); |
| 321 | ReadMessage(sockfd,buffer); |
| 322 | // printf("experience: %s\n", buffer); |
| 323 | past_exp[i][j] = atof(buffer); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return 1; |
| 328 | } |
| 329 | |
| 330 | |
398 | | //printf("add row to cbr table\n"); |
399 | | rc = cbr_add_row(mycbr, cols, vals, num_cols); |
| 433 | float vals[num_cols]; |
| 434 | /*// sample table entry |
| 435 | vals[0] = 1e3f; // throughput |
| 436 | vals[1] = 1; // spectral_efficiency |
| 437 | vals[2] = -3.50; // log10_ber |
| 438 | vals[3] = 1; // mod_scheme |
| 439 | vals[4] = -3.5f; // tx_power |
| 440 | vals[5] = 10.0f; // SNR |
| 441 | vals[6] = 0.762; // utility*/ |
| 442 | printf("here\n"); |
| 443 | for (i = 0; i < num_rows; i++){ |
| 444 | for (j = 0; j < num_cols; j++){ |
| 445 | vals[j] = past_exp[i][j]; |
| 446 | } |
| 447 | printf("add row to cbr table\n"); |
| 448 | rc = cbr_add_row(mycbr, cols, vals, num_cols); |
| 449 | } |
| 544 | // get experience size rom server |
| 545 | int num_rows, num_cols; |
| 546 | GetExperienceSize(sockfd, &num_rows, &num_cols); |
| 547 | //printf("number of rows: %d, number of columns: %d\n", |
| 548 | // num_rows, num_cols); |
| 549 | // get experience |
| 550 | float **past_exp; |
| 551 | int i, j; |
| 552 | past_exp = (float **)malloc(sizeof(float)*num_rows); |
| 553 | for (i = 0; i< 1; i++){ |
| 554 | past_exp[i] = (float*)malloc(sizeof(float)*num_cols); |
| 555 | } |
| 556 | GetExperience(sockfd, num_rows, num_cols, past_exp); |
| 557 | for (i = 0; i < num_rows; i++){ |
| 558 | for (j = 0; j < num_cols; j++){ |
| 559 | printf("experience: %f\n", past_exp[i][j]); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | // calculate utility |
| 564 | |
| 565 | |
499 | | num_cols = num_cols + 1; |
500 | | RunCBREngine(uList, pList, oList, &ce_info, num_cols); |
| 571 | num_cols = num_cols + 1; // overall utility |
| 572 | printf("number of rows: %d, number of columns: %d\n", |
| 573 | num_rows, num_cols); |
| 574 | RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows, |
| 575 | past_exp); |
515 | | /* char counter[50]; |
516 | | char var[50]; |
517 | | // utility |
518 | | for (i = 0; i < ce_info.numUtilities; i++){ |
519 | | sprintf(var, "%f", uList[i].value); |
520 | | SendMessage(sockfd, var); |
521 | | } |
522 | | // parameter |
523 | | for (i = 0; i < ce_info.numParameters; i++){ |
524 | | sprintf(var, "%f", pList[i].value); |
525 | | SendMessage(sockfd, var); |
526 | | } |
527 | | // observable |
528 | | for (i = 0; i < ce_info.numObservables; i++){ |
529 | | sprintf(var, "%f", oList[i].value); |
530 | | SendMessage(sockfd, var); |
531 | | }*/ |
532 | | |