OverSim
StrategyRegions Class Reference

#include <StrategyRegions.h>

Inheritance diagram for StrategyRegions:
AbstractSendStrategy

Public Member Functions

 StrategyRegions ()
 .cc
virtual ~StrategyRegions ()
virtual GlobalViewBuilderCallgetCoordinateMessage ()
virtual void handleCoordinateRpcCall (GlobalViewBuilderCall *globalViewBuilderCall)
virtual std::string getStrategyDataStatus ()
 return a short status of the running send strategy
virtual std::vector
< std::vector< double > > 
getGlobalViewData ()
 return the decodes global View Data
virtual void setMyCoordinates (const AbstractNcsNodeInfo &ncsInfo)
virtual void cleanUpCoordData (const treeNodeMap &currentTreeChildNodes)
 cleanup the coordinate map and remove data of nodes which are not longer in the branch
virtual std::string getStrategyCombinedParams ()
 return a string of the currently used strategy params
void debugRegionData ()
- Public Member Functions inherited from AbstractSendStrategy
 AbstractSendStrategy ()
 .cc
virtual ~AbstractSendStrategy ()
virtual void initialize (GlobalViewBuilder *globalViewBuilder)
 set a pointer to the neighborCache to access the optional parameters for the strategies
virtual void initializeStrategy ()
 stub method to initialize the concrete strategy
virtual void setThisNode (const NodeHandle thisNode)
 Set the Nodehandle of the own node to identify the own coordinates.

Protected Types

typedef std::vector< long > regionVector
 The regionVector is a vector of integer values, each value represents a coordinate vector.
typedef std::pair
< TransportAddress,
regionCountMap
nodeRegionData
typedef UNORDERED_MAP
< TransportAddress,
regionCountMap,
TransportAddress::hashFcn
branchRegionDataMap

Protected Member Functions

long convertCoordVectorToRegion (std::vector< double > coordVector)
 convert a vector of doubles (=dimensions) to a single integer
std::vector< double > convertRegionToCoordVector (int region, int dimCount)
 convert the region ID to a vector of doubles
const regionCountMap getCombinedRegionsMap ()
void setBranchCoordinates (const NodeHandle &node, regionCountMap countMap)
 set the regions delivered by a child to our regionCountMap
int getSizePerDim ()
int getMaxSpread ()
double checkMaxSpread (double dimValue)

Protected Attributes

branchRegionDataMap regionData
- Protected Attributes inherited from AbstractSendStrategy
NodeHandle thisNode
GlobalViewBuilderglobalViewBuilder
int lastSendCount
 the quantity of coordinates sent by last message

Detailed Description

Definition at line 37 of file StrategyRegions.h.

Member Typedef Documentation

Definition at line 63 of file StrategyRegions.h.

typedef std::vector<long> StrategyRegions::regionVector
protected

The regionVector is a vector of integer values, each value represents a coordinate vector.

Definition at line 61 of file StrategyRegions.h.

Constructor & Destructor Documentation

StrategyRegions::StrategyRegions ( )

.cc

Author
Daniel Lienert

Definition at line 29 of file StrategyRegions.cc.

{
EV << "|DD|> StrategyRegions::StrategyRegions (Using Send Strategy 'Regions') <||" << endl;
}
StrategyRegions::~StrategyRegions ( )
virtual

Definition at line 35 of file StrategyRegions.cc.

{
// TODO Auto-generated destructor stub
}

Member Function Documentation

double StrategyRegions::checkMaxSpread ( double  dimValue)
protected

Definition at line 172 of file StrategyRegions.cc.

Referenced by convertCoordVectorToRegion().

{
double maxSpread = static_cast<double>(getMaxSpread());
if(dimValue < 0.0) {
if(dimValue > (maxSpread * -1.0)) {
return dimValue;
} else {
return (maxSpread * -1.0);
}
} else {
if(dimValue < maxSpread) {
return dimValue;
} else {
return maxSpread;
}
}
}
void StrategyRegions::cleanUpCoordData ( const treeNodeMap currentTreeChildNodes)
virtual

cleanup the coordinate map and remove data of nodes which are not longer in the branch

Reimplemented from AbstractSendStrategy.

Definition at line 290 of file StrategyRegions.cc.

{
branchRegionDataMap::const_iterator regionDataMapIterator =
regionData.begin();
if (regionDataMapIterator == regionData.end()) return;
do {
if (currentTreeChildNodes.find(regionDataMapIterator->first) ==
currentTreeChildNodes.end() &&
regionDataMapIterator->first != thisNode) {
regionDataMapIterator = regionData.erase(regionDataMapIterator);
//assert(regionDataMapIterator != regionData.end());
} else ++regionDataMapIterator;
} while (regionDataMapIterator != regionData.end());
}
long StrategyRegions::convertCoordVectorToRegion ( std::vector< double >  coordVector)
protected

