Index: /vtcross/trunk/src/cognitive_engines/cbr.c
===================================================================
--- /vtcross/trunk/src/cognitive_engines/cbr.c	(revision 228)
+++ /vtcross/trunk/src/cognitive_engines/cbr.c	(revision 230)
@@ -222,5 +222,5 @@
     }
 
-    printf("search command: %s\n", _cbr->command);
+    //printf("search command: %s\n", _cbr->command);
 
     //ExecuteCommand(_cbr);
@@ -235,4 +235,43 @@
 }
 
+
+// update a row 
+int cbr_update(cbr _cbr, char *_where[], char*_set[], float *_wherevals, float *_setvals, 
+		unsigned int _wherelen, unsigned int _setlen)
+{
+    unsigned int i;
+    
+    // generate command
+    //printf("%s\n", _cbr->command);
+    strcpy(_cbr->command, "UPDATE ");
+    strcat(_cbr->command, _cbr->tablename);
+    
+    strcat(_cbr->command, " SET ");
+    for (i=0; i<_setlen; i++) {
+        strcat(_cbr->command, _set[i]);
+        strcat(_cbr->command, " = ");
+        sprintf(_cbr->command, "%s%f", _cbr->command, _setvals[i]);
+        strcat(_cbr->command, "  ");
+        if (i != _setlen-1) // not last entry
+            strcat(_cbr->command, ", ");
+    }
+    strcat(_cbr->command, " WHERE ");
+
+    for (i=0; i<_wherelen; i++) {
+        strcat(_cbr->command, _where[i]);
+        strcat(_cbr->command, " = ");
+        sprintf(_cbr->command, "%s%f", _cbr->command, _wherevals[i]);
+        strcat(_cbr->command, "  ");
+        if (i != _wherelen-1) // not last entry
+            strcat(_cbr->command, "AND ");
+    }
+    strcat(_cbr->command, ";");
+    
+    //printf("search command: %s\n", _cbr->command);
+    // execute add command
+    ExecuteCommand(_cbr);
+
+    return 0;
+}
 
 // cbr add a row
@@ -264,4 +303,5 @@
     strcat(_cbr->command, ");");
     
+    //printf("search command: %s\n", _cbr->command);
     // execute add command
     ExecuteCommand(_cbr);
Index: /vtcross/trunk/src/cognitive_engines/CognitiveEngine.cpp
===================================================================
--- /vtcross/trunk/src/cognitive_engines/CognitiveEngine.cpp	(revision 228)
+++ /vtcross/trunk/src/cognitive_engines/CognitiveEngine.cpp	(revision 230)
@@ -12,4 +12,5 @@
 #include <cstring>
 #include <stdint.h>
+#include <math.h>
 
 #include "vtcross/common.h"
@@ -94,4 +95,66 @@
 
 void 
