| 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 "CSatisfiableCalculationJobsQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CSatisfiableCalculationJobsQuery::CSatisfiableCalculationJobsQuery() { |
| 32 |
mJobCalculationError = false; |
| 33 |
mQueryError = false; |
| 34 |
mJobCalcedNegative = false; |
| 35 |
mJobCalcedCount = 0; |
| 36 |
mJobTotalCount = 0; |
| 37 |
mQueryResult = nullptr; |
| 38 |
mQueryStats = nullptr; |
| 39 |
mConfig = nullptr; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
CSatisfiableCalculationJobsQuery::~CSatisfiableCalculationJobsQuery() { |
| 44 |
qDeleteAll(mJobDataList); |
| 45 |
delete mQueryResult; |
| 46 |
delete mQueryStats; |
| 47 |
delete mConfig; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
CSatisfiableCalculationJobsQuery* CSatisfiableCalculationJobsQuery::setCalculationConfiguration(CCalculationConfigurationExtension *calculationConfiguration) { |
| 52 |
mConfig = calculationConfiguration; |
| 53 |
return this; |
| 54 |
} |
| 55 |
|
| 56 |
CCalculationConfigurationExtension* CSatisfiableCalculationJobsQuery::getCalculationConfiguration() { |
| 57 |
return mConfig; |
| 58 |
} |
| 59 |
|
| 60 |
CQUERYLIST<CCalculationJob*> CSatisfiableCalculationJobsQuery::getJobList() { |
| 61 |
return *((CQUERYLIST<CCalculationJob*>*)&mJobDataList); |
| 62 |
} |
| 63 |
|
| 64 |
CQUERYLIST<CSatisfiableCalculationJob*> CSatisfiableCalculationJobsQuery::getSatisfiableCalculationJobList() { |
| 65 |
return mJobDataList; |
| 66 |
} |
| 67 |
|
| 68 |
QString CSatisfiableCalculationJobsQuery::getQueryName() { |
| 69 |
return mQueryName; |
| 70 |
} |
| 71 |
|
| 72 |
CSatisfiableCalculationJobsQuery* CSatisfiableCalculationJobsQuery::setQueryName(const QString& queryName) { |
| 73 |
mQueryName = queryName; |
| 74 |
return this; |
| 75 |
} |
| 76 |
|
| 77 |
QString CSatisfiableCalculationJobsQuery::getQueryString() { |
| 78 |
return mQueryString; |
| 79 |
} |
| 80 |
|
| 81 |
bool CSatisfiableCalculationJobsQuery::hasAnswer() { |
| 82 |
return mJobCalcedNegative || mJobCalcedCount >= mJobTotalCount; |
| 83 |
} |
| 84 |
|
| 85 |
bool CSatisfiableCalculationJobsQuery::hasError() { |
| 86 |
return mQueryError || CQuery::hasError(); |
| 87 |
} |
| 88 |
|
| 89 |
bool CSatisfiableCalculationJobsQuery::getResult(bool queryPositive) { |
| 90 |
if (queryPositive) { |
| 91 |
return mJobCalcedNegative ? false : mJobCalcedCount>= mJobTotalCount; |
| 92 |
} else { |
| 93 |
return mJobCalcedNegative; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
CQueryResult* CSatisfiableCalculationJobsQuery::getQueryResult() { |
| 99 |
if (!mQueryResult) { |
| 100 |
if (hasAnswer()) { |
| 101 |
mQueryResult = new CBooleanQueryResult(getResult()); |
| 102 |
} |
| 103 |
} |
| 104 |
return mQueryResult; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
QString CSatisfiableCalculationJobsQuery::getAnswerString() { |
| 110 |
if (hasAnswer()) { |
| 111 |
if (getResult() == true) { |
| 112 |
return mPositiveAnswerString; |
| 113 |
} else { |
| 114 |
return mNegativeAnswerString; |
| 115 |
} |
| 116 |
} |
| 117 |
return mNoAnswerString; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
CQuery* CSatisfiableCalculationJobsQuery::addErrorString(const QString& errorString) { |
| 122 |
CQuery::addErrorString(errorString); |
| 123 |
mQueryError = true; |
| 124 |
return this; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
CSatisfiableCalculationJobsQuery* CSatisfiableCalculationJobsQuery::setQueryString(const QString& text) { |
| 130 |
mQueryString = text; |
| 131 |
return this; |
| 132 |
} |
| 133 |
|
| 134 |
CSatisfiableCalculationJobsQuery* CSatisfiableCalculationJobsQuery::setAnswerString(const QString& positiveText, const QString& negativeText, const QString& noAnswerText) { |
| 135 |
mPositiveAnswerString = positiveText; |
| 136 |
mNegativeAnswerString = negativeText; |
| 137 |
mNoAnswerString = noAnswerText; |
| 138 |
return this; |
| 139 |
} |
| 140 |
|
| 141 |
bool CSatisfiableCalculationJobsQuery::canCancelRemainingJobs() { |
| 142 |
return mJobCalcedNegative; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
CSatisfiableCalculationJobsQuery* CSatisfiableCalculationJobsQuery::addTestSatisfiableCalculationJob(CSatisfiableCalculationJob* satCalculationJob, bool mustBeSatisfiableForPositive) { |
| 147 |
mJobDataList.append(satCalculationJob); |
| 148 |
mJobTotalCount++; |
| 149 |
CSatisfiableCalculationJobQueryData* queryData = new CSatisfiableCalculationJobQueryData(this,mustBeSatisfiableForPositive); |
| 150 |
satCalculationJob->setQueryData(queryData); |
| 151 |
return this; |
| 152 |
} |
| 153 |
|
| 154 |
bool CSatisfiableCalculationJobsQuery::interpreteJobSatisfiableCalculation(CSatisfiableCalculationJob* satCalculationJob, bool satisfiable, bool calculationError, QString* newAnserString) { |
| 155 |
bool queryFinished = false; |
| 156 |
CSatisfiableCalculationJobQueryData* queryData = (CSatisfiableCalculationJobQueryData*)satCalculationJob->getQueryData(); |
| 157 |
if (calculationError) { |
| 158 |
mQueryError = true; |
| 159 |
queryData->setJobCalculationError(true); |
| 160 |
} else { |
| 161 |
if (!queryData->isJobCalculated()) { |
| 162 |
mJobCalcedCount++; |
| 163 |
} |
| 164 |
queryData->setJobCalculated(true); |
| 165 |
queryData->setJobCalculationSatisfiable(satisfiable); |
| 166 |
if (queryData->needsJobSatisfiabilityForPositiveQueryAnswer() != satisfiable) { |
| 167 |
mJobCalcedNegative = true; |
| 168 |
} |
| 169 |
} |
| 170 |
if (hasAnswer() || hasError()) { |
| 171 |
queryFinished = true; |
| 172 |
if (newAnserString) { |
| 173 |
*newAnserString = getAnswerString(); |
| 174 |
} |
| 175 |
} |
| 176 |
return queryFinished; |
| 177 |
} |
| 178 |
|
| 179 |
CSatisfiableCalculationJobsQuery* CSatisfiableCalculationJobsQuery::setQueryStatistics(CQueryStatistics* stats) { |
| 180 |
mQueryStats = stats; |
| 181 |
return this; |
| 182 |
} |
| 183 |
|
| 184 |
CQueryStatistics* CSatisfiableCalculationJobsQuery::getQueryStatistics() { |
| 185 |
return mQueryStats; |
| 186 |
} |
| 187 |
|
| 188 |
}; // end namespace Query |
| 189 |
|
| 190 |
}; // end namespace Reasoner |
| 191 |
|
| 192 |
}; // end namespace Konclude |