| 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 "COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Realizer { |
| 29 |
|
| 30 |
|
| 31 |
COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator(const CRealizationIndividualInstanceItemReference& indiInstItemRef, CBackendRepresentativeMemoryCacheReader* backendAssocCacheReader, COptimizedKPSetRoleInstancesItem* roleInstancesItem, bool inversed, COptimizedKPSetIndividualInstantiatedItemMultiHash* individualInstantiatedItemHash, CIndividualVector* individualVector, bool considerSameMergedIndis) { |
| 32 |
mIndiInstItemRef = indiInstItemRef; |
| 33 |
mRoleInstancesItem = roleInstancesItem; |
| 34 |
mInversed = inversed; |
| 35 |
mIndividualInstantiatedItemHash = individualInstantiatedItemHash; |
| 36 |
mIndividualVector = individualVector; |
| 37 |
|
| 38 |
mAllowPossibleFillers = false; |
| 39 |
|
| 40 |
mConsiderSameMergedIndis = considerSameMergedIndis; |
| 41 |
|
| 42 |
mHasCurrentIndiId = false; |
| 43 |
mCurrentIndiId = -1; |
| 44 |
mCurrentIndiInstItemRef = CRealizationIndividualInstanceItemReference(); |
| 45 |
mInitializationRequired = false; |
| 46 |
mNeighbourPossibleInstanceDataIteratorsInitialized = false; |
| 47 |
mNeighbourPossibleInstanceDataIteratorsFinished = false; |
| 48 |
mNeighbourArrayIteratorsInitialized = false; |
| 49 |
mNeighbourArrayIteratorsFinished = false; |
| 50 |
mNeighbourComplexDataIteratorsInitialized = false; |
| 51 |
mNeighbourComplexDataIteratorsFinished = false; |
| 52 |
mCurrentNeighbourArrayVisitingPositionCursor = 0; |
| 53 |
|
| 54 |
mNeighbourPossibleInstanceDataIterationNewlyInitialized = false; |
| 55 |
mNeighbourComplexDataIterationNewlyInitialized = false; |
| 56 |
|
| 57 |
mBackendAssocCacheReader = backendAssocCacheReader; |
| 58 |
mSameMergedIndisInCache = mBackendAssocCacheReader->hasSameIndividualsMergings(); |
| 59 |
|
| 60 |
mComplexRoleDataPointer = nullptr; |
| 61 |
mIndiAssData = nullptr; |
| 62 |
|
| 63 |
mNeighbourArrayIndiVisitedCount = 0; |
| 64 |
mNeighbourArrayIndiMergedCount = 0; |
| 65 |
mNeighbourArrayVisistedCount = 0; |
| 66 |
mNeighbourArrayCount = 0; |
| 67 |
mNeighbourArrayVisitedPosIndiCount = 0; |
| 68 |
|
| 69 |
moveToNextPossiblePosition(false); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::moveToNextPossiblePosition(bool forceNextPosition) { |
| 76 |
if (forceNextPosition) { |
| 77 |
mHasCurrentIndiId = false; |
| 78 |
mCurrentIndiId = -1; |
| 79 |
mCurrentIndiInstItemRef = CRealizationIndividualInstanceItemReference(); |
| 80 |
mInitializationRequired = false; |
| 81 |
} |
| 82 |
|
| 83 |
if (!mHasCurrentIndiId && (!mNeighbourArrayIteratorsInitialized || !mNeighbourArrayIteratorsFinished)) { |
| 84 |
if (!mIndiAssData) { |
| 85 |
mIndiAssData = mBackendAssocCacheReader->getIndividualAssociationData(mIndiInstItemRef.getIndividualID()); |
| 86 |
} |
| 87 |
if (!mIndiAssData) { |
| 88 |
mInitializationRequired = true; |
| 89 |
} else { |
| 90 |
if (!mNeighbourArrayIteratorsInitialized) { |
| 91 |
initializeNeighbourArrayIteration(); |
| 92 |
} |
| 93 |
|
| 94 |
if (mNeighbourArrayIteratorsInitialized && !mNeighbourArrayIteratorsFinished) { |
| 95 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourArray* roleSetNeighbourArray = mIndiAssData->getRoleSetNeighbourArray(); |
| 96 |
bool isSameMerged = false; |
| 97 |
while ((!mHasCurrentIndiId || isSameMerged) && mSingleNeighLabelDetDataHashIt != mSingleNeighLabelDetDataHashItEnd) { |
| 98 |
isSameMerged = false; |
| 99 |
mHasCurrentIndiId = false; |
| 100 |
|
| 101 |
if (!roleSetNeighbourArray->at(mSingleNeighLabelDetDataHashIt.value()->getLabelArrayIndex()).visitNeighbourIndividualIdsFromCursor([&](cint64 neighbourId, cint64 cursor)->bool { |
| 102 |
mHasCurrentIndiId = true; |
| 103 |
mCurrentIndiId = neighbourId; |
| 104 |
|
| 105 |
COptimizedKPSetIndividualItem* currentIndividualItem = mIndividualInstantiatedItemHash->getIndividualInstantiatedItem(mCurrentIndiId); |
| 106 |
CIndividual* curentIndividual = nullptr; |
| 107 |
if (!currentIndividualItem) { |
| 108 |
curentIndividual = mIndividualVector->getData(mCurrentIndiId); |
| 109 |
} else { |
| 110 |
curentIndividual = currentIndividualItem->getIndividual(); |
| 111 |
} |
| 112 |
mCurrentIndiInstItemRef = CRealizationIndividualInstanceItemReference(CIndividualReference(curentIndividual, mCurrentIndiId), currentIndividualItem); |
| 113 |
|
| 114 |
if (!mConsiderSameMergedIndis && isSameIndividualsMerged(mCurrentIndiInstItemRef)) { |
| 115 |
isSameMerged = true; |
| 116 |
} |
| 117 |
|
| 118 |
++mNeighbourArrayIndiVisitedCount; |
| 119 |
if (isSameMerged) { |
| 120 |
++mNeighbourArrayIndiMergedCount; |
| 121 |
} |
| 122 |
mCurrentNeighbourArrayVisitingPositionCursor = cursor; |
| 123 |
return false; |
| 124 |
}, mCurrentNeighbourArrayVisitingPositionCursor)) { |
| 125 |
mCurrentNeighbourArrayVisitingPositionCursor = 0; |
| 126 |
++mSingleNeighLabelDetDataHashIt; |
| 127 |
|
| 128 |
if (mSingleNeighLabelDetDataHashIt != mSingleNeighLabelDetDataHashItEnd) { |
| 129 |
cint64 arrayPosIndiCount = roleSetNeighbourArray->at(mSingleNeighLabelDetDataHashIt.value()->getLabelArrayIndex()).getIndividualCount(); |
| 130 |
mNeighbourArrayVisitedPosIndiCount += arrayPosIndiCount; |
| 131 |
mNeighbourArrayVisistedCount++; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
if (!mHasCurrentIndiId) { |
| 138 |
mNeighbourArrayIteratorsFinished = true; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
} |
| 144 |
if (mNeighbourArrayIteratorsFinished) { |
| 145 |
mHasCurrentIndiId = false; |
| 146 |
mCurrentIndiId = -1; |
| 147 |
mCurrentIndiInstItemRef = CRealizationIndividualInstanceItemReference(); |
| 148 |
mInitializationRequired = false; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
if (!mHasCurrentIndiId && (!mNeighbourPossibleInstanceDataIteratorsInitialized || !mNeighbourPossibleInstanceDataIteratorsFinished)) { |
| 153 |
if (!mNeighbourPossibleInstanceDataIteratorsInitialized) { |
| 154 |
initializePossibleInstanceDataIteration(); |
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
if (!mNeighbourPossibleInstanceDataIteratorsFinished) { |
| 160 |
if (!mNeighbourPossibleInstanceDataIterationNewlyInitialized && forceNextPosition && mNeighbourPossibleInstanceDataIt != mNeighbourPossibleInstanceDataItEnd) { |
| 161 |
++mNeighbourPossibleInstanceDataIt; |
| 162 |
} |
| 163 |
mNeighbourPossibleInstanceDataIterationNewlyInitialized = false; |
| 164 |
while (!mHasCurrentIndiId && mNeighbourPossibleInstanceDataIt != mNeighbourPossibleInstanceDataItEnd) { |
| 165 |
mCurrentIndiId = mNeighbourPossibleInstanceDataIt.key(); |
| 166 |
COptimizedKPSetIndividualItem* currentIndividualItem = mNeighbourPossibleInstanceDataIt->mNeighbourIndividualItem; |
| 167 |
mCurrentIndiInstItemRef = CRealizationIndividualInstanceItemReference(currentIndividualItem->getIndividualReference(), currentIndividualItem); |
| 168 |
|
| 169 |
if (!mConsiderSameMergedIndis && isSameIndividualsMerged(mCurrentIndiInstItemRef)) { |
| 170 |
++mNeighbourPossibleInstanceDataIt; |
| 171 |
} else { |
| 172 |
COptimizedKPSetRoleInstancesData* instanceData = mNeighbourPossibleInstanceDataIt->mInstanceItemData; |
| 173 |
if (instanceData->mKnownInstance || mAllowPossibleFillers && instanceData->mPossibleInstance && !instanceData->mTestedInstance) { |
| 174 |
mHasCurrentIndiId = true; |
| 175 |
} else if (!mAllowPossibleFillers && instanceData->mPossibleInstance && !instanceData->mKnownInstance && !instanceData->mTestedInstance) { |
| 176 |
mInitializationRequired = true; |
| 177 |
return false; |
| 178 |
} else { |
| 179 |
++mNeighbourPossibleInstanceDataIt; |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
if (!mHasCurrentIndiId) { |
| 185 |
mNeighbourPossibleInstanceDataIteratorsFinished = true; |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
if (!mHasCurrentIndiId && (!mNeighbourComplexDataIteratorsInitialized || !mNeighbourComplexDataIteratorsFinished)) { |
| 193 |
if (!mNeighbourComplexDataIteratorsInitialized) { |
| 194 |
initializeComplexDataIteration(); |
| 195 |
} |
| 196 |
|
| 197 |
if (mNeighbourComplexDataIteratorsInitialized && !mNeighbourComplexDataIteratorsFinished) { |
| 198 |
|
| 199 |
if (!mNeighbourComplexDataIterationNewlyInitialized && forceNextPosition && mNeighbourComplexInstanceDataIt != mNeighbourComplexInstanceDataItEnd) { |
| 200 |
++mNeighbourComplexInstanceDataIt; |
| 201 |
} |
| 202 |
mNeighbourComplexDataIterationNewlyInitialized = false; |
| 203 |
while (!mHasCurrentIndiId && mNeighbourComplexInstanceDataIt != mNeighbourComplexInstanceDataItEnd) { |
| 204 |
|
| 205 |
mCurrentIndiId = mNeighbourComplexInstanceDataIt.key(); |
| 206 |
COptimizedKPSetIndividualItem* currentIndividualItem = mNeighbourComplexInstanceDataIt->mNeighbourIndividualItem; |
| 207 |
CIndividual* curentIndividual = nullptr; |
| 208 |
if (!currentIndividualItem) { |
| 209 |
currentIndividualItem = mIndividualInstantiatedItemHash->getIndividualInstantiatedItem(mCurrentIndiId); |
| 210 |
} |
| 211 |
if (!currentIndividualItem) { |
| 212 |
curentIndividual = mIndividualVector->getData(mCurrentIndiId); |
| 213 |
} else { |
| 214 |
curentIndividual = currentIndividualItem->getIndividual(); |
| 215 |
} |
| 216 |
mCurrentIndiInstItemRef = CRealizationIndividualInstanceItemReference(CIndividualReference(curentIndividual, mCurrentIndiId), currentIndividualItem); |
| 217 |
|
| 218 |
if (!mConsiderSameMergedIndis && isSameIndividualsMerged(mCurrentIndiInstItemRef)) { |
| 219 |
++mNeighbourComplexInstanceDataIt; |
| 220 |
} else { |
| 221 |
if (mNeighbourComplexInstanceDataIt->mInstanceItemData->mKnownInstance || mAllowPossibleFillers && mNeighbourComplexInstanceDataIt->mInstanceItemData->mPossibleInstance && !mNeighbourComplexInstanceDataIt->mInstanceItemData->mTestedInstance) { |
| 222 |
mHasCurrentIndiId = true; |
| 223 |
} else if (!mAllowPossibleFillers && mNeighbourComplexInstanceDataIt->mInstanceItemData->mPossibleInstance && !mNeighbourComplexInstanceDataIt->mInstanceItemData->mKnownInstance && !mNeighbourComplexInstanceDataIt->mInstanceItemData->mTestedInstance) { |
| 224 |
mInitializationRequired = true; |
| 225 |
return false; |
| 226 |
} else { |
| 227 |
++mNeighbourComplexInstanceDataIt; |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
if (!mHasCurrentIndiId) { |
| 233 |
mNeighbourComplexDataIteratorsFinished = true; |
| 234 |
} |
| 235 |
|
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
return mHasCurrentIndiId && !mInitializationRequired; |
| 241 |
|
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::initializeComplexDataIteration() { |
| 247 |
if (mRoleInstancesItem->hasComplexRoleData() && mRoleInstancesItem->getIndividualIdComplexRoleDataHash()->contains(mIndiInstItemRef.getIndividualID())) { |
| 248 |
if (!mComplexRoleDataPointer) { |
| 249 |
mComplexRoleDataPointer = &mRoleInstancesItem->getIndividualIdComplexRoleDataHash()->operator[](mIndiInstItemRef.getIndividualID()); |
| 250 |
} |
| 251 |
if (*mComplexRoleDataPointer == nullptr) { |
| 252 |
mInitializationRequired = true; |
| 253 |
} else if (!(*mComplexRoleDataPointer)->isInitialized(mInversed)) { |
| 254 |
mInitializationRequired = true; |
| 255 |
} else { |
| 256 |
mNeighbourComplexDataIterationNewlyInitialized = true; |
| 257 |
mNeighbourComplexDataIteratorsInitialized = true; |
| 258 |
COptimizedKPSetIndividualComplexRoleExplicitIndirectLinksData* indiExplicitIndirectLinkComplexRepresentationData = (COptimizedKPSetIndividualComplexRoleExplicitIndirectLinksData*)(*mComplexRoleDataPointer); |
| 259 |
COptimizedKPSetRoleInstancesHash* neighbourHash = indiExplicitIndirectLinkComplexRepresentationData->getRoleNeighbourInstancesHash(mInversed, false); |
| 260 |
if (neighbourHash) { |
| 261 |
mNeighbourComplexInstanceDataIt = neighbourHash->constBegin(); |
| 262 |
mNeighbourComplexInstanceDataItEnd = neighbourHash->constEnd(); |
| 263 |
} |
| 264 |
} |
| 265 |
} else { |
| 266 |
mNeighbourComplexDataIteratorsInitialized = true; |
| 267 |
} |
| 268 |
return mNeighbourComplexDataIterationNewlyInitialized; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
void COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::initializePossibleInstanceDataIteration() { |
| 273 |
COptimizedKPSetIndividualItem* indiInstItem = (COptimizedKPSetIndividualItem*)mIndiInstItemRef.getRealizationInstanceItem(); |
| 274 |
mNeighbourPossibleInstanceDataIteratorsInitialized = true; |
| 275 |
mNeighbourPossibleInstanceDataIterationNewlyInitialized = true; |
| 276 |
if (indiInstItem && indiInstItem->getKnownPossibleRoleNeighboursInstancesHash()->contains(mRoleInstancesItem)) { |
| 277 |
COptimizedKPSetRoleNeighbourInstancesHashData& neighbourPossibleInstanceHashData = indiInstItem->getKnownPossibleRoleNeighboursInstancesHash()->operator[](mRoleInstancesItem); |
| 278 |
COptimizedKPSetRoleInstancesHash* neighbourPossibleInstanceHash = neighbourPossibleInstanceHashData.getRoleNeighbourInstancesHash(mInversed, false); |
| 279 |
if (neighbourPossibleInstanceHash) { |
| 280 |
mNeighbourPossibleInstanceDataIt = neighbourPossibleInstanceHash->constBegin(); |
| 281 |
mNeighbourPossibleInstanceDataItEnd = neighbourPossibleInstanceHash->constEnd(); |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
void COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::initializeNeighbourArrayIteration() { |
| 287 |
mCurrentNeighbourArrayVisitingPositionCursor = 0; |
| 288 |
mNeighbourArrayIteratorsInitialized = true; |
| 289 |
CBackendRepresentativeMemoryLabelCacheItem* combinedNeigRoleSetLabel = mIndiAssData->getLabelCacheEntry(CBackendRepresentativeMemoryLabelCacheItem::NEIGHBOUR_INSTANTIATED_ROLE_SET_COMBINATION_LABEL); |
| 290 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourArray* roleSetNeighbourArray = mIndiAssData->getRoleSetNeighbourArray(); |
| 291 |
|
| 292 |
COptimizedKPSetRoleInstancesCombinedNeighbourRoleSetCacheLabelData* roleItemCompNeighLabelData = mRoleInstancesItem->getCombinedNeighbourCacheLabelItemDataHash(mInversed)->value(combinedNeigRoleSetLabel); |
| 293 |
if (roleItemCompNeighLabelData && roleItemCompNeighLabelData->hasKnownInstancesLabelItems()) { |
| 294 |
QHash<CBackendRepresentativeMemoryLabelCacheItem*, COptimizedKPSetRoleInstancesSingleNeighbourRoleSetCacheLabelData*>* singleNeighLabelDetDataHash = roleItemCompNeighLabelData->getKnownInstancesLabelItemDataHash(); |
| 295 |
mSingleNeighLabelDetDataHashIt = singleNeighLabelDetDataHash->constBegin(); |
| 296 |
mSingleNeighLabelDetDataHashItEnd = singleNeighLabelDetDataHash->constEnd(); |
| 297 |
mNeighbourArrayCount = singleNeighLabelDetDataHash->size(); |
| 298 |
} |
| 299 |
|
| 300 |
if (mSingleNeighLabelDetDataHashIt != mSingleNeighLabelDetDataHashItEnd) { |
| 301 |
cint64 arrayPosIndiCount = roleSetNeighbourArray->at(mSingleNeighLabelDetDataHashIt.value()->getLabelArrayIndex()).getIndividualCount(); |
| 302 |
mNeighbourArrayVisitedPosIndiCount += arrayPosIndiCount; |
| 303 |
mNeighbourArrayVisistedCount++; |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
//if (roleItemCompNeighLabelData && roleItemCompNeighLabelData->hasPossibleInstancesLabelItems()) { |
| 308 |
// QHash<CBackendRepresentativeMemoryLabelCacheItem*, COptimizedKPSetRoleInstancesSingleNeighbourRoleSetCacheLabelData*>* singleNeighLabelNonDetDataHash = roleItemCompNeighLabelData->getPossibleInstancesLabelItemDataHash(); |
| 309 |
// mSingleNeighLabelNonDetDataHashIt = singleNeighLabelNonDetDataHash->constBegin(); |
| 310 |
// mSingleNeighLabelNonDetDataHashItEnd = singleNeighLabelNonDetDataHash->constEnd(); |
| 311 |
//} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::isSameIndividualsMerged(const CRealizationIndividualInstanceItemReference& indiInstItemRef) { |
| 318 |
if (indiInstItemRef.getRealizationInstanceItem()) { |
| 319 |
COptimizedKPSetIndividualItem* indiItem = (COptimizedKPSetIndividualItem*)indiInstItemRef.getRealizationInstanceItem(); |
| 320 |
if (indiItem->getIndividualId() != indiInstItemRef.getIndividualID() || indiItem->isItemSameIndividualMerged()) { |
| 321 |
return true; |
| 322 |
} |
| 323 |
return false; |
| 324 |
} else { |
| 325 |
if (mSameMergedIndisInCache) { |
| 326 |
CBackendRepresentativeMemoryCacheIndividualAssociationData* neighbourIndiAssData = mBackendAssocCacheReader->getIndividualAssociationData(indiInstItemRef.getIndividualID()); |
| 327 |
return neighbourIndiAssData->hasRepresentativeSameIndividualMerging(); |
| 328 |
} else { |
| 329 |
return false; |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::requiresInitialization() { |
| 336 |
return mInitializationRequired; |
| 337 |
} |
| 338 |
|
| 339 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::begin() { |
| 340 |
if (mInitializationRequired) { |
| 341 |
mInitializationRequired = false; |
| 342 |
moveToNextPossiblePosition(false); |
| 343 |
} |
| 344 |
return !mInitializationRequired; |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::atEnd() { |
| 350 |
return !mHasCurrentIndiId && !mInitializationRequired; |
| 351 |
} |
| 352 |
|
| 353 |
CRealizationRemainingInstancesEstimation COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::remainingInstancesEstimation() { |
| 354 |
CRealizationRemainingInstancesEstimation estimation; |
| 355 |
if (!mNeighbourArrayIteratorsInitialized) { |
| 356 |
initializeNeighbourArrayIteration(); |
| 357 |
} |
| 358 |
double remainingIndiCount = 0; |
| 359 |
if (!mNeighbourArrayIteratorsFinished) { |
| 360 |
remainingIndiCount = mNeighbourArrayVisitedPosIndiCount - mNeighbourArrayIndiVisitedCount; |
| 361 |
double remainingNeighbourArrayCount = mNeighbourArrayCount - mNeighbourArrayVisistedCount; |
| 362 |
double remainingNeighbourArrayIndiCount = (double)mNeighbourArrayVisitedPosIndiCount / (double)mNeighbourArrayVisistedCount * remainingNeighbourArrayCount; |
| 363 |
remainingIndiCount += remainingNeighbourArrayIndiCount; |
| 364 |
if (mNeighbourArrayIndiMergedCount > 0) { |
| 365 |
remainingIndiCount = remainingIndiCount * (double)(mNeighbourArrayIndiVisitedCount - mNeighbourArrayIndiMergedCount) / (double)(mNeighbourArrayIndiVisitedCount); |
| 366 |
} |
| 367 |
} |
| 368 |
if (!mNeighbourPossibleInstanceDataIteratorsFinished) { |
| 369 |
// TODO: make more precise |
| 370 |
remainingIndiCount += 1.; |
| 371 |
} |
| 372 |
if (!mNeighbourComplexDataIteratorsFinished) { |
| 373 |
// TODO: make more precise |
| 374 |
remainingIndiCount += 1.; |
| 375 |
} |
| 376 |
estimation.setEstimatedCount(remainingIndiCount); |
| 377 |
return estimation; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::moveNext() { |
| 382 |
moveToNextPossiblePosition(true); |
| 383 |
return mHasCurrentIndiId && !mInitializationRequired; |
| 384 |
} |
| 385 |
|
| 386 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::moveTo(const CRealizationIndividualInstanceItemReference& indiInstItemRef, bool moveOver) { |
| 387 |
return false; |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
CRealizationIndividualInstanceItemReference COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::currentIndividualInstanceItemReference() { |
| 393 |
return mCurrentIndiInstItemRef; |
| 394 |
} |
| 395 |
|
| 396 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::isCurrentInstancePossible() { |
| 397 |
return mCurrentIndiInstanceOnlyPossible; |
| 398 |
} |
| 399 |
|
| 400 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::isCurrentInstanceCertain() { |
| 401 |
return !mCurrentIndiInstanceOnlyPossible; |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
CRealizationIndividualInstanceItemReferenceIterator* COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::getCopy() { |
| 406 |
COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator* copiedIterator = new COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator(mIndiInstItemRef, mBackendAssocCacheReader, mRoleInstancesItem, mInversed, mIndividualInstantiatedItemHash, mIndividualVector, mConsiderSameMergedIndis); |
| 407 |
|
| 408 |
|
| 409 |
copiedIterator->mNeighbourPossibleInstanceDataIteratorsInitialized = mNeighbourPossibleInstanceDataIteratorsInitialized; |
| 410 |
copiedIterator->mNeighbourPossibleInstanceDataIteratorsFinished = mNeighbourPossibleInstanceDataIteratorsFinished; |
| 411 |
copiedIterator->mNeighbourPossibleInstanceDataIt = mNeighbourPossibleInstanceDataIt; |
| 412 |
copiedIterator->mNeighbourPossibleInstanceDataItEnd = mNeighbourPossibleInstanceDataItEnd; |
| 413 |
|
| 414 |
copiedIterator->mNeighbourArrayIteratorsInitialized = mNeighbourArrayIteratorsInitialized; |
| 415 |
copiedIterator->mNeighbourArrayIteratorsFinished = mNeighbourArrayIteratorsFinished; |
| 416 |
copiedIterator->mIndiAssData = mIndiAssData; |
| 417 |
copiedIterator->mSingleNeighLabelDetDataHashIt = mSingleNeighLabelDetDataHashIt; |
| 418 |
copiedIterator->mSingleNeighLabelDetDataHashItEnd = mSingleNeighLabelDetDataHashItEnd; |
| 419 |
copiedIterator->mCurrentNeighbourArrayVisitingPositionCursor = mCurrentNeighbourArrayVisitingPositionCursor; |
| 420 |
|
| 421 |
copiedIterator->mNeighbourComplexDataIteratorsInitialized = mNeighbourComplexDataIteratorsInitialized; |
| 422 |
copiedIterator->mNeighbourComplexDataIteratorsFinished = mNeighbourComplexDataIteratorsFinished; |
| 423 |
copiedIterator->mNeighbourComplexInstanceDataIt = mNeighbourComplexInstanceDataIt; |
| 424 |
copiedIterator->mNeighbourComplexInstanceDataItEnd = mNeighbourComplexInstanceDataItEnd; |
| 425 |
|
| 426 |
copiedIterator->mAllowPossibleFillers = mAllowPossibleFillers; |
| 427 |
copiedIterator->mComplexRoleDataPointer = mComplexRoleDataPointer; |
| 428 |
copiedIterator->mInitializationRequired = mInitializationRequired; |
| 429 |
|
| 430 |
copiedIterator->mCurrentIndiId = mCurrentIndiId; |
| 431 |
copiedIterator->mHasCurrentIndiId = mHasCurrentIndiId; |
| 432 |
copiedIterator->mCurrentIndiInstItemRef = mCurrentIndiInstItemRef; |
| 433 |
copiedIterator->mCurrentIndiInstanceOnlyPossible = mCurrentIndiInstanceOnlyPossible; |
| 434 |
|
| 435 |
copiedIterator->mNeighbourPossibleInstanceDataIterationNewlyInitialized = mNeighbourPossibleInstanceDataIterationNewlyInitialized; |
| 436 |
copiedIterator->mNeighbourComplexDataIterationNewlyInitialized = mNeighbourComplexDataIterationNewlyInitialized; |
| 437 |
|
| 438 |
copiedIterator->mNeighbourArrayIndiVisitedCount = mNeighbourArrayIndiVisitedCount; |
| 439 |
copiedIterator->mNeighbourArrayIndiMergedCount = mNeighbourArrayIndiMergedCount; |
| 440 |
copiedIterator->mNeighbourArrayVisistedCount = mNeighbourArrayVisistedCount; |
| 441 |
copiedIterator->mNeighbourArrayCount = mNeighbourArrayCount; |
| 442 |
copiedIterator->mNeighbourArrayVisitedPosIndiCount = mNeighbourArrayVisitedPosIndiCount; |
| 443 |
|
| 444 |
return copiedIterator; |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
CRealizationIndividualSorting COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::getSorting() { |
| 449 |
return CRealizationIndividualSorting(Realization::CRealizationIndividualSorting::SORT_TYPE_NOTHING, Realization::CRealizationIndividualSorting::SORT_ORDER_NOTHING, Realization::CRealizationIndividualSorting::SORT_GROUP_NOTHING); |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
CRealizationIndividualInstanceItemReference COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::getQueryingIndividualInstanceItemReference() { |
| 454 |
return mIndiInstItemRef; |
| 455 |
} |
| 456 |
|
| 457 |
COptimizedKPSetRoleInstancesItem* COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::getQueryingRoleInstancesItem() { |
| 458 |
return mRoleInstancesItem; |
| 459 |
} |
| 460 |
|
| 461 |
bool COptimizedRepresentativeKPSetUnsortedIndividualRoleFillerItemIterator::getQueryingRoleInstancesItemInversion() { |
| 462 |
return mInversed; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
}; // end namespace Realizer |
| 467 |
|
| 468 |
}; // end namespace Reasoner |
| 469 |
|
| 470 |
}; // end namespace Konclude |