+CognitiveEngine::ReceiveFeedback(Observable *observables, Parameter *parameters)
+{ 
+   LOG("Cognitive Engine:: Receiving feedback.\n");
+	
+	uint32_t numberColumns = 
+		radioInfo->numParameters +
+		radioInfo->numUtilities;
+
+	uint32_t obsColumns = radioInfo->numObservables + 1;
+
+	float valList[numberColumns];
+	float obsVals[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++;
+    }  
+    obsList[columnObsIndex] = "utility";
+
+    size_t columnIndex = 0;
+    for (size_t i = 0; i < radioInfo->numParameters; i++){
+		nameList[columnIndex] = (char*)parameters[i].name.c_str();
+        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++;
+	}
+	// Calculate Utility
+	float newUtilityValue = 0;
+
+    for(size_t i = 0; i < radioInfo->numUtilities; i++) {
+		newUtilityValue = newUtilityValue + (uList[i].target - observables[i].value);
+	}
+	obsVals[obsValueIndex] = newUtilityValue;
+
+	size_t returnValueIndex = 0;
+    for(size_t i = 0; i < radioInfo->numParameters; i++) {
+		valList[returnValueIndex] = parameters[i].value;
+		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);
+}
+
+
+void 
 CognitiveEngine::WaitForSignal()
 {
@@ -110,9 +173,24 @@
         // MUCH faster since instead of donig string compares we can simply
         // switch on the integer value...
-        if(strcmp(buffer, "request_optimization") == 0) {
+        if(strcmp(buffer, "update_performance") == 0) {
             
+            /* Receive Set of current Parameters */
+            memset(buffer, 0, 256);
+            ReadMessage(commandSocketFD,buffer);
+            uint32_t numParameters = atoi(buffer);
+   
+            Parameter *p = new Parameter[numParameters];
+ 
+            for(size_t i = 0; i < numParameters; i++) {
+                memset(buffer, 0, 256);
+                ReadMessage(commandSocketFD, buffer);
+                p[i].name = std::string(buffer);
+    
+                memset(buffer, 0, 256);
+                ReadMessage(commandSocketFD, buffer);
+                p[i].value = atof(buffer);
+            } 
+
             /* Receive Set of Observables */
-			LOG("Cognitive Engine:: Receiving Observable Parameters\n");
-
             memset(buffer, 0, 256);
             ReadMessage(commandSocketFD,buffer);
@@ -131,4 +209,30 @@
             }  
 
+			ReceiveFeedback(o,p);
+
+            delete [] o;
+            delete [] p;
+		} 
+		else if(strcmp(buffer, "request_optimization") == 0) {
+            
+            /* Receive Set of Observables */
+			LOG("\nCognitive Engine:: Receiving Observable Parameters\n");
+
+            memset(buffer, 0, 256);
+            ReadMessage(commandSocketFD,buffer);
+            uint32_t numObservables = atoi(buffer);
+   
+            Observable *o = new Observable[numObservables];
+ 
+            for(size_t i = 0; i < numObservables; i++) {
+                memset(buffer, 0, 256);
+                ReadMessage(commandSocketFD, buffer);
+                o[i].name = std::string(buffer);
+    
+                memset(buffer, 0, 256);
+                ReadMessage(commandSocketFD, buffer);
+                o[i].value = atof(buffer);
+            }  
+
             /* Receive Set of current Parameters */
 			LOG("Cognitive Engine:: Receiving Current Transmission Parameters\n");
@@ -156,5 +260,5 @@
 
             // TODO need to actually do something with the observables here
-            
+           
 			LOG("Cognitive Engine:: Sending Optimal Parameters to Application.\n");
 			char numParametersChar[10];
@@ -453,5 +557,5 @@
 
     for(size_t i = 0; i < radioInfo->numUtilities; i++) {
-        searchNames[i] = (char*)uList[i].name.c_str();
+        searchNames[i] = (char*)observables[i].name.c_str();
 	}
 
@@ -492,10 +596,21 @@
 	if(rc == 0){
         /* Adapt the returned parameters to meet the objective */
-
+	    
+        WARNING("Cognitive Engine:: Found\n");
+
+		// Should do a random adaptation.. 
+		if(returnValues[numberColumns-1] < 0) {
+			returnValues[2] = returnValues[2] - 15;
+			returnValues[3] = returnValues[3] - 2;
+        } else {
+			returnValues[2] = returnValues[2] + 15;
+			returnValues[3] = returnValues[3] + 2;
+		}
     } else if(rc == 31337){
+        WARNING("Cognitive Engine:: Not Found.\n");
 		/* No rows in the CBR, pick default parameters */
 		// Currently this is hard coded and implementation specific!
-	    //returnValues[2] = currentParameters[0].value + 5;
-	    //returnValues[3] = currentParameters[1].value + 10;
+	    returnValues[2] = currentParameters[0].value + 5;
+	    returnValues[3] = currentParameters[1].value + 10;
         
 	} else {
@@ -516,6 +631,26 @@
 		returnValueIndex++;
 	}
+    returnValues[returnValueIndex] = 0;
+
+    char *allNames[numberColumns];
+	size_t allNameIndex = 0;
+    for(size_t i = 0; i < radioInfo->numUtilities; i++) {
+        allNames[allNameIndex] = (char*)uList[i].name.c_str();
+		returnValues[allNameIndex] = uList[i].target;
+		allNameIndex++;
+	}
+    for(size_t i = 0; i < radioInfo->numParameters; i++) {
+        allNames[allNameIndex] = (char*)pList[i].name.c_str();
+		allNameIndex++;
+	}
+    for(size_t i = 0; i < radioInfo->numObservables; i++) {
+        allNames[allNameIndex] = (char*)oList[i].name.c_str();
+		returnValues[allNameIndex] = 0;
+		allNameIndex++;
+	}
+    allNames[allNameIndex] = "utility";
 
 	// Add row to CBR. 
+	cbr_add_row(myCBR, allNames, returnValues, returnValueIndex+1);
 
 	return pList;
@@ -535,13 +670,5 @@
 void 
 CognitiveEngine::ReceiveFeedback(Observable *observables, Parameter *parameters, \
-    Utility *utilities)
-{
-    LOG("Cognitive Engine:: Receiving feedback.\n");
-}
-
-
-void 
-CognitiveEngine::ReceiveFeedback(Observable *observables, Parameter *parameters, \
-    Utility *utilities, std::string service)
+    std::string service)
 {
     LOG("Cognitive Engine:: Receiving feedback.\n");
Index: /vtcross/trunk/src/include/vtcross/libvtcross.h
===================================================================
--- /vtcross/trunk/src/include/vtcross/libvtcross.h	(revision 228)
+++ /vtcross/trunk/src/include/vtcross/libvtcross.h	(revision 230)
@@ -86,7 +86,6 @@
  * radio's performance?
  */
-bool UpdateParameterPerformance(Parameter *radioParameters, \
-        Observable *radioObservables, Utility *radioUtilies);
-
+bool UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o, \
+        uint32_t numObservables);
 
 /* Deactivate/Activate/Disconnect a component by id.
@@ -107,4 +106,6 @@
  */
 uint32_t GetNumParameters();
+uint32_t GetNumObservables();
+uint32_t GetNumUtilities();
 
 
Index: /vtcross/trunk/src/include/vtcross/components.h
===================================================================
--- /vtcross/trunk/src/include/vtcross/components.h	(revision 228)
+++ /vtcross/trunk/src/include/vtcross/components.h	(revision 230)
@@ -272,7 +272,7 @@
          */
         void ReceiveFeedback(Observable *observables,\
-                Parameter *parameters, Utility *utilities);
+                Parameter *parameters);
         void ReceiveFeedback(Observable *observables, \
-                Parameter *parameters, Utility *utilities, std::string service);
+                Parameter *parameters, std::string service);
 
 
@@ -352,5 +352,7 @@
         bool SendRadioConfiguration(int32_t socketFD);
         bool SendRadioExperience(int32_t socketFD);
