| 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 "CCacheAnswersWeightedUsageCostItem.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Answerer { |
| 29 |
|
| 30 |
|
| 31 |
CCacheAnswersWeightedUsageCostItem::CCacheAnswersWeightedUsageCostItem() { |
| 32 |
mComputationCost = 0; |
| 33 |
mLastCacheInstalledCostWeightedUsage = -1; |
| 34 |
mTimeCostMeasurementTimer = nullptr; |
| 35 |
mCacheUpdateQueued = false; |
| 36 |
mQueryUsageCount = 0; |
| 37 |
mCacheWeightedUsageFactor = 0; |
| 38 |
mPrevComputationCost = 0; |
| 39 |
mTotalQueryUsageCount = 0; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
CCacheAnswersWeightedUsageCostItem::~CCacheAnswersWeightedUsageCostItem() { |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
cint64 CCacheAnswersWeightedUsageCostItem::getQueryUsageCount() { |
| 49 |
return mQueryUsageCount; |
| 50 |
} |
| 51 |
|
| 52 |
CCacheAnswersWeightedUsageCostItem* CCacheAnswersWeightedUsageCostItem::incQueryUsageCount(cint64 count) { |
| 53 |
mTotalQueryUsageCount++; |
| 54 |
mQueryUsageCount += count; |
| 55 |
return this; |
| 56 |
} |
| 57 |
|
| 58 |
CCacheAnswersWeightedUsageCostItem* CCacheAnswersWeightedUsageCostItem::decQueryUsageCount(cint64 count) { |
| 59 |
mQueryUsageCount -= count; |
| 60 |
return this; |
| 61 |
} |
| 62 |
|
| 63 |
CCacheAnswersWeightedUsageCostItem* CCacheAnswersWeightedUsageCostItem::setQueryUsageCount(cint64 count) { |
| 64 |
mQueryUsageCount = count; |
| 65 |
return this; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
double CCacheAnswersWeightedUsageCostItem::getCacheWeightedUsageFactor() { |
| 70 |
return mCacheWeightedUsageFactor; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
CCacheAnswersWeightedUsageCostItem* CCacheAnswersWeightedUsageCostItem::setCacheWeightedUsageFactor(double factor) { |
| 75 |
mCacheWeightedUsageFactor = factor; |
| 76 |
return this; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
CCacheAnswersWeightedUsageCostItem* CCacheAnswersWeightedUsageCostItem::incCacheWeightedUsageFactor(double factor) { |
| 81 |
mCacheWeightedUsageFactor += factor; |
| 82 |
return this; |
| 83 |
} |
| 84 |
|
| 85 |
double CCacheAnswersWeightedUsageCostItem::getLastCacheInstalledCostWeightedUsage() { |
| 86 |
return mLastCacheInstalledCostWeightedUsage; |
| 87 |
} |
| 88 |
|
| 89 |
CCacheAnswersWeightedUsageCostItem* CCacheAnswersWeightedUsageCostItem::setLastCacheInstalledCostWeightedUsage(double usageWeightedCost) { |
| 90 |
mLastCacheInstalledCostWeightedUsage = usageWeightedCost; |
| 91 |
return this; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
bool CCacheAnswersWeightedUsageCostItem::isCacheUpdateQueued() { |
| 98 |
return mCacheUpdateQueued; |
| 99 |
} |
| 100 |
|
| 101 |
CCacheAnswersWeightedUsageCostItem* CCacheAnswersWeightedUsageCostItem::setCacheUpdateQueued(bool queued) { |
| 102 |
mCacheUpdateQueued = queued; |
| 103 |
return this; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
bool CCacheAnswersWeightedUsageCostItem::clearComputation() { |
| 110 |
mPrevComputationCost = mComputationCost; |
| 111 |
mComputationCost = 0; |
| 112 |
return true; |
| 113 |
} |
| 114 |
|
| 115 |
bool CCacheAnswersWeightedUsageCostItem::startComputationCostMearsuring() { |
| 116 |
if (!mTimeCostMeasurementTimer) { |
| 117 |
mTimeCostMeasurementTimer = new QTime(); |
| 118 |
mTimeCostMeasurementTimer->start(); |
| 119 |
return true; |
| 120 |
} else { |
| 121 |
return false; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
bool CCacheAnswersWeightedUsageCostItem::stopComputationCostMearsuring() { |
| 126 |
if (mTimeCostMeasurementTimer) { |
| 127 |
mComputationCost += mTimeCostMeasurementTimer->elapsed(); |
| 128 |
mComputationCost = qMax(0.1, mComputationCost); |
| 129 |
delete mTimeCostMeasurementTimer; |
| 130 |
mTimeCostMeasurementTimer = nullptr; |
| 131 |
return true; |
| 132 |
} else { |
| 133 |
return false; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
bool CCacheAnswersWeightedUsageCostItem::isComputationCostMeasuring() { |
| 138 |
return mTimeCostMeasurementTimer != nullptr; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
double CCacheAnswersWeightedUsageCostItem::getComputationCost() { |
| 143 |
return mComputationCost; |
| 144 |
} |
| 145 |
|
| 146 |
}; // end namespace Answerer |
| 147 |
|
| 148 |
}; // end namespace Reasoner |
| 149 |
|
| 150 |
}; // end namespace Konclude |