| 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 |
#ifndef KONCLUDE_REASONER_KERNEL_MANAGER_CREASONERMANAGERTHREAD_H |
| 22 |
#define KONCLUDE_REASONER_KERNEL_MANAGER_CREASONERMANAGERTHREAD_H |
| 23 |
|
| 24 |
// Qt includes |
| 25 |
#include <QLinkedList> |
| 26 |
#include <QSet> |
| 27 |
|
| 28 |
// Namespace includes |
| 29 |
#include "CReasonerManager.h" |
| 30 |
#include "CPrecomputationManager.h" |
| 31 |
#include "CPreprocessingManager.h" |
| 32 |
#include "COntologyRequirementPair.h" |
| 33 |
#include "CRequirementPreparingData.h" |
| 34 |
#include "CReasoningTaskData.h" |
| 35 |
#include "CRealizationManager.h" |
| 36 |
|
| 37 |
|
| 38 |
// Other includes |
| 39 |
#include "Reasoner/Kernel/Calculation/CCalculationManager.h" |
| 40 |
#include "Reasoner/Kernel/Calculation/CConfigDependedCalculationEnvironmentFactory.h" |
| 41 |
#include "Reasoner/Kernel/Calculation/CTaskHandleAlgorithmBuilder.h" |
| 42 |
#include "Reasoner/Kernel/Calculation/CConfigDependedCalculationFactory.h" |
| 43 |
|
| 44 |
#include "Reasoner/Kernel/Algorithm/CCalculationTableauCompletionTaskHandleAlgorithm.h" |
| 45 |
#include "Reasoner/Kernel/Algorithm/CCalculationTableauApproximationSaturationTaskHandleAlgorithm.h" |
| 46 |
#include "Reasoner/Kernel/Algorithm/CCalculationChooseTaskHandleAlgorithm.h" |
| 47 |
#include "Reasoner/Kernel/Algorithm/CUnsatisfiableCacheHandler.h" |
| 48 |
#include "Reasoner/Kernel/Algorithm/CSatisfiableExpanderCacheHandler.h" |
| 49 |
#include "Reasoner/Kernel/Algorithm/CReuseCompletionGraphCacheHandler.h" |
| 50 |
#include "Reasoner/Kernel/Algorithm/CSaturationNodeExpansionCacheHandler.h" |
| 51 |
#include "Reasoner/Kernel/Algorithm/CSaturationNodeBackendAssociationCacheHandler.h" |
| 52 |
#include "Reasoner/Kernel/Algorithm/CIndividualNodeBackendCacheHandler.h" |
| 53 |
|
| 54 |
#include "Reasoner/Ontology/COntologyProcessingRequirementExpander.h" |
| 55 |
#include "Reasoner/Ontology/COntologyProcessingStepRequirement.h" |
| 56 |
#include "Reasoner/Ontology/COntologyProcessingStepVector.h" |
| 57 |
#include "Reasoner/Ontology/COntologyProcessingConceptSaturationRequirement.h" |
| 58 |
|
| 59 |
#include "Reasoner/Query/CJobSatisfiableCallbackContextData.h" |
| 60 |
#include "Reasoner/Query/CJobProvidedQuery.h" |
| 61 |
#include "Reasoner/Query/CRealizationPremisingQuery.h" |
| 62 |
#include "Reasoner/Query/CTaxonomyPremisingQuery.h" |
| 63 |
#include "Reasoner/Query/CConsistencePremisingQuery.h" |
| 64 |
#include "Reasoner/Query/CQueryInconsitentOntologyError.h" |
| 65 |
#include "Reasoner/Query/CQueryUnspecifiedStringError.h" |
| 66 |
#include "Reasoner/Query/CIsTriviallyConsistentQuery.h" |
| 67 |
#include "Reasoner/Query/CClassificationPremisingQuery.h" |
| 68 |
#include "Reasoner/Query/CComplexAnsweringQuery.h" |
| 69 |
#include "Reasoner/Query/CComplexConceptAnsweringQuery.h" |
| 70 |
#include "Reasoner/Query/CComplexAssertionsIndividualVariablesAnsweringQuery.h" |
| 71 |
#include "Reasoner/Query/CComplexAxiomsDataPropertyVariablesAnsweringQuery.h" |
| 72 |
|
| 73 |
#include "Reasoner/Kernel/Manager/Events/CJobCalculatedSatisfiableCallbackEvent.h" |
| 74 |
#include "Reasoner/Kernel/Manager/Events/CReasoningSatisfiableCalculationJobEvent.h" |
| 75 |
#include "Reasoner/Kernel/Manager/Events/CCalcQueryEvent.h" |
| 76 |
#include "Reasoner/Kernel/Manager/Events/CCalcedQueryEvent.h" |
| 77 |
#include "Reasoner/Kernel/Manager/Events/CQueriedTaxonomyComputedCallbackEvent.h" |
| 78 |
#include "Reasoner/Kernel/Manager/Events/CQueryJobCalculatedSatisfiableCallbackEvent.h" |
| 79 |
#include "Reasoner/Kernel/Manager/Events/CRequirementProcessedCallbackEvent.h" |
| 80 |
#include "Reasoner/Kernel/Manager/Events/CPrepareOntologyEvent.h" |
| 81 |
|
| 82 |
|
| 83 |
#include "Concurrent/CIntervalThread.h" |
| 84 |
#include "Concurrent/Callback/CBlockingCallbackData.h" |
| 85 |
|
| 86 |
#include "Reasoner/Kernel/Cache/COccurrenceUnsatisfiableCache.h" |
| 87 |
#include "Reasoner/Kernel/Cache/COccurrenceUnsatisfiableCacheReader.h" |
| 88 |
#include "Reasoner/Kernel/Cache/COccurrenceUnsatisfiableCacheWriter.h" |
| 89 |
#include "Reasoner/Kernel/Cache/CSignatureSatisfiableExpanderCache.h" |
| 90 |
#include "Reasoner/Kernel/Cache/CSignatureSatisfiableExpanderCacheWriter.h" |
| 91 |
#include "Reasoner/Kernel/Cache/CSignatureSatisfiableExpanderCacheReader.h" |
| 92 |
#include "Reasoner/Kernel/Cache/CReuseCompletionGraphCache.h" |
| 93 |
#include "Reasoner/Kernel/Cache/CSaturationNodeAssociatedExpansionCache.h" |
| 94 |
#include "Reasoner/Kernel/Cache/CComputedConsequencesCache.h" |
| 95 |
#include "Reasoner/Kernel/Cache/CBackendRepresentativeMemoryCache.h" |
| 96 |
#include "Reasoner/Kernel/Cache/COccurrenceStatisticsCache.h" |
| 97 |
|
| 98 |
#include "Reasoner/Classifier/CClassificationManager.h" |
| 99 |
#include "Reasoner/Classifier/CClassifiedCallbackDataContext.h" |
| 100 |
|
| 101 |
#include "Reasoner/Answerer/CAnsweringManager.h" |
| 102 |
#include "Reasoner/Answerer/CAnsweringManagerThread.h" |
| 103 |
|
| 104 |
|
| 105 |
#include "Config/CGlobalConfigurationProvider.h" |
| 106 |
#include "Config/CConfigDataReader.h" |
| 107 |
|
| 108 |
#include "Control/Command/CConfigManagerReader.h" |
| 109 |
|
| 110 |
|
| 111 |
// Logger includes |
| 112 |
#include "Logger/CLogger.h" |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
namespace Konclude { |
| 117 |
|
| 118 |
using namespace Config; |
| 119 |
|
| 120 |
using namespace Concurrent; |
| 121 |
using namespace Callback; |
| 122 |
using namespace Scheduler; |
| 123 |
|
| 124 |
using namespace Control::Command; |
| 125 |
|
| 126 |
namespace Reasoner { |
| 127 |
|
| 128 |
using namespace Query; |
| 129 |
using namespace Classifier; |
| 130 |
using namespace Ontology; |
| 131 |
using namespace Preprocess; |
| 132 |
using namespace Consistiser; |
| 133 |
using namespace Answerer; |
| 134 |
|
| 135 |
namespace Kernel { |
| 136 |
|
| 137 |
using namespace Cache; |
| 138 |
using namespace Task; |
| 139 |
using namespace Calculation; |
| 140 |
using namespace Algorithm; |
| 141 |
|
| 142 |
namespace Manager { |
| 143 |
|
| 144 |
using namespace Events; |
| 145 |
|
| 146 |
/*! |
| 147 |
* |
| 148 |
* \class CReasonerManagerThread |
| 149 |
* \author Andreas Steigmiller |
| 150 |
* \version 0.1 |
| 151 |
* \brief TODO |
| 152 |
* |
| 153 |
*/ |
| 154 |
class CReasonerManagerThread : public CReasonerManager, public CIntervalThread, public CTaskHandleAlgorithmBuilder { |
| 155 |
// public methods |
| 156 |
public: |
| 157 |
//! Constructor |
| 158 |
CReasonerManagerThread(CWatchDog *threadWatchDog = 0); |
| 159 |
|
| 160 |
//! Destructor |
| 161 |
virtual ~CReasonerManagerThread(); |
| 162 |
|
| 163 |
|
| 164 |
virtual CReasonerManager* reasoningSatisfiableCalcualtionJob(CSatisfiableCalculationJob* satCalcJob, CCallbackData* callback); |
| 165 |
virtual CJobSatisfiableResult* reasoningSatisfiableCalcualtionJob(CSatisfiableCalculationJob* satCalcJob); |
| 166 |
|
| 167 |
virtual CReasonerManager* reasoningQuery(CQuery *query, CCallbackData *callback); |
| 168 |
virtual CReasonerManager* reasoningQuery(CQuery *query); |
| 169 |
|
| 170 |
|
| 171 |
virtual CReasonerManager* prepareOntology(CConcreteOntology* ontology, const QList<COntologyProcessingRequirement*>& reqList, CCallbackData *callback); |
| 172 |
virtual CReasonerManager* prepareOntology(CConcreteOntology* ontology, const QList<COntologyProcessingRequirement*>& reqList); |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
virtual COccurrenceStatisticsCache* getOccurrenceStatisticsCache(); |
| 177 |
|
| 178 |
virtual CUnsatisfiableCache *getUnsatisfiableCache(); |
| 179 |
|
| 180 |
virtual CCompletionGraphCache *getCompletionGraphCache(); |
| 181 |
virtual CBackendCache* getBackendAssociationCache(); |
| 182 |
virtual CSaturationCache* getSaturationAssociationExpansionCache(); |
| 183 |
|
| 184 |
virtual CReasonerManager *initializeManager(CConfigurationProvider *configurationProvider); |
| 185 |
|
| 186 |
virtual CTaskHandleAlgorithm *createTaskHandleAlgorithm(); |
| 187 |
|
| 188 |
|
| 189 |
virtual CCalculationManager *getCalculationManager(); |
| 190 |
virtual CPrecomputationManager* getPrecomputationManager(); |
| 191 |
virtual CPreprocessingManager* getPreprocessingManager(); |
| 192 |
virtual CRealizationManager* getRealizationManager(); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
// protected methods |
| 198 |
protected: |
| 199 |
virtual bool processCustomsEvents(QEvent::Type type, CCustomEvent *event); |
| 200 |
|
| 201 |
virtual void threadStarted(); |
| 202 |
virtual void threadStopped(); |
| 203 |
|
| 204 |
virtual void logQueryProgressUpdates(); |
| 205 |
|
| 206 |
virtual void readConfig(CConfigurationBase *config); |
| 207 |
|
| 208 |
|
| 209 |
virtual bool processTimer(qint64 timerID); |
| 210 |
|
| 211 |
|
| 212 |
virtual const QList<COntologyRequirementPair> getRequirementsForQuery(CQuery* query); |
| 213 |
|
| 214 |
virtual void prepareOntologyReasoning(CPrepareOntologyEvent* poe); |
| 215 |
virtual void prepareQueryReasoning(CCalcQueryEvent *cqe); |
| 216 |
virtual void initiateQueryReasoning(CQuery* query, CCallbackData* callbackData, CReasoningTaskData* reasoningData, const QList<COntologyRequirementPair>& failedRequirementList); |
| 217 |
virtual void continueRequirementProcessing(CRequirementPreparingData* reqData, CConcreteOntology* ontology); |
| 218 |
virtual void finishQueryReasoning(CCalcedQueryEvent *cqe); |
| 219 |
|
| 220 |
|
| 221 |
virtual void prepareSatisfiableBoxReasoning(CReasoningSatisfiableCalculationJobEvent *cbse); |
| 222 |
virtual void finishSatisfiableBoxReasoning(CJobCalculatedSatisfiableCallbackEvent *cbsce); |
| 223 |
virtual void finishQuerySatisfiableBoxReasoning(CQueryJobCalculatedSatisfiableCallbackEvent *cbsce); |
| 224 |
|
| 225 |
virtual void loggingCalculationStatistics(); |
| 226 |
virtual QString getLoggingCalculationStatisticsTimeSizeString(double milliseconds); |
| 227 |
virtual QString getLoggingCalculationStatisticsMemorySizeString(cint64 memSize); |
| 228 |
|
| 229 |
|
| 230 |
// protected variables |
| 231 |
protected: |
| 232 |
|
| 233 |
|
| 234 |
CWatchDog *mWatchDog; |
| 235 |
|
| 236 |
QHash<cint64,CReasoningTaskData*> mReasoningTaskDataHash; |
| 237 |
QHash<CQuery*,CCallbackData*> mQueryCallbackHash; |
| 238 |
QHash<CSatisfiableCalculationJob*,CCallbackData*> mJobCallbackHash; |
| 239 |
|
| 240 |
QSet<CRequirementPreparingData*> mProcessingRequirementsSet; |
| 241 |
|
| 242 |
QSet<CQuery*> mCalculatingQuerySet; |
| 243 |
QSet<CSatisfiableCalculationJob*> mCalcJobSet; |
| 244 |
|
| 245 |
QSet< QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE> > mProcessingStartMessageSet; |
| 246 |
QSet< QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE> > mProcessingEndMessageSet; |
| 247 |
|
| 248 |
|
| 249 |
QHash<cint64,QTime> mCalcQueryJobStartTimeHash; |
| 250 |
|
| 251 |
COccurrenceUnsatisfiableCache *unsatCache; |
| 252 |
CSignatureSatisfiableExpanderCache* mSatExpCache; |
| 253 |
CReuseCompletionGraphCache* mReuseCompGraphCache; |
| 254 |
CSaturationNodeAssociatedExpansionCache* mSatNodeExpCache; |
| 255 |
CComputedConsequencesCache* mCompConsCache; |
| 256 |
CBackendRepresentativeMemoryCache* mBackendAssCache; |
| 257 |
COccurrenceStatisticsCache* mOccStatsCache; |
| 258 |
|
| 259 |
|
| 260 |
static const qint64 PROGRESSQUERYTIMER = 1; |
| 261 |
|
| 262 |
CConfigurationProvider* configProvider; |
| 263 |
CClassificationManager* classificationMan; |
| 264 |
|
| 265 |
CCalculationManager* mCalculationManager; |
| 266 |
CPrecomputationManager* mPrecomputationManager; |
| 267 |
CPreprocessingManager* mPreprocessingManager; |
| 268 |
CRealizationManager* mRealizationManager; |
| 269 |
CAnsweringManager* mAnswererManager; |
| 270 |
|
| 271 |
bool mAnswererPrepared = false; |
| 272 |
QList<CRequirementProcessedCallbackEvent*> mAnswererPreparedCallbackQueue; |
| 273 |
|
| 274 |
|
| 275 |
COntologyProcessingRequirementExpander* mRequirementExpander; |
| 276 |
|
| 277 |
cint64 mWorkControllerCount; |
| 278 |
bool mConfgAdaptThreadPoolToWorkerCount; |
| 279 |
cint64 mBlockThreadPoolThreadCount; |
| 280 |
QSemaphore mBlockThreadPoolThreadsBlockingSemaphore; |
| 281 |
QSemaphore mBlockThreadPoolThreadsReleasingSemaphore; |
| 282 |
|
| 283 |
// private methods |
| 284 |
private: |
| 285 |
bool updateBeginingCalculationStatistics(CReasoningTaskData* reaTaskData, CConfiguration* config = nullptr); |
| 286 |
bool updateFinishingCalculationStatistics(CReasoningTaskData* reaTaskData, CQueryStatistics* queryStat, CConfiguration* config = nullptr); |
| 287 |
|
| 288 |
// private variables |
| 289 |
private: |
| 290 |
|
| 291 |
}; |
| 292 |
|
| 293 |
}; // end namespace Manager |
| 294 |
|
| 295 |
}; // end namespace Kernel |
| 296 |
|
| 297 |
}; // end namespace Reasoner |
| 298 |
|
| 299 |
}; // end namespace Konclude |
| 300 |
|
| 301 |
#endif // KONCLUDE_REASONER_KERNEL_MANAGER_CREASONERMANAGERTHREAD_H |