- 
+
+		bool UpdateParameterPerformance(int32_t socketFD);
+
         bool SML_present;
         bool PE_present;
Index: /vtcross/trunk/src/shell/CognitiveRadioShell.cpp
===================================================================
--- /vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 229)
+++ /vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 230)
@@ -552,5 +552,70 @@
 }
 
-
+bool
+CognitiveRadioShell::UpdateParameterPerformance(int32_t socketFD)
+{
+    char counter[55];
+    uint32_t numObservables,numParameters;
+    char var[50];
+    char buffer[256];
+
+	/* Receive Set of Parameters */
+    memset(buffer, 0, 256);
+    ReadMessage(commandSocketFD,buffer);
+    numParameters = atoi(buffer);
+  
+    Parameter *p = new Parameter[numParameters];
+
+    for (size_t i = 0; i < numParameters; i++){
+        memset(buffer, 0, 256);
+        ReadMessage(commandSocketFD,buffer);
+        p[i].name = std::string(buffer);
+        memset(buffer, 0, 256);
+        ReadMessage(commandSocketFD,buffer);
+        p[i].value = atof(buffer);
+    }
+
+    /* Receive Set of Observables */
+    memset(buffer, 0, 256);
+    ReadMessage(commandSocketFD, buffer);
+    numObservables = atoi(buffer);
+  
+    Observable *o = new Observable[numObservables];
+ 
+    for(size_t i = 0; i < numObservables; i++) {
+        memset(buffer, 0, 256);
+        ReadMessage(commandSocketFD, buffer);
+        o[i].name = std::string(buffer);
+   
+        memset(buffer, 0, 256);
+        ReadMessage(commandSocketFD, buffer);
+        o[i].value = atof(buffer);
+    }
+
+
+    SendMessage(ceSocketFD, "update_performance");
+   
+    // Send Parameters 
+    memset(counter, 0, 55);
+    sprintf(counter, "%i", numParameters);
+    SendMessage(ceSocketFD, counter);
+    
+    for(size_t i = 0; i < numParameters; i++) {
+        SendMessage(ceSocketFD,p[i].name.c_str());
+        sprintf(var,"%f",p[i].value);
+        SendMessage(ceSocketFD,var);  
+    }   
+    
+    // Send Observables
+    sprintf(counter, "%i", numObservables);
+    SendMessage(ceSocketFD, counter);
+    for(size_t i = 0; i < numObservables; i++) {
+        SendMessage(ceSocketFD, o[i].name.c_str());
+        sprintf(var, "%f", o[i].value);
+        SendMessage(ceSocketFD, var); 
+    }   
+    
+    return 1;
+}
 void
 CognitiveRadioShell::HandleMessage(int32_t socketFD)
