Changeset 458
- Timestamp:
- 09/03/09 00:23:49 (15 years ago)
- Location:
- vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp
r457 r458 29 29 30 30 #define TXPOWER 1 31 #define DECREMENTSCALE 5 32 #define INCREMENTSCALE 5 31 #define BER_ENV 1 32 #define BER_OBJ 1 33 34 #define DECREMENTSCALE 5 35 #define INCREMENTSCALE 5 36 37 #define EVF 20 33 38 34 39 static cbr myCBR; … … 100 105 } 101 106 107 // This function needs serious help and is very confusing 108 102 109 void 103 110 CognitiveEngine::ReceiveFeedback(Observable *observables, Parameter *parameters) … … 106 113 107 114 uint32_t numberColumns = 108 radioInfo->numParameters + 109 radioInfo->numUtilities; 110 111 uint32_t obsColumns = radioInfo->numObservables + 1; 115 radioInfo->numParameters; 116 117 uint32_t utilColumns = radioInfo->numUtilities + 1; 112 118 113 119 float valList[numberColumns]; 114 float obsVals[numberColumns];120 float newUtilityVals[numberColumns]; 115 121 char *nameList[numberColumns]; 116 char * obsList[obsColumns];117 118 size_t column ObsIndex = 0;119 for (size_t i = 0; i < radioInfo->num Observables; i++){120 obsList[columnObsIndex] = (char*)observables[i].name.c_str();121 column ObsIndex++;122 char *utilList[utilColumns]; 123 124 size_t columnUtilIndex = 0; 125 for (size_t i = 0; i < radioInfo->numUtilities; i++){ 126 utilList[columnUtilIndex] = (char*)uList[i].name.c_str(); 127 columnUtilIndex++; 122 128 } 123 obsList[columnObsIndex] = (char*) "utility";129 utilList[columnUtilIndex] = (char*) "utility"; 124 130 125 131 size_t columnIndex = 0; … … 128 134 columnIndex++; 129 135 } 130 for (size_t i = 0; i < radioInfo->numUtilities; i++){ 131 nameList[columnIndex] = (char*)uList[i].name.c_str(); 132 columnIndex++; 133 } 134 135 size_t obsValueIndex = 0; 136 for(size_t i = 0; i < radioInfo->numObservables; i++) { 137 obsVals[obsValueIndex] = observables[i].value; 138 obsValueIndex++; 136 137 size_t newUtilityValueIndex = 0; 138 for(size_t i = 0; i < radioInfo->numUtilities; i++) { 139 140 // This is a special case because the observable is also the utility 141 newUtilityVals[newUtilityValueIndex] = observables[i].value; 142 newUtilityValueIndex++; 139 143 } 140 144 … … 142 146 float newUtilityValue = 0; 143 147 144 // This should probably take into acount that the BER has a log distribution,145 // we are getting raw BER values here.146 148 for(size_t i = 0; i < radioInfo->numUtilities; i++) { 147 149 newUtilityValue = newUtilityValue + (uList[i].target - observables[i].value); 148 150 } 149 obsVals[obsValueIndex] = newUtilityValue;151 newUtilityVals[newUtilityValueIndex] = newUtilityValue; 150 152 151 153 size_t returnValueIndex = 0; … … 154 156 returnValueIndex++; 155 157 } 156 for(size_t i = 0; i < radioInfo->numUtilities; i++) { 157 valList[returnValueIndex] = uList[i].target; 158 returnValueIndex++; 159 } 160 161 cbr_update(myCBR, nameList, obsList, valList, obsVals, 162 numberColumns, obsColumns); 158 159 // cbr_update(database,where,set,whereval,setval,..) 160 cbr_update(myCBR, nameList, utilList, valList, newUtilityVals, 161 numberColumns, utilColumns); 163 162 } 164 163 … … 642 641 LOG("Cognitive Engine:: Generating solution.\n"); 643 642 644 char *searchNames[radioInfo->numUtilities]; 643 char *searchNames[radioInfo->numObservables]; 644 645 for(size_t i = 0; i < radioInfo->numObservables; i++) { 646 searchNames[i] = (char*)observables[i].name.c_str(); 647 } 648 649 float searchVals[radioInfo->numObservables]; 645 650 646 651 for(size_t i = 0; i < radioInfo->numUtilities; i++) { 647 searchNames[i] = (char*)observables[i].name.c_str(); 648 } 649 650 float searchVals[radioInfo->numUtilities]; 651 652 for(size_t i = 0; i < radioInfo->numUtilities; i++) { 653 searchVals[i] = uList[i].target; 652 searchVals[i] = observables[i].value; 654 653 } 655 654 … … 681 680 /* CBR specific call */ 682 681 uint32_t rc = cbr_search(myCBR, searchNames, searchOps, searchVals, 683 radioInfo->numUtilities, returnValues );682 radioInfo->numUtilities, returnValues, EVF); 684 683 685 684 if(rc == 0){ … … 689 688 /* Should do a random adaptation.. */ 690 689 if(returnValues[numberColumns-1] > (uList[0].target * 0.2)) { 691 returnValues[1] = returnValues[1] - DECREMENTSCALE*returnValues[numberColumns-1]; 690 returnValues[1] = returnValues[1] - DECREMENTSCALE*fabs(returnValues[numberColumns-1]); 691 LOG("RREEEALLLY CLOSE1\n %f", fabs(returnValues[numberColumns-1])); 692 692 } else if(returnValues[numberColumns-1] < -(uList[0].target * 0.2)) { 693 returnValues[1] = returnValues[1] + INCREMENTSCALE*returnValues[numberColumns-1]; 693 LOG("RREEEALLLY CLOSE2\n %f", fabs(returnValues[numberColumns-1])); 694 returnValues[1] = returnValues[1] + INCREMENTSCALE*fabs(returnValues[numberColumns-1]); 695 } else { 696 LOG("RREEEALLLY CLOSE\n"); 694 697 } 695 698 } else if(rc == 31337) { … … 697 700 /* No rows in the CBR, pick default parameters */ 698 701 /* Currently this is hard coded and implementation specific! */ 699 returnValues[1] = currentParameters[0].value + .25;702 returnValues[1] = currentParameters[0].value; 700 703 701 704 } else { … … 731 734 for(size_t i = 0; i < radioInfo->numObservables; i++) { 732 735 allNames[allNameIndex] = (char*)oList[i].name.c_str(); 733 returnValues[allNameIndex] = 0;736 returnValues[allNameIndex] = observables[i].value; 734 737 allNameIndex++; 735 738 } -
vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/cbr.c
r457 r458 129 129 strcat(_cbr->command, ", "); 130 130 } 131 strcat(_cbr->command, ", timestamp DATE, PRIMARY KEY( biterrorrate,tx_power));");131 strcat(_cbr->command, ", timestamp DATE, PRIMARY KEY(tx_power));"); 132 132 133 133 // execute create table command … … 190 190 float *_vals, 191 191 unsigned int _n, 192 float *_retvals) 192 float *_retvals, 193 int evf) 193 194 { 194 195 int rc; 196 float lower_limit; 197 float upper_limit; 195 198 // generate command 196 199 strcpy(_cbr->command, "select "); … … 211 214 212 215 strcat(_cbr->command, _names[i]); 213 strcat(_cbr->command, ops_str[_ops[i]]); 214 sprintf(str_buffer, "%E", _vals[i]); 215 strcat(_cbr->command, str_buffer); 216 strcat(_cbr->command, " between "); 217 218 lower_limit = _vals[i]*(1-((float)evf/100)); 219 upper_limit = _vals[i]*(1+((float)evf/100)); 220 221 printf("%f %f %f\n", lower_limit, upper_limit, _vals[i]); 222 223 sprintf(_cbr->command, "%s%f", _cbr->command, lower_limit); 224 strcat(_cbr->command, " and "); 225 sprintf(_cbr->command, "%s%f", _cbr->command, upper_limit); 216 226 217 227