Index: vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/cbr.c
===================================================================
--- vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/cbr.c	(revision 457)
+++ vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/cbr.c	(revision 458)
@@ -129,5 +129,5 @@
             strcat(_cbr->command, ", ");
     }
-    strcat(_cbr->command, ", timestamp DATE, PRIMARY KEY(biterrorrate,tx_power));");
+    strcat(_cbr->command, ", timestamp DATE, PRIMARY KEY(tx_power));");
 
     // execute create table command
@@ -190,7 +190,10 @@
     float *_vals,
     unsigned int _n,
-    float *_retvals)
+    float *_retvals,
+    int evf)
 {   
     int rc;
+    float lower_limit;
+    float upper_limit;
     // generate command
     strcpy(_cbr->command, "select ");
@@ -211,7 +214,14 @@
 
         strcat(_cbr->command, _names[i]);
-        strcat(_cbr->command, ops_str[_ops[i]]);
-        sprintf(str_buffer, "%E", _vals[i]);
-        strcat(_cbr->command, str_buffer);
+        strcat(_cbr->command, " between ");
+        
+        lower_limit = _vals[i]*(1-((float)evf/100));
+        upper_limit = _vals[i]*(1+((float)evf/100));
+
+	printf("%f %f %f\n", lower_limit, upper_limit, _vals[i]);
+
+        sprintf(_cbr->command, "%s%f", _cbr->command, lower_limit);
+        strcat(_cbr->command, " and ");
+        sprintf(_cbr->command, "%s%f", _cbr->command, upper_limit);
 
 
Index: vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp
===================================================================
--- vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp	(revision 457)
+++ vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp	(revision 458)
@@ -29,6 +29,11 @@
 
 #define TXPOWER 1
-#define DECREMENTSCALE 5
-#define INCREMENTSCALE 5
+#define BER_ENV 1
+#define BER_OBJ 1
+
+#define DECREMENTSCALE 5 
+#define INCREMENTSCALE 5 
+
+#define EVF 20
 
 static cbr myCBR;
@@ -100,4 +105,6 @@
 }
 
+// This function needs serious help and is very confusing
+
 void 
 CognitiveEngine::ReceiveFeedback(Observable *observables, Parameter *parameters)
@@ -106,20 +113,19 @@
     
     uint32_t numberColumns = 
-        radioInfo->numParameters +
-        radioInfo->numUtilities;
-
-    uint32_t obsColumns = radioInfo->numObservables + 1;
+        radioInfo->numParameters;
+
+    uint32_t utilColumns = radioInfo->numUtilities + 1;
 
     float valList[numberColumns];
-    float obsVals[numberColumns];
+    float newUtilityVals[numberColumns];
     char *nameList[numberColumns];
-    char *obsList[obsColumns];
-
-    size_t columnObsIndex = 0;
-    for (size_t i = 0; i < radioInfo->numObservables; i++){
-        obsList[columnObsIndex] = (char*)observables[i].name.c_str();
-        columnObsIndex++;
+    char *utilList[utilColumns];
+
+    size_t columnUtilIndex = 0;
+    for (size_t i = 0; i < radioInfo->numUtilities; i++){
+        utilList[columnUtilIndex] = (char*)uList[i].name.c_str();
+        columnUtilIndex++;
     }  
-    obsList[columnObsIndex] = (char*) "utility";
+    utilList[columnUtilIndex] = (char*) "utility";
 
     size_t columnIndex = 0;
@@ -128,13 +134,11 @@
         columnIndex++;
     }   
