| 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 "CEqualDepthCacheOrientatedProcessingPriorityStrategy.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Strategy { |
| 31 |
|
| 32 |
CEqualDepthCacheOrientatedProcessingPriorityStrategy::CEqualDepthCacheOrientatedProcessingPriorityStrategy() { |
| 33 |
} |
| 34 |
|
| 35 |
CEqualDepthCacheOrientatedProcessingPriorityStrategy::~CEqualDepthCacheOrientatedProcessingPriorityStrategy() { |
| 36 |
} |
| 37 |
|
| 38 |
double CEqualDepthCacheOrientatedProcessingPriorityStrategy::getPriorityForTaskBranching(CSatisfiableCalculationTask* branchingTask, CSatisfiableCalculationTask* parentTask, CIndividualProcessNode* indiProcessNode, CConceptDescriptor* branchingConcept, CSortedNegLinker<CConcept*>* branchedConcept, cint64 branchNumber, CDisjunctBranchingStatistics* branchStats) { |
| 39 |
double parentDepth = parentTask->getTaskDepth(); |
| 40 |
double priority = 0.; |
| 41 |
double maxBranchCount = branchingConcept->getConcept()->getOperandCount(); |
| 42 |
double parentPriority = parentTask->getTaskPriority(); |
| 43 |
|
| 44 |
bool disjunctCached = false; |
| 45 |
|
| 46 |
CConcreteOntology* ontology = branchingTask->getProcessingDataBox()->getOntology(); |
| 47 |
CConsistence* consistence = ontology->getConsistence(); |
| 48 |
if (consistence) { |
| 49 |
CConsistenceData* consData = consistence->getConsistenceModelData(); |
| 50 |
if (consData) { |
| 51 |
CConsistenceTaskData* consTaskData = dynamic_cast<CConsistenceTaskData*>(consData); |
| 52 |
if (consTaskData) { |
| 53 |
CSatisfiableCalculationTask* compGraphCachedCalcTask = consTaskData->getCompletionGraphCachedSatisfiableTask(); |
| 54 |
if (compGraphCachedCalcTask) { |
| 55 |
CIndividualProcessNodeVector* compGraphCachedProcNodeVec = compGraphCachedCalcTask->getProcessingDataBox()->getIndividualProcessNodeVector(); |
| 56 |
if (indiProcessNode->getIndividualNodeID() <= compGraphCachedProcNodeVec->getItemMaxIndex()) { |
| 57 |
CIndividualProcessNode* compIndiProcNode = compGraphCachedProcNodeVec->getData(indiProcessNode->getIndividualNodeID()); |
| 58 |
if (compIndiProcNode && compIndiProcNode->getReapplyConceptLabelSet(false)->containsConcept(branchedConcept->getData(),branchedConcept->isNegated())) { |
| 59 |
disjunctCached = true; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
double prioritySubOffset = 0.2; |
| 68 |
if (disjunctCached) { |
| 69 |
prioritySubOffset = 0.3; |
| 70 |
} |
| 71 |
|
| 72 |
double learningOffset = 0.0; |
| 73 |
double branchOffset = -branchNumber / (10 * maxBranchCount); |
| 74 |
if (branchStats) { |
| 75 |
cint64 clashCount = branchStats->getClashInvolvedCount(); |
| 76 |
cint64 expandedCount = branchStats->getExpandedCount(); |
| 77 |
cint64 satCount = branchStats->getSatisfiableOccurrenceCount(); |
| 78 |
if (clashCount != 0 || expandedCount != 0 || satCount != 0) { |
| 79 |
branchOffset = -branchNumber / (100000 * maxBranchCount); |
| 80 |
} |
| 81 |
double clashFactor = 0; |
| 82 |
if (expandedCount != 0) { |
| 83 |
clashFactor = qMax(qMin(clashCount / (double)expandedCount,1.0),0.0); |
| 84 |
} else if (clashCount != 0) { |
| 85 |
clashFactor = (1./(clashCount*10)); |
| 86 |
} |
| 87 |
double satFactor = 0; |
| 88 |
if (expandedCount != 0) { |
| 89 |
satFactor = qMax(qMin(satCount / (double)expandedCount,1.0),0.0); |
| 90 |
} else if (satCount != 0) { |
| 91 |
satFactor = (1./(satCount*10)); |
| 92 |
} |
| 93 |
learningOffset = 0.0; |
| 94 |
learningOffset += satFactor - clashFactor; |
| 95 |
learningOffset = learningOffset/10.; |
| 96 |
if (expandedCount != 0) { |
| 97 |
learningOffset += 1./(expandedCount*10000); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
priority = parentDepth + 1. + prioritySubOffset + learningOffset + branchOffset; |
| 102 |
return priority; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
}; // end namespace Strategy |
| 108 |
|
| 109 |
}; // end namespace Kernel |
| 110 |
|
| 111 |
}; // end namespace Reasoner |
| 112 |
|
| 113 |
}; // end namespace Konclude |