Changeset 475 for vtcross/trunk/src
- Timestamp:
- 09/09/09 14:01:13 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/cognitive_engines/DSA_CE/DSA_CognitiveEngine.cpp
r469 r475 19 19 #include <stdint.h> 20 20 #include <cmath> 21 #include <string> 21 22 22 23 #include "vtcross/cbr.h" … … 124 125 float valList[numberColumns]; 125 126 float obsVals[numberColumns]; 126 char *nameList[numberColumns];127 char *obsList[obsColumns];128 char *searchNames[1];127 string nameList[numberColumns]; 128 string obsList[obsColumns]; 129 string searchNames[1]; 129 130 float searchVals[1]; 130 131 int searchOps[1]; … … 133 134 size_t columnObsIndex = 0; 134 135 for (size_t i = 0; i < radioInfo->numObservables; i++){ 135 obsList[columnObsIndex] = (char*)observables[i].name.c_str();136 obsList[columnObsIndex] = observables[i].name; 136 137 columnObsIndex++; 137 138 } 138 139 139 140 std::string utility_name = "utility"; 140 obsList[columnObsIndex] = (char*) utility_name.c_str();141 obsList[columnObsIndex] = utility_name; 141 142 142 143 size_t columnIndex = 0; 143 144 for (size_t i = 0; i < radioInfo->numParameters; i++){ 144 nameList[columnIndex] = (char*)parameters[i].name.c_str();145 nameList[columnIndex] = parameters[i].name; 145 146 columnIndex++; 146 147 } … … 154 155 /* Make sure we do not return any entries for the current channel */ 155 156 std::string channel_name = "channel"; 156 searchNames[0] = (char *) channel_name.c_str();157 searchNames[0] = channel_name; 157 158 searchOps[0] = 0; 158 159 searchVals[0] = parameters[0].value; … … 671 672 672 673 uint32_t channel = 0; 673 char *searchNames[1];674 char *sumSearchName;674 string searchNames[1]; 675 string sumSearchName; 675 676 float searchVals[1]; 676 677 float utilArray[(int)pList[0].max]; 677 678 int searchOps[1]; 678 uint32_t numberColumns = radioInfo->numUtilities + 679 radioInfo->numParameters + 680 radioInfo->numObservables + 1; 679 uint32_t numberColumns = radioInfo->numUtilities + radioInfo->numParameters + \ 680 radioInfo->numObservables + 1; 681 681 682 682 float returnValues[numberColumns]; … … 685 685 // Total sum of utilities in sumRetVals[0] 686 686 687 std::string channel_name = "channel"; 688 std::string utility_name = "utility"; 689 690 for( int i = 0 ; i < pList[0].max ; i++ ) { 691 692 searchNames[0] = (char*) pList[0].name.c_str(); 687 string channel_name = "channel"; 688 string utility_name = "utility"; 689 690 for(int32_t i = 0 ; i < pList[0].max ; i++ ) { 691 searchNames[0] = pList[0].name; 693 692 searchOps[0] = 0; 694 693 searchVals[0] = i+1; … … 700 699 // No entry - must add 701 700 702 char *rowNames[numberColumns];701 string rowNames[numberColumns]; 703 702 size_t rowIndex = 0; 704 703 for(size_t j = 0; j < radioInfo->numUtilities; j++) { 705 rowNames[rowIndex] = (char*)uList[j].name.c_str();704 rowNames[rowIndex] = uList[j].name; 706 705 rowIndex++; 707 706 } 708 707 for(size_t j = 0; j < radioInfo->numParameters; j++) { 709 rowNames[rowIndex] = (char*)pList[j].name.c_str();708 rowNames[rowIndex] = pList[j].name; 710 709 if(pList[j].name == "channel") 711 710 returnValues[rowIndex] = i+1; … … 713 712 } 714 713 for(size_t j = 0; j < radioInfo->numObservables; j++) { 715 rowNames[rowIndex] = (char*)oList[j].name.c_str();714 rowNames[rowIndex] = oList[j].name; 716 715 rowIndex++; 717 716 } 718 717 719 rowNames[rowIndex] = (char *) utility_name.c_str();718 rowNames[rowIndex] = utility_name; 720 719 returnValues[rowIndex] = 500; 721 720 … … 730 729 printf("1: %f\t2: %f\t3: %f\t4: %f\n",utilArray[0],utilArray[1],utilArray[2],utilArray[3]); 731 730 // Get sum of all the channel utilities. 732 sumSearchName = (char *) utility_name.c_str();731 sumSearchName = utility_name; 733 732 uint32_t rc = myCBR->SearchSum(sumSearchName, sumRetVals); 734 733 … … 745 744 } 746 745 747 searchNames[0] = (char*) pList[0].name.c_str();746 searchNames[0] = pList[0].name; 748 747 searchOps[0] = 0; 749 748 searchVals[0] = channel; … … 774 773 //returnValues[returnValueIndex] = 0; 775 774 776 char *allNames[numberColumns];775 string allNames[numberColumns]; 777 776 size_t allNameIndex = 0; 778 777 for(size_t i = 0; i < radioInfo->numUtilities; i++) { 779 allNames[allNameIndex] = (char*)uList[i].name.c_str();778 allNames[allNameIndex] = uList[i].name; 780 779 returnValues[allNameIndex] = uList[i].target; 781 780 allNameIndex++; 782 781 } 783 782 for(size_t i = 0; i < radioInfo->numParameters; i++) { 784 allNames[allNameIndex] = (char*)pList[i].name.c_str();783 allNames[allNameIndex] = pList[i].name; 785 784 allNameIndex++; 786 785 } 787 786 for(size_t i = 0; i < radioInfo->numObservables; i++) { 788 allNames[allNameIndex] = (char*)oList[i].name.c_str();787 allNames[allNameIndex] = oList[i].name; 789 788 // returnValues[allNameIndex] = 0; 790 789 allNameIndex++; 791 790 } 792 791 793 allNames[allNameIndex] = (char *) utility_name.c_str();792 allNames[allNameIndex] = utility_name; 794 793 795 794 /* Add the new optimized set to the CBR database */ … … 823 822 CognitiveEngine::BuildCognitiveEngine() 824 823 { 825 char filename[] = {"ex1"}; 826 char tablename[] = {"data"}; 827 828 uint32_t numberColumns = 829 radioInfo->numUtilities + 830 radioInfo->numParameters + 831 radioInfo->numObservables + 1; 832 833 char *cols[numberColumns]; 824 string filename = "ex1"; 825 string tablename = "data"; 826 827 uint32_t numberColumns = radioInfo->numUtilities + radioInfo->numParameters + \ 828 radioInfo->numObservables + 1; 829 830 string cols[numberColumns]; 834 831 835 832 size_t columnIndex = 0; 836 833 for (size_t i = 0; i < radioInfo->numUtilities; i++){ 837 cols[columnIndex] = (char*)uList[i].name.c_str();834 cols[columnIndex] = uList[i].name; 838 835 columnIndex++; 839 836 } 840 837 841 char *paramCols[radioInfo->numParameters];838 string paramCols[radioInfo->numParameters]; 842 839 size_t paramColumnIndex = 0; 843 840 // Also need to make parameters the unique key 844 841 for (size_t i = 0; i < radioInfo->numParameters; i++){ 845 cols[columnIndex] = (char*)pList[i].name.c_str();846 paramCols[paramColumnIndex] = (char*)pList[i].name.c_str();842 cols[columnIndex] = pList[i].name; 843 paramCols[paramColumnIndex] = pList[i].name; 847 844 columnIndex++; 848 845 paramColumnIndex++; … … 850 847 851 848 for (size_t i = 0; i < radioInfo->numObservables; i++){ 852 cols[columnIndex] = (char*)oList[i].name.c_str();849 cols[columnIndex] = oList[i].name; 853 850 columnIndex++; 854 851 } 855 852 856 853 std::string utility_name = "utility"; 857 cols[columnIndex] = (char *)utility_name.c_str();854 cols[columnIndex] = utility_name; 858 855 859 856 myCBR = new CBR(filename, tablename, cols, paramCols, numberColumns, radioInfo->numParameters);