24 #include <boost/version.hpp> 32 double minAverageRecognitionRuntime = std::numeric_limits<double>::max();
33 double maxAverageRecognitionRuntime = std::numeric_limits<double>::min();
35 double minCost = std::numeric_limits<double>::max();
36 double maxCost = std::numeric_limits<double>::min();
41 for (
unsigned int i = 0; i < history.size(); ++i)
44 for (
unsigned int j = 0; j < history[i].size(); ++j)
46 if (history[i][j].second != 0)
57 tc.
er = topology->evaluationResult;
58 tc.
index = topology->index;
61 double cost = globalCostFunction->calculateCost(topology);
62 cost = cost == std::numeric_limits<double>::max() ? -1 : cost;
65 minCost = std::min(minCost, cost);
66 maxCost = std::max(maxCost, cost == std::numeric_limits<double>::infinity() ? 0 : cost);
87 #if (BOOST_VERSION >= 105600) 88 boost::property_tree::xml_writer_settings<std::string> settings(
'\t', 1);
90 boost::property_tree::xml_writer_settings<char> settings(
'\t', 1);
97 std::vector<ptree> roots =
createSVG(it->second);
98 for (
unsigned int i = 0; i < roots.size(); ++i)
100 std::string svgFileName =
mOutputPath.string() +
"/visulisation- " 101 + it->first +
"_" + std::to_string(i);
102 boost::property_tree::write_xml(svgFileName +
".svg", roots[i], std::locale(), settings);
109 std::vector<int> xValues;
110 unsigned int center = imageWidth / 2;
112 for (
unsigned int i = 0; i < numTopologies;)
118 if (numCirclesThisLine % 2 == 0)
120 half = numCirclesThisLine / 2;
126 half = (numCirclesThisLine - 1) / 2;
130 for (
unsigned int j = 0; j < numCirclesThisLine; j++)
132 xValues.push_back(x);
135 i += numCirclesThisLine;
142 std::vector<std::vector<int>>& seperatorLinePositions,
143 unsigned int& imgWidth,
unsigned int& imgHeight)
145 unsigned int numStartingTopologies = 0;
146 unsigned int maxRoundSize = 0;
148 for (
unsigned int i = 0; i < optimizationRuns.size(); ++i)
151 numStartingTopologies += optRun.
allRounds[0].evaluatedTopologies.size();
152 for (
unsigned int j = 0; j < optRun.
allRounds.size(); ++j)
154 maxRoundSize = std::max(maxRoundSize,
155 (
unsigned int) optRun.
allRounds[j].evaluatedTopologies.size());
160 std::max(maxRoundSize, numStartingTopologies));
162 imgWidth = maxNumTopologiesPerLine * 2 *
MAX_CIRCLE_RADIUS + (maxNumTopologiesPerLine + 2)
165 std::vector<int> startingXValues =
calculateXValues(numStartingTopologies, imgWidth);
166 unsigned int startingXValuesIndex = 0;
170 unsigned int maxY = 0;
172 for (
unsigned int i = 0; i < optimizationRuns.size(); ++i)
175 seperatorLinePositions.push_back(std::vector<int>());
177 unsigned int index = 0;
179 for (
unsigned int j = 0; j < optRun.
allRounds.size(); ++j)
182 std::vector<int> xValues;
189 for (
unsigned int k = 0; k < optRun.
allRounds[j].evaluatedTopologies.size(); ++k)
193 y +=
PADDING + MAX_CIRCLE_RADIUS * 2;
199 x = startingXValues[startingXValuesIndex];
200 startingXValuesIndex++;
213 if (j != optimizationRuns[i].allRounds.size() - 1)
215 seperatorLinePositions[i].push_back(y + MAX_CIRCLE_RADIUS + 2 *
PADDING);
220 y +=
PADDING + MAX_CIRCLE_RADIUS * 2;
223 maxY = std::max(y, maxY);
231 std::vector<ptree> roots;
233 std::vector<std::vector<int>> seperatorLinePositions;
234 unsigned int imgWidth, imgHeight;
237 double maxAverageRecognitionRuntime = std::numeric_limits<double>::min();
238 double minAverageRecognitionRuntime = std::numeric_limits<double>::max();
240 for (
unsigned int i = 0; i < optimizationRuns.size(); ++i)
248 for (
unsigned int i = 0; i < optimizationRuns.size(); ++i)
251 std::vector<std::string> linePoints;
252 std::vector<ptree> circleNodes;
253 std::vector<ptree> textNodes;
254 unsigned int index = 0;
256 for (
unsigned int j = 0; j < optRun.
allRounds.size(); ++j)
263 int y = imgHeight - tc.
y;
264 std::string highlightColor =
"";
269 linePoints.push_back(std::to_string(x) +
"," + std::to_string(y));
302 minAverageRecognitionRuntime,
303 maxAverageRecognitionRuntime),
305 foundChosen, highlightColor));
307 std::ostringstream lineTwo;
308 std::ostringstream lineThree;
309 lineTwo << std::fixed << std::setprecision(3) << tc.
cost;
310 lineThree << std::fixed << std::setprecision(3)
314 lineTwo.str(), lineThree.str(),
324 svg.put(
"<xmlattr>.xmlns",
"http://www.w3.org/2000/svg") ;
325 svg.put(
"<xmlattr>.width", std::to_string(imgWidth)) ;
326 svg.put(
"<xmlattr>.height", std::to_string(imgHeight)) ;
327 svg.put(
"<xmlattr>.background",
"white") ;
329 svg.add_child(
"rect",
genRectSVG(0, 0, imgWidth, imgHeight,
"white"));
332 for (
unsigned int j = 0; j < circleNodes.size(); ++j)
334 svg.add_child(
"circle", circleNodes[j]);
337 for (
unsigned int j = 0; j < textNodes.size(); ++j)
339 svg.add_child(
"text", textNodes[j]);
342 for (
unsigned int j = 0; j < seperatorLinePositions[i].size(); ++j)
348 root.add_child(
"svg", svg);
349 roots.push_back(root);
356 bool highlight,
const std::string& highlightColor)
359 circleNode.put(
"<xmlattr>.cx", std::to_string(x));
360 circleNode.put(
"<xmlattr>.cy", std::to_string(y));
361 circleNode.put(
"<xmlattr>.r", std::to_string(radius));
362 circleNode.put(
"<xmlattr>.fill", circleColor);
365 circleNode.put(
"<xmlattr>.stroke", highlightColor);
366 circleNode.put(
"<xmlattr>.stroke-width", std::to_string(
HIGHLIGHT_WIDTH));
372 const std::string& lineThree,
int x,
int y)
375 textNode.put(
"<xmlattr>.y", std::to_string(y));
376 textNode.put(
"<xmlattr>.x", std::to_string(x));
377 textNode.put(
"<xmlattr>.fill",
"black");
378 textNode.put(
"<xmlattr>.font-family",
"Courier New");
379 textNode.put(
"<xmlattr>.text-anchor",
"middle");
380 textNode.put(
"<xmlattr>.font-weight",
"bold");
381 textNode.put(
"<xmlattr>.font-size", std::to_string(
FONT_SIZE) +
"px") ;
384 lOne.put(
"", lineOne);
385 lOne.put(
"<xmlattr>.x", std::to_string(x +
FONT_SIZE / 4));
386 lOne.put(
"<xmlattr>.dy", - (
int)
FONT_SIZE * 1.25);
387 lOne.put(
"<xmlattr>.font-style",
"italic");
390 lTwo.put(
"", lineTwo);
391 lTwo.put(
"<xmlattr>.x", std::to_string(x + FONT_SIZE / 4));
392 lTwo.put(
"<xmlattr>.dy", FONT_SIZE * 1.25);
395 lThree.put(
"", lineThree);
396 lThree.put(
"<xmlattr>.x", std::to_string(x));
397 lThree.put(
"<xmlattr>.dy", FONT_SIZE * 1.25);
399 textNode.add_child(
"tspan", lOne);
400 textNode.add_child(
"tspan", lTwo);
401 textNode.add_child(
"tspan", lThree);
408 ptree sepeartorLineNode;
409 sepeartorLineNode.put(
"<xmlattr>.stroke-dasharray",
"5, 5");
410 sepeartorLineNode.put(
"<xmlattr>.y1", std::to_string(y));
411 sepeartorLineNode.put(
"<xmlattr>.y2", std::to_string(y));
412 sepeartorLineNode.put(
"<xmlattr>.x1", std::to_string(x1));
413 sepeartorLineNode.put(
"<xmlattr>.x2", std::to_string(x2));
414 sepeartorLineNode.put(
"<xmlattr>.stroke",
"black");
415 sepeartorLineNode.put(
"<xmlattr>.stroke-width",
"3");
417 return sepeartorLineNode;
422 std::string linePointsString =
"";
423 if (linePoints.size() != 0)
425 linePointsString += linePoints[0];
426 for (
unsigned int i = 1; i < linePoints.size(); ++i)
428 linePointsString +=
" " + linePoints[i];
433 lineNode.put(
"<xmlattr>.points", linePointsString);
434 lineNode.put(
"<xmlattr>.style",
"fill:none;stroke:" 442 unsigned int height,
const std::string& colorString)
445 rectNode.put(
"<xmlattr>.x", std::to_string(x));
446 rectNode.put(
"<xmlattr>.y", std::to_string(y));
447 rectNode.put(
"<xmlattr>.width", std::to_string(width));
448 rectNode.put(
"<xmlattr>.height", std::to_string(height));
449 rectNode.put(
"<xmlattr>.style",
"fill:" + colorString);
458 ptree optimizationRun;
470 optimizationRun.add_child(
NAME_ROUND, erNode);
495 if (cost == std::numeric_limits<double>::infinity())
496 return "rgb(255, 0, 0)";
498 double diff = maxCost - minCost;
499 double halfWay = diff / 2;
500 double ratio = 255 / halfWay;
501 double normedCost= cost - minCost;
502 double redValue, greenValue, blueValue = 0;
503 if (normedCost < halfWay)
505 redValue = normedCost * ratio;
511 greenValue = (2 * halfWay - normedCost) * ratio;
514 return "rgb(" + std::to_string((
int) redValue) +
"," 515 + std::to_string((
int) greenValue) +
"," 516 + std::to_string((
int) blueValue) +
")";
520 double minAverageRecognitionRuntime,
521 double maxAverageRecognitionRuntime)
523 double diff = maxAverageRecognitionRuntime - minAverageRecognitionRuntime;
524 double ratio = (averageRecognitionRuntime - minAverageRecognitionRuntime) / diff;
const std::string ATR_CHOSEN_INDEX
const unsigned int MIN_CIRCLE_RADIUS
double calculateCircleRadius(double evaluationDuration, double minEvaluationDuration, double maxEvaluationDuration)
unsigned int selectedTopologyType
double averageRecognitionRuntime
const std::string ATR_PATTERN_NAME
boost::shared_ptr< CostFunction< InstanceType >> CostFunctionPtr
const unsigned int MAX_CIRCLE_RADIUS
std::map< std::string, std::vector< OptimizationRun > > mPatternNameToOptimizationRuns
void calculatePositions(std::vector< OptimizationRun > &optimizationRuns, std::vector< std::vector< int >> &seperatorLinePositions, unsigned int &imgWidth, unsigned int &imgHeight)
ptree createXML(const std::string &patternName)
unsigned int falsePositives
ptree genCircleSVG(double radius, int x, int y, const std::string &circleColor, bool highlight, const std::string &highlightColor)
double maxAverageRecognitionRuntime
std::vector< TopologyContainer > evaluatedTopologies
const unsigned int LINE_WIDTH
const std::string ATR_EVALUATION_RESULT
const unsigned int FONT_SIZE
double minAverageRecognitionRuntime
const std::string NAME_OPTIMIZATION_RUN
boost::shared_ptr< Topology > TopologyPtr
const unsigned int MAX_TOPOLOGIES_PER_LINE
const std::string ATR_ROUND_NUMBER
const std::string COLOR_BEST
ptree genTextSVG(const std::string &lineOne, const std::string &lineTwo, const std::string &lineThree, int x, int y)
ptree genTopologyContainerXML(TopologyContainer tc)
const std::string COLOR_RANDOM_WALK_HIGHLIGHT
const std::string COLOR_HIGHLIGHT
std::vector< OptimizationRound > mAllEvaluationRounds
std::vector< int > calculateXValues(unsigned int numTopologies, unsigned int imageWidth)
const std::string ATR_RELATION_IDS
int selectedTopologyIndex
ptree genRectSVG(int x, int y, unsigned int width, unsigned int height, const std::string &colorString)
const std::string COLOR_FIRST_HIGHLIGHT
const std::string COLOR_RANDOM_RESTART_HIGHLIGHT
std::vector< ptree > createSVG(std::vector< OptimizationRun > optimizationRuns)
ptree genSeparatorLineSVG(int y, int x1, int x2)
const unsigned int HIGHLIGHT_WIDTH
ptree genPolylineSVG(std::vector< std::string > linePoints)
ptree genEvaluationRoundXML(unsigned int roundNumber, unsigned int chosenIndex)
this namespace contains all generally usable classes.
const std::string NAME_ROUND
void processHistory(std::vector< std::vector< std::pair< TopologyPtr, unsigned int >>> &history, CostFunctionPtr< TopologyPtr > globalCostFunction, const std::string &patternName)
const std::string NAME_TOPOLOGY
std::string genRGBString(double cost, double minCost, double maxCost)
std::vector< OptimizationRound > allRounds
const unsigned int PADDING
const std::string COLOR_LAST_HIGHLIGHT