| 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 "CSaturationNodeExpansionCacheHandler.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Algorithm { |
| 31 |
|
| 32 |
CSaturationNodeExpansionCacheHandler::CSaturationNodeExpansionCacheHandler(CSaturationNodeAssociatedExpansionCacheReader* satCacheReader, CSaturationNodeAssociatedExpansionCacheWriter* satCacheWriter) { |
| 33 |
mSatCacheReader = satCacheReader; |
| 34 |
mSatCacheWriter = satCacheWriter; |
| 35 |
|
| 36 |
mTmpContext = nullptr; |
| 37 |
mMemAllocMan = nullptr; |
| 38 |
mWriteData = nullptr; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
CIndividualSaturationProcessNode* CSaturationNodeExpansionCacheHandler::getSaturationIndividualNodeForConcept(CConcept* concept, bool negation, CCalculationAlgorithmContext* calcAlgContext) { |
| 44 |
|
| 45 |
CConceptData* conceptData = concept->getConceptData(); |
| 46 |
CIndividualSaturationProcessNode* saturationIndiNode = nullptr; |
| 47 |
if (conceptData) { |
| 48 |
CConceptProcessData* conProcData = (CConceptProcessData*)conceptData; |
| 49 |
CConceptReferenceLinking* conRefLinking = conProcData->getConceptReferenceLinking(); |
| 50 |
if (conRefLinking) { |
| 51 |
CConceptSaturationReferenceLinkingData* confSatRefLinkingData = (CConceptSaturationReferenceLinkingData*)conRefLinking; |
| 52 |
CSaturationConceptReferenceLinking* satCalcRefLinkData = confSatRefLinkingData->getConceptSaturationReferenceLinkingData(false); |
| 53 |
if (satCalcRefLinkData) { |
| 54 |
saturationIndiNode = (CIndividualSaturationProcessNode*)satCalcRefLinkData->getIndividualProcessNodeForConcept(); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
return saturationIndiNode; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
bool CSaturationNodeExpansionCacheHandler::cacheUnsatisfiableConcept(CConcept* concept, CCalculationAlgorithmContext* calcAlgContext) { |
| 66 |
CIndividualSaturationProcessNode* saturationIndiNode = getSaturationIndividualNodeForConcept(concept,false,calcAlgContext); |
| 67 |
|
| 68 |
if (saturationIndiNode && !saturationIndiNode->getIndirectStatusFlags()->hasClashedFlag()) { |
| 69 |
// try caching |
| 70 |
prepareCacheMessages(calcAlgContext); |
| 71 |
CTaskMemoryPoolAllocationManager* satCacheMemMan = mMemAllocMan; |
| 72 |
CContextBase* tmpContext = mTmpContext; |
| 73 |
|
| 74 |
CSaturationNodeAssociatedExpansionCacheUnsatisfiabilityWriteData* unsatWriteData = CObjectAllocator< CSaturationNodeAssociatedExpansionCacheUnsatisfiabilityWriteData >::allocateAndConstruct(satCacheMemMan); |
| 75 |
unsatWriteData->initUnsatisfiabilityWriteData(saturationIndiNode); |
| 76 |
addCacheMessages(unsatWriteData,calcAlgContext); |
| 77 |
return true; |
| 78 |
} |
| 79 |
|
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
bool CSaturationNodeExpansionCacheHandler::isConceptUnsatisfiableCached(CConcept* concept, bool negation, CCalculationAlgorithmContext* calcAlgContext) { |
| 86 |
CIndividualSaturationProcessNode* saturationIndiNode = getSaturationIndividualNodeForConcept(concept,negation,calcAlgContext); |
| 87 |
if (saturationIndiNode) { |
| 88 |
return saturationIndiNode->getIndirectStatusFlags()->hasClashedFlag(); |
| 89 |
} |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
bool CSaturationNodeExpansionCacheHandler::isNodeSatisfiableCached(CIndividualProcessNode* individualProcessNode, CSaturationNodeAssociatedConceptExpansion*& expansion, CCalculationAlgorithmContext* calcAlgContext) { |
| 95 |
CIndividualNodeSaturationBlockingData* satBlockData = individualProcessNode->getIndividualSaturationBlockingData(false); |
| 96 |
CReapplyConceptLabelSet* conSet = individualProcessNode->getReapplyConceptLabelSet(false); |
| 97 |
if (conSet && satBlockData) { |
| 98 |
cint64 totalConceptCount = conSet->getConceptCount(); |
| 99 |
CConceptDescriptor* lastAddedConDes = conSet->getAddingSortedConceptDescriptionLinker(); |
| 100 |
|
| 101 |
|
| 102 |
CIndividualSaturationProcessNode* saturationNode = satBlockData->getSaturationIndividualNode(); |
| 103 |
|
| 104 |
|
| 105 |
if (satBlockData->getLastConfirmedConceptDescriptior() == lastAddedConDes) { |
| 106 |
CIndividualSaturationProcessNodeStatusFlags* flags = saturationNode->getIndirectStatusFlags(); |
| 107 |
if (!flags->hasFlags(CIndividualSaturationProcessNodeStatusFlags::INDSATFLAGINSUFFICIENT | CIndividualSaturationProcessNodeStatusFlags::INDSATFLAGCLASHED,false)) { |
| 108 |
return true; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
CReapplyConceptSaturationLabelSet* satConSet = saturationNode->getReapplyConceptSaturationLabelSet(false); |
| 114 |
|
| 115 |
CSaturationNodeAssociatedExpansionCacheEntry* cacheEntry = mSatCacheReader->getCacheEntry(saturationNode); |
| 116 |
if (cacheEntry) { |
| 117 |
CConceptDescriptor* lastConDes = satBlockData->getLastConfirmedConceptDescriptior(); |
| 118 |
CConceptDescriptor* conDes = conSet->getAddingSortedConceptDescriptionLinker(); |
| 119 |
cint64 conSetSignature = conSet->getConceptSignature()->getSignatureValue(); |
| 120 |
|
| 121 |
|
| 122 |
CSaturationNodeAssociatedDeterministicConceptExpansion* detExpansion = cacheEntry->getDeterministicConceptExpansion(); |
| 123 |
if (detExpansion && !detExpansion->requiresNonDeterministicExpansion()) { |
| 124 |
if (testNodeMatchingExpansion(detExpansion,nullptr,conSet,satBlockData,calcAlgContext)) { |
| 125 |
expansion = detExpansion; |
| 126 |
return true; |
| 127 |
} |
| 128 |
} |
| 129 |
CSaturationNodeAssociatedNondeterministicConceptExpansion* nondetExpansionLinker = cacheEntry->getNondeterministicConceptExpansionLinker(); |
| 130 |
for (CSaturationNodeAssociatedNondeterministicConceptExpansion* nondetExpansionLinkerIt = nondetExpansionLinker; nondetExpansionLinkerIt; nondetExpansionLinkerIt = nondetExpansionLinkerIt->getNext()) { |
| 131 |
CSaturationNodeAssociatedNondeterministicConceptExpansion* nondetExpansion = nondetExpansionLinkerIt; |
| 132 |
if (testNodeMatchingExpansion(nondetExpansion,detExpansion,conSet,satBlockData,calcAlgContext)) { |
| 133 |
expansion = nondetExpansion; |
| 134 |
return true; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
} |
| 142 |
return false; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
bool CSaturationNodeExpansionCacheHandler::getCachedDeterministicExpansion(CIndividualSaturationProcessNode* saturationNode, CSaturationNodeAssociatedDeterministicConceptExpansion*& expansion, CCalculationAlgorithmContext* calcAlgContext) { |
| 149 |
CSaturationNodeAssociatedExpansionCacheEntry* cacheEntry = mSatCacheReader->getCacheEntry(saturationNode); |
| 150 |
if (cacheEntry) { |
| 151 |
CSaturationNodeAssociatedDeterministicConceptExpansion* detExpansion = cacheEntry->getDeterministicConceptExpansion(); |
| 152 |
if (detExpansion) { |
| 153 |
expansion = detExpansion; |
| 154 |
return true; |
| 155 |
} |
| 156 |
} |
| 157 |
return false; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
bool CSaturationNodeExpansionCacheHandler::testNodeMatchingExpansion(CSaturationNodeAssociatedConceptExpansion* expansion, CSaturationNodeAssociatedConceptExpansion* alternativeExpansion, CReapplyConceptLabelSet* conSet, CIndividualNodeSaturationBlockingData* satBlockData, CCalculationAlgorithmContext* calcAlgContext) { |
| 163 |
cint64 conSetSignature = conSet->getConceptSignature()->getSignatureValue(); |
| 164 |
if (expansion->getConceptSetSignature() != conSetSignature) { |
| 165 |
return false; |
| 166 |
} |
| 167 |
cint64 totalConceptCount = conSet->getConceptCount(); |
| 168 |
if (expansion->getTotalConceptCount() != totalConceptCount) { |
| 169 |
return false; |
| 170 |
} |
| 171 |
CConceptDescriptor* lastConDes = satBlockData->getLastConfirmedConceptDescriptior(); |
| 172 |
CConceptDescriptor* conDes = conSet->getAddingSortedConceptDescriptionLinker(); |
| 173 |
|
| 174 |
for (CConceptDescriptor* conDesIt = conDes; conDesIt != lastConDes; conDesIt = conDesIt->getNext()) { |
| 175 |
CCacheValue cacheValue(getCacheValueForConcept(conDesIt,calcAlgContext)); |
| 176 |
if (!expansion->hasConceptExpansionLinker(&cacheValue)) { |
| 177 |
if (!alternativeExpansion || !alternativeExpansion->hasConceptExpansionLinker(&cacheValue)) { |
| 178 |
return false; |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
CSaturationNodeAssociatedDependentNominalSet* dependentNominalSet = expansion->getDependentNominalSet(false); |
| 184 |
if (dependentNominalSet) { |
| 185 |
CIndividualProcessNodeVector* indiVec = calcAlgContext->getProcessingDataBox()->getIndividualProcessNodeVector(); |
| 186 |
for (CSaturationNodeAssociatedDependentNominalSet::const_iterator it = dependentNominalSet->constBegin(), itEnd = dependentNominalSet->constEnd(); it != itEnd; ++it) { |
| 187 |
cint64 dependentNominalID = -(*it); |
| 188 |
bool nominalStillCached = false; |
| 189 |
CIndividualProcessNode* indiNode = indiVec->getData(dependentNominalID); |
| 190 |
if (indiNode) { |
| 191 |
if (dependentNominalID <= calcAlgContext->getMaxCompletionGraphCachedIndividualNodeID() && indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHED)) { |
| 192 |
if (!indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHINGINVALID) && !indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHINGINVALIDATED)) { |
| 193 |
nominalStillCached = true; |
| 194 |
} |
| 195 |
} else if (indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFSYNCHRONIZEDBACKEND)) { |
| 196 |
nominalStillCached = true; |
| 197 |
} |
| 198 |
} else { |
| 199 |
nominalStillCached = true; |
| 200 |
} |
| 201 |
if (!nominalStillCached) { |
| 202 |
return false; |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
return true; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
CCacheValue CSaturationNodeExpansionCacheHandler::getCacheValueForConcept(CConceptDescriptor* conDes, CCalculationAlgorithmContext* calcAlgContext) { |
| 212 |
return getCacheValueForConcept(conDes->getConcept(),conDes->isNegated(),calcAlgContext); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
CCacheValue CSaturationNodeExpansionCacheHandler::getCacheValueForConcept(CConcept* concept, bool negation, CCalculationAlgorithmContext* calcAlgContext) { |
| 218 |
cint64 conTag = concept->getConceptTag(); |
| 219 |
CCacheValue::CACHEVALUEIDENTIFIER cacheValueIdentifier = CCacheValue::CACHEVALTAGANDCONCEPT; |
| 220 |
if (negation) { |
| 221 |
cacheValueIdentifier = CCacheValue::CACHEVALTAGANDNEGATEDCONCEPT; |
| 222 |
} |
| 223 |
CCacheValue cacheValue; |
| 224 |
cacheValue.initCacheValue(conTag,(cint64)concept,cacheValueIdentifier); |
| 225 |
return cacheValue; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
bool CSaturationNodeExpansionCacheHandler::prepareCacheMessages(CCalculationAlgorithmContext* calcAlgContext) { |
| 231 |
if (!mMemAllocMan) { |
| 232 |
CTaskMemoryPoolAllocationManager satCacheMemManCreaterMemMan(&mMemPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager()); |
| 233 |
mMemAllocMan = CObjectAllocator<CTaskMemoryPoolAllocationManager>::allocateAndConstruct(&satCacheMemManCreaterMemMan); |
| 234 |
mMemAllocMan->initTaskMemoryPoolAllocationManager(&mMemPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager()); |
| 235 |
mTmpContext = CObjectParameterizingAllocator< CContextBase,CMemoryAllocationManager* >::allocateAndConstructAndParameterize(mMemAllocMan,mMemAllocMan); |
| 236 |
return true; |
| 237 |
} |
| 238 |
return false; |
| 239 |
} |
| 240 |
|
| 241 |
bool CSaturationNodeExpansionCacheHandler::commitCacheMessages(CCalculationAlgorithmContext* calcAlgContext) { |
| 242 |
if (mWriteData) { |
| 243 |
CSaturationNodeAssociatedExpansionCacheWriteData* commitWriteData = nullptr; |
| 244 |
CSaturationNodeAssociatedExpansionCacheWriteData* writeDataIt = mWriteData; |
| 245 |
while (writeDataIt) { |
| 246 |
CSaturationNodeAssociatedExpansionCacheWriteData* tmpWriteData = writeDataIt; |
| 247 |
writeDataIt = (CSaturationNodeAssociatedExpansionCacheWriteData*)writeDataIt->getNext(); |
| 248 |
tmpWriteData->clearNext(); |
| 249 |
if (commitWriteData) { |
| 250 |
commitWriteData = (CSaturationNodeAssociatedExpansionCacheWriteData*)tmpWriteData->append(commitWriteData); |
| 251 |
} else { |
| 252 |
commitWriteData = tmpWriteData; |
| 253 |
} |
| 254 |
} |
| 255 |
mSatCacheWriter->writeCacheData(commitWriteData,mMemPoolCon.takeMemoryPools()); |
| 256 |
mWriteData = nullptr; |
| 257 |
mMemAllocMan = nullptr; |
| 258 |
mTmpContext = nullptr; |
| 259 |
return true; |
| 260 |
} |
| 261 |
return false; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
bool CSaturationNodeExpansionCacheHandler::addCacheMessages(CSaturationNodeAssociatedExpansionCacheWriteData* expandWriteData, CCalculationAlgorithmContext* calcAlgContext) { |
| 267 |
if (mWriteData) { |
| 268 |
mWriteData = (CSaturationNodeAssociatedExpansionCacheWriteData*)expandWriteData->append(mWriteData); |
| 269 |
} else { |
| 270 |
mWriteData = expandWriteData; |
| 271 |
} |
| 272 |
//commitCacheMessages(calcAlgContext); |
| 273 |
return true; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
bool CSaturationNodeExpansionCacheHandler::testNodeCachingPossible(CIndividualProcessNode* individualProcessNode, bool& onlyIfCompletelyDeterministic, bool& onlyAllNondeterministic, CSaturationNodeAssociatedExpansionCacheEntry*& cacheEntry, CCalculationAlgorithmContext* calcAlgContext) { |
| 282 |
onlyIfCompletelyDeterministic = false; |
| 283 |
cacheEntry = nullptr; |
| 284 |
CIndividualNodeSaturationBlockingData* satBlockData = individualProcessNode->getIndividualSaturationBlockingData(false); |
| 285 |
CReapplyConceptLabelSet* conSet = individualProcessNode->getReapplyConceptLabelSet(false); |
| 286 |
if (conSet && satBlockData) { |
| 287 |
cint64 totalConceptCount = conSet->getConceptCount(); |
| 288 |
CConceptDescriptor* lastAddedConDes = conSet->getAddingSortedConceptDescriptionLinker(); |
| 289 |
|
| 290 |
CIndividualSaturationProcessNode* saturationNode = satBlockData->getSaturationIndividualNode(); |
| 291 |
CReapplyConceptSaturationLabelSet* satConSet = saturationNode->getReapplyConceptSaturationLabelSet(false); |
| 292 |
|
| 293 |
if (!saturationNode->isCompleted()) { |
| 294 |
return false; |
| 295 |
} |
| 296 |
|
| 297 |
cacheEntry = mSatCacheReader->getCacheEntry(saturationNode); |
| 298 |
if (cacheEntry) { |
| 299 |
cint64 conSetSignature = conSet->getConceptSignature()->getSignatureValue(); |
| 300 |
CSaturationNodeAssociatedDeterministicConceptExpansion* conExp = cacheEntry->getDeterministicConceptExpansion(); |
| 301 |
if (conExp && !conExp->requiresNonDeterministicExpansion()) { |
| 302 |
return false; |
| 303 |
} |
| 304 |
if (!cacheEntry->areMoreNondeterministicExpansionAllowed() || conExp && conExp->getConceptSetSignature() == conSetSignature) { |
| 305 |
onlyIfCompletelyDeterministic = true; |
| 306 |
} else { |
| 307 |
for (CSaturationNodeAssociatedNondeterministicConceptExpansion* conExpIt = cacheEntry->getNondeterministicConceptExpansionLinker(); conExpIt; conExpIt = conExpIt->getNext()) { |
| 308 |
if (conExpIt->getConceptSetSignature() == conSetSignature) { |
| 309 |
onlyIfCompletelyDeterministic = true; |
| 310 |
break; |
| 311 |
} |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
// test compatible nominal nodes |
| 317 |
CSuccessorConnectedNominalSet* depNominalSet = individualProcessNode->getSuccessorNominalConnectionSet(false); |
| 318 |
if (depNominalSet) { |
| 319 |
CIndividualProcessNodeVector* indiVec = calcAlgContext->getProcessingDataBox()->getIndividualProcessNodeVector(); |
| 320 |
for (CSuccessorConnectedNominalSet::const_iterator it = depNominalSet->constBegin(), itEnd = depNominalSet->constEnd(); it != itEnd; ++it) { |
| 321 |
cint64 nominalNodeID = *it; |
| 322 |
bool nominalStillCached = false; |
| 323 |
CIndividualProcessNode* indiNode = indiVec->getData(nominalNodeID); |
| 324 |
if (indiNode) { |
| 325 |
if (nominalNodeID <= calcAlgContext->getMaxCompletionGraphCachedIndividualNodeID() && indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHED)) { |
| 326 |
if (!indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHINGINVALID) && !indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHINGINVALIDATED)) { |
| 327 |
nominalStillCached = true; |
| 328 |
if (indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHEDNODEEXTENDED)) { |
| 329 |
onlyAllNondeterministic = true; |
| 330 |
} |
| 331 |
} |
| 332 |
} else if (indiNode->hasProcessingRestrictionFlags(CIndividualProcessNode::PRFSYNCHRONIZEDBACKEND)) { |
| 333 |
nominalStillCached = true; |
| 334 |
} |
| 335 |
} |
| 336 |
if (!nominalStillCached) { |
| 337 |
return false; |
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
return true; |
| 342 |
} |
| 343 |
return false; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
bool CSaturationNodeExpansionCacheHandler::tryNodeSatisfiableCaching(CIndividualProcessNode* individualProcessNode, CCalculationAlgorithmContext* calcAlgContext) { |
| 349 |
|
| 350 |
// test whether node can be cached |
| 351 |
|
| 352 |
bool cachingOnlyIfDeterministic = false; |
| 353 |
bool onlyAllNondeterministic = false; |
| 354 |
CSaturationNodeAssociatedExpansionCacheEntry* cacheEntry = nullptr; |
| 355 |
if (testNodeCachingPossible(individualProcessNode,cachingOnlyIfDeterministic,onlyAllNondeterministic,cacheEntry,calcAlgContext)) { |
| 356 |
CIndividualNodeSaturationBlockingData* satBlockData = individualProcessNode->getIndividualSaturationBlockingData(false); |
| 357 |
CConceptDescriptor* lastConDes = satBlockData->getLastConfirmedConceptDescriptior(); |
| 358 |
CIndividualSaturationProcessNode* satIndiNode = satBlockData->getSaturationIndividualNode(); |
| 359 |
CSaturationConceptDataItem* conceptSatItem = (CSaturationConceptDataItem*)satIndiNode->getSaturationConceptReferenceLinking();; |
| 360 |
if (conceptSatItem) { |
| 361 |
CConcept* saturationConcept = conceptSatItem->getSaturationConcept(); |
| 362 |
|
| 363 |
//if (CIRIName::getRecentIRIName(saturationConcept->getClassNameLinker()) == "http://www.owllink.org/testsuite/galen#Transport") { |
| 364 |
// bool debug = true; |
| 365 |
//} |
| 366 |
|
| 367 |
CReapplyConceptLabelSet* conSet = individualProcessNode->getReapplyConceptLabelSet(false); |
| 368 |
cint64 totalConceptCount = conSet->getConceptCount(); |
| 369 |
cint64 conSetSignature = conSet->getConceptSignature()->getSignatureValue(); |
| 370 |
|
| 371 |
|
| 372 |
CConceptDescriptor* conDes = conSet->getAddingSortedConceptDescriptionLinker(); |
| 373 |
CConceptDescriptor* lastPossiblyNonDeterministicConDes = nullptr; |
| 374 |
CConceptDescriptor* satConDes = nullptr; |
| 375 |
CDependencyTrackPoint* satConDepTrackPoint = nullptr; |
| 376 |
if (conSet->getConceptDescriptor(saturationConcept,satConDes,satConDepTrackPoint)) { |
| 377 |
for (CConceptDescriptor* conDesIt = conDes; conDesIt != lastConDes; conDesIt = conDesIt->getNext()) { |
| 378 |
CDependencyTrackPoint* depTrackPoint = conDesIt->getDependencyTrackPoint(); |
| 379 |
if (onlyAllNondeterministic) { |
| 380 |
lastPossiblyNonDeterministicConDes = conDesIt; |
| 381 |
} else if (!isDeterministicallyDependingOnSaturationConcept(individualProcessNode,depTrackPoint,satConDes,calcAlgContext)) { |
| 382 |
lastPossiblyNonDeterministicConDes = conDesIt; |
| 383 |
} |
| 384 |
} |
| 385 |
if (!cachingOnlyIfDeterministic || lastPossiblyNonDeterministicConDes == nullptr) { |
| 386 |
|
| 387 |
prepareCacheMessages(calcAlgContext); |
| 388 |
CTaskMemoryPoolAllocationManager* satCacheMemMan = mMemAllocMan; |
| 389 |
CContextBase* tmpContext = mTmpContext; |
| 390 |
|
| 391 |
CSaturationNodeAssociatedExpansionCacheExpansionWriteData* detExpWriteData = nullptr; |
| 392 |
CSaturationNodeAssociatedExpansionCacheExpansionWriteData* nondetExpWriteData = nullptr; |
| 393 |
|
| 394 |
|
| 395 |
bool hasTightAtMostRestriction = false; |
| 396 |
for (CConceptDescriptor* conDesIt = conDes; conDesIt && !hasTightAtMostRestriction; conDesIt = conDesIt->getNext()) { |
| 397 |
CConcept* concept = conDesIt->getConcept(); |
| 398 |
bool negation = conDesIt->isNegated(); |
| 399 |
cint64 conCode = concept->getConceptOperator()->getOperatorCode(); |
| 400 |
if (negation && conCode == CCATLEAST || !negation && conCode == CCATMOST) { |
| 401 |
CRole* role = concept->getRole(); |
| 402 |
cint64 parameter = concept->getParameter(); |
| 403 |
cint64 cardinality = parameter+1*negation; |
| 404 |
|
| 405 |
if (individualProcessNode->getRoleSuccessorCount(role) >= cardinality) { |
| 406 |
hasTightAtMostRestriction = true; |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
CSaturationNodeAssociatedDependentNominalSet* nomDepSet = nullptr; |
| 412 |
|
| 413 |
CSuccessorConnectedNominalSet* successorNominalConnSet = individualProcessNode->getSuccessorNominalConnectionSet(false); |
| 414 |
if (successorNominalConnSet) { |
| 415 |
nomDepSet = CObjectParameterizingAllocator< CSaturationNodeAssociatedDependentNominalSet,CContext* >::allocateAndConstructAndParameterize(satCacheMemMan,tmpContext); |
| 416 |
for (CSuccessorConnectedNominalSet::const_iterator it = successorNominalConnSet->constBegin(), itEnd = successorNominalConnSet->constEnd(); it != itEnd; ++it) { |
| 417 |
cint64 nominalID = -(*it); |
| 418 |
nomDepSet->insert(nominalID); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
if (lastPossiblyNonDeterministicConDes) { |
| 424 |
// create non-deterministic expansion data |
| 425 |
nondetExpWriteData = CObjectAllocator< CSaturationNodeAssociatedExpansionCacheExpansionWriteData >::allocateAndConstruct(satCacheMemMan); |
| 426 |
|
| 427 |
CSaturationNodeAssociatedConceptLinker* nonDetConceptLinker = nullptr; |
| 428 |
CConceptDescriptor* conDesStop = lastPossiblyNonDeterministicConDes->getNext(); |
| 429 |
for (CConceptDescriptor* conDesIt = conDes; conDesIt != conDesStop; conDesIt = conDesIt->getNext()) { |
| 430 |
const CCacheValue& cacheValue(getCacheValueForConcept(conDesIt->getConcept(),conDesIt->isNegated(),calcAlgContext)); |
| 431 |
CSaturationNodeAssociatedConceptLinker* assConceptLinker = CObjectAllocator< CSaturationNodeAssociatedConceptLinker >::allocateAndConstruct(satCacheMemMan); |
| 432 |
assConceptLinker->initConceptLinker(cacheValue); |
| 433 |
nonDetConceptLinker = assConceptLinker->append(nonDetConceptLinker); |
| 434 |
} |
| 435 |
|
| 436 |
nondetExpWriteData->initExpansionWriteData(satIndiNode,nonDetConceptLinker); |
| 437 |
nondetExpWriteData->setDeterministicExpansion(false); |
| 438 |
nondetExpWriteData->setTightAtMostRestriction(hasTightAtMostRestriction); |
| 439 |
nondetExpWriteData->setConceptSetSignature(conSetSignature); |
| 440 |
nondetExpWriteData->setTotalConceptCount(totalConceptCount); |
| 441 |
nondetExpWriteData->setDependentNominalSet(nomDepSet); |
| 442 |
|
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
if (!lastPossiblyNonDeterministicConDes || lastPossiblyNonDeterministicConDes->getNext() != lastConDes) { |
| 447 |
|
| 448 |
CSaturationNodeAssociatedDeterministicConceptExpansion* detConExp = nullptr; |
| 449 |
if (cacheEntry) { |
| 450 |
detConExp = cacheEntry->getDeterministicConceptExpansion(); |
| 451 |
} |
| 452 |
CSaturationNodeAssociatedConceptLinker* detConceptLinker = nullptr; |
| 453 |
|
| 454 |
CConceptDescriptor* conDesStart = nullptr; |
| 455 |
if (lastPossiblyNonDeterministicConDes) { |
| 456 |
conDesStart = lastPossiblyNonDeterministicConDes->getNext(); |
| 457 |
} |
| 458 |
if (!conDesStart) { |
| 459 |
conDesStart = conDes; |
| 460 |
} |
| 461 |
for (CConceptDescriptor* conDesIt = conDesStart; conDesIt != lastConDes; conDesIt = conDesIt->getNext()) { |
| 462 |
CCacheValue cacheValue(getCacheValueForConcept(conDesIt->getConcept(),conDesIt->isNegated(),calcAlgContext)); |
| 463 |
if (!detConExp || !detConExp->hasConceptExpansionLinker(&cacheValue)) { |
| 464 |
CSaturationNodeAssociatedConceptLinker* assConceptLinker = CObjectAllocator< CSaturationNodeAssociatedConceptLinker >::allocateAndConstruct(satCacheMemMan); |
| 465 |
assConceptLinker->initConceptLinker(cacheValue); |
| 466 |
detConceptLinker = assConceptLinker->append(detConceptLinker); |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
if (detConceptLinker || !detConExp || detConExp->requiresNonDeterministicExpansion() && !detConceptLinker) { |
| 471 |
detExpWriteData = CObjectAllocator< CSaturationNodeAssociatedExpansionCacheExpansionWriteData >::allocateAndConstruct(satCacheMemMan); |
| 472 |
detExpWriteData->initExpansionWriteData(satIndiNode,detConceptLinker); |
| 473 |
detExpWriteData->setDeterministicExpansion(true); |
| 474 |
if (!lastPossiblyNonDeterministicConDes) { |
| 475 |
detExpWriteData->setRequiresNondeterministicExpansion(false); |
| 476 |
detExpWriteData->setTightAtMostRestriction(hasTightAtMostRestriction); |
| 477 |
detExpWriteData->setConceptSetSignature(conSetSignature); |
| 478 |
detExpWriteData->setTotalConceptCount(totalConceptCount); |
| 479 |
detExpWriteData->setDependentNominalSet(nomDepSet); |
| 480 |
} |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
bool wroteCacheData = false; |
| 486 |
if (nondetExpWriteData) { |
| 487 |
wroteCacheData = true; |
| 488 |
addCacheMessages(nondetExpWriteData,calcAlgContext); |
| 489 |
} |
| 490 |
if (detExpWriteData) { |
| 491 |
wroteCacheData = true; |
| 492 |
addCacheMessages(detExpWriteData,calcAlgContext); |
| 493 |
} |
| 494 |
return wroteCacheData; |
| 495 |
|
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
return false; |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
bool CSaturationNodeExpansionCacheHandler::isDeterministicallyDependingOnSaturationConcept(CIndividualProcessNode* individualNode, CDependencyTrackPoint* depTrackPoint, CConceptDescriptor* saturationConceptDescriptor, CCalculationAlgorithmContext* calcAlgContext) { |
| 511 |
CDependencyTrackPoint* satConDepTrackPoint = saturationConceptDescriptor->getDependencyTrackPoint(); |
| 512 |
if (!satConDepTrackPoint || !depTrackPoint) { |
| 513 |
return false; |
| 514 |
} else { |
| 515 |
if (satConDepTrackPoint->getBranchingTag() != depTrackPoint->getBranchingTag()) { |
| 516 |
return false; |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
cint64 ancDepth = individualNode->getIndividualAncestorDepth(); |
| 521 |
if (ancDepth <= 0) { |
| 522 |
if (depTrackPoint->isPointingToIndependentDependencyNode()) { |
| 523 |
return false; |
| 524 |
} |
| 525 |
} else { |
| 526 |
CDependencyNode* depNode = depTrackPoint->getDependencyNode(); |
| 527 |
if (depNode->hasAppropriateIndividualNode()) { |
| 528 |
CIndividualProcessNode* appIndiNode = depNode->getAppropriateIndividualNode(); |
| 529 |
cint64 appIndiAncDepth = appIndiNode->getIndividualAncestorDepth(); |
| 530 |
if (appIndiAncDepth < ancDepth) { |
| 531 |
return false; |
| 532 |
} |
| 533 |
//if (!appIndiNode->isNominalIndividual()) { |
| 534 |
//} |
| 535 |
} else { |
| 536 |
CDependencyNode::DEPENDENCNODEYTYPE depType = depNode->getDependencyType(); |
| 537 |
if (depType == CDependencyNode::DNTMERGEDCONCEPT) { |
| 538 |
return false; |
| 539 |
} |
| 540 |
} |
| 541 |
} |
| 542 |
return true; |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
}; // end namespace Algorithm |
| 551 |
|
| 552 |
}; // end namespace Kernel |
| 553 |
|
| 554 |
}; // end namespace Reasoner |
| 555 |
|
| 556 |
}; // end namespace Konclude |