OverSim
StrategySimplifyCoords.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #include "StrategySimplifyCoords.h"
25 #include <GlobalViewBuilder.h>
26 
28  // TODO Auto-generated constructor stub
29 }
30 
32  // TODO Auto-generated destructor stub
33 }
34 
36 
37  std::vector<double> tmpDimVector = ncsInfo.getCoords();
38  simpleCoordCountMap tmpCountMap;
39  tmpCountMap.insert(simpleCoordPair(simplify(tmpDimVector),1));
40 
41  setBranchCoordinates(thisNode, tmpCountMap); // i am my own branch here ...
42 }
43 
45 
46  if(coordData.find(node) != coordData.end()) {
47  coordData.find(node)->second = countMap;
48  } else {
49  coordData.insert(nodeCoordData(node, countMap));
50  }
51 }
52 
54 
55  SimpleCoordStrategyCall* msg = new SimpleCoordStrategyCall("SimpleCoordStrategyCall");
56  SimpleCoordDataContainer tmpSimpleCoordContainer;
57 
58  tmpSimpleCoordContainer.coordData = getCombinedCoordCountMap();
59 
60  msg->setCoordData(tmpSimpleCoordContainer);
61  msg->setBitLength(SIMPLECOORDSTRATEGYCALL_L(msg));
62 
63  return msg;
64 }
65 
67  simpleCoordCountMap combinedCoordMap;
68  simpleCoordCountMap branchCoordMap;
69 
70  branchCoordDataMap::const_iterator coordDataIterator = coordData.begin();
71 
72  while(coordDataIterator != coordData.end()) {
73 
74  branchCoordMap = coordDataIterator->second;
75 
76  simpleCoordCountMap::iterator bSCMapIterator = branchCoordMap.begin();
77 
78  while(bSCMapIterator != branchCoordMap.end()) {
79 
80  if(combinedCoordMap.find(bSCMapIterator->first) == combinedCoordMap.end()) {
81  combinedCoordMap.insert(simpleCoordPair(bSCMapIterator->first, bSCMapIterator->second));
82  } else {
83  combinedCoordMap.find(bSCMapIterator->first)->second += bSCMapIterator->second;
84  }
85 
86  bSCMapIterator++;
87  }
88 
89  coordDataIterator++;
90  }
91 
92  return combinedCoordMap;
93 }
94 
96  SimpleCoordStrategyCall* simpleCoordStrategyCall = dynamic_cast<SimpleCoordStrategyCall*>(globalViewBuilderCall);
97 
98  setBranchCoordinates(simpleCoordStrategyCall->getSrcNode(), simpleCoordStrategyCall->getCoordData().coordData);
99 }
100 
102  std::stringstream tempStr;
103 
105  simpleCoordCountMap::const_iterator coordIterator = coordMap.begin();
106 
107  while(coordIterator != coordMap.end()) {
108 
109  tempStr << "(";
110 
111  std::vector<int> vDim = coordIterator->first.coordData;
112  std::vector<int>::const_iterator vDimIterator = vDim.begin();
113  while(vDimIterator != vDim.end()) {
114 
115  tempStr << (*vDimIterator) << ";";
116 
117  vDimIterator++;
118  }
119 
120  tempStr << "):" << coordIterator->second << "|";
121 
122  coordIterator++;
123  }
124 
125 
126 
127  return tempStr.str();
128 }
129 
130 
132 
133  std::stringstream tempStr;
134  tempStr << globalViewBuilder->parProxy("gvbSendStrategy").stdstringValue();
135  tempStr << "/";
136  tempStr << globalViewBuilder->parProxy("gvbStrategySimplifyCoordsFactor").longValue();
137 
138  return tempStr.str();
139 }
140 
141 
142 void StrategySimplifyCoords::cleanUpCoordData(const treeNodeMap& currentTreeChildNodes) {
143 
144  branchCoordDataMap::const_iterator coordMapIterator = coordData.begin();
145 
146  while(coordMapIterator != coordData.end()) {
147 
148  if(currentTreeChildNodes.find(coordMapIterator->first) == currentTreeChildNodes.end() && coordMapIterator->first != thisNode) {
149  coordData.erase(coordMapIterator);
150  }
151 
152  coordMapIterator++;
153  }
154 }
155 
156 
157 
158 SimpleCoordinate StrategySimplifyCoords::simplify(std::vector<double> coordVector) {
159 
160  int simplifyFactor = globalViewBuilder->parProxy("gvbStrategySimplifyCoordsFactor");
161  int simplified = 0;
162  SimpleCoordinate outVector;
163  std::vector<double>::const_iterator dimIterator = coordVector.begin();
164 
165  while(dimIterator != coordVector.end()) {
166 
167  simplified = static_cast<int>((*dimIterator)*simplifyFactor + 0.5);
168  outVector.coordData.push_back(simplified);
169  dimIterator++;
170  }
171 
172  return outVector;
173 }
174 
175 std::vector<double> StrategySimplifyCoords::decode(SimpleCoordinate simplifiedVector) {
176 
177  int simplifyFactor = globalViewBuilder->parProxy("gvbStrategySimplifyCoordsFactor");
178  double dimension = 0.0;
179 
180  std::vector<int>::const_iterator dimIterator = simplifiedVector.coordData.begin();
181  std::vector<double> outVector;
182 
183  while(dimIterator != simplifiedVector.coordData.end()) {
184  dimension = static_cast<double>(*dimIterator) / static_cast<double>(simplifyFactor);
185  outVector.push_back(dimension);
186 
187  dimIterator++;
188  }
189 
190  return outVector;
191 
192 }
193 
194 std::vector<std::vector<double> > StrategySimplifyCoords::getGlobalViewData() {
195 
197  simpleCoordCountMap::const_iterator coordIterator = coordMap.begin();
198 
199  std::vector<std::vector<double> > globalViewData;
200  int i;
201 
202  while(coordIterator != coordMap.end()) {
203 
204  for(i=1; i<=coordIterator->second; i++) {
205  globalViewData.push_back(decode(coordIterator->first));
206  }
207 
208  coordIterator++;
209  }
210 
211  return globalViewData;
212 
213 }