[532] | 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 file provides a default implementation for a case-based-reasoning based |
---|
| 18 | * cognitive engine. |
---|
| 19 | */ |
---|
| 20 | |
---|
[545] | 21 | #include "CBR_CE.h" |
---|
[532] | 22 | |
---|
| 23 | |
---|
| 24 | using namespace std; |
---|
| 25 | |
---|
| 26 | |
---|
[545] | 27 | CBR_CE::CBR_CE(const char* serverName, const char* serverPort, \ |
---|
| 28 | const int32_t numFields, const bool SML) \ |
---|
| 29 | : CognitiveEngine(serverName, serverPort, numFields, SML) |
---|
[532] | 30 | { |
---|
[545] | 31 | BuildCognitiveEngine(); |
---|
| 32 | } |
---|
[532] | 33 | |
---|
| 34 | |
---|
| 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 | |
---|
| 75 | Parameter* |
---|
| 76 | CBR_CE::GetSolution(Observable *observables, Parameter *currentParameters) |
---|
| 77 | { |
---|
| 78 | LOG("Cognitive Engine:: Generating solution.\n"); |
---|
| 79 | |
---|
| 80 | string searchNames[radioInfo->numUtilities]; |
---|
| 81 | |
---|
| 82 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
---|
| 83 | searchNames[i] = observables[i].name; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | float searchVals[radioInfo->numUtilities]; |
---|
| 87 | |
---|
| 88 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
---|
| 89 | searchVals[i] = uList[i].target; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | uint32_t numberColumns = radioInfo->numUtilities + radioInfo->numParameters \ |
---|
| 93 | + radioInfo->numObservables + 1; |
---|
| 94 | |
---|
| 95 | float returnValues[numberColumns]; |
---|
| 96 | |
---|
| 97 | int searchOps[radioInfo->numUtilities]; |
---|
| 98 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
---|
| 99 | |
---|
| 100 | /* If the goal is to maximum, set the search operation to |
---|
| 101 | * return values greater than the target. |
---|
| 102 | * |
---|
| 103 | * If the goal is to minimize, set the search operation to |
---|
| 104 | * return values less than the target. |
---|
| 105 | * |
---|
| 106 | * NOTE: the values '2' and '4' here are from some old preprocesser |
---|
| 107 | * definitions, which I will copy here until I can figure out just what |
---|
| 108 | * exactly they were for: |
---|
| 109 | 42 #define EQ 0 // equals |
---|
| 110 | 43 #define NE 1 // not equals |
---|
| 111 | 44 #define GT 2 // greater than |
---|
| 112 | 45 #define GE 3 // greater than or equal to |
---|
| 113 | 46 #define LT 4 // less than |
---|
| 114 | 47 #define LE 5 // less than or equal to |
---|
| 115 | */ |
---|
| 116 | if(strcmp(uList[i].goal.c_str(), "max") == 0) { |
---|
| 117 | searchOps[i] = 2; |
---|
| 118 | } else if(strcmp(uList[i].goal.c_str(), "min") == 0) { |
---|
| 119 | searchOps[i] = 4; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | /* CBR specific call */ |
---|
| 124 | uint32_t rc = myCBR->Search(searchNames, searchOps, searchVals, |
---|
| 125 | radioInfo->numUtilities, returnValues); |
---|
| 126 | |
---|
| 127 | if(rc == 0){ |
---|
| 128 | /* Adapt the returned parameters to meet the objective */ |
---|
| 129 | LOG("Cognitive Engine:: Found\n"); |
---|
| 130 | |
---|
| 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 | } |
---|
| 139 | } else if(rc == 31337) { |
---|
| 140 | LOG("Cognitive Engine:: Not Found.\n"); |
---|
| 141 | /* No rows in the CBR, pick default parameters */ |
---|
| 142 | /* 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 | } |
---|
| 149 | |
---|
| 150 | size_t returnValueIndex = 0; |
---|
| 151 | for(size_t i = 0; i < radioInfo->numUtilities; i++) { |
---|
| 152 | uList[i].value = returnValues[returnValueIndex]; |
---|
| 153 | returnValueIndex++; |
---|
| 154 | } |
---|
| 155 | for(size_t i = 0; i < radioInfo->numParameters; i++) { |
---|
| 156 | pList[i].value = returnValues[returnValueIndex]; |
---|
| 157 | returnValueIndex++; |
---|
| 158 | } |
---|
| 159 | for(size_t i = 0; i < radioInfo->numObservables; i++) { |
---|
| 160 | oList[i].value = returnValues[returnValueIndex]; |
---|
| 161 | returnValueIndex++; |
---|
| 162 | } |
---|
| 163 | returnValues[returnValueIndex] = 0; |
---|
| 164 | |
---|
| 165 | string allNames[numberColumns]; |
---|
| 166 | 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 | } |
---|
| 172 | for(size_t i = 0; i < radioInfo->numParameters; i++) { |
---|
| 173 | allNames[allNameIndex] = pList[i].name; |
---|
| 174 | allNameIndex++; |
---|
| 175 | } |
---|
| 176 | for(size_t i = 0; i < radioInfo->numObservables; i++) { |
---|
| 177 | allNames[allNameIndex] = oList[i].name; |
---|
| 178 | returnValues[allNameIndex] = 0; |
---|
| 179 | allNameIndex++; |
---|
| 180 | } |
---|
| 181 | allNames[allNameIndex] = "utility"; |
---|
| 182 | |
---|
| 183 | // Add row to CBR. |
---|
| 184 | myCBR->AddRow(allNames, returnValues, returnValueIndex + 1); |
---|
| 185 | |
---|
| 186 | return pList; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
| 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 | |
---|
| 200 | void |
---|
| 201 | CBR_CE::ReceiveFeedback(Observable *observables, Parameter *parameters) |
---|
| 202 | { |
---|
| 203 | LOG("Cognitive Engine:: Receiving feedback.\n"); |
---|
| 204 | |
---|
| 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; |
---|
| 232 | 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"); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | void |
---|
| 266 | CBR_CE::BuildCognitiveEngine() |
---|
| 267 | { |
---|
| 268 | string filename = "ex1"; |
---|
| 269 | string tablename = "data"; |
---|
| 270 | |
---|
| 271 | uint32_t numberColumns = radioInfo->numUtilities + radioInfo->numParameters \ |
---|
| 272 | + radioInfo->numObservables + 1; |
---|
| 273 | |
---|
| 274 | string cols[numberColumns]; |
---|
| 275 | |
---|
| 276 | size_t columnIndex = 0; |
---|
| 277 | for (size_t i = 0; i < radioInfo->numUtilities; i++){ |
---|
| 278 | cols[columnIndex] = uList[i].name; |
---|
| 279 | 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++){ |
---|
| 286 | cols[columnIndex] = oList[i].name; |
---|
| 287 | columnIndex++; |
---|
| 288 | } |
---|
| 289 | cols[columnIndex] = "utility"; |
---|
| 290 | |
---|
| 291 | myCBR = new CBR(filename, tablename, cols, numberColumns); |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | void |
---|
| 296 | CBR_CE::PerformUpdatePerformance() |
---|
| 297 | { |
---|
| 298 | /* Receive Set of current Parameters */ |
---|
| 299 | char buffer[256]; |
---|
| 300 | memset(buffer, 0, 256); |
---|
| 301 | ReadMessage(commandSocketFD, buffer); |
---|
| 302 | uint32_t numParameters = atoi(buffer); |
---|
| 303 | |
---|
| 304 | Parameter *p = new Parameter[numParameters]; |
---|
| 305 | |
---|
| 306 | for(size_t i = 0; i < numParameters; i++) { |
---|
| 307 | memset(buffer, 0, 256); |
---|
| 308 | ReadMessage(commandSocketFD, buffer); |
---|
| 309 | p[i].name = std::string(buffer); |
---|
| 310 | |
---|
| 311 | memset(buffer, 0, 256); |
---|
| 312 | ReadMessage(commandSocketFD, buffer); |
---|
| 313 | p[i].value = atof(buffer); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | /* Receive Set of Observables */ |
---|
| 317 | memset(buffer, 0, 256); |
---|
| 318 | ReadMessage(commandSocketFD, buffer); |
---|
| 319 | uint32_t numObservables = atoi(buffer); |
---|
| 320 | |
---|
| 321 | Observable *o = new Observable[numObservables]; |
---|
| 322 | |
---|
| 323 | for(size_t i = 0; i < numObservables; i++) { |
---|
| 324 | memset(buffer, 0, 256); |
---|
| 325 | ReadMessage(commandSocketFD, buffer); |
---|
| 326 | o[i].name = std::string(buffer); |
---|
| 327 | |
---|
| 328 | memset(buffer, 0, 256); |
---|
| 329 | ReadMessage(commandSocketFD, buffer); |
---|
| 330 | o[i].value = atof(buffer); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | ReceiveFeedback(o, p); |
---|
| 334 | |
---|
| 335 | delete [] o; |
---|
| 336 | delete [] p; |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | void |
---|
| 341 | CBR_CE::PerformRequestOptimizationService() |
---|
| 342 | { |
---|
| 343 | // THIS IS CURRENTLY IN DEMO MODE |
---|
| 344 | |
---|
| 345 | /* Receive Set of Observables */ |
---|
| 346 | LOG("\nCognitive Engine:: Receiving service name\n"); |
---|
| 347 | |
---|
| 348 | 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 | |
---|
| 356 | memset(buffer, 0, 256); |
---|
| 357 | ReadMessage(commandSocketFD,buffer); |
---|
| 358 | uint32_t numObservables = atoi(buffer); |
---|
| 359 | |
---|
| 360 | Observable *o = new Observable[numObservables]; |
---|
| 361 | |
---|
| 362 | for(size_t i = 0; i < numObservables; i++) { |
---|
| 363 | memset(buffer, 0, 256); |
---|
| 364 | ReadMessage(commandSocketFD, buffer); |
---|
| 365 | o[i].name = std::string(buffer); |
---|
| 366 | |
---|
| 367 | memset(buffer, 0, 256); |
---|
| 368 | ReadMessage(commandSocketFD, buffer); |
---|
| 369 | o[i].value = atof(buffer); |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | /* Receive Set of current Parameters */ |
---|
| 373 | LOG("Cognitive Engine:: Receiving Current Transmission Parameters\n"); |
---|
| 374 | |
---|
| 375 | memset(buffer, 0, 256); |
---|
| 376 | ReadMessage(commandSocketFD, buffer); |
---|
| 377 | uint32_t numCurrentParameters = atoi(buffer); |
---|
| 378 | |
---|
| 379 | Parameter *cp = new Parameter[numCurrentParameters]; |
---|
| 380 | |
---|
| 381 | for(size_t i = 0; i < numCurrentParameters; i++) { |
---|
| 382 | memset(buffer, 0, 256); |
---|
| 383 | ReadMessage(commandSocketFD, buffer); |
---|
| 384 | cp[i].name = std::string(buffer); |
---|
| 385 | |
---|
| 386 | memset(buffer, 0, 256); |
---|
| 387 | ReadMessage(commandSocketFD, buffer); |
---|
| 388 | 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"); |
---|
| 444 | |
---|
| 445 | memset(buffer, 0, 256); |
---|
| 446 | 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 | } |
---|
| 460 | LOG("Cognitive Engine:: Processing parameters....\n"); |
---|
| 461 | |
---|
| 462 | Parameter *solutionSet; |
---|
| 463 | |
---|
| 464 | solutionSet = GetSolution(o,cp); |
---|
| 465 | |
---|
| 466 | // TODO need to actually do something with the observables here |
---|
| 467 | |
---|
| 468 | LOG("Cognitive Engine:: Sending Optimal Parameters to Application.\n"); |
---|
| 469 | char numParametersChar[10]; |
---|
| 470 | char solutionValue[50]; |
---|
| 471 | sprintf(numParametersChar, "%i", radioInfo->numParameters); |
---|
| 472 | SendMessage(commandSocketFD, numParametersChar); |
---|
| 473 | for(size_t i = 0; i < radioInfo->numParameters; i++) { |
---|
| 474 | SendMessage(commandSocketFD, solutionSet[i].name.c_str()); |
---|
| 475 | memset(solutionValue, 0, 50); |
---|
| 476 | sprintf(solutionValue, "%f", solutionSet[i].value); |
---|
| 477 | SendMessage(commandSocketFD, solutionValue); |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | delete [] o; |
---|
| 481 | 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 | } |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | |
---|
| 547 | void |
---|
| 548 | CBR_CE::PerformResetEngineCognitive() |
---|
| 549 | { |
---|
| 550 | Reset(); |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | |
---|
| 554 | void |
---|
| 555 | CBR_CE::PerformShutdownEngineCognitive() |
---|
| 556 | { |
---|
| 557 | Shutdown(); |
---|
| 558 | } |
---|
| 559 | |
---|