[16] | 1 | // |
---|
| 2 | // |
---|
| 3 | // |
---|
| 4 | |
---|
| 5 | #include <stdio.h> |
---|
| 6 | #include "cbr.h" |
---|
| 7 | |
---|
[31] | 8 | int main(int argc, char **argv) { |
---|
| 9 | |
---|
| 10 | /*char * cols[] = { |
---|
[16] | 11 | "BER", "throughput", |
---|
| 12 | "mod_scheme", "tx_power", |
---|
| 13 | "noise_power", "path_loss", |
---|
| 14 | "utility" |
---|
[28] | 15 | };*/ |
---|
| 16 | |
---|
[31] | 17 | const char * xmlfilename; |
---|
| 18 | if (argc == 1){ |
---|
| 19 | printf("wrong! please specify xml file as parameter.\n"); |
---|
| 20 | return 0; |
---|
| 21 | } else { |
---|
| 22 | xmlfilename = argv[1]; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | ezxml_t f2 = ezxml_parse_file(xmlfilename), engine2; |
---|
| 26 | ezxml_t utilities, utility; |
---|
| 27 | ezxml_t parameters, parameter, affect; |
---|
| 28 | ezxml_t observables, observable; |
---|
[36] | 29 | printf("here\n"); |
---|
[31] | 30 | const char *enginename, *enginefilename; |
---|
| 31 | const char *utilityname[10], *utilityunits[10], *utilitygoal[10], *utilitytarget[10]; |
---|
| 32 | const char *parametername[10], *parameterunits[10], *parametermin[10], *parametermax[10], *parameterstep[10]; |
---|
| 33 | const char *affectutility_p[10], *affectrelationship_p[10]; |
---|
| 34 | const char *observablename[10]; |
---|
| 35 | const char *affectutility_o[10], *affectrelationship_o[10]; |
---|
| 36 | |
---|
| 37 | unsigned int i_u; |
---|
| 38 | unsigned int i_p, i_pa; |
---|
| 39 | unsigned int i_o, i_oa; |
---|
| 40 | |
---|
| 41 | for (engine2 = ezxml_child(f2, "engine"); engine2; engine2 = engine2->next){ |
---|
| 42 | // get engine name |
---|
| 43 | enginename = ezxml_attr(engine2, "name"); |
---|
| 44 | |
---|
| 45 | // get engine file name |
---|
| 46 | enginefilename = ezxml_attr(engine2, "filename"); |
---|
| 47 | //printf("engine name: %s, engine file name: %s\n", enginename, enginefilename); |
---|
| 48 | |
---|
| 49 | // get utilities |
---|
| 50 | utilities = ezxml_child(engine2, "utilities"); |
---|
| 51 | i_u = 0; // index for utilities |
---|
| 52 | //printf("utilities: "); |
---|
| 53 | for (utility = ezxml_child(utilities, "utility"); utility; utility = utility->next){ |
---|
| 54 | utilityname[i_u] = ezxml_attr(utility, "name"); |
---|
| 55 | utilityunits[i_u] = ezxml_attr(utility, "units"); |
---|
| 56 | utilitygoal[i_u] = ezxml_attr(utility, "goal"); |
---|
| 57 | utilitytarget[i_u] = ezxml_attr(utility, "target"); |
---|
| 58 | //printf(" %s", utilityname[i_u]); |
---|
| 59 | i_u++; |
---|
| 60 | } |
---|
| 61 | //printf("\n"); |
---|
| 62 | //printf("number of utilities: %d\n", i_u); |
---|
| 63 | |
---|
| 64 | // get parameters |
---|
| 65 | parameters = ezxml_child(engine2, "parameters"); |
---|
| 66 | i_p = 0; // index for parameters |
---|
| 67 | i_pa = 0; // index for affect |
---|
| 68 | //printf("parameters: "); |
---|
| 69 | for (parameter = ezxml_child(parameters, "parameter"); parameter; parameter = parameter->next){ |
---|
| 70 | parametername[i_p] = ezxml_attr(parameter, "name"); |
---|
| 71 | parameterunits[i_p] = ezxml_attr(parameter, "units"); |
---|
| 72 | parametermin[i_p] = ezxml_attr(parameter, "min"); |
---|
| 73 | parametermax[i_p] = ezxml_attr(parameter, "max"); |
---|
| 74 | parameterstep[i_p] = ezxml_attr(parameter, "step"); |
---|
| 75 | //printf(" %s", parametername[i_p]); |
---|
| 76 | i_p++; |
---|
| 77 | for (affect = ezxml_child(parameter, "affect"); affect; affect = affect->next){ |
---|
| 78 | affectutility_p[i_pa] = ezxml_attr(affect, "utility"); |
---|
| 79 | affectrelationship_p[i_pa] = ezxml_attr(affect, "relationship"); |
---|
| 80 | i_pa++; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | //printf("\n"); |
---|
| 84 | //printf("number of parameters: %d\n", i_p); |
---|
| 85 | //printf("number of affects: %d\n", i_pa); |
---|
| 86 | |
---|
| 87 | // get observables |
---|
| 88 | observables = ezxml_child(engine2, "observables"); |
---|
| 89 | i_o = 0; // index for observables |
---|
| 90 | i_oa = 0; // index for affect |
---|
| 91 | //printf("observables: "); |
---|
| 92 | for (observable = ezxml_child(observables, "observable"); observable; observable = observable->next){ |
---|
| 93 | observablename[i_o] = ezxml_attr(observable, "name"); |
---|
| 94 | //printf(" %s", observablename[i_o]); |
---|
| 95 | i_o++; |
---|
| 96 | for (affect = ezxml_child(observable, "affect"); affect; affect = affect->next){ |
---|
| 97 | affectutility_o[i_oa] = ezxml_attr(affect, "utility"); |
---|
| 98 | affectrelationship_o[i_oa] = ezxml_attr(affect, "relationship"); |
---|
| 99 | i_oa++; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | //printf("\n"); |
---|
| 103 | //printf("number of observables: %d\n", i_o); |
---|
| 104 | //printf("number of affects: %d\n", i_oa); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | free(f2); |
---|
| 108 | |
---|
[36] | 109 | unsigned int num_cols = 7; |
---|
[31] | 110 | char * cols[num_cols]; |
---|
[36] | 111 | /*unsigned int num_cols; |
---|
| 112 | char ** cols;*/ |
---|
| 113 | unsigned int i; |
---|
[31] | 114 | for (i = 0; i < i_u; i++){ |
---|
| 115 | cols[i] = utilityname[i]; |
---|
| 116 | } |
---|
| 117 | for (; i < i_u+i_p; i++){ |
---|
| 118 | cols[i] = parametername[i-i_u]; |
---|
| 119 | } |
---|
| 120 | for (; i < i_u+i_p+i_o; i++){ |
---|
| 121 | cols[i] = observablename[i-i_u-i_p]; |
---|
| 122 | } |
---|
[36] | 123 | num_cols = i; |
---|
[31] | 124 | |
---|
| 125 | printf("column names:"); |
---|
[28] | 126 | for (i = 0; i<num_cols; i++){ |
---|
| 127 | printf(" %s",cols[i]); |
---|
| 128 | } |
---|
| 129 | printf("\n"); |
---|
[36] | 130 | printf("number of columns: %d\n", num_cols); |
---|
[28] | 131 | |
---|
[16] | 132 | float vals[num_cols]; |
---|
[20] | 133 | vals[0] = 1e-3f; // BER |
---|
| 134 | vals[1] = 10e3f; // throughput |
---|
| 135 | vals[2] = 1; // mod_scheme |
---|
| 136 | vals[3] = -3.0f; // tx_power |
---|
| 137 | vals[4] = -50.0f; // noise_power |
---|
| 138 | vals[5] = 125.0f; // path_loss |
---|
| 139 | vals[6] = 0.762; // utility |
---|
[16] | 140 | int rc; |
---|
| 141 | |
---|
[18] | 142 | // create cbr database/table |
---|
[16] | 143 | cbr mycbr = cbr_create("ex1", "data", cols, num_cols); |
---|
| 144 | |
---|
| 145 | // add row here |
---|
| 146 | rc = cbr_add_row(mycbr, cols, vals, num_cols); |
---|
| 147 | |
---|
| 148 | // print |
---|
| 149 | cbr_print(mycbr); |
---|
| 150 | |
---|
[20] | 151 | // simple search: find entry where... |
---|
| 152 | // BER < 1e-2 and path_loss > 100 |
---|
| 153 | char * search_names[] = {"BER", "path_loss"}; |
---|
| 154 | int search_ops[] = {LT, GT}; |
---|
| 155 | float search_vals[] = {1e-2f, 100.f}; |
---|
| 156 | float retvals[num_cols]; |
---|
| 157 | rc = cbr_search(mycbr, search_names, search_ops, search_vals, 2, retvals); |
---|
| 158 | |
---|
[16] | 159 | // clean up |
---|
| 160 | cbr_free(mycbr); |
---|
| 161 | |
---|
| 162 | printf("done.\n"); |
---|
| 163 | return 0; |
---|
| 164 | } |
---|
| 165 | |
---|