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