| 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 "CSatisfiableTaskMarkerIndividualPropagationAnalyser.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Algorithm { |
| 31 |
|
| 32 |
|
| 33 |
CSatisfiableTaskMarkerIndividualPropagationAnalyser::CSatisfiableTaskMarkerIndividualPropagationAnalyser() { |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
bool CSatisfiableTaskMarkerIndividualPropagationAnalyser::readCalculationConfig(CCalculationConfigurationExtension *config) { |
| 39 |
if (config) { |
| 40 |
return true; |
| 41 |
} |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
CIndividualProcessNode* CSatisfiableTaskMarkerIndividualPropagationAnalyser::getCorrectedIndividualNode(cint64 baseIndiID, CIndividualProcessNodeVector* indiNodeVec) { |
| 47 |
CIndividualProcessNode* indi = indiNodeVec->getData(baseIndiID); |
| 48 |
while (indi->hasMergedIntoIndividualNodeID()) { |
| 49 |
indi = indiNodeVec->getData(indi->getMergedIntoIndividualNodeID()); |
| 50 |
} |
| 51 |
return indi; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
bool CSatisfiableTaskMarkerIndividualPropagationAnalyser::analyseSatisfiableTask(CSatisfiableCalculationTask* statCalcTask, CCalculationAlgorithmContext* calcAlgContext) { |
| 56 |
CSatisfiableTaskRealizationMarkedCandidatesMessageAdapter* realMessAdapter = statCalcTask->getRealizationMarkedCandidatesMessageAdapter(); |
| 57 |
if (realMessAdapter) { |
| 58 |
CRealizationMessageObserver* realMessObserver = realMessAdapter->getRealizationMessageDataObserver(); |
| 59 |
CIndividualReference individualReference = realMessAdapter->getTestingIndividualReference(); |
| 60 |
CConcreteOntology* ontology = realMessAdapter->getTestingOntology(); |
| 61 |
|
| 62 |
|
| 63 |
CTaskProcessorContext* taskProcessorContext = calcAlgContext->getUsedTaskProcessorContext(); |
| 64 |
CTaskHandleMemoryAllocationManager* taskMemMan = calcAlgContext->getTemporaryMemoryAllocationManager(); |
| 65 |
|
| 66 |
CMemoryPoolContainer memPoolCon; |
| 67 |
CTaskMemoryPoolAllocationManager realMessMemManCreaterMemMan(&memPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager()); |
| 68 |
CTaskMemoryPoolAllocationManager* tempMemAllocMan = CObjectAllocator<CTaskMemoryPoolAllocationManager>::allocateAndConstruct(&realMessMemManCreaterMemMan); |
| 69 |
tempMemAllocMan->initTaskMemoryPoolAllocationManager(&memPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager()); |
| 70 |
CContextBase* tmpContext = CObjectParameterizingAllocator< CContextBase,CMemoryAllocationManager* >::allocateAndConstructAndParameterize(tempMemAllocMan,tempMemAllocMan); |
| 71 |
|
| 72 |
|
| 73 |
CRealizationMessageData* realMessageData = nullptr; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
CProcessingDataBox* procDataBox = calcAlgContext->getProcessingDataBox(); |
| 78 |
cint64 maxDetBranchTag = procDataBox->getMaximumDeterministicBranchTag(); |
| 79 |
CIndividualVector* indiVec = procDataBox->getOntology()->getABox()->getIndividualVector(); |
| 80 |
CMarkerIndividualNodeHash* markerIndiNodeHash = procDataBox->getMarkerIndividualNodeHash(false); |
| 81 |
if (markerIndiNodeHash) { |
| 82 |
for (CPROCESSHASH< CConcept*, CMarkerIndividualNodeData >::const_iterator it = markerIndiNodeHash->constBegin(), itEnd = markerIndiNodeHash->constEnd(); it != itEnd; ++it) { |
| 83 |
CConcept* markerConcept = it.key(); |
| 84 |
CIndividualRoleCandidateTestingData testingData = realMessAdapter->getIndividualRoleCandidateTestingDataByMarkerConcept(markerConcept); |
| 85 |
CXLinker<CIndividualReference>* detIndiCandLinker = nullptr; |
| 86 |
CXLinker<CIndividualReference>* ndetIndiCandLinker = nullptr; |
| 87 |
CMarkerIndividualNodeData data = it.value(); |
| 88 |
CXNegLinker<CIndividualProcessNode*>* candIndiLinker = data.getMarkerIndividualNodeLinker(); |
| 89 |
for (CXNegLinker<CIndividualProcessNode*>* candIndiLinkerIt = candIndiLinker; candIndiLinkerIt; candIndiLinkerIt = candIndiLinkerIt->getNext()) { |
| 90 |
CIndividualProcessNode* indiNode = candIndiLinkerIt->getData(); |
| 91 |
CIndividual* candIndividual = indiNode->getNominalIndividual(); |
| 92 |
if (candIndividual) { |
| 93 |
CXLinker<CIndividualReference>* tmpLinker = CObjectAllocator< CXLinker<CIndividualReference> >::allocateAndConstruct(tempMemAllocMan); |
| 94 |
if (candIndividual->isTemporaryIndividual()) { |
| 95 |
tmpLinker->initLinker(CIndividualReference(candIndividual->getIndividualID())); |
| 96 |
} else { |
| 97 |
tmpLinker->initLinker(candIndividual); |
| 98 |
} |
| 99 |
bool nondeterministicallyAdded = candIndiLinkerIt->isNegated(); |
| 100 |
if (nondeterministicallyAdded) { |
| 101 |
ndetIndiCandLinker = tmpLinker->append(ndetIndiCandLinker); |
| 102 |
} else { |
| 103 |
detIndiCandLinker = tmpLinker->append(detIndiCandLinker); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
CIndividualMergingHash* indiMergingHash = indiNode->getIndividualMergingHash(false); |
| 108 |
if (indiMergingHash) { |
| 109 |
|
| 110 |
for (CIndividualMergingHash::const_iterator indiIt = indiMergingHash->constBegin(), indiItEnd = indiMergingHash->constEnd(); indiIt != indiItEnd; ++indiIt) { |
| 111 |
|
| 112 |
if (indiIt.value().isMergedWithIndividual()) { |
| 113 |
cint64 indiIDIt = indiIt.key(); |
| 114 |
CIndividual* mergedIndividual = indiVec->getData(indiIDIt); |
| 115 |
|
| 116 |
if (mergedIndividual != candIndividual) { |
| 117 |
|
| 118 |
CDependencyTrackPoint* mergeDepTrackPoint = indiIt.value().getDependencyTrackPoint(); |
| 119 |
bool nonDetMerged = true; |
| 120 |
if (mergeDepTrackPoint && mergeDepTrackPoint->getBranchingTag() <= maxDetBranchTag) { |
| 121 |
nonDetMerged = false; |
| 122 |
} |
| 123 |
if (nonDetMerged) { |
| 124 |
CXLinker<CIndividualReference>* nomTmpLinker = CObjectAllocator< CXLinker<CIndividualReference> >::allocateAndConstruct(tempMemAllocMan); |
| 125 |
if (mergedIndividual->isTemporaryIndividual()) { |
| 126 |
nomTmpLinker->initLinker(CIndividualReference(mergedIndividual->getIndividualID())); |
| 127 |
} else { |
| 128 |
nomTmpLinker->initLinker(mergedIndividual); |
| 129 |
} |
| 130 |
ndetIndiCandLinker = nomTmpLinker->append(ndetIndiCandLinker); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
CRealizationMarkerCandidatesMessageData* realMarkCandMessageData = CObjectAllocator<CRealizationMarkerCandidatesMessageData>::allocateAndConstruct(tempMemAllocMan); |
| 141 |
realMarkCandMessageData->initRealizationMarkerCandidatesMessageData(individualReference, testingData, markerConcept,detIndiCandLinker,ndetIndiCandLinker); |
| 142 |
realMessageData = realMarkCandMessageData->append(realMessageData); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
} |
| 147 |
if (realMessageData) { |
| 148 |
realMessObserver->tellRealizationMessage(ontology,realMessageData,memPoolCon.takeMemoryPools()); |
| 149 |
} else { |
| 150 |
taskMemMan->releaseTemporaryMemoryPools(memPoolCon.takeMemoryPools()); |
| 151 |
} |
| 152 |
|
| 153 |
if (individualReference.isNonEmpty()) { |
| 154 |
return true; |
| 155 |
} |
| 156 |
} |
| 157 |
return false; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
}; // end namespace Algorithm |
| 164 |
|
| 165 |
}; // end namespace Kernel |
| 166 |
|
| 167 |
}; // end namespace Reasoner |
| 168 |
|
| 169 |
}; // end namespace Konclude |