convert a vector of doubles (=dimensions) to a single integer

Parameters
std::vector<double>coordVector
Returns
long region ID

Definition at line 193 of file StrategyRegions.cc.

Referenced by setMyCoordinates().

{
int sizePerDim = getSizePerDim();
int rangeShift = static_cast<int> (sizePerDim / 2);
int maxSpread = getMaxSpread();
long region = 0;
int currentDimension = 0;
for(Coords::iterator coordIt = coordVector.begin();
coordIt < coordVector.end(); coordIt++) {
// normalize to coordSize
double coordNormalized = ((checkMaxSpread(*coordIt) /
static_cast<double>(maxSpread)) *
static_cast<double>(rangeShift));
// round normalized coords
if (coordNormalized > 0) coordNormalized += .5;
else coordNormalized -= .5;
// shift coords
int coordNormAndShifted = static_cast<int>(coordNormalized) +
rangeShift;
//std::cout << coordNormalized << " " << coordNormAndShifted << std::endl;
// TODO special case (wrong rounding?)
if (coordNormAndShifted == pow(sizePerDim , currentDimension))
coordNormAndShifted -= 1;
// calc region number
region += coordNormAndShifted * pow(sizePerDim , currentDimension);
currentDimension++;
}
//test
/*
Coords tmpConvertBack = convertRegionToCoordVector(region, coordVector.size());
std::cout << coordVector << " " << tmpConvertBack << std::endl;
*/
return region;
}
std::vector< double > StrategyRegions::convertRegionToCoordVector ( int  region,
int  dimCount 
)
protected

convert the region ID to a vector of doubles

Parameters
intregion
intdimCount count of dimension of the original coordVector
Returns
std::vector<double> coordVector

Definition at line 239 of file StrategyRegions.cc.

Referenced by getGlobalViewData().

{
int sizePerDim = getSizePerDim();
int maxSpread = getMaxSpread();
int rangeShift = static_cast<int> (sizePerDim / 2);
std::vector<double> rCoordVector; // reverse Vector
std::vector<double> CoordVector;
int normDim = 0;
int dimShifted = 0;
int subRegionSize = 0;
double tmpDimension;
for (int curDim = dimCount; curDim >= 1; curDim--) {
subRegionSize = pow(sizePerDim, (curDim - 1));
dimShifted = static_cast<int>(region / subRegionSize);
normDim = dimShifted - rangeShift;
region -= subRegionSize * dimShifted;
tmpDimension = (static_cast<double>(normDim) /
static_cast<double>(rangeShift)) *
static_cast<double>(maxSpread);
rCoordVector.push_back(tmpDimension);
}
// reverse vector
std::vector<double>::iterator vectorIterator;
for(vectorIterator = rCoordVector.end();
vectorIterator > rCoordVector.begin(); vectorIterator--) {
CoordVector.push_back((*(vectorIterator-1)));
}
return CoordVector;
}
void StrategyRegions::debugRegionData ( )
const regionCountMap StrategyRegions::getCombinedRegionsMap ( )
protected

Definition at line 65 of file StrategyRegions.cc.

Referenced by getCoordinateMessage(), getGlobalViewData(), and getStrategyDataStatus().

{
regionCountMap combinedRegionMap;
regionCountMap branchRegionMap;
branchRegionDataMap::const_iterator regionDataMapIterator = regionData.begin();
while(regionDataMapIterator != regionData.end()) {
branchRegionMap = regionDataMapIterator->second;
regionCountMap::iterator bRMapIterator = branchRegionMap.begin();
while(bRMapIterator != branchRegionMap.end()) {
if(combinedRegionMap.find(bRMapIterator->first) == combinedRegionMap.end()) {
combinedRegionMap.insert(regionCountPair(bRMapIterator->first, bRMapIterator->second));
} else {
combinedRegionMap.find(bRMapIterator->first)->second += bRMapIterator->second;
}
bRMapIterator++;
}
regionDataMapIterator++;
}
return combinedRegionMap;
}
GlobalViewBuilderCall * StrategyRegions::getCoordinateMessage ( )
virtual

Reimplemented from AbstractSendStrategy.

Definition at line 41 of file StrategyRegions.cc.

{
RegionsStrategyCall* msg = new RegionsStrategyCall("RegionsStrategyCall");
RegionDataContainer tmpRegionContainer;
tmpRegionContainer.regionData = getCombinedRegionsMap();
msg->setRegionData(tmpRegionContainer);
msg->setBitLength(REGIONSSTRATEGYCALL_L(msg));
return msg;
}
std::vector< std::vector< double > > StrategyRegions::getGlobalViewData ( )
virtual

