| 133 | /* Receive Set of current Parameters */ |
| 134 | LOG("Cognitive Engine:: Receiving Current Transmission Parameters\n"); |
| 135 | |
| 136 | memset(buffer, 0, 256); |
| 137 | ReadMessage(commandSocketFD,buffer); |
| 138 | uint32_t numCurrentParameters = atoi(buffer); |
| 139 | |
| 140 | Parameter *cp = new Parameter[numCurrentParameters]; |
| 141 | |
| 142 | for(size_t i = 0; i < numCurrentParameters; i++) { |
| 143 | memset(buffer, 0, 256); |
| 144 | ReadMessage(commandSocketFD, buffer); |
| 145 | cp[i].name = std::string(buffer); |
| 146 | |
| 147 | memset(buffer, 0, 256); |
| 148 | ReadMessage(commandSocketFD, buffer); |
| 149 | cp[i].value = atof(buffer); |
| 150 | } |
129 | | |
130 | | SendMessage(commandSocketFD,"1"); |
131 | | SendMessage(commandSocketFD,"txPower"); |
132 | | SendMessage(commandSocketFD,"10"); |
| 160 | char numParametersChar[10]; |
| 161 | char solutionValue[50]; |
| 162 | sprintf(numParametersChar,"%i",radioInfo->numParameters); |
| 163 | SendMessage(commandSocketFD,numParametersChar); |
| 164 | for(size_t i = 0; i < radioInfo->numParameters; i++) { |
| 165 | SendMessage(commandSocketFD,solutionSet[i].name.c_str()); |
| 166 | memset(solutionValue, 0, 50); |
| 167 | sprintf(solutionValue,"%f",solutionSet[i].value); |
| 168 | SendMessage(commandSocketFD,solutionValue); |
| 169 | } |
411 | | } |
412 | | |
413 | | void |
414 | | CognitiveEngine::GetSolution(Observable *observables, std::string service) |
| 451 | |
| 452 | char *searchNames[radioInfo->numUtilities]; |
| 453 | |
| 454 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
| 455 | searchNames[i] = (char*)uList[i].name.c_str(); |
| 456 | } |
| 457 | |
| 458 | float searchVals[radioInfo->numUtilities]; |
| 459 | |
| 460 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
| 461 | searchVals[i] = uList[i].target; |
| 462 | } |
| 463 | |
| 464 | uint32_t numberColumns = |
| 465 | radioInfo->numUtilities + |
| 466 | radioInfo->numParameters + |
| 467 | radioInfo->numObservables + 1; |
| 468 | |
| 469 | float returnValues[numberColumns]; |
| 470 | |
| 471 | int searchOps[radioInfo->numUtilities]; |
| 472 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
| 473 | |
| 474 | /* If the goal is to maximum, set the search operation to |
| 475 | * return values greater than the target. |
| 476 | * |
| 477 | * If the goal is to minimize, set the search operation to |
| 478 | * return values less than the target. |
| 479 | */ |
| 480 | |
| 481 | if(strcmp(uList[i].goal.c_str(),"max") == 0) { |
| 482 | searchOps[i] = GT; |
| 483 | } else if(strcmp(uList[i].goal.c_str(),"min") == 0) { |
| 484 | searchOps[i] = LT; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | /* CBR specific call */ |
| 489 | uint32_t rc = cbr_search(myCBR, searchNames, searchOps, searchVals, |
| 490 | radioInfo->numUtilities, returnValues); |
| 491 | |
| 492 | if(rc == 0){ |
| 493 | /* Adapt the returned parameters to meet the objective */ |
| 494 | |
| 495 | } else if(rc == 31337){ |
| 496 | /* No rows in the CBR, pick default parameters */ |
| 497 | // Currently this is hard coded and implementation specific! |
| 498 | //returnValues[2] = currentParameters[0].value + 5; |
| 499 | //returnValues[3] = currentParameters[1].value + 10; |
| 500 | |
| 501 | } else { |
| 502 | WARNING("Cognitive Engine:: Search return an invalid value.\n"); |
| 503 | } |
| 504 | |
| 505 | size_t returnValueIndex = 0; |
| 506 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
| 507 | uList[i].value = returnValues[returnValueIndex]; |
| 508 | returnValueIndex++; |
| 509 | } |
| 510 | for(size_t i = 0; i < radioInfo->numParameters; i++) { |
| 511 | pList[i].value = returnValues[returnValueIndex]; |
| 512 | returnValueIndex++; |
| 513 | } |
| 514 | for(size_t i = 0; i < radioInfo->numObservables; i++) { |
| 515 | oList[i].value = returnValues[returnValueIndex]; |
| 516 | returnValueIndex++; |
| 517 | } |
| 518 | |
| 519 | // Add row to CBR. |
| 520 | |
| 521 | return pList; |
| 522 | |
| 523 | } |
| 524 | |
| 525 | |
| 526 | Parameter* |
| 527 | CognitiveEngine::GetSolution(Observable *observables, Parameter *currentParameters, std::string service) |
| 549 | |
| 550 | |
| 551 | void |
| 552 | CognitiveEngine::BuildCognitiveEngine() |
| 553 | { |
| 554 | char filename[] = {"ex1"}; |
| 555 | char tablename[] = {"data"}; |
| 556 | |
| 557 | uint32_t numberColumns = |
| 558 | radioInfo->numUtilities + |
| 559 | radioInfo->numParameters + |
| 560 | radioInfo->numObservables + 1; |
| 561 | |
| 562 | char *cols[numberColumns]; |
| 563 | |
| 564 | size_t columnIndex = 0; |
| 565 | for (size_t i = 0; i < radioInfo->numUtilities; i++){ |
| 566 | cols[columnIndex] = (char*)uList[i].name.c_str(); |
| 567 | columnIndex++; |
| 568 | } |
| 569 | for (size_t i = 0; i < radioInfo->numParameters; i++){ |
| 570 | cols[columnIndex] = (char*)pList[i].name.c_str(); |
| 571 | columnIndex++; |
| 572 | } |
| 573 | for (size_t i = 0; i < radioInfo->numObservables; i++){ |
| 574 | cols[columnIndex] = (char*)oList[i].name.c_str(); |
| 575 | columnIndex++; |
| 576 | } |
| 577 | cols[columnIndex] = "utility"; |
| 578 | |
| 579 | myCBR = cbr_create(filename, tablename, cols, numberColumns); |
| 580 | } |
| 581 | |