Show
Ignore:
Timestamp:
02/09/09 16:51:58 (15 years ago)
Author:
trnewman
Message:

Cleaned up the code and put in the hooks for optimization request messages

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/CR_engines/CBR/src/main_cognitive_engine.c

    r89 r95  
    285285    strcpy(buffer, "xml received"); 
    286286    SendMessage(sockfd, buffer); 
    287     printf("xml reception done\n"); 
     287    //printf("xml reception done\n"); 
    288288     
    289289    return 1; 
     
    306306} 
    307307 
     308int GetRequest(int sockfd) 
     309{ 
     310    char buffer[256]; 
     311 
     312        bzero(buffer,256); 
     313        ReadMessage(sockfd,buffer); 
     314 
     315    return 1; 
     316} 
    308317 
    309318int GetExperience(int sockfd, int num_rows, int num_cols,  
     
    536545    // get xml info from server 
    537546    GetXMLFromServer(sockfd, uList, pList, oList, &ce_info); 
    538     print_current_config(uList, pList, oList, &ce_info);  
    539  
     547    printf("Received Radio Operation Profile from Server Successfully.\n\n"); 
     548    //print_current_config(uList, pList, oList, &ce_info);  
     549     
     550     
    540551    // get experience size from server 
    541552    int num_rows, num_cols; 
    542553    GetExperienceSize(sockfd, &num_rows, &num_cols); 
     554     
    543555    // get experience 
    544556    int i, j; 
    545     /*float **past_exp; 
    546     past_exp = (float **)malloc(sizeof(float)*num_rows); 
    547     for (i = 0; i< 1; i++){ 
    548         past_exp[i] = (float*)malloc(sizeof(float)*num_cols); 
    549     }*/ 
    550557    float past_exp[num_rows][num_cols]; 
    551558    GetExperience(sockfd, num_rows, num_cols, past_exp); 
    552     for (i = 0; i < num_rows; i++){ 
    553         printf("experience #%d:\n", i+1); 
    554         for (j = 0; j < num_cols; j++){ 
    555         printf(" %f", past_exp[i][j]); 
    556         } 
    557         printf("\n"); 
    558     } 
    559     
     559    printf("Received Previous Radio Experience from Server Successfully.\n\n"); 
     560     
    560561    // calculate utility 
    561      
    562562 
    563563    // cbr operation 
     
    567567    num_cols = num_cols + ce_info.numObservables; 
    568568    num_cols = num_cols + 1;    // overall utility 
    569     printf("number of rows: %d, number of columns: %d\n", 
    570             num_rows, num_cols); 
    571     RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows,  
     569    
     570    //while(1) { 
     571         
     572        // Wait until request is received from server to perform optimization  
     573        //printf("Waiting for Request for optimization from Server\n\n"); 
     574        //GetRequest(sockfd); 
     575        //printf("Received optimization request from server\n\n"); 
     576        RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows,  
    572577            past_exp);     
    573     // print out results 
    574     //int i; 
    575     printf("search result: "); 
    576     for (i=0;i<ce_info.numUtilities; i++) 
    577         printf("%f, ",uList[i].value); 
    578     for (i=0;i<ce_info.numParameters; i++) 
    579         printf("%f, ",pList[i].value); 
    580     for (i=0;i<ce_info.numObservables; i++) 
    581         printf("%f, ",oList[i].value); 
    582     printf("\n"); 
    583      
    584     // send results back to server 
    585     SendCEResults(sockfd, uList, pList, oList, &ce_info); 
    586  
    587  
    588   return 0; 
    589 } 
     578    
     579        printf("Sending optimization results to server.\n\n"); 
     580        // send results back to server 
     581        SendCEResults(sockfd, uList, pList, oList, &ce_info); 
     582    //} 
     583     
     584    return 0; 
     585}