| 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 "CIndividualReactivationProcessingQueue.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
|
| 33 |
CIndividualReactivationProcessingQueue::CIndividualReactivationProcessingQueue(CProcessContext* processContext) |
| 34 |
: mProcessContext(processContext),mPriorityIndiReactivationMap(processContext) { |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
CIndividualReactivationProcessingQueue* CIndividualReactivationProcessingQueue::initProcessingQueue(CIndividualReactivationProcessingQueue* processingQueue) { |
| 39 |
if (processingQueue) { |
| 40 |
mPriorityIndiReactivationMap = processingQueue->mPriorityIndiReactivationMap; |
| 41 |
} else { |
| 42 |
mPriorityIndiReactivationMap.clear(); |
| 43 |
} |
| 44 |
return this; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
bool CIndividualReactivationProcessingQueue::takeNextReactivationIndividual(CIndividualProcessNode*& indiNode, bool& forceReactivation) { |
| 49 |
CIndividualProcessNode* nextNode = nullptr; |
| 50 |
if (!mPriorityIndiReactivationMap.isEmpty()) { |
| 51 |
CPROCESSMAP<CIndividualDepthPriority,CIndividualForceReactivationData>::iterator it = mPriorityIndiReactivationMap.begin(); |
| 52 |
CIndividualForceReactivationData& data = it.value(); |
| 53 |
forceReactivation = data.mForceReactivation; |
| 54 |
indiNode = data.mIndiNode; |
| 55 |
it = mPriorityIndiReactivationMap.erase(it); |
| 56 |
return true; |
| 57 |
} |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
bool CIndividualReactivationProcessingQueue::getNextReactivationIndividual(CIndividualProcessNode*& indiNode, bool& forceReactivation) { |
| 62 |
CIndividualProcessNode* nextNode = nullptr; |
| 63 |
if (!mPriorityIndiReactivationMap.isEmpty()) { |
| 64 |
CPROCESSMAP<CIndividualDepthPriority,CIndividualForceReactivationData>::iterator it = mPriorityIndiReactivationMap.begin(); |
| 65 |
CIndividualForceReactivationData& data = it.value(); |
| 66 |
forceReactivation = data.mForceReactivation; |
| 67 |
indiNode = data.mIndiNode; |
| 68 |
return true; |
| 69 |
} |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
bool CIndividualReactivationProcessingQueue::hasQueuedIndividual(CIndividualProcessNode* individual) { |
| 75 |
CIndividualProcessNode* nextNode = nullptr; |
| 76 |
if (!mPriorityIndiReactivationMap.isEmpty()) { |
| 77 |
CIndividualDepthPriority priority(individual->getIndividualNominalLevelOrAncestorDepth(),individual->getIndividualNodeID()); |
| 78 |
return mPriorityIndiReactivationMap.contains(priority); |
| 79 |
} |
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
bool CIndividualReactivationProcessingQueue::insertReactivationIndiviudal(CIndividualProcessNode* individual, bool forceReactivation) { |
| 85 |
CIndividualDepthPriority priority(individual->getIndividualNominalLevelOrAncestorDepth(),individual->getIndividualNodeID()); |
| 86 |
CIndividualForceReactivationData& inFoReDa = mPriorityIndiReactivationMap[priority]; |
| 87 |
bool newEntry = inFoReDa.mIndiNode == nullptr || !inFoReDa.mForceReactivation && forceReactivation; |
| 88 |
inFoReDa.mForceReactivation = forceReactivation; |
| 89 |
inFoReDa.mIndiNode = individual; |
| 90 |
return newEntry; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
bool CIndividualReactivationProcessingQueue::isEmpty() { |
| 95 |
return mPriorityIndiReactivationMap.count() <= 0; |
| 96 |
} |
| 97 |
|
| 98 |
cint64 CIndividualReactivationProcessingQueue::getQueuedIndividualCount() { |
| 99 |
return mPriorityIndiReactivationMap.count(); |
| 100 |
} |
| 101 |
|
| 102 |
bool CIndividualReactivationProcessingQueue::hasQueuedIndividuals() { |
| 103 |
return mPriorityIndiReactivationMap.count() > 0; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
}; // end namespace Process |
| 108 |
|
| 109 |
}; // end namespace Kernel |
| 110 |
|
| 111 |
}; // end namespace Reasoner |
| 112 |
|
| 113 |
}; // end namespace Konclude |