Changeset 87 for vtcross

Show
Ignore:
Timestamp:
11/26/08 19:34:48 (16 years ago)
Author:
ahe
Message:

send experience to ce

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp

    r86 r87  
    338338} 
    339339 
    340 void UpdateCEExperience(float * exp[]) { 
    341  
     340void UpdateCEExperience(int socketfd, int num_rows, int num_cols,  
     341        float * past_exp[])  
     342{ 
     343    char buffer[256]; 
     344    int i, j; 
     345        char counter[55]; 
     346        char var[50]; 
     347 
     348    for (i = 0; i < num_rows; i++){ 
     349        for (j = 0; j< num_cols; j++){ 
     350                sprintf(var,"%f",past_exp[i][j]); 
     351        printf("%f, \n", past_exp[i][j]); 
     352        printf("%s, \n", var); 
     353        } 
     354    } 
     355     
     356    // send the number of rows to the ce first 
     357        sprintf(counter,"%d",num_rows); 
     358        SendMessage(socketfd,counter); 
     359    // send the number of columns to the ce 
     360        sprintf(counter,"%d",num_cols); 
     361        SendMessage(socketfd,counter); 
     362    // update ce with experience 
     363    for (i = 0; i < num_rows; i++){ 
     364        for (j = 0; j< num_cols; j++){ 
     365                sprintf(var,"%f",past_exp[i][j]); 
     366                SendMessage(socketfd,var); 
     367        } 
     368    } 
    342369} 
    343370 
     
    348375// Update operating settings 
    349376// This function will interact with the hardware "drivers" 
    350 void UpdateRadioSettings() { 
    351  
     377void UpdateRadioSettings()  
     378{ 
    352379} 
    353380 
     
    356383        CE_Info *ce_info) 
    357384{ 
    358     string message; 
    359385    char buffer[256]; 
    360386    int i; 
     
    399425         
    400426        float **past_exp; 
     427    int num_rows, num_cols; 
    401428 
    402429        // Set fake current environment params = current environment 
    403         //RequestCEOptimization(); 
    404430        RequestCEOptimization(socketfd, uList, pList, oList, ce_info); 
    405431 
    406432        // Act like we are updating the hardware tranmission settings 
    407         //UpdateRadioSettings(socketfd, uList, pList, oList, ce_info); 
    408433        UpdateRadioSettings(); 
    409434 
    410435        // Send back fake utility values 
    411         UpdateCEExperience(past_exp);    
    412 } 
    413  
    414 void StartMessaging(int socketfd, Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) { 
    415  
    416         float **past_exp; 
    417  
     436    // need to initialize 
     437        //UpdateCEExperience(socketfd, num_rows, num_cols, past_exp);    
     438} 
     439 
     440void StartMessaging(int socketfd, Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info)  
     441{ 
    418442        LoadCEConfiguration(socketfd, uList, pList, oList, ce_info); 
    419443         
    420         UpdateCEExperience(past_exp);    
     444    // cr experience 
     445    float **past_exp; 
     446        int num_cols; 
     447    // get number of columns 
     448    num_cols = ce_info->numUtilities + ce_info->numParameters; 
     449    num_cols = num_cols + ce_info->numObservables; 
     450    num_cols = num_cols + 1;    // overall utility 
     451    int num_rows = 1; 
     452    past_exp = (float **)malloc(sizeof(float)*num_rows); 
     453    int i; 
     454    for (i=0; i<num_rows; i++){ 
     455        past_exp[i] = (float*)malloc(sizeof(float)*num_cols); 
     456    } 
     457    // sample experience #1 
     458    past_exp[0][0] = 1e3f;  // throughput 
     459    past_exp[0][1] = 1;     // spectral_efficiency 
     460    past_exp[0][2] = -3.5;  // log10_ber 
     461    past_exp[0][3] = 1;     // mod_scheme 
     462    past_exp[0][4] = -3.5;  // tx_power 
     463    past_exp[0][5] = 10.0;  // SNR 
     464    past_exp[0][6] = 0.762; // overall utility 
     465    /*// sample experience #2 
     466    past_exp[1][0] = 1e2f;  // throughput 
     467    past_exp[1][1] = 1;     // spectral_efficiency 
     468    past_exp[1][2] = -3.5;  // log10_ber 
     469    past_exp[1][3] = 1;     // mod_scheme 
     470    past_exp[1][4] = -3.5;  // tx_power 
     471    past_exp[1][5] = 3.0;  // SNR 
     472    past_exp[1][6] = 0.462; // overall utility*/ 
     473 
     474 
     475        // update ce with experience 
     476    UpdateCEExperience(socketfd, num_rows, num_cols, past_exp);  
    421477 
    422478        RunSimulator(socketfd, uList, pList, oList, ce_info);