Index: vtcross/branches/trnewman/CR_engines/CBR/src/main_cognitive_engine.c
===================================================================
--- vtcross/branches/trnewman/CR_engines/CBR/src/main_cognitive_engine.c	(revision 83)
+++ vtcross/branches/trnewman/CR_engines/CBR/src/main_cognitive_engine.c	(revision 88)
@@ -291,4 +291,42 @@
 
 
+int GetExperienceSize(int sockfd, int *num_rows, int *num_cols)
+{
+    char buffer[256];
+    
+    // number of rows
+    bzero(buffer,256);
+    ReadMessage(sockfd,buffer);
+    *num_rows = atoi(buffer);
+    // number of columns
+    bzero(buffer,256);
+    ReadMessage(sockfd,buffer);
+    *num_cols = atoi(buffer);
+    /*printf("number of rows: %d, number of columns: %d\n", 
+            *num_rows, *num_cols); */
+    return 1;
+}
+
+
+int GetExperience(int sockfd, int num_rows, int num_cols, 
+        float **past_exp)
+{
+    char buffer[256];
+    int i, j;
+
+    // read experience
+    for (i = 0; i < num_rows; i++){
+        for (j = 0; j < num_cols; j++){
+	    bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+    //    printf("experience: %s\n", buffer);
+        past_exp[i][j] = atof(buffer);
+        }
+    }
+
+    return 1;
+}
+
+
 void print_current_config(struct Utility uList[], 
         struct Parameter pList[], 
@@ -342,17 +380,19 @@
 int RunCBREngine(struct Utility uList[], struct Parameter pList[],
         struct Observable oList[], struct CE_Info *ce_info, 
-        int num_cols)
-{
-    
-    int i;
+        int num_cols, int num_rows, float ** past_exp)
+{
+    
+    int i, j;
 
     // get column names
     //char *cols[50];
+    //char cols[num_cols][50];
     char **cols;
     cols = (char **)malloc(sizeof(char)*num_cols);
-    int j = 0;
+    j = 0;
     for (i = 0; i < ce_info->numUtilities; i++){
         cols[j] = malloc(strlen(uList[i].name)+1);
         cols[j] = uList[i].name;
+    //    strcpy(cols[j], uList[i].name);
         j++;
     }
@@ -360,4 +400,5 @@
         cols[j] = malloc(strlen(pList[i].name)+1);
         cols[j] = pList[i].name;
+    //    strcpy(cols[j], pList[i].name);
         j++;
     }
@@ -365,18 +406,12 @@
         cols[j] = malloc(strlen(oList[i].name)+1);
         cols[j] = oList[i].name;
+    //    strcpy(cols[j], oList[i].name);
         j++;
     }
+    printf("number of columns: %d, %d\n", num_cols, j);
     cols[j] = malloc(strlen("utility")+1);
     cols[j] = "utility";
-    
-    // sample table entry
-    float vals[num_cols];
-    vals[0] = 10e3f;    // throughput
-    vals[1] = 1;        // spectral_efficiency
-    vals[2] = 1e-3f;    // log10_ber
-    vals[3] = 1;        // mod_scheme
-    vals[4] = -3.0f;    // tx_power
-    vals[5] = 10.0f;   // SNR
-    vals[6] = 0.762;    // utility
+    //strcpy(cols[j], "utility");
+    printf("here\n");
     
     printf("number of columns: %d\n", num_cols);
@@ -396,6 +431,21 @@
     
     // add row here
-    //printf("add row to cbr table\n");
-    rc = cbr_add_row(mycbr, cols, vals, num_cols);
+    float vals[num_cols];
+    /*// sample table entry
+    vals[0] = 1e3f;    // throughput
+    vals[1] = 1;        // spectral_efficiency
+    vals[2] = -3.50;    // log10_ber
+    vals[3] = 1;        // mod_scheme
+    vals[4] = -3.5f;    // tx_power
+    vals[5] = 10.0f;   // SNR
+    vals[6] = 0.762;    // utility*/
+    printf("here\n");
+    for (i = 0; i < num_rows; i++){
+        for (j = 0; j < num_cols; j++){
+            vals[j] = past_exp[i][j];
+        }
+        printf("add row to cbr table\n");
+        rc = cbr_add_row(mycbr, cols, vals, num_cols);
+    }
     
     // print
@@ -423,5 +473,5 @@
     float retvals[num_cols];
     rc = cbr_search(mycbr, search_names, search_ops, 
-            search_vals, 2, retvals);
+            search_vals, ce_info->numUtilities, retvals);
 
     j = 0;
@@ -492,13 +542,38 @@
     print_current_config(uList, pList, oList, &ce_info); 
 
+    // get experience size rom server
+    int num_rows, num_cols;
+    GetExperienceSize(sockfd, &num_rows, &num_cols);
+    //printf("number of rows: %d, number of columns: %d\n", 
+    //        num_rows, num_cols); 
+    // get experience
+    float **past_exp;
+    int i, j;
+    past_exp = (float **)malloc(sizeof(float)*num_rows);
+    for (i = 0; i< 1; i++){
+        past_exp[i] = (float*)malloc(sizeof(float)*num_cols);
+    }
+    GetExperience(sockfd, num_rows, num_cols, past_exp);
+    for (i = 0; i < num_rows; i++){
+        for (j = 0; j < num_cols; j++){
+        printf("experience: %f\n", past_exp[i][j]);
+        }
+    }
+   
+    // calculate utility
+    
+
     // cbr operation
-    unsigned int num_cols;
+    //unsigned int num_cols;
     // get number of columns
     num_cols = ce_info.numUtilities + ce_info.numParameters;
     num_cols = num_cols + ce_info.numObservables;
-    num_cols = num_cols + 1;
-    RunCBREngine(uList, pList, oList, &ce_info, num_cols);    
+    num_cols = num_cols + 1;    // overall utility
+    printf("number of rows: %d, number of columns: %d\n",
+            num_rows, num_cols);
+    RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows, 
+            past_exp);    
     // print out results
-    int i;
+    //int i;
     printf("search result: ");
     for (i=0;i<ce_info.numUtilities; i++)
@@ -513,22 +588,4 @@
     SendCEResults(sockfd, uList, pList, oList, &ce_info);
 
-/*    char counter[50];
-    char var[50];
-    // utility
-    for (i = 0; i < ce_info.numUtilities; i++){
-        sprintf(var, "%f", uList[i].value);
-        SendMessage(sockfd, var);
-    }
-    // parameter
-    for (i = 0; i < ce_info.numParameters; i++){
-        sprintf(var, "%f", pList[i].value);
-        SendMessage(sockfd, var);
-    }
-    // observable
-    for (i = 0; i < ce_info.numObservables; i++){
-        sprintf(var, "%f", oList[i].value);
-        SendMessage(sockfd, var);
-    }*/
-
 
   return 0;