-    for (size_t i = 0; i < radioInfo->numUtilities; i++){
-        nameList[columnIndex] = (char*)uList[i].name.c_str();
-        columnIndex++;
-    }   
-
-    size_t obsValueIndex = 0;
-    for(size_t i = 0; i < radioInfo->numObservables; i++) {
-        obsVals[obsValueIndex] = observables[i].value;
-        obsValueIndex++;
+
+    size_t newUtilityValueIndex = 0;
+    for(size_t i = 0; i < radioInfo->numUtilities; i++) {
+
+	// This is a special case because the observable is also the utility
+        newUtilityVals[newUtilityValueIndex] = observables[i].value;
+        newUtilityValueIndex++;
     }
 
@@ -142,10 +146,8 @@
     float newUtilityValue = 0;
 
-    // This should probably take into acount that the BER has a log distribution, 
-    //  we are getting raw BER values here.
     for(size_t i = 0; i < radioInfo->numUtilities; i++) {
         newUtilityValue = newUtilityValue + (uList[i].target - observables[i].value);
     }
-    obsVals[obsValueIndex] = newUtilityValue;
+    newUtilityVals[newUtilityValueIndex] = newUtilityValue;
 
     size_t returnValueIndex = 0;
@@ -154,11 +156,8 @@
         returnValueIndex++;
     }
-    for(size_t i = 0; i < radioInfo->numUtilities; i++) {
-        valList[returnValueIndex] = uList[i].target;
-        returnValueIndex++;
-    }
-
-    cbr_update(myCBR, nameList, obsList, valList, obsVals, 
-            numberColumns, obsColumns);
+
+    // cbr_update(database,where,set,whereval,setval,..)
+    cbr_update(myCBR, nameList, utilList, valList, newUtilityVals, 
+            numberColumns, utilColumns);
 }
 
@@ -642,14 +641,14 @@
     LOG("Cognitive Engine:: Generating solution.\n");
 
-    char *searchNames[radioInfo->numUtilities];
+    char *searchNames[radioInfo->numObservables];
+
+    for(size_t i = 0; i < radioInfo->numObservables; i++) {
+        searchNames[i] = (char*)observables[i].name.c_str();
+    }
+
+    float searchVals[radioInfo->numObservables];
 
     for(size_t i = 0; i < radioInfo->numUtilities; i++) {
-        searchNames[i] = (char*)observables[i].name.c_str();
-    }
-
-    float searchVals[radioInfo->numUtilities];
-
-    for(size_t i = 0; i < radioInfo->numUtilities; i++) {
-        searchVals[i] = uList[i].target;
+        searchVals[i] = observables[i].value;
     }
 
@@ -681,5 +680,5 @@
     /* CBR specific call */
     uint32_t rc = cbr_search(myCBR, searchNames, searchOps, searchVals,
-            radioInfo->numUtilities, returnValues);
+            radioInfo->numUtilities, returnValues, EVF);
 
     if(rc == 0){
@@ -689,7 +688,11 @@
         /* Should do a random adaptation.. */
         if(returnValues[numberColumns-1] > (uList[0].target * 0.2)) {
-            returnValues[1] = returnValues[1] - DECREMENTSCALE*returnValues[numberColumns-1];
+            returnValues[1] = returnValues[1] - DECREMENTSCALE*fabs(returnValues[numberColumns-1]);
+		LOG("RREEEALLLY CLOSE1\n %f", fabs(returnValues[numberColumns-1]));
         } else if(returnValues[numberColumns-1] < -(uList[0].target * 0.2)) {
-            returnValues[1] = returnValues[1] + INCREMENTSCALE*returnValues[numberColumns-1];
+		LOG("RREEEALLLY CLOSE2\n %f", fabs(returnValues[numberColumns-1]));
+            returnValues[1] = returnValues[1] + INCREMENTSCALE*fabs(returnValues[numberColumns-1]);
+        } else {
+		LOG("RREEEALLLY CLOSE\n");
         }
     } else if(rc == 31337) {
@@ -697,5 +700,5 @@
         /* No rows in the CBR, pick default parameters */
         /* Currently this is hard coded and implementation specific! */
-        returnValues[1] = currentParameters[0].value + .25;
+        returnValues[1] = currentParameters[0].value;
         
     } else {
@@ -731,5 +734,5 @@
     for(size_t i = 0; i < radioInfo->numObservables; i++) {
         allNames[allNameIndex] = (char*)oList[i].name.c_str();
-        returnValues[allNameIndex] = 0;
+        returnValues[allNameIndex] = observables[i].value;
         allNameIndex++;
     }