@@ -572,4 +637,14 @@
     } else if(strcmp(buffer, "deregister_sml") == 0) {
         DeregisterSML(socketFD);
+    } else if(strcmp(buffer, "update_performance") == 0) {
+        UpdateParameterPerformance(socketFD);
+    } else if(strcmp(buffer,"get_number_utilities") == 0) {
+		char numUtilities[20];
+		sprintf(numUtilities,"%i",radio_info->numUtilities);
+        SendMessage(commandSocketFD,numUtilities);
+    } else if(strcmp(buffer,"get_number_observables") == 0) {
+		char numObservables[20];
+		sprintf(numObservables,"%i",radio_info->numObservables);
+        SendMessage(commandSocketFD,numObservables);
     } else if(strcmp(buffer,"get_number_parameters") == 0) {
 		char numParameters[20];
Index: /vtcross/trunk/src/libvtcross/libvtcross_demo.cpp
===================================================================
--- /vtcross/trunk/src/libvtcross/libvtcross_demo.cpp	(revision 228)
+++ /vtcross/trunk/src/libvtcross/libvtcross_demo.cpp	(revision 230)
@@ -23,20 +23,33 @@
 main(int32_t argc, char *argv[])
 {
-    Observable *o = new Observable[1];
+
+	for(size_t i = 0; i < 10; i++) {
+    Observable *o = new Observable[2];
     Parameter *currentParameters = new Parameter[2];
     Parameter * p;
 
 	uint32_t numParameters;
+	uint32_t numObservables;
+	uint32_t numUtilities;
 
-    o[0].name = "PER";
-	o[0].value = 12.00;
+    o[0].name = "throughput";
+	o[0].value = 150.00;
+    o[1].name = "PER";
+	o[1].value = 12.00;
 
-    currentParameters[0].name = "tx_power";
-    currentParameters[0].value = 10.0;
-    currentParameters[1].name = "bandwidth";
-    currentParameters[1].value = 300.0;
+	if(i == 0) {
+    currentParameters[0].name = "bandwidth";
+    currentParameters[0].value = 300.0;
+    currentParameters[1].name = "tx_power";
+    currentParameters[1].value = 10.0;
 
-    p = GetOptimalParameters(o,1,currentParameters,2);
+	} else {
+    currentParameters[0].value = p[0].value;
+    currentParameters[1].value = p[1].value;
+	}
+    p = GetOptimalParameters(o,2,currentParameters,2);
     numParameters = GetNumParameters();
+    numObservables = GetNumObservables();
+    numUtilities = GetNumUtilities();
 
 	printf("Application:: Received the following parameters.\n");
@@ -48,12 +61,13 @@
 	// Try them out! Do they work?
     
-    Utility *resultingUtility = new Utility[2];
-	
-	// UpdateParameterPerformance(p,o,resultingUtility);	
+    o[0].value = 0.5*p[0].value + .1*p[1].value;
+    o[1].value = 15-p[1].value;
+
+	UpdateParameterPerformance(p,numParameters,o,numObservables);	
 	
 	
 	delete [] p; 
     delete [] o; 
-
+	}
 	return 0;
 }
Index: /vtcross/trunk/src/libvtcross/libvtcross.cpp
===================================================================
--- /vtcross/trunk/src/libvtcross/libvtcross.cpp	(revision 229)
+++ /vtcross/trunk/src/libvtcross/libvtcross.cpp	(revision 230)
@@ -25,4 +25,36 @@
     
     return socket;
+}
+
+uint32_t
+GetNumObservables()
+{
+	uint32_t socketfd, numObservables;
+    char buffer[256];
+
+    socketfd = ConnectToRemoteComponent();
+    SendMessage(socketfd,"get_number_observables");
+    
+    memset(buffer, 0, 256);
+    ReadMessage(socketfd, buffer);
+    numObservables = atoi(buffer);
+	
+	return numObservables; 
+}
+
+uint32_t
+GetNumUtilities()
+{
+	uint32_t socketfd, numUtilities;
+    char buffer[256];
+
+    socketfd = ConnectToRemoteComponent();
+    SendMessage(socketfd,"get_number_utilities");
+    
+    memset(buffer, 0, 256);
+    ReadMessage(socketfd, buffer);
+    numUtilities = atoi(buffer);
+	
+	return numUtilities; 
 }
 
@@ -106,2 +138,32 @@
 }
 
+bool
+UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o,
+		uint32_t numObservables)
+{
+	char counter[55];
+    char var[50];
+
+    uint32_t socketFD = ConnectToRemoteComponent();
+    SendMessage(socketFD, "update_performance");
+    
+    // Send Parameters 
+    memset(counter, 0, 55);
+    sprintf(counter, "%i", numParameters);
+    SendMessage(socketFD, counter);
+	
+	for(size_t i = 0; i < numParameters; i++) {
+        SendMessage(socketFD,p[i].name.c_str());
+        sprintf(var,"%f",p[i].value);
+        SendMessage(socketFD,var);	
+    }
+    
+	// Send Observables
+    sprintf(counter, "%i", numObservables);
+    SendMessage(socketFD, counter);
+    for(size_t i = 0; i < numObservables; i++) {
+        SendMessage(socketFD, o[i].name.c_str());
+        sprintf(var, "%f", o[i].value);
+        SendMessage(socketFD, var);	
+    }
+}
