| 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 "CSatisfiableCalculationTaskFromCalculationJobGenerator.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Generator { |
| 29 |
|
| 30 |
|
| 31 |
CSatisfiableCalculationTaskFromCalculationJobGenerator::CSatisfiableCalculationTaskFromCalculationJobGenerator(CGeneratorTaskHandleContextBase* genTaskHandleContext) { |
| 32 |
mGenTaskHandleContext = genTaskHandleContext; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
CSatisfiableCalculationTask* CSatisfiableCalculationTaskFromCalculationJobGenerator::createSatisfiableCalculationTask(CCalculationJob* calculationJob, CCallbackData* additionalCalculatedCallback) { |
| 37 |
return createSatisfiableCalculationTask(calculationJob->getOntology(),calculationJob,additionalCalculatedCallback); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
CSatisfiableCalculationTask* CSatisfiableCalculationTaskFromCalculationJobGenerator::createApproximatedSaturationCalculationTask(CConcreteOntology *ontology, CApproximatedSaturationCalculationJob* approxSaturCalcJob, CCallbackData* additionalCalculatedCallback) { |
| 47 |
|
| 48 |
CSatisfiableCalculationTask* baseTask = nullptr; |
| 49 |
CSaturationData* saturData = approxSaturCalcJob->getContinueSaturationData(); |
| 50 |
if (saturData) { |
| 51 |
CSaturationTaskData* taskSaturData = dynamic_cast<CSaturationTaskData*>(saturData); |
| 52 |
if (taskSaturData) { |
| 53 |
baseTask = taskSaturData->getSaturationTask(); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
CSatisfiableCalculationTask* satCalcTask = CObjectMemoryPoolAllocator<CSatisfiableCalculationTask>::allocateAndConstructWithMemroyPool(mGenTaskHandleContext->getTaskHandleMemoryAllocationManager()); |
| 58 |
if (baseTask) { |
| 59 |
satCalcTask->initUndependedSatisfiableCalculationTask(baseTask,approxSaturCalcJob->getCalculationConfiguration(),approxSaturCalcJob->getCalclulationStatisticsCollector(),mGenTaskHandleContext); |
| 60 |
} else { |
| 61 |
satCalcTask->initSatisfiableCalculationTask(ontology,approxSaturCalcJob->getCalculationConfiguration(),approxSaturCalcJob->getCalclulationStatisticsCollector(),mGenTaskHandleContext); |
| 62 |
} |
| 63 |
CProcessContext* procContext = satCalcTask->getProcessContext(mGenTaskHandleContext); |
| 64 |
|
| 65 |
|
| 66 |
CProcessingDataBox* dataBox = satCalcTask->getProcessingDataBox(); |
| 67 |
if (approxSaturCalcJob->getOccurrenceStatisticsCollectingAdapter()) { |
| 68 |
dataBox->setNominalDelayedIndividualSaturationProcessNodeLinker(nullptr); |
| 69 |
} |
| 70 |
|
| 71 |
CIndividualSaturationProcessNodeVector* indiNodeVec = dataBox->getIndividualSaturationProcessNodeVector(); |
| 72 |
|
| 73 |
CMemoryAllocationManager* memMan = procContext->getUsedMemoryAllocationManager(); |
| 74 |
cint64 nextIndiID = qMax((cint64)1,indiNodeVec->getItemCount()); |
| 75 |
nextIndiID = qMax(nextIndiID, dataBox->getOntology()->getABox()->getNextIndividualId(false) + 1); |
| 76 |
|
| 77 |
bool separateSaturation = approxSaturCalcJob->isSeparateSaturation(); |
| 78 |
CIndividualVector* indiVector = dataBox->getIndividualVector(true); |
| 79 |
|
| 80 |
CApproximatedSaturationCalculationConstructionConstruct* satCalcConsConstruct = approxSaturCalcJob->getSatisfiableCalculationConstructionConstructs(); |
| 81 |
while (satCalcConsConstruct) { |
| 82 |
CSaturationConceptReferenceLinking* satConRefLink = satCalcConsConstruct->getSaturationConceptReferenceLinking(); |
| 83 |
CSaturationIndividualReferenceLinking* satIndiRefLink = satCalcConsConstruct->getSaturationIndividualReferenceLinking(); |
| 84 |
CIndividual* nominalIndi = satCalcConsConstruct->getIndividual(); |
| 85 |
cint64 individualID = 1; |
| 86 |
bool nominalIndiTriplesAssertions = false; |
| 87 |
|
| 88 |
if (!nominalIndi && satCalcConsConstruct->getIndividualID() >= 0) { |
| 89 |
individualID = satCalcConsConstruct->getIndividualID(); |
| 90 |
nominalIndi = CObjectAllocator<CIndividual>::allocateAndConstruct(memMan); |
| 91 |
nominalIndi->initIndividual(individualID); |
| 92 |
nominalIndi->setTemporaryIndividual(true); |
| 93 |
indiVector->setLocalData(individualID, nominalIndi); |
| 94 |
|
| 95 |
if (satIndiRefLink) { |
| 96 |
CIndividualProcessData* nominalIndiProData = CObjectAllocator<CIndividualProcessData>::allocateAndConstruct(memMan); |
| 97 |
nominalIndiProData->initIndividualProcessExtensionData(); |
| 98 |
nominalIndiProData->setSaturationReferenceLinkingData(satIndiRefLink); |
| 99 |
nominalIndi->setIndividualData(nominalIndiProData); |
| 100 |
} |
| 101 |
|
| 102 |
nominalIndiTriplesAssertions = true; |
| 103 |
} else if (nominalIndi) { |
| 104 |
individualID = (nominalIndi->getIndividualID()); |
| 105 |
nominalIndiTriplesAssertions = nominalIndi->hasIndividualName(); |
| 106 |
nominalIndiTriplesAssertions = true; |
| 107 |
} else { |
| 108 |
individualID = nextIndiID++; |
| 109 |
} |
| 110 |
|
| 111 |
CIndividualSaturationProcessNode* indiNode = CObjectParameterizingAllocator< CIndividualSaturationProcessNode,CProcessContext* >::allocateAndConstructAndParameterize(memMan,procContext); |
| 112 |
indiNode->initIndividualSaturationProcessNode(individualID,satConRefLink,satIndiRefLink); |
| 113 |
if (nominalIndi) { |
| 114 |
indiNode->setNominalIndividual(nominalIndi); |
| 115 |
} |
| 116 |
indiNode->setSeparated(separateSaturation); |
| 117 |
indiNode->setNominalIndividualTriplesAssertions(nominalIndiTriplesAssertions); |
| 118 |
|
| 119 |
if (satConRefLink) { |
| 120 |
satConRefLink->setIndividualProcessNodeForConcept(indiNode); |
| 121 |
} |
| 122 |
if (satIndiRefLink) { |
| 123 |
satIndiRefLink->setIndividualProcessNodeForIndividual(indiNode); |
| 124 |
} |
| 125 |
|
| 126 |
indiNodeVec->setLocalData(individualID,indiNode); |
| 127 |
|
| 128 |
bool processing = satCalcConsConstruct->getQueueProcessing(); |
| 129 |
CIndividualSaturationProcessNodeLinker* indiProcNodeLinker = CObjectAllocator< CIndividualSaturationProcessNodeLinker >::allocateAndConstruct(memMan); |
| 130 |
indiProcNodeLinker->initProcessNodeLinker(indiNode,processing); |
| 131 |
indiNode->setIndividualSaturationProcessNodeLinker(indiProcNodeLinker); |
| 132 |
if (processing) { |
| 133 |
dataBox->addIndividualSaturationProcessNodeLinker(indiProcNodeLinker); |
| 134 |
} |
| 135 |
|
| 136 |
satCalcConsConstruct = satCalcConsConstruct->getNextConstruct(); |
| 137 |
} |
| 138 |
|
| 139 |
CApproximatedSaturationCalculationProcessingConstruct* satCalcProcConstruct = approxSaturCalcJob->getSatisfiableCalculationProcessingConstructs(); |
| 140 |
while (satCalcProcConstruct) { |
| 141 |
CSaturationConceptReferenceLinking* satConRefLink = satCalcProcConstruct->getSaturationConceptReferenceLinking(); |
| 142 |
if (satConRefLink) { |
| 143 |
CIndividualSaturationProcessNode* indiNode = (CIndividualSaturationProcessNode*)satConRefLink->getIndividualProcessNodeForConcept(); |
| 144 |
if (!indiNode->isInitialized()) { |
| 145 |
CIndividualSaturationProcessNodeLinker* indiProcNodeLinker = indiNode->getIndividualSaturationProcessNodeLinker(); |
| 146 |
indiProcNodeLinker->setNegation(true); |
| 147 |
dataBox->addIndividualSaturationProcessNodeLinker(indiProcNodeLinker); |
| 148 |
} |
| 149 |
} |
| 150 |
CSaturationIndividualReferenceLinking* satIndiRefLink = satCalcProcConstruct->getSaturationIndividualReferenceLinking(); |
| 151 |
if (satIndiRefLink) { |
| 152 |
CIndividualSaturationProcessNode* indiNode = (CIndividualSaturationProcessNode*)satIndiRefLink->getIndividualProcessNodeForConcept(); |
| 153 |
if (!indiNode->isInitialized()) { |
| 154 |
|
| 155 |
CIndividualSaturationProcessNodeLinker* indiProcNodeLinker = indiNode->getIndividualSaturationProcessNodeLinker(); |
| 156 |
indiProcNodeLinker->setNegation(true); |
| 157 |
dataBox->addIndividualSaturationProcessNodeLinker(indiProcNodeLinker); |
| 158 |
} |
| 159 |
} |
| 160 |
satCalcProcConstruct = satCalcProcConstruct->getNextConstruct(); |
| 161 |
} |
| 162 |
|
| 163 |
if (additionalCalculatedCallback) { |
| 164 |
satCalcTask->addCallbackLinker(additionalCalculatedCallback); |
| 165 |
} |
| 166 |
|
| 167 |
satCalcTask->setSaturationIndividualsAnalysationObserver(approxSaturCalcJob->getSaturationIndividualsAnalysationObserver()); |
| 168 |
satCalcTask->setOccurrenceStatisticsCollectingAdapter(approxSaturCalcJob->getOccurrenceStatisticsCollectingAdapter()); |
| 169 |
|
| 170 |
satCalcTask->setConsistenceAdapter(approxSaturCalcJob->getSaturationTaskPreyingAdapter()); |
| 171 |
|
| 172 |
satCalcTask->setCalculationTaskType(CSatisfiableCalculationTask::CALCULATIONTABLEAUAPPROXIMATEDSATURATIONTASK); |
| 173 |
|
| 174 |
return satCalcTask; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
CSatisfiableCalculationTask* CSatisfiableCalculationTaskFromCalculationJobGenerator::createSatisfiableCalculationTask(CConcreteOntology *ontology, CCalculationJob* calculationJob, CCallbackData* additionalCalculatedCallback) { |
| 181 |
CSatisfiableCalculationJob* satCalcJob = dynamic_cast<CSatisfiableCalculationJob*>(calculationJob); |
| 182 |
cint64 firstPossibleNewIndividualID = 1; |
| 183 |
if (satCalcJob) { |
| 184 |
CSatisfiableCalculationTask* baseTask = nullptr; |
| 185 |
bool lastConDesReapplication = false; |
| 186 |
bool clearIndiProcessingQueue = false; |
| 187 |
if (satCalcJob->getConsecutivelyCalculationJobInstantiation()) { |
| 188 |
baseTask = dynamic_cast<CSatisfiableCalculationTask*>(satCalcJob->getConsecutivelyCalculationJobInstantiation()); |
| 189 |
lastConDesReapplication = false; |
| 190 |
} |
| 191 |
if (!baseTask) { |
| 192 |
CConsistence* consistence = ontology->getConsistence(); |
| 193 |
CConsistenceTaskData* consTaskData = nullptr; |
| 194 |
if (consistence) { |
| 195 |
CConsistenceData* consData = consistence->getConsistenceModelData(); |
| 196 |
if (consData) { |
| 197 |
consTaskData = dynamic_cast<CConsistenceTaskData*>(consData); |
| 198 |
} |
| 199 |
} |
| 200 |
if (consTaskData) { |
| 201 |
baseTask = consTaskData->getDeterministicSatisfiableTask(); |
| 202 |
if (satCalcJob->allowNonDeterministicSatisfiableCalculationContinuation()) { |
| 203 |
baseTask = consTaskData->getCompletionGraphCachedSatisfiableTask(); |
| 204 |
} else { |
| 205 |
clearIndiProcessingQueue = true; |
| 206 |
} |
| 207 |
firstPossibleNewIndividualID = consTaskData->getCompletionGraphCachedSatisfiableTask()->getProcessingDataBox()->getNextIndividualNodeID(false); |
| 208 |
lastConDesReapplication = baseTask != consTaskData->getCompletionGraphCachedSatisfiableTask(); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
return createSatisfiableCalculationTaskExtension(ontology,calculationJob,baseTask,lastConDesReapplication,clearIndiProcessingQueue, firstPossibleNewIndividualID,additionalCalculatedCallback); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
CApproximatedSaturationCalculationJob* approxSaturCalcJob = dynamic_cast<CApproximatedSaturationCalculationJob*>(calculationJob); |
| 217 |
if (approxSaturCalcJob) { |
| 218 |
CCalculationConfigurationExtension* calcConfig = approxSaturCalcJob->getCalculationConfiguration(); |
| 219 |
CSatisfiableCalculationTask* satCalcTask = nullptr; |
| 220 |
satCalcTask = createApproximatedSaturationCalculationTask(ontology,approxSaturCalcJob,additionalCalculatedCallback); |
| 221 |
return satCalcTask; |
| 222 |
|
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
return nullptr; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
CSatisfiableCalculationTask* CSatisfiableCalculationTaskFromCalculationJobGenerator::createSatisfiableCalculationTaskExtension(CCalculationJob* calculationJob, CSatisfiableCalculationTask* baseTask, bool lastConDesReapplication, bool clearIndiProcessingQueue, cint64 firstPossibleNewIndividualID, CCallbackData* additionalCalculatedCallback) { |
| 231 |
return createSatisfiableCalculationTaskExtension(calculationJob->getOntology(),calculationJob,baseTask,lastConDesReapplication,clearIndiProcessingQueue, firstPossibleNewIndividualID,additionalCalculatedCallback); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
CSatisfiableCalculationTask* CSatisfiableCalculationTaskFromCalculationJobGenerator::createSatisfiableCalculationTaskExtension(CConcreteOntology *ontology, CCalculationJob* calculationJob, CSatisfiableCalculationTask* baseTask, bool lastConDesReapplication, bool clearIndiProcessingQueue, cint64 firstPossibleNewIndividualID, CCallbackData* additionalCalculatedCallback) { |
| 237 |
|
| 238 |
CSatisfiableCalculationJob* satCalcJob = dynamic_cast<CSatisfiableCalculationJob*>(calculationJob); |
| 239 |
|
| 240 |
if (satCalcJob) { |
| 241 |
|
| 242 |
bool requiresTaskCalc = false; |
| 243 |
|
| 244 |
CSatisfiableCalculationTask* satCalcTask = CObjectMemoryPoolAllocator<CSatisfiableCalculationTask>::allocateAndConstructWithMemroyPool(mGenTaskHandleContext->getTaskHandleMemoryAllocationManager()); |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
bool recreateNodesForIndividuals = false; |
| 249 |
if (clearIndiProcessingQueue) { |
| 250 |
bool avoidIndividualReprocessing = satCalcJob->getCalculationConfiguration()->isAvoidRepeatedIndividualProcessingActivated(); |
| 251 |
if (!avoidIndividualReprocessing) { |
| 252 |
clearIndiProcessingQueue = false; |
| 253 |
|
| 254 |
if (satCalcJob->getCalculationConfiguration()->isForceNodesRecreationForRepeatedIndividualProcessingActivated()) { |
| 255 |
baseTask = nullptr; |
| 256 |
|
| 257 |
if (!recreateNodesForIndividuals) { |
| 258 |
for (CSatisfiableCalculationConstruct* satCalcConstructIt = satCalcJob->getSatisfiableCalculationConstructs(); satCalcConstructIt && !clearIndiProcessingQueue; satCalcConstructIt = satCalcConstructIt->getNextConstruct()) { |
| 259 |
CIndividual* individual = satCalcConstructIt->getIndividual(); |
| 260 |
if (individual) { |
| 261 |
recreateNodesForIndividuals = true; |
| 262 |
} |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
if (!recreateNodesForIndividuals) { |
| 267 |
if (calculationJob->getOntology()->getStructureSummary()->hasNominalOccurrence() || calculationJob->getOntology()->getTBox()->getUniversalConnectionNominalValueConcept()) { |
| 268 |
recreateNodesForIndividuals = true; |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
} |
| 273 |
} else { |
| 274 |
|
| 275 |
bool confCompletionGraphCaching = satCalcJob->getCalculationConfiguration()->isCompletionGraphCachingActivated(); |
| 276 |
if (!confCompletionGraphCaching) { |
| 277 |
|
| 278 |
if (clearIndiProcessingQueue) { |
| 279 |
for (CSatisfiableCalculationConstruct* satCalcConstructIt = satCalcJob->getSatisfiableCalculationConstructs(); satCalcConstructIt && !clearIndiProcessingQueue; satCalcConstructIt = satCalcConstructIt->getNextConstruct()) { |
| 280 |
CIndividual* individual = satCalcConstructIt->getIndividual(); |
| 281 |
if (individual) { |
| 282 |
clearIndiProcessingQueue = false; |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
if (clearIndiProcessingQueue) { |
| 288 |
if (calculationJob->getOntology()->getStructureSummary()->hasNominalOccurrence() || calculationJob->getOntology()->getTBox()->getUniversalConnectionNominalValueConcept()) { |
| 289 |
clearIndiProcessingQueue = false; |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
if (baseTask) { |
| 298 |
satCalcTask->initUndependedSatisfiableCalculationTask(baseTask,satCalcJob->getCalculationConfiguration(),satCalcJob->getCalclulationStatisticsCollector(),mGenTaskHandleContext); |
| 299 |
} else { |
| 300 |
satCalcTask->initSatisfiableCalculationTask(ontology,satCalcJob->getCalculationConfiguration(),satCalcJob->getCalclulationStatisticsCollector(),mGenTaskHandleContext); |
| 301 |
} |
| 302 |
CProcessContext* procContext = satCalcTask->getProcessContext(mGenTaskHandleContext); |
| 303 |
if (baseTask) { |
| 304 |
CProcessTagger* processTagger = procContext->getUsedProcessTagger(); |
| 305 |
processTagger->incLocalizationTag(); |
| 306 |
} |
| 307 |
|
| 308 |
satCalcTask->setConsistenceAdapter(satCalcJob->getSatisfiableTaskPreyingAdapter()); |
| 309 |
satCalcTask->setClassificationMessageAdapter(satCalcJob->getSatisfiableClassificationMessageAdapter()); |
| 310 |
satCalcTask->setRealizationMarkedCandidatesMessageAdapter(satCalcJob->getRealizationMarkedCandidatesMessageAdapter()); |
| 311 |
satCalcTask->setSatisfiableTaskIncrementalConsistencyTestingAdapter(satCalcJob->getSatisfiableTaskIncrementalConsistencyTestingAdapter()); |
| 312 |
satCalcTask->setSatisfiableTaskIndividualDependenceTrackingAdapter(satCalcJob->getSatisfiableTaskIndividualDependenceTrackingAdapter()); |
| 313 |
satCalcTask->setPossibleAssertionCollectionAdapter(satCalcJob->getPossibleAssertionCollectionAdapter()); |
| 314 |
satCalcTask->setSatisfiableClassificationRoleMarkedMessageAdapter(satCalcJob->getSatisfiableClassificationRoleMarkedMessageAdapter()); |
| 315 |
satCalcTask->setSatisfiableAnswererSubsumptionMessageAdapter(satCalcJob->getSatisfiableAnswererSubsumptionMessageAdapter()); |
| 316 |
satCalcTask->setSatisfiableAnswererInstancePropagationMessageAdapter(satCalcJob->getSatisfiableAnswererInstancePropagationMessageAdapter()); |
| 317 |
satCalcTask->setSatisfiableAnswererBindingPropagationAdapter(satCalcJob->getSatisfiableAnswererBindingPropagationAdapter()); |
| 318 |
satCalcTask->setSatisfiablePossibleInstancesMergingAdapter(satCalcJob->getSatisfiablePossibleInstancesMergingAdapter()); |
| 319 |
satCalcTask->setSatisfiableRepresentativeBackendCacheUpdatingAdapter(satCalcJob->getSatisfiableRepresentativeBackendCacheUpdatingAdapter()); |
| 320 |
satCalcTask->setSatisfiableAnswererMaterializationAdapter(satCalcJob->getSatisfiableAnswererMaterializationAdapter()); |
| 321 |
satCalcTask->setCancellationAdapter(satCalcJob->getCancellationAdapter()); |
| 322 |
|
| 323 |
|
| 324 |
CProcessingDataBox* dataBox = satCalcTask->getProcessingDataBox(); |
| 325 |
if (baseTask) { |
| 326 |
dataBox->setProcessingOntology(ontology); |
| 327 |
} |
| 328 |
dataBox->setConstructedIndividualNode(nullptr); |
| 329 |
dataBox->setReapplicationLastConceptDesciptorOnLastIndividualNodeRequired(lastConDesReapplication); |
| 330 |
|
| 331 |
if (satCalcTask->getSatisfiableTaskIncrementalConsistencyTestingAdapter()) { |
| 332 |
CConcreteOntology* prevOntology = satCalcTask->getSatisfiableTaskIncrementalConsistencyTestingAdapter()->getPreviousConsistentOntology(); |
| 333 |
|
| 334 |
CSatisfiableCalculationTask* prevDetConsTask = nullptr; |
| 335 |
CSatisfiableCalculationTask* prevNondetConsTask = nullptr; |
| 336 |
CConsistence* prevConsistence = prevOntology->getConsistence(); |
| 337 |
CConsistenceTaskData* prevConsTaskData = nullptr; |
| 338 |
if (prevConsistence) { |
| 339 |
CConsistenceData* prevConsData = prevConsistence->getConsistenceModelData(); |
| 340 |
if (prevConsData) { |
| 341 |
prevConsTaskData = dynamic_cast<CConsistenceTaskData*>(prevConsData); |
| 342 |
} |
| 343 |
} |
| 344 |
if (prevConsTaskData) { |
| 345 |
prevDetConsTask = prevConsTaskData->getDeterministicSatisfiableTask(); |
| 346 |
prevNondetConsTask = prevConsTaskData->getCompletionGraphCachedSatisfiableTask(); |
| 347 |
} |
| 348 |
if (prevDetConsTask) { |
| 349 |
CProcessTagger* prevProcessTagger = prevDetConsTask->getProcessingDataBox()->getProcessContext()->getUsedProcessTagger(); |
| 350 |
CProcessTagger* processTagger = procContext->getUsedProcessTagger(); |
| 351 |
processTagger->initProcessTagger(prevProcessTagger); |
| 352 |
processTagger->incLocalizationTag(); |
| 353 |
} |
| 354 |
if (prevNondetConsTask) { |
| 355 |
firstPossibleNewIndividualID = prevNondetConsTask->getProcessingDataBox()->getNextIndividualNodeID(false); |
| 356 |
} |
| 357 |
prevDetConsTask->getProcessingDataBox()->setIncrementalExpansionID(satCalcTask->getSatisfiableTaskIncrementalConsistencyTestingAdapter()->getIncrementalRevisionID()); |
| 358 |
} |
| 359 |
if (satCalcTask->getSatisfiableTaskIndividualDependenceTrackingAdapter()) { |
| 360 |
dataBox->setIndividualDependenceTrackingRequired(true); |
| 361 |
} |
| 362 |
|
| 363 |
CIndividualProcessNodeVector* indiNodeVec = dataBox->getIndividualProcessNodeVector(); |
| 364 |
|
| 365 |
if (clearIndiProcessingQueue) { |
| 366 |
dataBox->clearIndividualProcessingQueues(); |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
CIndividualUnsortedProcessingQueue* indiNodeQueue = dataBox->getIndividualImmediatelyProcessingQueue(true); |
| 371 |
|
| 372 |
CDependencyTrackPoint* independentBaseDepTrackPoint = dataBox->getBranchingTree(true)->getBaseDependencyNode(true)->getContinueDependencyTrackPoint(); |
| 373 |
|
| 374 |
CMemoryAllocationManager* memMan = procContext->getUsedMemoryAllocationManager(); |
| 375 |
|
| 376 |
|
| 377 |
firstPossibleNewIndividualID = qMax(firstPossibleNewIndividualID,indiNodeVec->getItemMaxIndex() + 1); |
| 378 |
|
| 379 |
cint64 baseIndiID = firstPossibleNewIndividualID; |
| 380 |
cint64 constructionIndiCount = 0; |
| 381 |
CIndividualVector* baseIndiVec = dataBox->getIndividualVector(true); |
| 382 |
|
| 383 |
CSatisfiableCalculationConstruct* satCalcConstruct = satCalcJob->getSatisfiableCalculationConstructs(); |
| 384 |
while (satCalcConstruct) { |
| 385 |
++constructionIndiCount; |
| 386 |
CIndividual* individual = satCalcConstruct->getIndividual(); |
| 387 |
cint64 individualNodeID = baseIndiID+satCalcConstruct->getRelativeNewNodeID(); |
| 388 |
bool nominalIndiTriplesAssertions = false; |
| 389 |
|
| 390 |
if (!individual && satCalcConstruct->getIndividualID() >= 0 && satCalcConstruct->getIndividualID() <= baseIndiVec->getItemMaxIndex()) { |
| 391 |
individual = baseIndiVec->getData(satCalcConstruct->getIndividualID()); |
| 392 |
} |
| 393 |
|
| 394 |
if (!individual && satCalcConstruct->getIndividualID() >= 0) { |
| 395 |
individualNodeID = -satCalcConstruct->getIndividualID(); |
| 396 |
individual = CObjectAllocator<CIndividual>::allocateAndConstruct(memMan); |
| 397 |
individual->initIndividual(-individualNodeID); |
| 398 |
individual->setTemporaryIndividual(true); |
| 399 |
baseIndiVec->setLocalData(-individualNodeID, individual); |
| 400 |
|
| 401 |
nominalIndiTriplesAssertions = true; |
| 402 |
} else if (individual) { |
| 403 |
individualNodeID = -(individual->getIndividualID()); |
| 404 |
nominalIndiTriplesAssertions = true; |
| 405 |
} else { |
| 406 |
cint64 fixedIndiID = satCalcConstruct->getIndividualID(); |
| 407 |
if (fixedIndiID >= 0) { |
| 408 |
individualNodeID = fixedIndiID; |
| 409 |
} |
| 410 |
} |
| 411 |
firstPossibleNewIndividualID = qMax(firstPossibleNewIndividualID,individualNodeID+1); |
| 412 |
|
| 413 |
CXSortedNegLinker<CConcept*>* satConJobLinker = nullptr; |
| 414 |
CSatisfiableCalculationConceptConstruct* satConCalcConstuct = dynamic_cast<CSatisfiableCalculationConceptConstruct*>(satCalcConstruct); |
| 415 |
if (satConCalcConstuct) { |
| 416 |
satConJobLinker = satConCalcConstuct->getConstructConceptLinker(); |
| 417 |
} |
| 418 |
|
| 419 |
CIndividualProcessNode* refIndiNode = indiNodeVec->getData(individualNodeID); |
| 420 |
// check whether individual is already processed |
| 421 |
if (satConJobLinker || !refIndiNode || !baseIndiVec || baseIndiVec->getData(-individualNodeID) != individual) { |
| 422 |
requiresTaskCalc = true; |
| 423 |
CIndividualProcessNode* indi = indiNodeVec->getLocalData(individualNodeID); |
| 424 |
CIndividualProcessNode* localIndi = indi; |
| 425 |
if (!localIndi) { |
| 426 |
localIndi = CObjectParameterizingAllocator< CIndividualProcessNode,CProcessContext* >::allocateAndConstructAndParameterize(memMan,procContext); |
| 427 |
localIndi->initDependencyTracker(independentBaseDepTrackPoint); |
| 428 |
if (refIndiNode) { |
| 429 |
while (refIndiNode->hasMergedIntoIndividualNodeID()) { |
| 430 |
cint64 corrIndiID = refIndiNode->getMergedIntoIndividualNodeID(); |
| 431 |
refIndiNode = indiNodeVec->getData(corrIndiID); |
| 432 |
individualNodeID = corrIndiID; |
| 433 |
} |
| 434 |
localIndi->initIndividualProcessNode(refIndiNode); |
| 435 |
localIndi->clearProcessingQueued(); |
| 436 |
localIndi->clearProcessingRestrictionFlags(CIndividualProcessNode::PRFCACHEDCOMPUTEDTYPESADDED); |
| 437 |
} else if (individual) { |
| 438 |
localIndi->setAssertionDataLinker(individual->getAssertionDataLinker()); |
| 439 |
localIndi->setAssertionConceptLinker(individual->getAssertionConceptLinker()); |
| 440 |
localIndi->setAssertionRoleLinker(individual->getAssertionRoleLinker()); |
| 441 |
localIndi->setReverseAssertionRoleLinker(individual->getReverseAssertionRoleLinker()); |
| 442 |
} |
| 443 |
|
| 444 |
localIndi->setIndividualNodeID(individualNodeID); |
| 445 |
if (individual) { |
| 446 |
if (!localIndi->getNominalIndividual()) { |
| 447 |
localIndi->setNominalIndividual(individual); |
| 448 |
} |
| 449 |
localIndi->setIndividualType(CIndividualProcessNode::NOMINALINDIVIDUALTYPE); |
| 450 |
} |
| 451 |
if (!individual || baseTask) { |
| 452 |
localIndi->addProcessingRestrictionFlags(CIndividualProcessNode::PRFINVALIDBLOCKINGORCACHING); |
| 453 |
} |
| 454 |
|
| 455 |
localIndi->setInitializingConceptLinker(nullptr); |
| 456 |
indiNodeVec->setLocalData(individualNodeID,localIndi); |
| 457 |
indiNodeQueue->insertIndiviudalProcessNode(localIndi); |
| 458 |
|
| 459 |
if (dataBox->getConstructedIndividualNode() == nullptr) { |
| 460 |
dataBox->setConstructedIndividualNode(localIndi); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
if (nominalIndiTriplesAssertions) { |
| 465 |
localIndi->setNominalIndividualTriplesAssertions(true); |
| 466 |
} |
| 467 |
|
| 468 |
CXSortedNegLinker<CConcept*>* initConLinker = nullptr; |
| 469 |
while (satConJobLinker) { |
| 470 |
CXSortedNegLinker<CConcept*>* tmpConLinker = CObjectAllocator< CXSortedNegLinker<CConcept*> >::allocateAndConstruct(memMan); |
| 471 |
initConLinker = tmpConLinker->initNegLinker(satConJobLinker->getData(),satConJobLinker->getNegation(),initConLinker); |
| 472 |
satConJobLinker = satConJobLinker->getNext(); |
| 473 |
} |
| 474 |
localIndi->addInitializingConceptLinker(initConLinker); |
| 475 |
|
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
satCalcConstruct = satCalcConstruct->getNextConstruct(); |
| 480 |
} |
| 481 |
|
| 482 |
if (recreateNodesForIndividuals) { |
| 483 |
|
| 484 |
CIndividualVector* indiVec = ontology->getABox()->getIndividualVector(false); |
| 485 |
QSet<CIndividual*>* activeIndiSet = ontology->getABox()->getActiveIndividualSet(false); |
| 486 |
cint64 maxTriplesIndexedIndiId = 0; |
| 487 |
cint64 maxABoxIndiId = 0; |
| 488 |
COntologyTriplesAssertionsAccessor* triplesAccessor = ontology->getOntologyTriplesData()->getTripleAssertionAccessor(); |
| 489 |
if (triplesAccessor) { |
| 490 |
maxTriplesIndexedIndiId = ontology->getOntologyTriplesData()->getTripleAssertionAccessor()->getMaxIndexedIndividualId(); |
| 491 |
} |
| 492 |
if (indiVec) { |
| 493 |
cint64 indiCount = indiVec->getItemCount(); |
| 494 |
for (cint64 i = 0; i < indiCount; ++i) { |
| 495 |
CIndividual* indi = indiVec->getData(i); |
| 496 |
if (indi && activeIndiSet->contains(indi)) { |
| 497 |
createIndividualNominalNodeForCalculationTask(ontology, indi, i, independentBaseDepTrackPoint, indiNodeQueue, indiNodeVec, procContext, memMan); |
| 498 |
} else if (i <= maxTriplesIndexedIndiId) { |
| 499 |
createIndividualNominalNodeForCalculationTask(ontology, indi, i, independentBaseDepTrackPoint, indiNodeQueue, indiNodeVec, procContext, memMan); |
| 500 |
} |
| 501 |
maxABoxIndiId = qMax(i, maxABoxIndiId); |
| 502 |
} |
| 503 |
} |
| 504 |
for (cint64 idx = maxABoxIndiId + 1; idx <= maxTriplesIndexedIndiId; ++idx) { |
| 505 |
createIndividualNominalNodeForCalculationTask(ontology, nullptr, idx, independentBaseDepTrackPoint, indiNodeQueue, indiNodeVec, procContext, memMan); |
| 506 |
} |
| 507 |
|
| 508 |
} |
| 509 |
|
| 510 |
dataBox->setFirstPossibleIndividualNodeID(firstPossibleNewIndividualID); |
| 511 |
dataBox->setMultipleConstructionIndividualNodes(constructionIndiCount > 1); |
| 512 |
|
| 513 |
if (additionalCalculatedCallback) { |
| 514 |
satCalcTask->addCallbackLinker(additionalCalculatedCallback); |
| 515 |
} |
| 516 |
|
| 517 |
return satCalcTask; |
| 518 |
|
| 519 |
} |
| 520 |
return nullptr; |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
bool CSatisfiableCalculationTaskFromCalculationJobGenerator::createIndividualNominalNodeForCalculationTask(CConcreteOntology *ontology, CIndividual* indi, cint64 i, CDependencyTrackPoint* independentBaseDepTrackPoint, CIndividualUnsortedProcessingQueue* indiNodeQueue, CIndividualProcessNodeVector* indiNodeVec, CProcessContext* procContext, CMemoryAllocationManager* memMan) { |
| 526 |
CIndividualProcessNode* indiNode = indiNodeVec->getData(-i); |
| 527 |
if (!indiNode) { |
| 528 |
indiNode = CObjectParameterizingAllocator< CIndividualProcessNode, CProcessContext* >::allocateAndConstructAndParameterize(memMan, procContext); |
| 529 |
indiNode->initDependencyTracker(independentBaseDepTrackPoint); |
| 530 |
if (indi) { |
| 531 |
indiNode->setAssertionDataLinker(indi->getAssertionDataLinker()); |
| 532 |
indiNode->setAssertionConceptLinker(indi->getAssertionConceptLinker()); |
| 533 |
indiNode->setAssertionRoleLinker(indi->getAssertionRoleLinker()); |
| 534 |
indiNode->setReverseAssertionRoleLinker(indi->getReverseAssertionRoleLinker()); |
| 535 |
} |
| 536 |
indiNode->setNominalIndividual(indi); |
| 537 |
|
| 538 |
indiNode->setIndividualNodeID(-i); |
| 539 |
indiNode->setIndividualType(CIndividualProcessNode::NOMINALINDIVIDUALTYPE); |
| 540 |
|
| 541 |
indiNodeVec->setLocalData(i, indiNode); |
| 542 |
indiNodeQueue->insertIndiviudalProcessNode(indiNode); |
| 543 |
return true; |
| 544 |
} |
| 545 |
return false; |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
}; // end namespace Generator |
| 551 |
|
| 552 |
}; // end namespace Reasoner |
| 553 |
|
| 554 |
}; // end namespace Konclude |