Changeset 545

Show
Ignore:
Timestamp:
03/04/10 12:21:27 (14 years ago)
Author:
bhilburn
Message:

Updated all cognitive engine examples to use new CBR structure.

Location:
vtcross/trunk/src/cognitive_engines
Files:
3 added
9 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/cognitive_engines/CBR_CE/CBR_CE.cpp

    r534 r545  
    1919 */ 
    2020 
    21 #include <cstdlib> 
    22 #include <cstring> 
    23 #include <stdint.h> 
    24 #include <cmath> 
    25 #include <string> 
    26  
    27 #include "vtcross/cbr.h" 
    28 #include "vtcross/cognitive_engine.h" 
    29 #include "vtcross/common.h" 
    30 #include "vtcross/containers.h" 
    31 #include "vtcross/debug.h" 
    32 #include "vtcross/error.h" 
    33 #include "vtcross/socketcomm.h" 
     21#include "CBR_CE.h" 
    3422 
    3523 
     
    3725 
    3826 
    39 class CBR_CE : public CognitiveEngine 
    40 { 
    41     public: 
    42         /*! Default constructor. */ 
    43         CBR_CE() : CognitiveEngine(){}; 
    44  
    45         /*! Default destructor. */ 
    46         ~CBR_CE(){}; 
    47  
    48         /*! \brief Preferred constructor. 
    49          * 
    50          * Overloaded constructor that creates a cognitive engine object and 
    51          * connects it to either the shell or an SML, depening on the SML bool. 
    52          * 
    53          * The 'numFields' parameter sets how large the parameter, observable, 
    54          * and utility arrays should be upon instantiation. 
    55          */ 
    56         CBR_CE(const char* serverName, const char* serverPort, \ 
    57                 const int32_t numFields, const bool SML) \ 
    58             : CognitiveEngine(serverName, serverPort, numFields, SML){} 
    59  
    60  
    61         void RegisterServices(); 
    62         void DeregisterServices(); 
    63  
    64         /*! \brief Request that the CE optimize a set of parameters.  
    65          * 
    66          * Find the most optimal set of transmission parameters given certain 
    67          * observables and possibly a service if the SML component is present 
    68          * and active. */ 
    69         Parameter *GetSolution(Observable *observables, \ 
    70                 Parameter *currentParameters); 
    71         Parameter *GetSolution(Observable *observables, \ 
    72                 Parameter *currentParameters, std::string service); 
    73  
    74         /*! \brief Receive feedback from the radio  
    75          * 
    76          * Receive a feedback from the radio regarding the performance of a 
    77          * certain set of parameters, possibly associated with a service. 
    78          * 
    79          * Feedback is a single set of performance statistics that is achieved 
    80          * corresponding to a specific set of transmission parameters.  Feedback 
    81          * helps a Cognitive Engine make better future decisions based upon  
    82          * more accurate performance statistics.  
    83          */ 
    84         void ReceiveFeedback(Observable *observables,Parameter *parameters); 
    85         void ReceiveFeedback(Observable *observables, Parameter *parameters, \ 
    86                 std::string service); 
    87  
    88  
    89         /*! \brief Initialize the CE and prepare it for operation.  
    90          * 
    91          * BuildCognitiveEngine performs the CE implementation specific work 
    92          * that defines the internals of a CE.  For example, a CBR CE engine 
    93          * would build the case-base reasoner or create the database, a neural 
    94          * network based CE may perform the initial training, a GA based CE 
    95          * may build the chromosome structure. 
    96          */ 
    97         void BuildCognitiveEngine(); 
    98  
    99         /*! \brief Each of these functions responds to a specific command. 
    100          * 
    101          * These functions are left principally un-implemented. It is the duty 
    102          * of child classes to implement these functions, as they define the 
    103          * cognitive engine's functionality. 
    104          */ 
    105         void PerformUpdatePerformance(); 
    106         void PerformRequestOptimizationService(); 
    107         void PerformRequestOptimization(); 
    108         void PerformQueryComponentType(); 
    109         void PerformConnectSML(); 
    110         void PerformDisconnectSML(); 
    111         void PerformResetEngineCognitive(); 
    112         void PerformShutdownEngineCognitive(); 
    113  
    114         CBR *myCBR; 
    115 }; 
     27CBR_CE::CBR_CE(const char* serverName, const char* serverPort, \ 
     28        const int32_t numFields, const bool SML) \ 
     29    : CognitiveEngine(serverName, serverPort, numFields, SML) 
     30{ 
     31    BuildCognitiveEngine(); 
     32} 
    11633 
    11734 
  • vtcross/trunk/src/cognitive_engines/CBR_CE/Makefile.am

    r532 r545  
    2222 
    2323cbr_demo_SOURCES = CBR_CE.cpp cbr_demo.cpp 
    24 cbr_demo_DEPENDENCIES = ../libce.a 
    25 cbr_demo_LDADD = -lsqlite3 ../libce.a $(CROSS_SOCKETCOMM_LA)  
     24cbr_demo_DEPENDENCIES = ../libce.a ../libcbr.a 
     25cbr_demo_LDADD = -lsqlite3 ../libce.a ../libcbr.a  $(CROSS_SOCKETCOMM_LA)  
    2626 
  • vtcross/trunk/src/cognitive_engines/CBR_CE/cbr_demo.cpp

    r532 r545  
    2727#include <stdint.h> 
    2828 
    29 #include "vtcross/cognitive_engine.h" 
    30 #include "vtcross/common.h" 
    31 #include "vtcross/containers.h" 
     29 
     30#include "CBR_CE.h" 
    3231#include "vtcross/debug.h" 
    3332#include "vtcross/error.h" 
    34 #include "vtcross/socketcomm.h" 
    3533 
    3634 
     
    4139       ERROR(1, "Usage: %s hostname port\n", argv[0]); 
    4240     
    43     CognitiveEngine cognitiveEngine(argv[1], argv[2], 10, false); 
     41    CBR_CE cognitiveEngine(argv[1], argv[2], 10, false); 
    4442 
    4543    LOG("Waiting for signal...\n"); 
  • vtcross/trunk/src/cognitive_engines/DSA_CE/DSA_CognitiveEngine.cpp

    r533 r545  
    1919 */ 
    2020 
    21 #include <cstdlib> 
    22 #include <cstring> 
    23 #include <stdint.h> 
    24 #include <cmath> 
    25 #include <string> 
    26  
    27 #include "vtcross/cbr.h" 
    28 #include "vtcross/cognitive_engine.h" 
    29 #include "vtcross/common.h" 
    30 #include "vtcross/components.h" 
    31 #include "vtcross/containers.h" 
    32 #include "vtcross/debug.h" 
    33 #include "vtcross/error.h" 
    34 #include "vtcross/socketcomm.h" 
    35  
    36  
    37 #define INTERFERENCE 0 
    38  
    39 #define CHANNEL 1 
    40  
    41 #define ENERGY 0 
    42 #define COMMUNICATION_TIME 1 
    43  
    44 #define UTILITY 4 
    45  
    46 class DSA_CE : public CognitiveEngine 
    47 { 
    48     public: 
    49         /*! Default constructor. */ 
    50         DSA_CE(); 
    51  
    52         /*! Default destructor. */ 
    53         ~DSA_CE(); 
    54  
    55         /*! \brief Preferred constructor. 
    56          * 
    57          * Overloaded constructor that creates a cognitive engine object and 
    58          * connects it to either the shell or an SML, depening on the SML bool. 
    59          * 
    60          * The 'numFields' parameter sets how large the parameter, observable, 
    61          * and utility arrays should be upon instantiation. 
    62          */ 
    63         DSA_CE(const char* serverName, const char* serverPort, \ 
    64                 const int32_t numFields, const bool SML); 
    65  
    66         void RegisterServices(); 
    67         void DeregisterServices(); 
    68  
    69         /*! \brief Request that the CE optimize a set of parameters.  
    70          * 
    71          * Find the most optimal set of transmission parameters given certain 
    72          * observables and possibly a service if the SML component is present 
    73          * and active. */ 
    74         Parameter *GetSolution(Observable *observables, \ 
    75                 Parameter *currentParameters); 
    76         Parameter *GetSolution(Observable *observables, \ 
    77                 Parameter *currentParameters, std::string service); 
    78  
    79         /*! \brief Receive feedback from the radio  
    80          * 
    81          * Receive a feedback from the radio regarding the performance of a 
    82          * certain set of parameters, possibly associated with a service. 
    83          * 
    84          * Feedback is a single set of performance statistics that is achieved 
    85          * corresponding to a specific set of transmission parameters.  Feedback 
    86          * helps a Cognitive Engine make better future decisions based upon  
    87          * more accurate performance statistics.  
    88          */ 
    89         void ReceiveFeedback(Observable *observables,Parameter *parameters); 
    90         void ReceiveFeedback(Observable *observables, Parameter *parameters, \ 
    91                 std::string service); 
    92  
    93  
    94         /*! \brief Initialize the CE and prepare it for operation.  
    95          * 
    96          * BuildCognitiveEngine performs the CE implementation specific work 
    97          * that defines the internals of a CE.  For example, a CBR CE engine 
    98          * would build the case-base reasoner or create the database, a neural 
    99          * network based CE may perform the initial training, a GA based CE 
    100          * may build the chromosome structure. 
    101          */ 
    102         void BuildCognitiveEngine(); 
    103  
    104         /*! \brief Each of these functions responds to a specific command. 
    105          * 
    106          * These functions are left principally un-implemented. It is the duty 
    107          * of child classes to implement these functions, as they define the 
    108          * cognitive engine's functionality. 
    109          */ 
    110         void PerformUpdatePerformance(); 
    111         void PerformRequestOptimizationService(); 
    112         void PerformRequestOptimization(); 
    113         void PerformQueryComponentType(); 
    114         void PerformConnectSML(); 
    115         void PerformDisconnectSML(); 
    116         void PerformResetEngineCognitive(); 
    117         void PerformShutdownEngineCognitive(); 
    118  
    119         CBR *myCBR; 
    120 }; 
     21#include "DSA_CognitiveEngine.h" 
     22 
     23 
     24using namespace std; 
     25 
    12126 
    12227DSA_CE::DSA_CE() 
     
    14651    LOG("Creating Cognitive Engine.\n"); 
    14752    srand ( time(NULL) ); 
     53 
     54    BuildCognitiveEngine(); 
    14855} 
    14956 
  • vtcross/trunk/src/cognitive_engines/DSA_CE/DSA_Demo.cpp

    r533 r545  
    2727#include <stdint.h> 
    2828 
    29 #include "vtcross/cognitive_engine.h" 
    30 #include "vtcross/common.h" 
    31 #include "vtcross/containers.h" 
     29#include "DSA_CognitiveEngine.h" 
    3230#include "vtcross/debug.h" 
    3331#include "vtcross/error.h" 
    34 #include "vtcross/socketcomm.h" 
    3532 
    3633 
     
    4138       ERROR(1, "Usage: %s hostname port\n", argv[0]); 
    4239     
    43     CognitiveEngine cognitiveEngine(argv[1], argv[2], 10, false); 
     40    DSA_CE cognitiveEngine(argv[1], argv[2], 10, false); 
    4441 
    4542    LOG("Waiting for signal...\n"); 
  • vtcross/trunk/src/cognitive_engines/DSA_CE/Makefile.am

    r533 r545  
    2222 
    2323DSA_Demo_SOURCES = DSA_CognitiveEngine.cpp DSA_Demo.cpp 
    24 DSA_Demo_DEPENDENCIES = ../libce.a 
    25 DSA_Demo_LDADD = -lsqlite3 ../libce.a $(CROSS_SOCKETCOMM_LA)  
     24DSA_Demo_DEPENDENCIES = ../libce.a ../libcbr.a 
     25DSA_Demo_LDADD = -lsqlite3 ../libce.a ../libcbr.a $(CROSS_SOCKETCOMM_LA)  
    2626 
  • vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/Makefile.am

    r534 r545  
    2222 
    2323OSSIE_Demo_SOURCES = OSSIE_CE.cpp OSSIE_Demo.cpp 
    24 OSSIE_Demo_DEPENDENCIES = ../libce.a 
    25 OSSIE_Demo_LDADD = -lsqlite3 ../libce.a $(CROSS_SOCKETCOMM_LA)  
     24OSSIE_Demo_DEPENDENCIES = ../libce.a ../libcbr.a 
     25OSSIE_Demo_LDADD = -lsqlite3 ../libce.a ../libcbr.a $(CROSS_SOCKETCOMM_LA)  
    2626 
  • vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_CE.cpp

    r534 r545  
    1 /* Virginia Tech Cognitive Radio Open Source Systems 
    2  * Virginia Tech, 2009 
    3  * 
    4  * LICENSE INFORMATION GOES HERE 
     1/* 
     2 Copyright 2009 Virginia Polytechnic Institute and State University   
     3 
     4 Licensed under the Apache License, Version 2.0 (the "License");  
     5 you may not use this file except in compliance with the License.  
     6 You may obtain a copy of the License at  
     7  
     8 http://www.apache.org/licenses/LICENSE-2.0  
     9 
     10 Unless required by applicable law or agreed to in writing, software  
     11 distributed under the License is distributed on an "AS IS" BASIS,  
     12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
     13 See the License for the specific language governing permissions and  
     14 limitations under the License.  
     15*/ 
     16 
     17/*! This CE was written to extend the functionality of a basic CBR-based CE for 
     18 * use with the OSSIE demonstration. This file contains the implementation for 
     19 * both the OSSIE CBR as well as the OSSIE Cognitive Engine. 
    520 */ 
    621 
    7 /*! This CE was written to extend the functionality of a basic CBR-based CE for 
    8  * use with the OSSIE demonstration. 
    9  */ 
    10  
    11  
    12 #include <cmath> 
    13 #include <cstdlib> 
    14 #include <cstring> 
    15 #include <stdint.h> 
    16 #include <string> 
    17  
    18 #include "vtcross/cbr.h" 
    19 #include "vtcross/cognitive_engine.h" 
    20 #include "vtcross/common.h" 
    21 #include "vtcross/containers.h" 
    22 #include "vtcross/debug.h" 
    23 #include "vtcross/error.h" 
    24 #include "vtcross/socketcomm.h" 
    25  
    26  
    27 #define TXPOWER 1 
    28 #define BER_ENV 1 
    29 #define BER_OBJ 1 
    30  
    31 #define DECREMENTSCALE 5  
    32 #define INCREMENTSCALE 5  
    33  
    34 #define EVF 20 
    35  
    36  
    37 /* ossieCBR Class  
    38  * 
    39  * Derives from the default VTCROSS CBR class to add the following functionality 
    40  * necessary for the OSSIE demo: 
    41  * 
    42  * TODO 
    43  */ 
    44 class ossieCBR : public CBR 
    45 { 
    46     public: 
    47         ossieCBR(); 
    48  
    49         ossieCBR(string _filename, string _tablename, string _cols[], uint32_t _len); 
    50  
    51         ~ossieCBR(){}; 
    52  
    53         int32_t Update(string _where[], string _set[], float *_wherevals, float *_setvals, \ 
    54                 unsigned int _wherelen, unsigned int _setlen); 
    55  
    56         int32_t Search(string _names[], int32_t *_ops, float *_vals, uint32_t _n, \ 
    57                 float *_retvals, int32_t evf); 
    58 }; 
     22 
     23#include "OSSIE_CE.h" 
     24 
     25 
     26using namespace std; 
    5927 
    6028 
     
    166134 
    167135 
    168 class OSSIE_CE : public CognitiveEngine 
    169 { 
    170     public: 
    171         /*! Default constructor. */ 
    172         OSSIE_CE() : CognitiveEngine(){}; 
    173  
    174         /*! Default destructor. */ 
    175         ~OSSIE_CE(); 
    176  
    177         /*! \brief Preferred constructor. 
    178          * 
    179          * Overloaded constructor that creates a cognitive engine object and 
    180          * connects it to either the shell or an SML, depening on the SML bool. 
    181          * 
    182          * The 'numFields' parameter sets how large the parameter, observable, 
    183          * and utility arrays should be upon instantiation. 
    184          */ 
    185         OSSIE_CE(const char* serverName, const char* serverPort, \ 
    186                 const int32_t numFields, const bool SML) \ 
    187             : CognitiveEngine(serverName, serverPort, numFields, SML){} 
    188  
    189  
    190         void RegisterServices(); 
    191         void DeregisterServices(); 
    192  
    193         /*! \brief Request that the CE optimize a set of parameters.  
    194          * 
    195          * Find the most optimal set of transmission parameters given certain 
    196          * observables and possibly a service if the SML component is present 
    197          * and active. */ 
    198         Parameter *GetSolution(Observable *observables, \ 
    199                 Parameter *currentParameters); 
    200         Parameter *GetSolution(Observable *observables, \ 
    201                 Parameter *currentParameters, std::string service); 
    202  
    203         /*! \brief Receive feedback from the radio  
    204          * 
    205          * Receive a feedback from the radio regarding the performance of a 
    206          * certain set of parameters, possibly associated with a service. 
    207          * 
    208          * Feedback is a single set of performance statistics that is achieved 
    209          * corresponding to a specific set of transmission parameters.  Feedback 
    210          * helps a Cognitive Engine make better future decisions based upon  
    211          * more accurate performance statistics.  
    212          */ 
    213         void ReceiveFeedback(Observable *observables,Parameter *parameters); 
    214         void ReceiveFeedback(Observable *observables, Parameter *parameters, \ 
    215                 std::string service); 
    216  
    217  
    218         /*! \brief Initialize the CE and prepare it for operation.  
    219          * 
    220          * BuildCognitiveEngine performs the CE implementation specific work 
    221          * that defines the internals of a CE.  For example, a CBR CE engine 
    222          * would build the case-base reasoner or create the database, a neural 
    223          * network based CE may perform the initial training, a GA based CE 
    224          * may build the chromosome structure. 
    225          */ 
    226         void BuildCognitiveEngine(); 
    227  
    228         /*! \brief Each of these functions responds to a specific command. 
    229          * 
    230          * These functions are left principally un-implemented. It is the duty 
    231          * of child classes to implement these functions, as they define the 
    232          * cognitive engine's functionality. 
    233          */ 
    234         void PerformUpdatePerformance(); 
    235         void PerformRequestOptimizationService(); 
    236         void PerformRequestOptimization(); 
    237         void PerformQueryComponentType(); 
    238         void PerformConnectSML(); 
    239         void PerformDisconnectSML(); 
    240         void PerformResetEngineCognitive(); 
    241         void PerformShutdownEngineCognitive(); 
    242  
    243         ossieCBR *myCBR; 
    244 }; 
     136OSSIE_CE::OSSIE_CE(const char* serverName, const char* serverPort, \ 
     137        const int32_t numFields, const bool SML) \ 
     138    : CognitiveEngine(serverName, serverPort, numFields, SML) 
     139{ 
     140    BuildCognitiveEngine(); 
     141} 
    245142 
    246143 
  • vtcross/trunk/src/cognitive_engines/OSSIE_DEMO_CE/OSSIE_Demo.cpp

    r534 r545  
    1717#include <stdint.h> 
    1818 
    19 #include "vtcross/cognitive_engine.h" 
    20 #include "vtcross/common.h" 
    21 #include "vtcross/containers.h" 
     19#include "OSSIE_CE.h" 
    2220#include "vtcross/debug.h" 
    2321#include "vtcross/error.h" 
    24 #include "vtcross/socketcomm.h" 
    2522 
    2623 
     
    3128       ERROR(1, "Usage: %s hostname port\n", argv[0]); 
    3229     
    33     CognitiveEngine cognitiveEngine(argv[1], argv[2], 10, false); 
     30    OSSIE_CE cognitiveEngine(argv[1], argv[2], 10, false); 
    3431 
    3532    LOG("Waiting for signal...\n");