Changeset 88 for vtcross/branches/trnewman/CR_engines/CBR
- Timestamp:
- 11/26/08 19:35:17 (16 years ago)
- Location:
- vtcross/branches/trnewman/CR_engines/CBR/src
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/trnewman/CR_engines/CBR/src/cbr.c
r79 r88 77 77 sqlite3_stmt * pStatement; 78 78 rc = sqlite3_prepare_v2(_cbr->db, _cbr->command, -1, &pStatement, NULL); 79 if (rc == SQLITE_OK && sqlite3_step(pStatement) == SQLITE_ROW){ 79 //if (rc == SQLITE_OK && sqlite3_step(pStatement) == SQLITE_ROW){ 80 if (rc == SQLITE_OK){ 81 if (sqlite3_step(pStatement) == SQLITE_ROW){ 82 printf("there is search return data\n"); 80 83 for (i=0; i<_cbr->num_columns; ++i) 81 84 _retvals[i] = sqlite3_column_double(pStatement, i); 82 } 85 } else { 86 printf("no matched rearch results. use default values\n"); 87 // set default values 88 _retvals[0] = 100; // throughput 89 _retvals[1] = 1; // spectral_efficiency 90 _retvals[2] = -2; // log10_ber 91 _retvals[3] = 1; // mod_scheme 92 _retvals[4] = -10; // tx_power 93 _retvals[5] = 10; // snr 94 _retvals[6] = 0.5; // utility 95 } 96 } 97 83 98 sqlite3_finalize(pStatement); 84 99 … … 202 217 unsigned int i; 203 218 char str_buffer[64]; 219 //printf("number of ops %d:\n", _n); 204 220 for (i=0; i<_n; i++) { 205 221 // ensure valid ops value -
vtcross/branches/trnewman/CR_engines/CBR/src/main_cognitive_engine.c
r83 r88 291 291 292 292 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 293 331 void print_current_config(struct Utility uList[], 294 332 struct Parameter pList[], … … 342 380 int RunCBREngine(struct Utility uList[], struct Parameter pList[], 343 381 struct Observable oList[], struct CE_Info *ce_info, 344 int num_cols )345 { 346 347 int i ;382 int num_cols, int num_rows, float ** past_exp) 383 { 384 385 int i, j; 348 386 349 387 // get column names 350 388 //char *cols[50]; 389 //char cols[num_cols][50]; 351 390 char **cols; 352 391 cols = (char **)malloc(sizeof(char)*num_cols); 353 intj = 0;392 j = 0; 354 393 for (i = 0; i < ce_info->numUtilities; i++){ 355 394 cols[j] = malloc(strlen(uList[i].name)+1); 356 395 cols[j] = uList[i].name; 396 // strcpy(cols[j], uList[i].name); 357 397 j++; 358 398 } … … 360 400 cols[j] = malloc(strlen(pList[i].name)+1); 361 401 cols[j] = pList[i].name; 402 // strcpy(cols[j], pList[i].name); 362 403 j++; 363 404 } … … 365 406 cols[j] = malloc(strlen(oList[i].name)+1); 366 407 cols[j] = oList[i].name; 408 // strcpy(cols[j], oList[i].name); 367 409 j++; 368 410 } 411 printf("number of columns: %d, %d\n", num_cols, j); 369 412 cols[j] = malloc(strlen("utility")+1); 370 413 cols[j] = "utility"; 371 372 // sample table entry 373 float vals[num_cols]; 374 vals[0] = 10e3f; // throughput 375 vals[1] = 1; // spectral_efficiency 376 vals[2] = 1e-3f; // log10_ber 377 vals[3] = 1; // mod_scheme 378 vals[4] = -3.0f; // tx_power 379 vals[5] = 10.0f; // SNR 380 vals[6] = 0.762; // utility 414 //strcpy(cols[j], "utility"); 415 printf("here\n"); 381 416 382 417 printf("number of columns: %d\n", num_cols); … … 396 431 397 432 // add row here 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 } 400 450 401 451 // print … … 423 473 float retvals[num_cols]; 424 474 rc = cbr_search(mycbr, search_names, search_ops, 425 search_vals, 2, retvals);475 search_vals, ce_info->numUtilities, retvals); 426 476 427 477 j = 0; … … 492 542 print_current_config(uList, pList, oList, &ce_info); 493 543 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 494 566 // cbr operation 495 unsigned int num_cols;567 //unsigned int num_cols; 496 568 // get number of columns 497 569 num_cols = ce_info.numUtilities + ce_info.numParameters; 498 570 num_cols = num_cols + ce_info.numObservables; 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); 501 576 // print out results 502 int i;577 //int i; 503 578 printf("search result: "); 504 579 for (i=0;i<ce_info.numUtilities; i++) … … 513 588 SendCEResults(sockfd, uList, pList, oList, &ce_info); 514 589 515 /* char counter[50];516 char var[50];517 // utility518 for (i = 0; i < ce_info.numUtilities; i++){519 sprintf(var, "%f", uList[i].value);520 SendMessage(sockfd, var);521 }522 // parameter523 for (i = 0; i < ce_info.numParameters; i++){524 sprintf(var, "%f", pList[i].value);525 SendMessage(sockfd, var);526 }527 // observable528 for (i = 0; i < ce_info.numObservables; i++){529 sprintf(var, "%f", oList[i].value);530 SendMessage(sockfd, var);531 }*/532 533 590 534 591 return 0;