root/vtcross/trunk/src/main_cbr.c @ 31

Revision 31, 5.3 KB (checked in by ahe, 16 years ago)

parse example.ce.xml and pass xml file name as parameter to main

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