[412] | 1 | /* |
---|
| 2 | Copyright 2009 Virginia Polytechnic Institute and State University |
---|
[222] | 3 | |
---|
[412] | 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 | |
---|
[222] | 17 | |
---|
| 18 | #include <cstdlib> |
---|
| 19 | #include <cstring> |
---|
| 20 | #include <stdint.h> |
---|
| 21 | |
---|
[239] | 22 | #include "vtcross/debug.h" |
---|
| 23 | #include "vtcross/error.h" |
---|
[222] | 24 | #include "vtcross/libvtcross.h" |
---|
| 25 | #include "vtcross/socketcomm.h" |
---|
| 26 | |
---|
| 27 | int32_t |
---|
| 28 | main(int32_t argc, char *argv[]) |
---|
| 29 | { |
---|
[535] | 30 | /* Set the location to localhost for this simple demo. */ |
---|
| 31 | SetCrossShellLocation("localhost", "40000"); |
---|
| 32 | |
---|
[232] | 33 | for(size_t i = 0; i < 10; i++) { |
---|
[231] | 34 | Observable *o = new Observable[2]; |
---|
| 35 | Parameter *currentParameters = new Parameter[2]; |
---|
| 36 | Parameter *p; |
---|
[222] | 37 | |
---|
[231] | 38 | uint32_t numParameters; |
---|
| 39 | uint32_t numObservables; |
---|
| 40 | uint32_t numUtilities; |
---|
[222] | 41 | |
---|
[231] | 42 | o[0].name = "throughput"; |
---|
| 43 | o[0].value = 150.00; |
---|
| 44 | o[1].name = "PER"; |
---|
| 45 | o[1].value = 12.00; |
---|
[222] | 46 | |
---|
[231] | 47 | if(i == 0) { |
---|
| 48 | currentParameters[0].name = "bandwidth"; |
---|
| 49 | currentParameters[0].value = 300.0; |
---|
| 50 | currentParameters[1].name = "tx_power"; |
---|
| 51 | currentParameters[1].value = 10.0; |
---|
| 52 | } else { |
---|
| 53 | currentParameters[0].value = p[0].value; |
---|
| 54 | currentParameters[1].value = p[1].value; |
---|
| 55 | } |
---|
[228] | 56 | |
---|
[535] | 57 | LOG("Application:: Requesting parameter optimization.\n"); |
---|
| 58 | |
---|
[231] | 59 | p = GetOptimalParameters(o,2,currentParameters,2); |
---|
| 60 | numParameters = GetNumParameters(); |
---|
| 61 | numObservables = GetNumObservables(); |
---|
| 62 | numUtilities = GetNumUtilities(); |
---|
[228] | 63 | |
---|
[231] | 64 | LOG("Application:: Received the following parameters.\n"); |
---|
| 65 | |
---|
| 66 | for(size_t i = 0; i < numParameters; i++) { |
---|
| 67 | LOG("%s:: %f\n", p[i].name.c_str(), p[i].value); |
---|
| 68 | } |
---|
[222] | 69 | |
---|
[231] | 70 | /* Try them out! Do they work? */ |
---|
| 71 | o[0].value = 0.5*p[0].value + .1*p[1].value; |
---|
| 72 | o[1].value = 15-p[1].value; |
---|
[230] | 73 | |
---|
[232] | 74 | UpdateParameterPerformance(p, numParameters, o, numObservables); |
---|
[231] | 75 | |
---|
| 76 | delete [] p; |
---|
| 77 | delete [] o; |
---|
[232] | 78 | } |
---|
[231] | 79 | |
---|
[232] | 80 | return 0; |
---|
[222] | 81 | } |
---|
| 82 | |
---|