57 EV <<
"[CoordBasedRouting::initialize()]\n No CBR area file found."
58 <<
" Using dCBR." << endl;
63 if (!check_for_xml_file) {
64 check_for_xml_file.close();
66 throw cRuntimeError(
"CBR area file not found!");
70 EV <<
"[CoordBasedRouting::initialize()]\n CBR area file '"
72 check_for_xml_file.close();
88 cXMLElement* rootElement = ev.getXMLDocument(areaCoordinateSource);
90 xmlDimensions = atoi(rootElement->getAttribute(
"dimensions"));
92 for (cXMLElement *area = rootElement->getFirstChildWithTag(
"area"); area;
93 area = area->getNextSiblingWithTag(
"area") ) {
95 for (cXMLElement *areavals = area->getFirstChild(); areavals;
96 areavals = areavals->getNextSibling() ) {
97 std::string tagname = std::string(areavals->getTagName());
98 if (tagname ==
"min") {
99 uint8_t currentdim = atoi(areavals->getAttribute(
"dimension"));
100 double value = atof(areavals->getNodeValue());
101 tmpArea.
min[currentdim] = value;
104 else if (tagname ==
"max") {
105 uint8_t currentdim = atoi(areavals->getAttribute(
"dimension"));
106 double value = atof(areavals->getNodeValue());
107 tmpArea.
max[currentdim] = value;
110 else if (tagname ==
"prefix") {
111 tmpArea.
prefix = areavals->getNodeValue();
114 gap->push_back(tmpArea);
117 EV <<
"[CoordBasedRouting::parseSource()]" << endl;
118 EV <<
" " <<
gap->size() <<
" prefix areas detected." << endl;
123 const std::string& prefix,
130 if (nodes.size() < 2 || prefix.length() >=
maxPrefix) {
132 CBRArea temp(bottoms, tops, prefix);
134 cap->push_back(temp);
139 uint8_t splitDim = depth %
ccdDim;
140 sort(nodes.begin(), nodes.end(),
leqDim(splitDim));
143 uint32_t newSize = nodes.size() / 2;
144 CD lnodes(newSize), rnodes(nodes.size() - newSize);
147 CD::iterator halfIt = nodes.begin();
148 for (uint32_t i = 0; i < newSize; ++i, ++halfIt);
149 assert(halfIt != nodes.end());
150 double splitCoord = (nodes[newSize - 1][splitDim] + nodes[newSize][splitDim]) / 2;
152 std::copy(nodes.begin(), halfIt, lnodes.begin());
153 std::copy(halfIt, nodes.end(), rnodes.begin());
156 Coords newBottoms, newTops;
157 newBottoms = bottoms;
159 newBottoms[splitDim] = newTops[splitDim] = splitCoord;
162 splitNodes(lnodes, prefix +
'0', bottoms, newTops, ++depth, cap);
163 splitNodes(rnodes, prefix +
'1', newBottoms, tops, depth, cap);
190 if (ccd.size() == 0)
return NULL;
201 splitNodes(nodes, prefix, bottoms, tops, 0, cap);
243 uint8_t bpd, uint8_t length,
246 std::string prefix =
getPrefix(coords, cap);
250 std::stringstream ss;
251 ss <<
"[CoordBasedRouting::getNodeId()]: No prefix for given coords (";
252 for (uint8_t i = 0; i < coords.size(); ++i) {
254 if (i != (coords.size() - 1)) {
258 ss <<
") found. Check your area source file!";
260 EV << ss.str() << endl;
264 std::string idString;
279 uint8_t beforeEnd = (startLength + prefix.length() < length) ?
280 (startLength + prefix.length()) : length;
283 uint8_t endLength = length - endPos;
286 for (uint8_t i = 0; i < startLength; i++)
291 if (endPos < idString.length())
292 idString.erase(endPos);
293 if (length < idString.length())
294 idString.erase(length);
297 for (uint8_t i = 0; i < endLength; i++)
308 EV <<
"[CoordBasedRouting::getNodeId()]\n"
309 <<
" calculated id: " << nodeId << endl;
321 bool areaFound =
false;
333 const AP* ap = ((cap != NULL) ? cap :
gap);
344 while (!areaFound && iter < ap->size()) {
346 CBRArea thisArea = (*ap)[iter];
350 for (uint8_t thisdim = 0; thisdim < coords.size(); thisdim++) {
351 if (coords[thisdim] < thisArea.
min[thisdim] ||
352 coords[thisdim] > thisArea.
max[thisdim]) {
361 EV <<
"[CoordBasedRouting::getPrefix()]\n"
362 <<
" calculated prefix: " << thisArea.
prefix << endl;
371 EV <<
"[CoordBasedRouting::getPrefix()]\n"
372 <<
" No corresponding prefix found, check your area source file!"
385 const AP* ap = ((cap != NULL) ? cap :
gap);
388 while (iter < ap->size()) {
389 CBRArea thisArea = (*ap)[iter];
397 if (destKey.
toString(2).substr(startbit, length) ==
398 thisArea.
prefix.substr(startbit, length)) {
402 double sumofsquares = 0;
404 areaCenterCoords[dim] =
405 (thisArea.
min[dim] + thisArea.
max[dim]) / 2;
406 sumofsquares += pow((coords[dim] - areaCenterCoords[dim]), 2);
408 return sqrt(sumofsquares);
414 throw cRuntimeError(
"[CoordBasedRouting::"
415 "getEuclidianDistanceByKeyAndCoords]: "
416 "No prefix for search key found!");
426 EV <<
"[CoordBasedRouting::checkDimensions()]" << endl;
427 EV <<
" ERROR: Given coordinate dimensions do not match dimensions "
428 "in the used area source file. Mapping results will be wrong."
439 : min(dim, 0.0), max(dim, 0.0)
447 for (uint i = 0; i < area.
min.size(); ++i) {
448 os <<
"|" << area.
min[i] <<
" - " << area.
max[i] <<
"|";
450 os <<
" -> \"" << area.
prefix <<
"\"";