Index: vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/cbr.c
===================================================================
--- vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/cbr.c	(revision 449)
+++ vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/cbr.c	(revision 457)
@@ -57,5 +57,5 @@
     char *zErrMsg = 0;
 
-    //printf("command: %s\n", _cbr->command);
+    printf("command: %s\n", _cbr->command);
     rc = sqlite3_exec(_cbr->db, _cbr->command, callback, 0, &zErrMsg);
     if( rc!=SQLITE_OK){
@@ -63,5 +63,5 @@
         sqlite3_free(zErrMsg);
     } else{
-        //printf("command executed.\n");
+        printf("command executed.\n");
     }
     return rc;
@@ -129,5 +129,5 @@
             strcat(_cbr->command, ", ");
     }
-    strcat(_cbr->command, ", timestamp DATE);");
+    strcat(_cbr->command, ", timestamp DATE, PRIMARY KEY(biterrorrate,tx_power));");
 
     // execute create table command
@@ -202,5 +202,5 @@
     unsigned int i;
     char str_buffer[64];
-    printf("number of ops %d:\n", _n);
+    //printf("number of ops %d:\n", _n);
     for (i=0; i<_n; i++) {
         // ensure valid ops value
@@ -212,5 +212,4 @@
         strcat(_cbr->command, _names[i]);
         strcat(_cbr->command, ops_str[_ops[i]]);
-    printf("search command: %s\n", _cbr->command);
         sprintf(str_buffer, "%E", _vals[i]);
         strcat(_cbr->command, str_buffer);
@@ -220,16 +219,16 @@
             strcat(_cbr->command, " AND ");
         else
-            strcat(_cbr->command, " order by utility, timestamp desc );");
-    }
-
-    //printf("search command: %s\n", _cbr->command);
+            strcat(_cbr->command, " order by abs(utility) asc, timestamp desc;");
+    }
+
+    printf("search command: %s\n", _cbr->command);
 
     //ExecuteCommand(_cbr);
     rc = ExecuteSearchCommand(_cbr, _retvals);
     
-    /*printf("search result: ");
-    for (i=0; i<_cbr->num_columns; i++)
+    printf("search result: ");
+    for (i=0; i<_cbr->num_columns +1; i++)
         printf("%f, ",_retvals[i]);
-    printf("\n");*/
+    printf("\n");
 
     return rc;
@@ -258,5 +257,5 @@
     }
    
-    strcat(_cbr->command, "timestamp = DATETIME('NOW')");
+    strcat(_cbr->command, ", timestamp = DATETIME('NOW')");
     
     strcat(_cbr->command, " WHERE ");
@@ -272,5 +271,5 @@
     strcat(_cbr->command, ";");
     
-    //printf("search command: %s\n", _cbr->command);
+    //printf("update command: %s\n", _cbr->command);
     // execute add command
     ExecuteCommand(_cbr);
@@ -286,5 +285,5 @@
     // generate command
     //printf("%s\n", _cbr->command);
-    strcpy(_cbr->command, "insert into ");
+    strcpy(_cbr->command, "replace into ");
     strcat(_cbr->command, _cbr->tablename);
     
Index: vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp
===================================================================
--- vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp	(revision 418)
+++ vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp	(revision 457)
@@ -29,4 +29,6 @@
 
 #define TXPOWER 1
+#define DECREMENTSCALE 5
+#define INCREMENTSCALE 5
 
 static cbr myCBR;
@@ -675,4 +677,6 @@
     }
 
+    cbr_print(myCBR);
+
     /* CBR specific call */
     uint32_t rc = cbr_search(myCBR, searchNames, searchOps, searchVals,
@@ -684,8 +688,8 @@
 
         /* Should do a random adaptation.. */
-        if(returnValues[numberColumns-1] < 0) {
-            returnValues[2] = returnValues[2] - 15;
-        } else {
-            returnValues[2] = returnValues[2] + 15;
+        if(returnValues[numberColumns-1] > (uList[0].target * 0.2)) {
+            returnValues[1] = returnValues[1] - DECREMENTSCALE*returnValues[numberColumns-1];
+        } else if(returnValues[numberColumns-1] < -(uList[0].target * 0.2)) {
+            returnValues[1] = returnValues[1] + INCREMENTSCALE*returnValues[numberColumns-1];
         }
     } else if(rc == 31337) {
@@ -693,5 +697,5 @@
         /* No rows in the CBR, pick default parameters */
         /* Currently this is hard coded and implementation specific! */
-        returnValues[2] = currentParameters[0].value + 5;
+        returnValues[1] = currentParameters[0].value + .25;
         
     } else {
