Debian Codegraph @

Source/Reasoner/Answerer/CComplexConceptStepInstanceComputationProcess.cpp

raw
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 "CComplexConceptStepInstanceComputationProcess.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Answerer {
29
30
31 CComplexConceptStepInstanceComputationProcess::CComplexConceptStepInstanceComputationProcess() : CComplexConceptStepComputationProcess(COMPUTATIONTYPEINSTANCES) {
32 mMaximalRequiredInstancesCount = 0;
33 mComputedInstancesCount = 0;
34 mRequiredAllInstances = false;
35 mAllInstancesComputed = false;
36 mExpectedInstancesCount = 0;
37 }
38
39
40 CComplexConceptStepInstanceComputationProcess::~CComplexConceptStepInstanceComputationProcess() {
41 }
42
43
44
45 bool CComplexConceptStepInstanceComputationProcess::requiresAdditionalInstanceComputation() {
46 if (mMaximalRequiredInstancesCount > mComputedInstancesCount) {
47 return true;
48 }
49 return false;
50 }
51
52 cint64 CComplexConceptStepInstanceComputationProcess::getComputedInstancesCount() {
53 return mComputedInstancesCount;
54 }
55
56 cint64 CComplexConceptStepInstanceComputationProcess::getRequiredInstancesCount() {
57 return mMaximalRequiredInstancesCount;
58 }
59
60 cint64 CComplexConceptStepInstanceComputationProcess::getAdditionalRequiredComputedInstancesCount() {
61 return mMaximalRequiredInstancesCount - mComputedInstancesCount;
62 }
63
64
65 CComplexConceptStepInstanceComputationProcess* CComplexConceptStepInstanceComputationProcess::updateComputedInstancesCount(cint64 instancesCount, function<void(CComputedItemDataNotificationLinker* notificationLinker)> waitingHandlerFunction) {
66 mComputedInstancesCount = instancesCount;
67 while (!mCountDataMap.isEmpty() && mCountDataMap.begin().key() <= instancesCount) {
68 CRequirementWaitingDependencyData& waitDepData = mCountDataMap.begin().value();
69 CComputedItemDataNotificationLinker* notificationLinker = waitDepData.takeNotificationLinker();
70 if (notificationLinker) {
71 waitingHandlerFunction(notificationLinker);
72 }
73 mCountDataMap.erase(mCountDataMap.begin());
74 }
75 return this;
76 }
77
78
79
80 CComplexConceptStepInstanceComputationProcess* CComplexConceptStepInstanceComputationProcess::updateAllInstancesComputed(function<void(CComputedItemDataNotificationLinker* notificationLinker)> waitingHandlerFunction) {
81 mAllInstancesComputed = true;
82 while (!mCountDataMap.isEmpty()) {
83 CRequirementWaitingDependencyData& waitDepData = mCountDataMap.begin().value();
84 CComputedItemDataNotificationLinker* notificationLinker = waitDepData.takeNotificationLinker();
85 if (notificationLinker) {
86 waitingHandlerFunction(notificationLinker);
87 }
88 mCountDataMap.erase(mCountDataMap.begin());
89 }
90 return this;
91 }
92
93
94
95 CComplexConceptStepInstanceComputationProcess* CComplexConceptStepInstanceComputationProcess::addComputedInstancesCountRequirement(cint64 count, CComputedItemDataNotificationLinker* notificationLinker) {
96 CRequirementWaitingDependencyData& depData = mCountDataMap[count];
97 if (notificationLinker) {
98 depData.addNotificationLinker(notificationLinker);
99 }
100 mMaximalRequiredInstancesCount = qMax(mMaximalRequiredInstancesCount, count);
101 return this;
102 }
103
104 CComplexConceptStepInstanceComputationProcess* CComplexConceptStepInstanceComputationProcess::clearComputedInstancesCount() {
105 mComputedInstancesCount = 0;
106 mStarted = false;
107 return this;
108 }
109
110
111
112 bool CComplexConceptStepInstanceComputationProcess::requiresAllInstanceComputation() {
113 return mRequiredAllInstances;
114 }
115
116 CComplexConceptStepInstanceComputationProcess* CComplexConceptStepInstanceComputationProcess::setAllInstanceComputationRequired(bool allInstancesRequired) {
117 mRequiredAllInstances = allInstancesRequired;
118 return this;
119 }
120
121
122 bool CComplexConceptStepInstanceComputationProcess::hasAllInstancesComputed() {
123 return mAllInstancesComputed;
124 }
125
126 CComplexConceptStepInstanceComputationProcess* CComplexConceptStepInstanceComputationProcess::setAllInstancesComputed(bool allInstancesComputed) {
127 mAllInstancesComputed = allInstancesComputed;
128 return this;
129 }
130
131
132 double CComplexConceptStepInstanceComputationProcess::getExpectedInstancesCount() {
133 return mExpectedInstancesCount;
134 }
135
136 CComplexConceptStepInstanceComputationProcess* CComplexConceptStepInstanceComputationProcess::setExpectedInstancesCount(double expectedCount) {
137 mExpectedInstancesCount = expectedCount;
138 return this;
139 }
140
141
142 }; // end namespace Answerer
143
144 }; // end namespace Reasoner
145
146 }; // end namespace Konclude