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. It defines its own CBR backend, as well as |
---|
19 | * its own CognitiveEngine, both of which inherit from the example classes. |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | #ifndef OSSIE_CE_H |
---|
24 | #define OSSIE_CE_H |
---|
25 | |
---|
26 | #include <cmath> |
---|
27 | #include <cstdlib> |
---|
28 | #include <cstring> |
---|
29 | #include <stdint.h> |
---|
30 | #include <string> |
---|
31 | |
---|
32 | #include "vtcross/cbr.h" |
---|
33 | #include "vtcross/cognitive_engine.h" |
---|
34 | #include "vtcross/common.h" |
---|
35 | #include "vtcross/containers.h" |
---|
36 | #include "vtcross/debug.h" |
---|
37 | #include "vtcross/error.h" |
---|
38 | #include "vtcross/socketcomm.h" |
---|
39 | |
---|
40 | |
---|
41 | #define TXPOWER 1 |
---|
42 | #define BER_ENV 1 |
---|
43 | #define BER_OBJ 1 |
---|
44 | #define DECREMENTSCALE 5 |
---|
45 | #define INCREMENTSCALE 5 |
---|
46 | #define EVF 20 |
---|
47 | |
---|
48 | |
---|
49 | /* ossieCBR Class |
---|
50 | * |
---|
51 | * Derives from the default VTCROSS CBR class to add the following functionality |
---|
52 | * necessary for the OSSIE demo: |
---|
53 | * |
---|
54 | * TODO |
---|
55 | */ |
---|
56 | class ossieCBR : public CBR |
---|
57 | { |
---|
58 | public: |
---|
59 | ossieCBR(); |
---|
60 | |
---|
61 | ossieCBR(std::string _filename, std::string _tablename, std::string _cols[], uint32_t _len); |
---|
62 | |
---|
63 | ~ossieCBR(){}; |
---|
64 | |
---|
65 | int32_t Update(std::string _where[], std::string _set[], float *_wherevals, float *_setvals, \ |
---|
66 | unsigned int _wherelen, unsigned int _setlen); |
---|
67 | |
---|
68 | int32_t Search(std::string _names[], int32_t *_ops, float *_vals, uint32_t _n, \ |
---|
69 | float *_retvals, int32_t evf); |
---|
70 | }; |
---|
71 | |
---|
72 | |
---|
73 | class OSSIE_CE : public CognitiveEngine |
---|
74 | { |
---|
75 | public: |
---|
76 | /*! Default constructor. */ |
---|
77 | OSSIE_CE() : CognitiveEngine(){}; |
---|
78 | |
---|
79 | /*! Default destructor. */ |
---|
80 | ~OSSIE_CE(); |
---|
81 | |
---|
82 | /*! \brief Preferred constructor. |
---|
83 | * |
---|
84 | * Overloaded constructor that creates a cognitive engine object and |
---|
85 | * connects it to either the shell or an SML, depening on the SML bool. |
---|
86 | * |
---|
87 | * The 'numFields' parameter sets how large the parameter, observable, |
---|
88 | * and utility arrays should be upon instantiation. |
---|
89 | */ |
---|
90 | OSSIE_CE(const char* serverName, const char* serverPort, \ |
---|
91 | const int32_t numFields, const bool SML); |
---|
92 | |
---|
93 | void RegisterServices(); |
---|
94 | void DeregisterServices(); |
---|
95 | |
---|
96 | /*! \brief Request that the CE optimize a set of parameters. |
---|
97 | * |
---|
98 | * Find the most optimal set of transmission parameters given certain |
---|
99 | * observables and possibly a service if the SML component is present |
---|
100 | * and active. */ |
---|
101 | Parameter *GetSolution(Observable *observables, \ |
---|
102 | Parameter *currentParameters); |
---|
103 | Parameter *GetSolution(Observable *observables, \ |
---|
104 | Parameter *currentParameters, std::string service); |
---|
105 | |
---|
106 | /*! \brief Receive feedback from the radio |
---|
107 | * |
---|
108 | * Receive a feedback from the radio regarding the performance of a |
---|
109 | * certain set of parameters, possibly associated with a service. |
---|
110 | * |
---|
111 | * Feedback is a single set of performance statistics that is achieved |
---|
112 | * corresponding to a specific set of transmission parameters. Feedback |
---|
113 | * helps a Cognitive Engine make better future decisions based upon |
---|
114 | * more accurate performance statistics. |
---|
115 | */ |
---|
116 | void ReceiveFeedback(Observable *observables,Parameter *parameters); |
---|
117 | void ReceiveFeedback(Observable *observables, Parameter *parameters, \ |
---|
118 | std::string service); |
---|
119 | |
---|
120 | |
---|
121 | /*! \brief Initialize the CE and prepare it for operation. |
---|
122 | * |
---|
123 | * BuildCognitiveEngine performs the CE implementation specific work |
---|
124 | * that defines the internals of a CE. For example, a CBR CE engine |
---|
125 | * would build the case-base reasoner or create the database, a neural |
---|
126 | * network based CE may perform the initial training, a GA based CE |
---|
127 | * may build the chromosome structure. |
---|
128 | */ |
---|
129 | void BuildCognitiveEngine(); |
---|
130 | |
---|
131 | /*! \brief Each of these functions responds to a specific command. |
---|
132 | * |
---|
133 | * These functions are left principally un-implemented. It is the duty |
---|
134 | * of child classes to implement these functions, as they define the |
---|
135 | * cognitive engine's functionality. |
---|
136 | */ |
---|
137 | void PerformUpdatePerformance(); |
---|
138 | void PerformRequestOptimizationService(); |
---|
139 | void PerformRequestOptimization(); |
---|
140 | void PerformQueryComponentType(); |
---|
141 | void PerformConnectSML(); |
---|
142 | void PerformDisconnectSML(); |
---|
143 | void PerformResetEngineCognitive(); |
---|
144 | void PerformShutdownEngineCognitive(); |
---|
145 | |
---|
146 | ossieCBR *myCBR; |
---|
147 | }; |
---|
148 | |
---|
149 | |
---|
150 | #endif |
---|