return the decodes global View Data

Implements AbstractSendStrategy.

Definition at line 120 of file StrategyRegions.cc.

{
// measurement of CCD size
/*
std::fstream f;
std::string name("CCD_");
name += simTime().str();
name += ".bin";
f.open(name.c_str(), std::ios::binary|std::ios::out);
for (regionCountMap::const_iterator it = tmpRCMap.begin(); it != tmpRCMap.end(); ++it) {
f.write((char*)&(it->first), sizeof(it->first));
f.write((char*)&(it->second), sizeof(it->second));
}
f.close();
*/
regionCountMap::iterator rcmIterator = tmpRCMap.begin();
std::vector<std::vector<double> > globalViewData;
while(rcmIterator != tmpRCMap.end()) {
for(int i = 0; i < rcmIterator->second; i++) {
globalViewData.push_back(convertRegionToCoordVector(rcmIterator->first, 2));
// TODO get the source dimension (2) dynamic from configuration
}
rcmIterator++;
}
return globalViewData;
}
int StrategyRegions::getMaxSpread ( )
protected

Definition at line 283 of file StrategyRegions.cc.

Referenced by checkMaxSpread(), convertCoordVectorToRegion(), convertRegionToCoordVector(), and getStrategyCombinedParams().

{
int maxSpread = globalViewBuilder->parProxy("gvbStrategyRegionsMaxSpread");
return maxSpread;
}
int StrategyRegions::getSizePerDim ( )
protected

Definition at line 275 of file StrategyRegions.cc.

Referenced by convertCoordVectorToRegion(), convertRegionToCoordVector(), and getStrategyCombinedParams().

{
int sizePerDim =
globalViewBuilder->parProxy("gvbStrategyRegionsSizePerDimension");
return sizePerDim;
}
std::string StrategyRegions::getStrategyCombinedParams ( )
virtual

return a string of the currently used strategy params

Implements AbstractSendStrategy.

Definition at line 53 of file StrategyRegions.cc.

{
std::stringstream tempStr;
tempStr << globalViewBuilder->parProxy("gvbSendStrategy").stdstringValue();
tempStr << "/";
tempStr << getMaxSpread();
tempStr << "/";
tempStr << getSizePerDim();
return tempStr.str();
}
std::string StrategyRegions::getStrategyDataStatus ( )
virtual

return a short status of the running send strategy

Reimplemented from AbstractSendStrategy.

Definition at line 102 of file StrategyRegions.cc.

{
std::stringstream tempStr;
regionCountMap::iterator rcmIterator = tmpRCMap.begin();
while (rcmIterator != tmpRCMap.end()) {
tempStr << rcmIterator->first << ':' << rcmIterator->second << ", ";
rcmIterator++;
}
tempStr << " CRM:" << tmpRCMap.size() << " BC:" << regionData.size();
return tempStr.str();
}
void StrategyRegions::handleCoordinateRpcCall ( GlobalViewBuilderCall globalViewBuilderCall)
virtual

Reimplemented from AbstractSendStrategy.

Definition at line 93 of file StrategyRegions.cc.

{
RegionsStrategyCall* regionsStrategyCall =
dynamic_cast<RegionsStrategyCall*>(globalViewBuilderCall);
setBranchCoordinates(regionsStrategyCall->getSrcNode(),
regionsStrategyCall->getRegionData().regionData);
}
void StrategyRegions::setBranchCoordinates ( const NodeHandle node,
regionCountMap  countMap 
)
protected

set the regions delivered by a child to our regionCountMap

Parameters
nodeNodeHandle assign the map to this node
countMapregionCountMap the map of the node

Definition at line 162 of file StrategyRegions.cc.

Referenced by handleCoordinateRpcCall(), and setMyCoordinates().

{
if(regionData.find(node) != regionData.end()) {
regionData.find(node)->second = countMap;
} else {
regionData.insert(nodeRegionData(node, countMap));
}
}
void StrategyRegions::setMyCoordinates ( const AbstractNcsNodeInfo ncsInfo)
virtual

Reimplemented from AbstractSendStrategy.

Definition at line 152 of file StrategyRegions.cc.

{
std::vector<double> tmpDimVector = ncsInfo.getCoords();
regionCountMap tmpCountMap;
tmpCountMap.insert(regionCountPair(convertCoordVectorToRegion(tmpDimVector),1));
setBranchCoordinates(thisNode, tmpCountMap); // i am my own branch here ...
}

Member Data Documentation

branchRegionDataMap StrategyRegions::regionData
protected

The documentation for this class was generated from the following files: