| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CReasonerEvaluationGroupReasonerWinnerCountCSVComparisonAnalyser.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
namespace Evaluation { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
CReasonerEvaluationGroupReasonerWinnerCountCSVComparisonAnalyser::CReasonerEvaluationGroupReasonerWinnerCountCSVComparisonAnalyser() { |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
CReasonerEvaluationGroupReasonerWinnerCountCSVComparisonAnalyser::~CReasonerEvaluationGroupReasonerWinnerCountCSVComparisonAnalyser() { |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
bool CReasonerEvaluationGroupReasonerWinnerCountCSVComparisonAnalyser::analyseGroupedEvaluationData(const QStringList& groubList, const QStringList& requestList, const QStringList& reasonerList, const QString& outputDirectory, CReasonerEvaluationAnalyseContext* context, CReasonerEvaluationGroupRequestSelector* selector) { |
| 41 |
|
| 42 |
mOutputFileName = QString("%1").arg(selector->getOutputString()); |
| 43 |
|
| 44 |
cint64 reasonerCount = reasonerList.count(); |
| 45 |
bool hasSelectedRequestFile = false; |
| 46 |
|
| 47 |
QDir outDir(outputDirectory); |
| 48 |
outDir.mkpath(mOutputFileName); |
| 49 |
|
| 50 |
cint64** winnerTable = new cint64*[reasonerCount]; |
| 51 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 52 |
cint64* tmpVec = new cint64[reasonerCount]; |
| 53 |
winnerTable[i] = tmpVec; |
| 54 |
for (cint64 j = 0; j < reasonerCount; ++j) { |
| 55 |
tmpVec[j] = 0; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
cint64** timesFasterTable = new cint64*[reasonerCount]; |
| 60 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 61 |
cint64* tmpVec = new cint64[reasonerCount]; |
| 62 |
timesFasterTable[i] = tmpVec; |
| 63 |
for (cint64 j = 0; j < reasonerCount; ++j) { |
| 64 |
tmpVec[j] = 0; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
double** fasterTable = new double*[reasonerCount]; |
| 69 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 70 |
double* tmpVec = new double[reasonerCount]; |
| 71 |
fasterTable[i] = tmpVec; |
| 72 |
for (cint64 j = 0; j < reasonerCount; ++j) { |
| 73 |
tmpVec[j] = 0.; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
QHash<QString,cint64*> reasonerWinnerCountHash; |
| 78 |
QHash<QString,cint64*> reasonerTimesFasterCountHash; |
| 79 |
QHash<QString,double*> reasonerFasterHash; |
| 80 |
QHash<QString,cint64> reasonerIndexHash; |
| 81 |
cint64 index = 0; |
| 82 |
foreach (QString reasonerString, reasonerList) { |
| 83 |
reasonerWinnerCountHash.insert(reasonerString,winnerTable[index]); |
| 84 |
reasonerTimesFasterCountHash.insert(reasonerString,timesFasterTable[index]); |
| 85 |
reasonerFasterHash.insert(reasonerString,fasterTable[index]); |
| 86 |
reasonerIndexHash.insert(reasonerString,index++); |
| 87 |
} |
| 88 |
|
| 89 |
cint64 requestCount = 0; |
| 90 |
|
| 91 |
foreach (QString groupString, groubList) { |
| 92 |
|
| 93 |
if (selector->isGroupSelected(groupString)) { |
| 94 |
|
| 95 |
QSet<QString>* groupRequestList = getGroupRequests(groupString); |
| 96 |
foreach (QString requestString, *groupRequestList) { |
| 97 |
|
| 98 |
if (selector->isRequestSelected(groupString,requestString)) { |
| 99 |
|
| 100 |
bool allDataAvailable = true; |
| 101 |
foreach (QString reasonerString, reasonerList) { |
| 102 |
CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString); |
| 103 |
if (!evalData || evalData->hasDataNotAvailableFlag()) { |
| 104 |
allDataAvailable = false; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
if (allDataAvailable) { |
| 110 |
|
| 111 |
hasSelectedRequestFile = true; |
| 112 |
requestCount++; |
| 113 |
|
| 114 |
QMap<double,QString> timeReasonerMap; |
| 115 |
|
| 116 |
QString requestReasonerTabList(requestString); |
| 117 |
foreach (QString reasonerString, reasonerList) { |
| 118 |
CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString); |
| 119 |
CReasonerEvaluationDoubleDataValue* doubleEvalData = dynamic_cast<CReasonerEvaluationDoubleDataValue*>(evalData); |
| 120 |
if (doubleEvalData) { |
| 121 |
timeReasonerMap.insertMulti(doubleEvalData->getValue(),reasonerString); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
cint64 index = 0; |
| 126 |
for (QMap<double,QString>::const_iterator it = timeReasonerMap.constBegin(), itEnd = timeReasonerMap.constEnd(); it != itEnd; ++it) { |
| 127 |
QString reasonerString = it.value(); |
| 128 |
cint64* tmpWinnerVec = reasonerWinnerCountHash.value(reasonerString); |
| 129 |
++tmpWinnerVec[index]; |
| 130 |
|
| 131 |
cint64* tmpTimesFasterVec = reasonerTimesFasterCountHash.value(reasonerString); |
| 132 |
QMap<double,QString>::const_iterator it2 = it; |
| 133 |
for (++it2; it2 != itEnd; ++it2) { |
| 134 |
QString slowerReasonerString = it2.value(); |
| 135 |
cint64 slowerReasonerIndex = reasonerIndexHash.value(slowerReasonerString); |
| 136 |
++tmpTimesFasterVec[slowerReasonerIndex]; |
| 137 |
} |
| 138 |
|
| 139 |
double* tmpFasterVec = reasonerFasterHash.value(reasonerString); |
| 140 |
for (QMap<double,QString>::const_iterator it2 = timeReasonerMap.constBegin(); it2 != itEnd; ++it2) { |
| 141 |
if (it != it2) { |
| 142 |
double val1 = it.key(); |
| 143 |
double val2 = it2.key(); |
| 144 |
QString otherReasonerString = it2.value(); |
| 145 |
cint64 otherReasonerIndex = reasonerIndexHash.value(otherReasonerString); |
| 146 |
double faster = (val2 / val1)-1; |
| 147 |
if (val2 < val1) { |
| 148 |
faster = -((val1 / val2)-1); |
| 149 |
} |
| 150 |
if (val2 == val1 || val1 == 0 || val2 == 0) { |
| 151 |
faster = 0.; |
| 152 |
} |
| 153 |
tmpFasterVec[otherReasonerIndex] += faster; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
++index; |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
if (requestCount > 0) { |
| 167 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 168 |
for (cint64 j = 0; j < reasonerCount; ++j) { |
| 169 |
fasterTable[i][j] = fasterTable[i][j] / (double)requestCount; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
if (hasSelectedRequestFile) { |
| 175 |
|
| 176 |
CReasonerEvaluationTableMultiFormatOutputWriter<cint64> winnerCountOutputWriter; |
| 177 |
winnerCountOutputWriter.addColumnTitles(QStringList()<<"Ranking"<<reasonerList); |
| 178 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 179 |
QString title = QString("# Rank %1").arg(i+1); |
| 180 |
winnerCountOutputWriter.addNewTableRow(title); |
| 181 |
foreach (QString reasonerString, reasonerList) { |
| 182 |
cint64* tmpVec = reasonerWinnerCountHash.value(reasonerString); |
| 183 |
cint64 rankCount = tmpVec[i]; |
| 184 |
winnerCountOutputWriter.addValuesToLastTableRow(QList<cint64>()<<rankCount); |
| 185 |
} |
| 186 |
} |
| 187 |
QStringList reasonerCompHighchartPlotFileList = winnerCountOutputWriter.writeCVSTable(outputDirectory+mOutputFileName+"winner-count"); |
| 188 |
if (context->isHighchartPlottingActivated()) { |
| 189 |
foreach (QString plotFileString, reasonerCompHighchartPlotFileList) { |
| 190 |
QString outputFile = plotFileString; |
| 191 |
outputFile.remove(".csv"); |
| 192 |
QString title = getPrettyTitleFromOutputFile(outputFile); |
| 193 |
context->getHighchartPlotter()->createReasonerWinnerCountPlot(plotFileString,context->getAdditionalTitleString()+title+" and Rankings",reasonerList,outputFile,selector->getNameString()+" :: "+context->getAdditionalTitleString()); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
CReasonerEvaluationTableMultiFormatOutputWriter<cint64> fasterCountOutputWriter; |
| 199 |
fasterCountOutputWriter.addColumnTitles(QStringList()<<"Reasoner"<<reasonerList); |
| 200 |
foreach (QString fasterReasonerString, reasonerList) { |
| 201 |
QString title = QString("# %1 is faster").arg(fasterReasonerString); |
| 202 |
fasterCountOutputWriter.addNewTableRow(title); |
| 203 |
cint64* tmpVec = reasonerTimesFasterCountHash.value(fasterReasonerString); |
| 204 |
foreach (QString reasonerString, reasonerList) { |
| 205 |
cint64 otherReasonerIndex = reasonerIndexHash.value(reasonerString); |
| 206 |
cint64 fasterCount = tmpVec[otherReasonerIndex]; |
| 207 |
fasterCountOutputWriter.addValuesToLastTableRow(QList<cint64>()<<fasterCount); |
| 208 |
} |
| 209 |
} |
| 210 |
fasterCountOutputWriter.writeCVSTable(outputDirectory+mOutputFileName+"faster-count"); |
| 211 |
|
| 212 |
|
| 213 |
CReasonerEvaluationTableMultiFormatOutputWriter<double> avgFasterOutputWriter; |
| 214 |
avgFasterOutputWriter.addColumnTitles(QStringList()<<"Reasoner"<<reasonerList); |
| 215 |
foreach (QString fasterReasonerString, reasonerList) { |
| 216 |
QString title = QString("average faster ratio for %1").arg(fasterReasonerString); |
| 217 |
avgFasterOutputWriter.addNewTableRow(title); |
| 218 |
double* tmpVec = reasonerFasterHash.value(fasterReasonerString); |
| 219 |
foreach (QString reasonerString, reasonerList) { |
| 220 |
cint64 otherReasonerIndex = reasonerIndexHash.value(reasonerString); |
| 221 |
double fasterRatio = tmpVec[otherReasonerIndex]; |
| 222 |
avgFasterOutputWriter.addValuesToLastTableRow(QList<double>()<<fasterRatio); |
| 223 |
} |
| 224 |
} |
| 225 |
avgFasterOutputWriter.writeCVSTable(outputDirectory+mOutputFileName+"faster-average"); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 230 |
delete [] winnerTable[i]; |
| 231 |
delete [] fasterTable[i]; |
| 232 |
delete [] timesFasterTable[i]; |
| 233 |
} |
| 234 |
delete [] winnerTable; |
| 235 |
delete [] fasterTable; |
| 236 |
delete [] timesFasterTable; |
| 237 |
|
| 238 |
return true; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
QString CReasonerEvaluationGroupReasonerWinnerCountCSVComparisonAnalyser::getPrettyTitleFromOutputFile(const QString& outputFile) { |
| 246 |
QString title = outputFile; |
| 247 |
title.remove("table"); |
| 248 |
cint64 slashPos = title.lastIndexOf("/"); |
| 249 |
if (slashPos >= 0) { |
| 250 |
title = title.mid(slashPos+1); |
| 251 |
} |
| 252 |
title.replace("-"," "); |
| 253 |
title.replace("winner","Winner"); |
| 254 |
title.replace("count","Count"); |
| 255 |
return title; |
| 256 |
} |
| 257 |
|
| 258 |
}; // end namespace Evaluation |
| 259 |
|
| 260 |
}; // end namespace Test |
| 261 |
|
| 262 |
}; // end namespace Konclude |