Show
Ignore:
Timestamp:
09/07/09 17:04:29 (15 years ago)
Author:
bhilburn
Message:

Fully implemented the CBR as a C++ class, and using it within the CBR_CE
component.

Files:
1 modified

Legend:

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

    r465 r468  
    1818#include <cstring> 
    1919#include <stdint.h> 
    20 #include <math.h> 
    21  
     20#include <cmath> 
     21 
     22#include "vtcross/cbr.h" 
    2223#include "vtcross/cognitive_engine.h" 
    2324#include "vtcross/common.h" 
     
    2627#include "vtcross/error.h" 
    2728#include "vtcross/socketcomm.h" 
    28 #include "vtcross/cbr.h" 
    29  
    30 // TODO this is really bad; need to move to a proper cbr.h 
    31 #include "cbr.c" 
    32  
    33 #include "sqlite3.h" 
    34 #include "sqlite3ext.h" 
    35  
    36  
    37 static cbr myCBR; 
    38  
     29 
     30static CBR *myCBR; 
    3931 
    4032CognitiveEngine::CognitiveEngine() 
     
    4840CognitiveEngine::~CognitiveEngine() 
    4941{ 
    50     cbr_free(myCBR); 
     42    delete myCBR; 
     43 
    5144    delete [] pList; 
    5245    delete [] oList; 
     
    160153    } 
    161154 
    162     cbr_update(myCBR, nameList, obsList, valList, obsVals,  
     155    myCBR->Update(nameList, obsList, valList, obsVals,  
    163156            numberColumns, obsColumns); 
    164157} 
     
    670663         * If the goal is to minimize, set the search operation to 
    671664         * return values less than the target. 
     665         * 
     666         * NOTE: the values '2' and '4' here are from some old preprocesser 
     667         * definitions, which I will copy here until I can figure out just what 
     668         * exactly they were for: 
     669                42      #define EQ 0    // equals 
     670                43      #define NE 1    // not equals 
     671                44      #define GT 2    // greater than 
     672                45      #define GE 3    // greater than or equal to 
     673                46      #define LT 4    // less than 
     674                47      #define LE 5    // less than or equal to 
    672675         */ 
    673676        if(strcmp(uList[i].goal.c_str(), "max") == 0) { 
    674             searchOps[i] = GT; 
     677            searchOps[i] = 2; 
    675678        } else if(strcmp(uList[i].goal.c_str(), "min") == 0) { 
    676             searchOps[i] = LT; 
     679            searchOps[i] = 4; 
    677680        } 
    678681    } 
    679682 
    680683    /* CBR specific call */ 
    681     uint32_t rc = cbr_search(myCBR, searchNames, searchOps, searchVals, 
     684    uint32_t rc = myCBR->Search(searchNames, searchOps, searchVals, 
    682685            radioInfo->numUtilities, returnValues); 
    683686 
     
    739742 
    740743    // Add row to CBR.  
    741     cbr_add_row(myCBR, allNames, returnValues, returnValueIndex+1); 
     744    myCBR->AddRow(allNames, returnValues, returnValueIndex+1); 
    742745 
    743746    return pList; 
     
    791794    cols[columnIndex] = (char *) "utility"; 
    792795 
    793     myCBR = cbr_create(filename, tablename, cols, numberColumns); 
    794 } 
    795  
     796    myCBR = new CBR(filename, tablename, cols, numberColumns); 
     797} 
     798