Changeset 554

Show
Ignore:
Timestamp:
05/17/10 03:14:03 (14 years ago)
Author:
nikhil
Message:
 
Location:
vtcross/branches/nikhil/crossmodel1
Files:
13 modified
1 copied

Legend:

Unmodified
Added
Removed
  • vtcross/branches/nikhil/crossmodel1/src/cognitive_engines/CBR.cpp

    r544 r554  
    2121 
    2222#include "vtcross/cbr.h" 
    23  
     23#include <iostream> 
    2424 
    2525using namespace std; 
     
    6666     * use. */ 
    6767    ExecuteCommand(); 
     68 
     69    std::cout << "Table Created" << std::endl; 
    6870} 
    6971 
     
    207209            command += " AND "; 
    208210        else 
    209             command += " order by utility desc;"; 
     211            command += ";"; 
    210212         
    211213    } 
  • vtcross/branches/nikhil/crossmodel1/src/cognitive_engines/CBR_CE/CBR_CE.cpp

    r545 r554  
    2020 
    2121#include "CBR_CE.h" 
    22  
     22#include <iostream> 
    2323 
    2424using namespace std; 
     
    3333 
    3434 
    35 void  
    36 CBR_CE::RegisterServices() 
    37 { 
    38     LOG("Cognitive Engine:: Registering services.\n"); 
    39  
    40     SendMessage(commandSocketFD, "register_service"); 
    41     SendMessage(commandSocketFD, "test_srv"); 
    42  
    43     SendMessage(commandSocketFD, "register_service"); 
    44     SendMessage(commandSocketFD, "test_srv1"); 
    45  
    46     SendMessage(commandSocketFD, "register_service"); 
    47     SendMessage(commandSocketFD, "test_srv2"); 
    48  
    49     SendMessage(commandSocketFD, "register_service"); 
    50     SendMessage(commandSocketFD, "test_srv3"); 
    51  
    52 } 
    53  
    54  
    55 void  
    56 CBR_CE::DeregisterServices() 
    57 { 
    58     LOG("Cognitive Engine:: Deregistering services.\n"); 
    59  
    60     SendMessage(commandSocketFD, "deregister_service"); 
    61     SendMessage(commandSocketFD, "test_srv"); 
    62  
    63     SendMessage(commandSocketFD, "deregister_service"); 
    64     SendMessage(commandSocketFD, "test_srv1"); 
    65  
    66     SendMessage(commandSocketFD, "deregister_service"); 
    67     SendMessage(commandSocketFD, "test_srv2"); 
    68  
    69     SendMessage(commandSocketFD, "deregister_service"); 
    70     SendMessage(commandSocketFD, "test_srv3"); 
    71  
    72 } 
    73  
    74  
    7535Parameter*  
    76 CBR_CE::GetSolution(Observable *observables, Parameter *currentParameters) 
     36CBR_CE::GetSolution(Observable *observables, Parameter *currentParameters, Utility *utilities) 
    7737{ 
    7838    LOG("Cognitive Engine:: Generating solution.\n"); 
     
    8141 
    8242    for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
    83         searchNames[i] = observables[i].name; 
     43        searchNames[i] = uList[i].name; 
    8444    } 
    8545 
     
    9050    } 
    9151 
    92     uint32_t numberColumns = radioInfo->numUtilities + radioInfo->numParameters \ 
    93                              + radioInfo->numObservables + 1; 
     52    uint32_t numberColumns = radioInfo->numParameters + radioInfo->numUtilities + radioInfo->numObservables + 1; 
    9453     
    9554    float returnValues[numberColumns]; 
     
    12988        LOG("Cognitive Engine:: Found\n"); 
    13089 
    131         /* Should do a random adaptation.. */ 
    132         if(returnValues[numberColumns-1] < 0) { 
    133             returnValues[2] = returnValues[2] - 15; 
    134             returnValues[3] = returnValues[3] - 2; 
    135         } else { 
    136             returnValues[2] = returnValues[2] + 15; 
    137             returnValues[3] = returnValues[3] + 2; 
    138         } 
    13990    } else if(rc == 31337) { 
    14091        LOG("Cognitive Engine:: Not Found.\n"); 
    14192        /* No rows in the CBR, pick default parameters */ 
    14293        /* Currently this is hard coded and implementation specific! */ 
    143         returnValues[2] = currentParameters[0].value + 5; 
    144         returnValues[3] = currentParameters[1].value + 10; 
    145          
    146     } else { 
    147         LOG("Cognitive Engine:: Search return an invalid value.\n"); 
    148     } 
     94 
     95        for (int i = 0; i < radioInfo->numParameters; i++) { 
     96            returnValues[i] = currentParameters[i].value + pList[i].step; 
     97            if (returnValues[i] > pList[i].max) { 
     98                std::cout << "SORRY CANT EXCEED MAX VALUE" << std::endl; 
     99                returnValues[i] = returnValues[i] - pList[i].step; 
     100            } 
     101            if (returnValues[i] < pList[i].min) { 
     102                std::cout << "SORRY CANT GO BELOW MIN VALUE" << std::endl; 
     103                returnValues[i] = returnValues[i] + pList[i].step ;               
     104            } 
     105        } 
     106 
     107        for (int i = 0; i < radioInfo->numUtilities; i++) 
     108            returnValues[radioInfo->numParameters + i] = uList[i].value; 
     109 
     110        for (int i = 0; i < radioInfo->numObservables; i++) 
     111            returnValues[radioInfo->numParameters + radioInfo->numUtilities + i] = oList[i].value; 
    149112 
    150113    size_t returnValueIndex = 0; 
    151114    for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
     115        pList[i].value = returnValues[returnValueIndex]; 
     116        returnValueIndex++; 
     117    } 
     118    for(size_t i = 0; i < radioInfo->numParameters; i++) { 
    152119        uList[i].value = returnValues[returnValueIndex]; 
    153         returnValueIndex++; 
    154     } 
    155     for(size_t i = 0; i < radioInfo->numParameters; i++) { 
    156         pList[i].value = returnValues[returnValueIndex]; 
    157120        returnValueIndex++; 
    158121    } 
     
    165128    string allNames[numberColumns]; 
    166129    size_t allNameIndex = 0; 
    167     for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
    168         allNames[allNameIndex] = uList[i].name; 
    169         returnValues[allNameIndex] = uList[i].target; 
    170         allNameIndex++; 
    171     } 
    172130    for(size_t i = 0; i < radioInfo->numParameters; i++) { 
    173131        allNames[allNameIndex] = pList[i].name; 
    174132        allNameIndex++; 
    175133    } 
     134    for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
     135        allNames[allNameIndex] = uList[i].name; 
     136        allNameIndex++; 
     137    } 
    176138    for(size_t i = 0; i < radioInfo->numObservables; i++) { 
    177139        allNames[allNameIndex] = oList[i].name; 
    178         returnValues[allNameIndex] = 0; 
    179140        allNameIndex++; 
    180141    } 
    181     allNames[allNameIndex] = "utility"; 
     142    allNames[allNameIndex] = "TotalWeight"; 
    182143 
    183144    // Add row to CBR.  
    184145    myCBR->AddRow(allNames, returnValues, returnValueIndex + 1); 
    185146 
     147        } else { 
     148        LOG("Cognitive Engine:: Search return an invalid value.\n"); 
     149    } 
     150 
     151 
    186152    return pList; 
    187153} 
    188154 
    189155 
    190 Parameter*  
    191 CBR_CE::GetSolution(Observable *observables, \ 
    192         Parameter *currentParameters, std::string service) 
    193 { 
    194     LOG("Cognitive Engine:: Generating solution for %s service.\n", service.c_str()); 
    195  
    196     return pList; 
    197 } 
    198  
    199  
    200156void  
    201 CBR_CE::ReceiveFeedback(Observable *observables, Parameter *parameters) 
     157CBR_CE::ReceiveFeedback(Observable *observables, Parameter *parameters, Utility *utilities) 
    202158{  
    203159    LOG("Cognitive Engine:: Receiving feedback.\n"); 
    204160     
    205     uint32_t numberColumns = radioInfo->numParameters + radioInfo->numUtilities; 
    206  
    207     uint32_t obsColumns = radioInfo->numObservables + 1; 
    208  
    209     float valList[numberColumns]; 
    210     float obsVals[numberColumns]; 
    211     string nameList[numberColumns]; 
    212     string obsList[obsColumns]; 
    213  
    214     size_t columnObsIndex = 0; 
    215     for (size_t i = 0; i < radioInfo->numObservables; i++){ 
    216         obsList[columnObsIndex] = observables[i].name; 
    217         columnObsIndex++; 
    218     }   
    219     obsList[columnObsIndex] = "utility"; 
    220  
    221     size_t columnIndex = 0; 
    222     for (size_t i = 0; i < radioInfo->numParameters; i++){ 
    223         nameList[columnIndex] = parameters[i].name; 
    224         columnIndex++; 
    225     }    
    226     for (size_t i = 0; i < radioInfo->numUtilities; i++){ 
    227         nameList[columnIndex] = uList[i].name; 
    228         columnIndex++; 
    229     }    
    230  
    231     size_t obsValueIndex = 0; 
     161    uint32_t numberColumns = radioInfo->numParameters + radioInfo->numUtilities + radioInfo->numObservables + 1; 
     162 
     163    uint32_t whereLen = radioInfo->numParameters; 
     164    uint32_t setLen = radioInfo->numUtilities + radioInfo->numObservables; 
     165 
     166 
     167    float whereValue[whereLen]; 
     168    float setValue[setLen]; 
     169    string whereList[whereLen]; 
     170    string setList[setLen]; 
     171 
     172 
     173    for(size_t i = 0; i < radioInfo->numParameters; i++) { 
     174        whereList[i] = parameters[i].name; 
     175        whereValue[i] = parameters[i].value; 
     176    } 
     177 
     178    size_t returnValueIndex = 0; 
     179    for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
     180        setList[returnValueIndex] = utilities[i].name; 
     181        setValue[returnValueIndex] = utilities[i].value;    
     182        returnValueIndex++; 
     183    } 
    232184    for(size_t i = 0; i < radioInfo->numObservables; i++) { 
    233         obsVals[obsValueIndex] = observables[i].value; 
    234         obsValueIndex++; 
    235     } 
    236  
    237     /* Calculate Utility */ 
    238     float newUtilityValue = 0; 
    239  
    240     for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
    241         newUtilityValue = newUtilityValue + (uList[i].target - observables[i].value); 
    242     } 
    243     obsVals[obsValueIndex] = newUtilityValue; 
    244  
    245     size_t returnValueIndex = 0; 
    246     for(size_t i = 0; i < radioInfo->numParameters; i++) { 
    247         valList[returnValueIndex] = parameters[i].value; 
    248         returnValueIndex++; 
    249     } 
    250     for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
    251         valList[returnValueIndex] = uList[i].target; 
    252         returnValueIndex++; 
    253     } 
    254 } 
    255  
    256  
    257 void  
    258 CBR_CE::ReceiveFeedback(Observable *observables, Parameter *parameters, \ 
    259     std::string service) 
    260 { 
    261     LOG("Cognitive Engine:: Receiving feedback.\n"); 
     185        setList[returnValueIndex] = observables[i].name; 
     186        setValue[returnValueIndex] = observables[i].value; 
     187        returnValueIndex++; 
     188    } 
     189 
     190 
     191myCBR->Update(whereList,setList,whereValue,setValue,whereLen,setLen); 
     192 
    262193} 
    263194 
     
    267198{ 
    268199    string filename = "ex1"; 
     200    string filename2 = "ex2"; 
    269201    string tablename = "data"; 
    270202 
    271     uint32_t numberColumns = radioInfo->numUtilities + radioInfo->numParameters \ 
     203    uint32_t numberColumns = radioInfo->numParameters + radioInfo->numUtilities \ 
    272204                             + radioInfo->numObservables + 1; 
    273205 
     206    uint32_t numberParameters = radioInfo->numParameters; 
     207    uint32_t numberUtilities = radioInfo->numUtilities; 
     208 
    274209    string cols[numberColumns]; 
     210    string Plist[numberParameters]; 
     211    string Ulist[numberUtilities]; 
     212    float Utarget[numberUtilities]; 
     213    string Ugoal[numberUtilities]; 
    275214 
    276215    size_t columnIndex = 0; 
     216    size_t Pindex = 0;              // new 
     217    size_t Uindex = 0;              // new 
     218 
     219 
     220    for (size_t i = 0; i < radioInfo->numParameters; i++){ 
     221        cols[columnIndex] = pList[i].name; 
     222        columnIndex++; 
     223        Plist[Pindex] = pList[i].name;   // new 
     224        Pindex++;                        // new 
     225    } 
    277226    for (size_t i = 0; i < radioInfo->numUtilities; i++){ 
    278227        cols[columnIndex] = uList[i].name; 
    279228        columnIndex++; 
    280     }    
    281     for (size_t i = 0; i < radioInfo->numParameters; i++){ 
    282         cols[columnIndex] = pList[i].name; 
    283         columnIndex++; 
    284     }    
    285     for (size_t i = 0; i < radioInfo->numObservables; i++){ 
     229        Ulist[Uindex] = uList[i].name;     // new 
     230        Utarget[Uindex] = uList[i].target; // new 
     231        Ugoal[Uindex] = uList[i].goal;     // new 
     232        Uindex++;                          // new 
     233 
     234    }       
     235    for (size_t i = 0; i < radioInfo->numObservables; i++){    
    286236        cols[columnIndex] = oList[i].name; 
    287         columnIndex++; 
    288     }    
    289     cols[columnIndex] = "utility"; 
     237        columnIndex++; 
     238    } 
     239    cols[columnIndex] = "TotalWeight";   
    290240 
    291241    myCBR = new CBR(filename, tablename, cols, numberColumns); 
     242 
    292243} 
    293244 
     
    296247CBR_CE::PerformUpdatePerformance() 
    297248{ 
     249 
    298250    /* Receive Set of current Parameters */ 
    299251    char buffer[256]; 
     
    314266    }  
    315267 
     268 
    316269    /* Receive Set of Observables */ 
    317270    memset(buffer, 0, 256); 
     
    329282        ReadMessage(commandSocketFD, buffer); 
    330283        o[i].value = atof(buffer); 
    331     }   
    332  
    333     ReceiveFeedback(o, p); 
     284    } 
     285 
     286 
     287    /* Receive Set of Utilities */ 
     288    memset(buffer, 0, 256); 
     289    ReadMessage(commandSocketFD, buffer); 
     290    uint32_t numUtilities = atoi(buffer); 
     291     
     292    Utility *u = new Utility[numUtilities]; 
     293 
     294    for(size_t i = 0; i < numUtilities; i++) { 
     295        memset(buffer, 0, 256); 
     296        ReadMessage(commandSocketFD, buffer); 
     297        u[i].name = std::string(buffer); 
     298         
     299        memset(buffer, 0, 256); 
     300        ReadMessage(commandSocketFD, buffer); 
     301        u[i].value = atof(buffer); 
     302    } 
     303  
     304    ReceiveFeedback(o, p, u); 
    334305 
    335306    delete [] o; 
    336307    delete [] p; 
     308    delete [] u; 
    337309} 
    338310 
    339311 
    340312void 
    341 CBR_CE::PerformRequestOptimizationService() 
    342 { 
    343    // THIS IS CURRENTLY IN DEMO MODE             
    344  
     313CBR_CE::PerformRequestOptimization() 
     314{ 
    345315    /* Receive Set of Observables */ 
    346     LOG("\nCognitive Engine:: Receiving service name\n"); 
     316    LOG("\nCognitive Engine:: Receiving Observables\n"); 
    347317 
    348318    char buffer[256]; 
    349     memset(buffer, 0, 256); 
    350     ReadMessage(commandSocketFD,buffer); 
    351     LOG("\nCognitive Engine:: Got service name, %s\n", buffer); 
    352  
    353     /* Receive Set of Observables */ 
    354     LOG("\nCognitive Engine:: Receiving Observable Parameters\n"); 
    355  
    356319    memset(buffer, 0, 256); 
    357320    ReadMessage(commandSocketFD,buffer); 
     
    387350        ReadMessage(commandSocketFD, buffer); 
    388351        cp[i].value = atof(buffer); 
    389     }   
    390     LOG("Cognitive Engine:: Processing parameters....\n"); 
    391  
    392     //Parameter *solutionSet; 
    393      
    394     //solutionSet = GetSolution(o,cp); 
    395  
    396     // TODO need to actually do something with the observables here 
    397     
    398     LOG("Cognitive Engine:: Sending Optimal Parameters to Application.\n"); 
    399     char numParametersChar[10]; 
    400     //char solutionValue[50]; 
    401     sprintf(numParametersChar, "%i", radioInfo->numParameters); 
    402     SendMessage(commandSocketFD, numParametersChar); 
    403     for(size_t i = 0; i < radioInfo->numParameters; i++) { 
    404         // TODO What's with all the commented-out code? 
    405         //SendMessage(commandSocketFD, solutionSet[i].name.c_str()); 
    406         SendMessage(commandSocketFD, "test"); 
    407         //memset(solutionValue, 0, 50); 
    408         //sprintf(solutionValue, "%f", solutionSet[i].value); 
    409         //SendMessage(commandSocketFD, solutionValue); 
    410         SendMessage(commandSocketFD, "00"); 
    411     } 
    412  
    413     delete [] o; 
    414     delete [] cp; 
    415  
    416 } 
    417  
    418  
    419 void 
    420 CBR_CE::PerformRequestOptimization() 
    421 { 
    422     /* Receive Set of Observables */ 
    423     LOG("\nCognitive Engine:: Receiving Observable Parameters\n"); 
    424  
    425     char buffer[256]; 
    426     memset(buffer, 0, 256); 
    427     ReadMessage(commandSocketFD,buffer); 
    428     uint32_t numObservables = atoi(buffer); 
    429  
    430     Observable *o = new Observable[numObservables]; 
    431  
    432     for(size_t i = 0; i < numObservables; i++) { 
    433         memset(buffer, 0, 256); 
    434         ReadMessage(commandSocketFD, buffer); 
    435         o[i].name = std::string(buffer); 
    436  
    437         memset(buffer, 0, 256); 
    438         ReadMessage(commandSocketFD, buffer); 
    439         o[i].value = atof(buffer); 
    440     }   
    441  
    442     /* Receive Set of current Parameters */ 
    443     LOG("Cognitive Engine:: Receiving Current Transmission Parameters\n"); 
     352    } 
     353 
     354    /* Receive Set of Utilities */ 
     355    LOG("Cognitive Engine:: Receiving Utilities\n"); 
    444356 
    445357    memset(buffer, 0, 256); 
    446358    ReadMessage(commandSocketFD, buffer); 
    447     uint32_t numCurrentParameters = atoi(buffer); 
    448  
    449     Parameter *cp = new Parameter[numCurrentParameters]; 
    450  
    451     for(size_t i = 0; i < numCurrentParameters; i++) { 
    452         memset(buffer, 0, 256); 
    453         ReadMessage(commandSocketFD, buffer); 
    454         cp[i].name = std::string(buffer); 
    455  
    456         memset(buffer, 0, 256); 
    457         ReadMessage(commandSocketFD, buffer); 
    458         cp[i].value = atof(buffer); 
    459     }   
     359    uint32_t numUtilities = atoi(buffer); 
     360 
     361    Utility *u = new Utility[numUtilities]; 
     362 
     363    for(size_t i = 0; i < numUtilities; i++) { 
     364        memset(buffer, 0, 256); 
     365        ReadMessage(commandSocketFD, buffer); 
     366        u[i].name = std::string(buffer); 
     367 
     368        memset(buffer, 0, 256); 
     369        ReadMessage(commandSocketFD, buffer); 
     370        u[i].value = atof(buffer); 
     371    } 
     372 
     373 
     374 
     375   
    460376    LOG("Cognitive Engine:: Processing parameters....\n"); 
    461377 
    462378    Parameter *solutionSet; 
    463379     
    464     solutionSet = GetSolution(o,cp); 
    465  
    466     // TODO need to actually do something with the observables here 
     380    solutionSet = GetSolution(o,cp,u); 
     381 
     382  
    467383    
    468384    LOG("Cognitive Engine:: Sending Optimal Parameters to Application.\n"); 
     
    480396    delete [] o; 
    481397    delete [] cp; 
    482 } 
    483  
    484  
    485 void 
    486 CBR_CE::PerformQueryComponentType() 
    487 { 
    488     SendComponentType(); 
    489 } 
    490  
    491  
    492 void 
    493 CBR_CE::PerformConnectSML() 
    494 { 
    495     /* This command implies that we are disconnecting from the shell and 
    496      * connecting to a SML component. */ 
    497     char serverName[256]; 
    498     char serverPort[256]; 
    499  
    500     // TODO is this going to end up being too slow? 
    501     memset(serverName, 0, 256); 
    502     memset(serverPort, 0, 256); 
    503  
    504     ReadMessage(commandSocketFD, serverName); 
    505     ReadMessage(commandSocketFD, serverPort); 
    506  
    507     /* Only continue if we are currently connected to a shell. */ 
    508     if(!SML_present) { 
    509         DeregisterComponent(); 
    510  
    511         shutdown(commandSocketFD, 2); 
    512         close(commandSocketFD); 
    513  
    514         ConnectToRemoteComponent(serverName, serverPort, true); 
    515     } 
    516 } 
    517  
    518  
    519 void 
    520 CBR_CE::PerformDisconnectSML() 
    521 { 
    522     /* This command implies that we are disconnecting from the SML and 
    523      * connecting to a shell component. */ 
    524     char serverName[256]; 
    525     char serverPort[256]; 
    526  
    527     // TODO is this going to end up being too slow? 
    528     memset(serverName, 0, 256); 
    529     memset(serverPort, 0, 256); 
    530  
    531     ReadMessage(commandSocketFD, serverName); 
    532     ReadMessage(commandSocketFD, serverPort); 
    533  
    534     /* We only want to do this if we are actually connected to an SML 
    535      * currently. */ 
    536     if(SML_present) { 
    537         DeregisterServices(); 
    538  
    539         shutdown(commandSocketFD, 2); 
    540         close(commandSocketFD); 
    541  
    542         ConnectToRemoteComponent(serverName, serverPort, false); 
    543     } 
     398    delete [] u; 
    544399} 
    545400 
  • vtcross/branches/nikhil/crossmodel1/src/cognitive_engines/CBR_CE/CBR_CE.h

    r545 r554  
    4242        /*! Default constructor. */ 
    4343        CBR_CE() : CognitiveEngine(){}; 
    44  
    4544        /*! Default destructor. */ 
    4645        ~CBR_CE(){}; 
     
    5756                const int32_t numFields, const bool SML); 
    5857 
    59         void RegisterServices(); 
    60         void DeregisterServices(); 
    61  
    6258        /*! \brief Request that the CE optimize a set of parameters.  
    6359         * 
     
    6662         * and active. */ 
    6763        Parameter *GetSolution(Observable *observables, \ 
    68                 Parameter *currentParameters); 
    69         Parameter *GetSolution(Observable *observables, \ 
    70                 Parameter *currentParameters, std::string service); 
     64                Parameter *currentParameters, Utility *utilities); 
    7165 
    7266        /*! \brief Receive feedback from the radio  
     
    8074         * more accurate performance statistics.  
    8175         */ 
    82         void ReceiveFeedback(Observable *observables,Parameter *parameters); 
    83         void ReceiveFeedback(Observable *observables, Parameter *parameters, \ 
    84                 std::string service); 
    85  
     76        void ReceiveFeedback(Observable *observables,Parameter *parameters, Utility *utilities); 
    8677 
    8778        /*! \brief Initialize the CE and prepare it for operation.  
     
    10293         */ 
    10394        void PerformUpdatePerformance(); 
    104         void PerformRequestOptimizationService(); 
    10595        void PerformRequestOptimization(); 
    106         void PerformQueryComponentType(); 
    107         void PerformConnectSML(); 
    108         void PerformDisconnectSML(); 
     96 
    10997        void PerformResetEngineCognitive(); 
    11098        void PerformShutdownEngineCognitive(); 
    11199 
    112100        CBR *myCBR; 
     101 
    113102}; 
    114103 
  • vtcross/branches/nikhil/crossmodel1/src/cognitive_engines/CognitiveEngine.cpp

    r544 r554  
    2525#include <cmath> 
    2626#include <string> 
     27#include <iostream> 
    2728 
    2829#include "vtcross/cognitive_engine.h" 
     
    6667 
    6768    ConnectToRemoteComponent(serverName, serverPort, SML); 
    68 } 
    69  
     69 
     70} 
    7071 
    7172void 
     
    8586    SML_present = SML; 
    8687 
    87     if(SML) { 
    88         LOG("Cognitive Engine connected to SML at %s.\n", serverName); 
     88 
     89// Considering only Shell to work in this project!! 
     90 
     91        LOG("Cognitive Engine connected to shell at %s.\n", serverName); 
    8992 
    9093        RegisterComponent(); 
    9194        ReceiveRadioConfiguration(); 
    9295        ReceiveExperience(); 
    93         RegisterServices(); 
    94     } 
    95     else { 
    96         LOG("Cognitive Engine connected to shell at %s.\n", serverName); 
    97  
    98         RegisterComponent(); 
    99         ReceiveRadioConfiguration(); 
    100         ReceiveExperience(); 
    101     } 
     96 
    10297} 
    10398 
     
    108103    char buffer[256]; 
    109104 
     105    std::cout << "IN WAITFORSIGNAL METHOD" << std::endl; 
     106 
    110107    while(true) { 
    111108        memset(buffer, 0, 256); 
     
    114111 
    115112        if(strcmp(buffer, "update_performance") == 0) { 
    116             PerformUpdatePerformance(); 
     113            PerformUpdatePerformance(); 
    117114        }  
    118         else if(strcmp(buffer, "request_optimization_service") == 0) { 
    119             PerformRequestOptimizationService(); 
    120         } 
    121115        else if(strcmp(buffer, "request_optimization") == 0) { 
    122116            PerformRequestOptimization(); 
    123117        } 
    124         else if(strcmp(buffer, "query_component_type") == 0) { 
    125             PerformQueryComponentType(); 
    126         } 
    127         else if(strcmp(buffer, "connect_sml") == 0) { 
    128             PerformConnectSML(); 
    129         } 
    130         else if(strcmp(buffer, "disconnect_sml") == 0) { 
    131             PerformDisconnectSML(); 
    132         } 
    133118        else if(strcmp(buffer, "reset_engine_cognitive") == 0) { 
    134119            PerformResetEngineCognitive(); 
     
    144129CognitiveEngine::Shutdown() 
    145130{ 
    146     if(SML_present) { 
    147         DeregisterServices(); 
    148131        DeregisterComponent(); 
    149     }  
    150     else { 
     132    // TODO Need to actually kill this process... 
     133} 
     134 
     135 
     136void 
     137CognitiveEngine::Reset() 
     138{ 
     139    LOG("Resetting Cognitive Engine.\n"); 
     140 
    151141        DeregisterComponent(); 
    152     } 
    153     // TODO Need to actually kill this process... 
    154 } 
    155  
    156  
    157 void 
    158 CognitiveEngine::Reset() 
    159 { 
    160     LOG("Resetting Cognitive Engine.\n"); 
    161  
    162     if(SML_present) { 
    163         DeregisterServices(); 
    164         DeregisterComponent(); 
    165     }  
    166     else { 
    167         DeregisterComponent(); 
    168     } 
    169142 
    170143    // TODO This function then needs to re-call "ConnectToRemoteComponent" to 
     
    325298 
    326299    LOG("Cognitive Engine:: Waiting for %i number of entries.\n", numberExp); 
    327   
    328300    SendMessage(commandSocketFD, "receive_exp_ack"); 
     301 
    329302} 
    330303 
     
    338311 
    339312Parameter*  
    340 CognitiveEngine::GetSolution(Observable *observables, Parameter *currentParameters) 
     313CognitiveEngine::GetSolution(Observable *observables, Parameter *currentParameters, Utility *utilities) 
    341314{ 
    342315    LOG("Cognitive Engine:: Generating solution.\n"); 
     
    348321 
    349322 
    350 Parameter*  
    351 CognitiveEngine::GetSolution(Observable *observables, \ 
    352         Parameter *currentParameters, std::string service) 
    353 { 
    354     LOG("Cognitive Engine:: Generating solution for %s service.\n", service.c_str()); 
    355  
    356     LOG("CognitiveEngine:: GetSolution with service not implemented.\n"); 
    357  
    358     return NULL; 
    359 } 
    360  
    361  
    362 void  
    363 CognitiveEngine::ReceiveFeedback(Observable *observables,Parameter *parameters) 
     323void  
     324CognitiveEngine::ReceiveFeedback(Observable *observables,Parameter *parameters, Utility *utilities) 
    364325{ 
    365326    LOG("Cognitive Engine:: Receiving feedback.\n"); 
     
    369330 
    370331 
    371 void  
    372 CognitiveEngine::ReceiveFeedback(Observable *observables, Parameter *parameters, \ 
    373     std::string service) 
    374 { 
    375     LOG("Cognitive Engine:: Receiving feedback.\n"); 
    376  
    377     LOG("CognitiveEngine:: ReceiveFeedback not implemented.\n"); 
    378 } 
    379  
    380  
    381332void 
    382333CognitiveEngine::BuildCognitiveEngine() 
     
    387338 
    388339void  
    389 CognitiveEngine::RegisterServices() 
    390 { 
    391     LOG("Cognitive Engine:: RegisterServices not implemented.\n"); 
    392 } 
    393  
    394  
    395 void  
    396 CognitiveEngine::DeregisterServices() 
    397 { 
    398     LOG("Cognitive Engine:: DeregisterServices not implemented.\n"); 
    399 } 
    400  
    401  
    402 void  
    403340CognitiveEngine::PerformUpdatePerformance() 
    404341{ 
     
    407344 
    408345void 
    409 CognitiveEngine::PerformRequestOptimizationService() 
    410 { 
    411 } 
    412  
    413  
    414 void 
    415346CognitiveEngine::PerformRequestOptimization() 
    416347{ 
     
    419350 
    420351void 
    421 CognitiveEngine::PerformQueryComponentType() 
    422 { 
    423 } 
    424  
    425  
    426 void 
    427 CognitiveEngine::PerformConnectSML() 
    428 { 
    429 } 
    430  
    431  
    432 void 
    433 CognitiveEngine::PerformDisconnectSML() 
    434 { 
    435 } 
    436  
    437  
    438 void 
    439352CognitiveEngine::PerformResetEngineCognitive() 
    440353{ 
  • vtcross/branches/nikhil/crossmodel1/src/include/vtcross/cognitive_engine.h

    r531 r554  
    7474        virtual void DeregisterComponent(); 
    7575 
    76         virtual void RegisterServices(); 
    77         virtual void DeregisterServices(); 
    78  
    7976        /*! \brief Receive radio XML configuration. 
    8077         *  
     
    9794         * and active. */ 
    9895        virtual Parameter *GetSolution(Observable *observables, \ 
    99                 Parameter *currentParameters); 
    100         virtual Parameter *GetSolution(Observable *observables, \ 
    101                 Parameter *currentParameters, std::string service); 
     96                Parameter *currentParameters, Utility *utilities); 
     97 
    10298 
    10399        /*! \brief Receive feedback from the radio  
     
    111107         * more accurate performance statistics.  
    112108         */ 
    113         virtual void ReceiveFeedback(Observable *observables,Parameter *parameters); 
    114         virtual void ReceiveFeedback(Observable *observables, Parameter *parameters, \ 
    115                 std::string service); 
     109        virtual void ReceiveFeedback(Observable *observables,Parameter *parameters, Utility *utilities); 
    116110 
    117111 
     
    133127         */ 
    134128        virtual void PerformUpdatePerformance(); 
    135         virtual void PerformRequestOptimizationService(); 
    136129        virtual void PerformRequestOptimization(); 
    137         virtual void PerformQueryComponentType(); 
    138         virtual void PerformConnectSML(); 
    139         virtual void PerformDisconnectSML(); 
    140130        virtual void PerformResetEngineCognitive(); 
    141131        virtual void PerformShutdownEngineCognitive(); 
  • vtcross/branches/nikhil/crossmodel1/src/include/vtcross/components.h

    r518 r554  
    119119         * Register or deregister services that this engine provides with the 
    120120         * service management layer. */ 
    121         virtual void RegisterServices() = 0; 
    122         virtual void DeregisterServices() = 0; 
     121//        virtual void RegisterServices() = 0; 
     122//        virtual void DeregisterServices() = 0; 
    123123}; 
    124124 
  • vtcross/branches/nikhil/crossmodel1/src/include/vtcross/cross_shell.h

    r537 r554  
    9393        void RegisterCognitiveEngine(int32_t socketFD); 
    9494        void DeregisterCognitiveEngine(int32_t socketFD); 
    95         void RegisterPolicyEngine(int32_t socketFD); 
    96         void DeregisterPolicyEngine(int32_t socketFD); 
    97         void RegisterSML(int32_t socketFD); 
    98         void DeregisterSML(int32_t socketFD); 
     95 
     96 
     97 
     98 
    9999         
    100100        /*! \brief Set the active mission. 
     
    104104         * This command is basically passed through the CRS to the SML. 
    105105         */ 
    106         void SetActiveMission(int32_t socketFD); 
     106 
    107107 
    108108        /* Handle a message that is received from a component. 
  • vtcross/branches/nikhil/crossmodel1/src/include/vtcross/libvtcross.h

    r536 r554  
    3939 * communicating with. Note that this can be a local or remote destination. 
    4040 */ 
     41 
    4142void SetCrossShellLocation(std::string hostname, std::string port); 
    4243 
     44Parameter* GetOptimalParameters(Observable *radioObservables, uint32_t numObservables, Parameter *currentParameters, uint32_t numCurrentParameters, Utility *radioUtilities, uint32_t numUtilities); 
    4345 
    44 /*! \brief  Parses XML configuration file and uses it to configure the radio.  
    45  * 
    46  * This function *must* be called when the radio first starts up, and may be 
    47  * called at any point after that to reconfigure the radio. 
    48  */ 
    49 bool ParseRadioConfiguration(); 
     46bool UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o, uint32_t numObservables, Utility *u, uint32_t numUtilities); 
    5047 
    51  
    52 /*! \brief Lists current radio configuration options loaded from the XML. 
    53  * 
    54  * TODO How are we listing these?  Are we simply returning them to stdout? 
    55  * Logging them? Returning strings?  Need to figure this out... 
    56  */ 
    57 void ListCurrentRadioConfiguration(); 
    58  
    59  
    60 /*! \brief View data from the current status of the radio.  
    61  * 
    62  * This function allows client code to capture radio properties at any certain 
    63  * instant.  Note, however, that these properties could be changing at very 
    64  * rapid rates. There is no guarantee that the return results from these 
    65  * functions will still be valid by the time the client code receives them. 
    66  */ 
    67 Observable* GetRadioObservables(); 
    68 Parameter* GetRadioParameters(); 
    69 Utility* GetRadioUtilities(); 
    70  
    71  
    72 /*! \brief View components currently connected to the radio by id.  
    73  * 
    74  * TODO Should there be another way to list components? If you have 10 cognitive 
    75  * engines, how are you going to know which is which just by id? 
    76  */ 
    77 uint32_t* GetConnectedCognitiveEngines(); 
    78 uint32_t* GetConnectedPolicyEngines(); 
    79 uint32_t* GetConnectedManagementServiceLayers(); 
    80 uint32_t* GetConnectedComponents(); 
    81  
    82  
    83 /*! \brief  Given a certain set of observables, ask the radio to find the  
    84  * optimum radio parameters and return them.  
    85  * 
    86  * TODO I'm a little confused about this function... why would anyone need to 
    87  * use this?  Shouldn't this be internal to the radio operation?  
    88  */ 
    89 Parameter* GetOptimalParameters(Observable *radioObservables, uint32_t numObservables,  
    90                 Parameter *currentParameters, uint32_t numCurrentParameters); 
    91  
    92  
    93 /*! \brief  Update the radio regarding its performance. 
    94  * 
    95  * TODO 
    96  */ 
    97 bool UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o, \ 
    98         uint32_t numObservables); 
    99  
    100 /*! \brief Deactivate/Activate/Disconnect a component by id. 
    101  */ 
    102 bool ActivateComponent(uint32_t id); 
    103 bool DeactivateComponent(uint32_t id); 
    104 bool DisconnectComponent(uint32_t id); 
    105  
    106 /*! \brief Set the active mission of the CROSS radio. 
    107  */ 
    108 uint32_t SetActiveMission(char * activeMission); 
    109  
    110 /*! \brief Shut down the radio. 
    111  * 
    112  * This function will deactivate and disconnect all radio components before 
    113  * finally shutting down the shell and stopping radio operations. 
    114  */ 
    115 bool Shutdown(); 
    116  
    117 /*! \brief Return total number of currently recognized transmission parameters. 
    118  */ 
    119 uint32_t GetNumParameters(); 
    120 uint32_t GetNumObservables(); 
    121 uint32_t GetNumUtilities(); 
    122  
     48uint32_t GetNum(std::string); 
    12349 
    12450#endif 
  • vtcross/branches/nikhil/crossmodel1/src/libvtcross/Makefile.am

    r429 r554  
    1818 
    1919lib_LTLIBRARIES = libvtcross.la 
    20 bin_PROGRAMS = libvtcross_demo libvtcross_demo_sml 
     20bin_PROGRAMS = libvtcross_demo  
    2121 
    2222libvtcross_la_SOURCES = libvtcross.cpp 
     
    2727libvtcross_demo_LDADD = $(CROSS_LA)  
    2828 
    29 libvtcross_demo_sml_SOURCES = libvtcross_demo_sml.cpp 
    30 libvtcross_demo_sml_LDADD = $(CROSS_LA) 
    31  
    3229SUBDIRS = . swig 
  • vtcross/branches/nikhil/crossmodel1/src/libvtcross/libvtcross.cpp

    r536 r554  
    5757// TODO the following three functions all do exactly the same thing.  Why not 
    5858// simply combine them? 
    59 uint32_t 
    60 GetNumObservables() 
    61 { 
    62     char buffer[256]; 
    6359 
    64     uint32_t socketfd = ConnectToShell(); 
    65     SendMessage(socketfd, "get_number_observables"); 
    66      
    67     memset(buffer, 0, 256); 
    68     ReadMessage(socketfd, buffer); 
    69     uint32_t numObservables = atoi(buffer); 
    70      
    71     return numObservables;  
    72 } 
    73  
    74 uint32_t 
    75 GetNumUtilities() 
    76 { 
    77     char buffer[256]; 
    78  
    79     uint32_t socketfd = ConnectToShell(); 
    80     SendMessage(socketfd, "get_number_utilities"); 
    81      
    82     memset(buffer, 0, 256); 
    83     ReadMessage(socketfd, buffer); 
    84     uint32_t numUtilities = atoi(buffer); 
    85      
    86     return numUtilities;  
    87 } 
    88  
    89 uint32_t 
    90 SetActiveMission(char * activeMission) 
    91 { 
    92     char buffer[256]; 
    93      
    94     uint32_t socketfd = ConnectToShell(); 
    95     SendMessage(socketfd, "set_active_mission"); 
    96  
    97     SendMessage(socketfd, activeMission); 
    98  
    99     //memset(buffer, 0, 256); 
    100     //ReadMessage(socketfd, buffer); 
    101  
    102     return 1; 
    103 } 
    104  
    105 uint32_t 
    106 GetNumParameters() 
    107 { 
    108     char buffer[256]; 
    109  
    110     uint32_t socketfd = ConnectToShell(); 
    111     SendMessage(socketfd, "get_number_parameters"); 
    112      
    113     memset(buffer, 0, 256); 
    114     ReadMessage(socketfd, buffer); 
    115     uint32_t numParameters = atoi(buffer); 
    116      
    117     return numParameters;  
    118 } 
    119 // end previous TODO 
    120  
    121 /* Given a certain set of observables, ask the radio to find the optimum radio 
    122  * parameters and return them.  
    123  * 
    124  * TODO I'm a little confused about this function... why would anyone need to 
    125  * use this?  Shouldn't this be internal to the radio operation?  
    126  * 
    127  * TODO this function is returning a pointer to allocated memory, which is fine, 
    128  * but we need to document this and make sure the caller is deallocating the 
    129  * memory when it is done using it. 
    130  */ 
    13160Parameter*  
    132 GetOptimalParameters(Observable *radioObservables, uint32_t numObservables, 
    133         Parameter *currentParameters, uint32_t numCurrentParameters) 
     61GetOptimalParameters(Observable *radioObservables, uint32_t numObservables, Parameter *currentParameters, uint32_t numCurrentParameters, Utility *radioUtilities, uint32_t numUtilities) 
    13462{ 
    13563    char var[50]; 
     
    16391    } 
    16492 
     93    /* Send Utilities */ 
     94    memset(counter, 0, 55); 
     95    sprintf(counter, "%i", numUtilities); 
     96    SendMessage(socketFD, counter); 
     97    for(size_t i = 0; i < numUtilities; i++) { 
     98        SendMessage(socketFD,radioUtilities[i].name.c_str()); 
     99        sprintf(var,"%f",radioUtilities[i].value); 
     100        SendMessage(socketFD,var); 
     101    } 
     102         
     103 
    165104    /* Receive Set of Parameters */ 
    166105    memset(buffer, 0, 256); 
     
    184123 
    185124bool 
    186 UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o, 
    187         uint32_t numObservables) 
     125UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o, uint32_t numObservables, Utility *u, uint32_t numUtilities) 
    188126{ 
    189127    char counter[55]; 
     
    205143     
    206144    // Send Observables 
     145    memset(counter, 0, 55); 
    207146    sprintf(counter, "%i", numObservables); 
    208147    SendMessage(socketFD, counter); 
     
    212151        SendMessage(socketFD, var);     
    213152    } 
     153 
     154    // Send Utilities 
     155    memset(counter, 0, 55); 
     156    sprintf(counter, "%i", numUtilities); 
     157    SendMessage(socketFD, counter); 
     158    for(size_t i = 0; i < numUtilities; i++) { 
     159        SendMessage(socketFD, u[i].name.c_str()); 
     160        sprintf(var, "%f", u[i].value); 
     161        SendMessage(socketFD, var); 
     162    } 
     163         
    214164} 
    215165 
    216 bool ActivateComponent(uint32_t id) { 
    217     return 1; 
    218 } 
    219 bool DeactivateComponent(uint32_t id) { 
    220     return 1; 
    221 }  
    222 bool DisconnectComponent(uint32_t id) { 
    223     return 1; 
    224 } 
     166uint32_t GetNum(string type) 
     167{ 
     168 
     169        char buffer[256]; 
     170        uint32_t socketfd = ConnectToShell(); 
     171         
     172        if (type == "parameters") 
     173                SendMessage(socketfd, "get_number_parameters"); 
     174        else if (type == "utilities") 
     175                SendMessage(socketfd, "get_number_utilities"); 
     176        else if (type == "observables") 
     177                SendMessage(socketfd, "get_number_observables");         
     178        else 
     179                LOG("Type not included, either 'parameters' or 'utilities' or 'observables'");   
     180 
     181        memset(buffer, 0, 256); 
     182        ReadMessage(socketfd, buffer); 
     183        uint32_t number = atoi(buffer); 
     184        return number; 
    225185 
    226186 
    227 /* View components currently connected to the radio by id.  
    228  * 
    229  * TODO Should there be another way to list components? If you have 10 cognitive 
    230  * engines, how are you going to know which is which just by id? 
    231  */ 
    232 uint32_t* GetConnectedCognitiveEngines() { 
    233187} 
    234 uint32_t* GetConnectedPolicyEngines(){ 
    235 } 
    236 uint32_t* GetConnectedManagementServiceLayers(){ 
    237 } 
    238 uint32_t* GetConnectedComponents(){ 
    239 } 
    240  
    241  
    242 /* View data from the current status of the radio.  
    243  * 
    244  * This function allows client code to capture radio properties at any certain 
    245  * instant.  Note, however, that these properties could be changing at very 
    246  * rapid rates. There is no guarantee that the return results from these 
    247  * functions will still be valid by the time the client code receives them. 
    248  */ 
    249 Observable* GetRadioObservables() { 
    250 } 
    251 Parameter* GetRadioParameters(){ 
    252 } 
    253 Utility* GetRadioUtilities(){ 
    254 } 
    255  
    256  
    257 /* Parses VTCROSS XML configuration file and uses it to configure the radio.  
    258  * 
    259  * This function *must* be called when the radio first starts up, and may be 
    260  * called at any point after that to reconfigure the radio. 
    261  */ 
    262 bool ParseRadioConfiguration(){ 
    263 } 
    264  
    265  
    266 /* Lists current radio configuration options loaded from the configuration XML 
    267  * file.  
    268  * 
    269  * TODO How are we listing these?  Are we simply returning them to stdout? 
    270  * Logging them? Returning strings?  Need to figure this out... 
    271  */ 
    272 void ListCurrentRadioConfiguration(){ 
    273 } 
    274  
    275 /* Shut down the radio. 
    276  * 
    277  * This function will deactivate and disconnect all radio components before 
    278  * finally shutting down the shell and stopping radio operations. 
    279  */ 
    280 bool Shutdown(){ 
    281 } 
    282  
  • vtcross/branches/nikhil/crossmodel1/src/libvtcross/libvtcross_demo.cpp

    r535 r554  
    2424#include "vtcross/libvtcross.h" 
    2525#include "vtcross/socketcomm.h" 
     26#include <iostream> 
    2627 
    2728int32_t  
     
    3132    SetCrossShellLocation("localhost", "40000"); 
    3233 
    33     for(size_t i = 0; i < 10; i++) { 
    34         Observable *o = new Observable[2]; 
    35         Parameter *currentParameters = new Parameter[2]; 
     34 
     35// need to include utilties also in system,..  
     36 
     37        Observable *o = new Observable[10]; 
     38        Parameter *currentParameters = new Parameter[10]; 
     39        Utility *u = new Utility[10]; 
    3640        Parameter *p; 
    3741 
     
    4044        uint32_t numUtilities; 
    4145 
    42         o[0].name = "throughput"; 
    43         o[0].value = 150.00; 
    44         o[1].name = "PER"; 
    45         o[1].value = 12.00; 
     46        u[0].name = "throughput"; 
     47//        u[0].value = 15 
     48        u[1].name = "PER"; 
     49//        u[1].value = 12.00; 
     50 
     51        numParameters = GetNum("parameters"); 
     52        numObservables = GetNum("observables"); 
     53        numUtilities = GetNum("utilities"); 
     54 
     55 
     56// This is for loop for performing 10 cycles of updates.. with CBR 
     57    for(size_t i = 0; i < 10; i++) { 
    4658 
    4759        if(i == 0) { 
    4860            currentParameters[0].name = "bandwidth"; 
    49             currentParameters[0].value = 300.0; 
     61            currentParameters[0].value = 200.0; 
    5062            currentParameters[1].name = "tx_power"; 
    5163            currentParameters[1].value = 10.0; 
     
    5769        LOG("Application:: Requesting parameter optimization.\n"); 
    5870 
    59         p = GetOptimalParameters(o,2,currentParameters,2); 
    60         numParameters = GetNumParameters(); 
    61         numObservables = GetNumObservables(); 
    62         numUtilities = GetNumUtilities(); 
     71        p = GetOptimalParameters(o,0,currentParameters,2,u,2); 
    6372 
    6473        LOG("Application:: Received the following parameters.\n"); 
     
    6877        } 
    6978 
    70         /* Try them out! Do they work? */ 
    71         o[0].value = 0.5*p[0].value + .1*p[1].value; 
    72         o[1].value = 15-p[1].value; 
     79///        Try them out! Do they work?  
     80        u[0].value = 2*p[0].value + 1*p[1].value + ((rand()*2.0/RAND_MAX - 1)*10.0); 
     81        u[1].value = 12-p[0].value/50 - p[1].value/3 + ((rand()*2.0/RAND_MAX - 1.0)*0.1); 
    7382 
    74         UpdateParameterPerformance(p, numParameters, o, numObservables);     
    75          
    76         delete [] p;  
    77         delete [] o;  
     83        if (u[1].value < 0)  
     84                u[1].value = 0;  
     85 
     86        LOG("utilities\n %s : %f \n %s : %f \n",u[0].name.c_str(),u[0].value,u[1].name.c_str(),u[1].value);      
     87 
     88        UpdateParameterPerformance(p, numParameters, o, numObservables, u, numUtilities);     
     89 
     90        usleep(1000);         
     91  
    7892    } 
    7993 
  • vtcross/branches/nikhil/crossmodel1/src/shell/CognitiveRadioShell.cpp

    r537 r554  
    183183        } 
    184184    } 
     185 
    185186     
    186187    /* Receive ACK for radio configuration */ 
     
    215216        return false; 
    216217    } 
     218 
    217219    return true; 
    218220} 
     
    252254} 
    253255 
    254  
    255 void 
    256 CognitiveRadioShell::RegisterPolicyEngine(int32_t socketFD) 
    257 { 
    258     LOG("Cognitive Radio Shell:: Received registration from Policy Engine on socket %d.\n", \ 
    259             socketFD); 
    260  
    261     PE_present = true; 
    262 } 
    263  
    264  
    265 void  
    266 CognitiveRadioShell::DeregisterPolicyEngine(int32_t socketFD) 
    267 { 
    268     LOG("Cognitive Radio Shell:: Received deregistration message from Policy Engine.\n"); 
    269  
    270     PE_present = false; 
    271      
    272     SendMessage(socketFD, "deregister_ack"); 
    273     shutdown(socketFD, 2); 
    274     close(socketFD); 
    275     LOG("Cognitive Radio Shell:: Socket %d closed.\n", socketFD); 
    276 } 
    277  
    278  
    279 void 
    280 CognitiveRadioShell::RegisterSML(int32_t socketFD) 
    281 { 
    282     LOG("Cognitive Radio Shell:: Received registration from SML on socket %d.\n", \ 
    283             socketFD); 
    284  
    285     SML_present = true; 
    286 } 
    287  
    288  
    289 void  
    290 CognitiveRadioShell::DeregisterSML(int32_t socketFD) 
    291 { 
    292     LOG("Cognitive Radio Shell:: Received deregistration message from SML.\n"); 
    293  
    294     SML_present = false; 
    295  
    296     SendMessage(socketFD, "deregister_ack"); 
    297     shutdown(socketFD, 2); 
    298     close(socketFD); 
    299     LOG("Cognitive Radio Shell:: Socket %d closed.\n", socketFD); 
    300 } 
    301  
    302 void  
    303 CognitiveRadioShell::SetActiveMission(int32_t socketFD) 
    304 { 
    305     char buffer[256]; 
    306  
    307     LOG("Cognitive Radio Shell:: Received Set Active Mission command from host.\n"); 
    308     
    309     /* Read the name of the active mission to be set from the host. */ 
    310     memset(buffer, 0, 256); 
    311     ReadMessage(commandSocketFD, buffer); 
    312  
    313     /* Send command to SML. */ 
    314     SendMessage(ceSocketFD, "set_active_mission"); 
    315     SendMessage(ceSocketFD, buffer); 
    316  
    317     /* Get ack from SML saying the mission was set properly */ 
    318     memset(buffer, 0, 256); 
    319     ReadMessage(ceSocketFD, buffer); 
    320  
    321     /* Forward ack to host */ 
    322     SendMessage(commandSocketFD, buffer); 
    323 } 
    324256 
    325257void  
     
    415347            } 
    416348 
    417             if(!match_found) {  
    418                 ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
    419                     oList[item_count].name.c_str(), oUtilName); 
    420             } 
    421             else 
    422                 match_found = false;     
     349   
     350//////////////////WE are not looking for relationship between them..             
     351//            if(!match_found) {  
     352//                ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
     353//                    oList[item_count].name.c_str(), oUtilName); 
     354//            } 
     355//            else 
     356//                match_found = false;     
    423357        } 
    424358        oList[item_count].numAffects = affect_count;  
     
    476410            } 
    477411 
    478             if(!match_found) { 
    479                 ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
    480                     pList[item_count].name.c_str(), pUtilName); 
    481             } 
    482  
    483             match_found = false;     
     412//            if(!match_found) { 
     413//                ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
     414//                    pList[item_count].name.c_str(), pUtilName); 
     415//            } 
     416 
     417//            match_found = false;     
    484418        } 
    485419 
     
    536470        cp[i].value = atof(buffer); 
    537471    } 
     472////////////// NEW    INCLUSION /////////////////// 
     473 
     474/* Receive Set of Utilities */ 
     475    memset(buffer, 0, 256); 
     476    ReadMessage(commandSocketFD,buffer); 
     477    uint32_t numUtilities = atoi(buffer); 
     478 
     479    LOG("Cognitive Radio Shell:: Attempting to get %i utilities.\n",numUtilities); 
     480    Utility *u = new Utility[numUtilities]; 
     481 
     482    for (size_t i = 0;i < numUtilities; i++){ 
     483        memset(buffer, 0, 256); 
     484        ReadMessage(commandSocketFD,buffer); 
     485        u[i].name = std::string(buffer); 
     486 
     487        memset(buffer, 0, 256); 
     488        ReadMessage(commandSocketFD,buffer); 
     489        u[i].value = atof(buffer); 
     490    } 
     491 
     492/////////////////////////////////////// 
    538493 
    539494    /* Send to Cognitive Engine  
     
    541496     * to send this information 
    542497     */ 
     498    SendMessage(ceSocketFD,"request_optimization"); 
     499 
    543500    LOG("Cognitive Radio Shell:: Passing on observables.\n"); 
    544     SendMessage(ceSocketFD,"request_optimization"); 
    545501    sprintf(counter,"%i",numObservables); 
    546502    SendMessage(ceSocketFD,counter); 
     
    559515        SendMessage(ceSocketFD,var);  
    560516    } 
     517 
     518/////////////  NEW  //////////////////////////////////////////////////////// 
     519    LOG("Cognitive Radio Shell:: Passing on utilities.\n"); 
     520    sprintf(counter,"%i",numUtilities); 
     521    SendMessage(ceSocketFD,counter); 
     522    for(size_t i = 0; i < numUtilities; i++) { 
     523        SendMessage(ceSocketFD,u[i].name.c_str()); 
     524        sprintf(var,"%f",u[i].value); 
     525        SendMessage(ceSocketFD,var); 
     526    } 
     527 
     528////////////// END of NEW ///////////////////////////////////// 
    561529 
    562530    /* Receive Set of Parameters */ 
     
    591559 
    592560    delete [] o; 
     561    delete [] u; 
    593562    delete [] p; 
    594563} 
     
    634603        ReadMessage(commandSocketFD, buffer); 
    635604        o[i].value = atof(buffer); 
     605    } 
     606 
     607    /* Receive Set of Utilities */ 
     608    memset(buffer, 0, 256); 
     609    ReadMessage(commandSocketFD, buffer); 
     610    uint32_t numUtilities = atoi(buffer); 
     611 
     612    Utility *u = new Utility[numUtilities]; 
     613 
     614    for(size_t i = 0; i < numUtilities; i++) { 
     615        memset(buffer, 0, 256); 
     616        ReadMessage(commandSocketFD, buffer); 
     617        u[i].name = std::string(buffer); 
     618 
     619        memset(buffer, 0, 256); 
     620        ReadMessage(commandSocketFD, buffer); 
     621        u[i].value = atof(buffer); 
    636622    } 
    637623 
     
    650636     
    651637    /* Send Observables */ 
     638    memset(counter, 0, 55); 
    652639    sprintf(counter, "%i", numObservables); 
    653640    SendMessage(ceSocketFD, counter); 
     
    658645    }    
    659646 
     647     /* Send Utilities */ 
     648     memset(counter, 0, 55); 
     649     sprintf(counter, "%i", numUtilities); 
     650     SendMessage(ceSocketFD,counter); 
     651     for(size_t i = 0; i < numUtilities; i++) { 
     652        SendMessage(ceSocketFD, u[i].name.c_str()); 
     653        sprintf(var, "%f", u[i].value); 
     654        SendMessage(ceSocketFD, var); 
     655     } 
     656 
     657 
    660658    delete [] p; 
    661659    delete [] o; 
     660    delete [] u; 
    662661} 
    663662 
     
    678677    } else if(strcmp(buffer, "deregister_engine_cognitive") == 0) { 
    679678        DeregisterCognitiveEngine(socketFD); 
    680     } else if(strcmp(buffer, "register_engine_policy") == 0) { 
    681         RegisterPolicyEngine(socketFD); 
    682     } else if(strcmp(buffer, "deregister_engine_policy") == 0) { 
    683         DeregisterPolicyEngine(socketFD); 
    684     } else if(strcmp(buffer, "register_sml") == 0) { 
    685         RegisterSML(socketFD); 
    686     } else if(strcmp(buffer, "deregister_sml") == 0) { 
    687         DeregisterSML(socketFD); 
    688679    } else if(strcmp(buffer, "update_performance") == 0) { 
    689680        UpdateParameterPerformance(socketFD); 
     
    703694        /* Receive optimization request and current environment */ 
    704695        GetOptimalParameters(socketFD);   
    705     } else if(strcmp(buffer, "set_active_mission") == 0) { 
    706         SetActiveMission(socketFD);   
    707     } else if(strcmp(buffer, "request_optimization_service") == 0) { 
    708         /* Receive optimization request and current environment */ 
    709         //GetOptimalParametersService(socketFD);   
    710     } 
     696    }  
    711697 
    712698    return ret; 
  • vtcross/branches/nikhil/crossmodel1/src/shell/configs/demo.xml

    r375 r554  
    88    <!-- utilities : QoS metrics --> 
    99    <utilities> 
    10         <utility name="tp" units="kbps" goal="max" target="125000" />  
    11         <utility name="packet_error" units="none" goal="min" target="1" /> 
     10        <utility name="throughput" units="kbps" goal="max" target="517" />  
     11        <utility name="PER" units="none" goal="min" target="1.2" /> 
    1212    </utilities> 
    1313 
    1414    <!-- radio parameters --> 
    1515    <parameters> 
    16         <parameter name="bandwidth" units="hz" min="1" max="255" step="1"> 
    17             <affect utility="tp" relationship="improve" /> 
     16        <parameter name="bandwidth" units="hz" min="1" max="255" step="10"> 
    1817        </parameter> 
    1918        <parameter name="tx_power" units="dBm" min="1" max="255" step="1"> 
    20             <affect utility="packet_error" relationship="improve"/> 
    2119        </parameter> 
    2220    </parameters> 
     
    2422    <!-- link/channel observations --> 
    2523    <observables> 
    26         <observable name="throughput"> 
    27             <affect utility="tp" relationship="improve" /> 
    28         </observable> 
    29         <observable name="PER"> 
    30             <affect utility="packet_error" relationship="improve" /> 
    31         </observable> 
    3224    </observables> 
    3325</engine>