| 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 "CConcreteConceptProcessingOperatorPriorityStrategy.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Strategy { |
| 31 |
|
| 32 |
CConcreteConceptProcessingOperatorPriorityStrategy::CConcreteConceptProcessingOperatorPriorityStrategy() { |
| 33 |
priCount = 200; |
| 34 |
priorities = new double[priCount]; |
| 35 |
symAccessPri = priorities+priCount/2; |
| 36 |
|
| 37 |
for (int i = 0; i < priCount; ++i) { |
| 38 |
priorities[i] = 0; |
| 39 |
} |
| 40 |
|
| 41 |
// The following priorities are similar to the FaCT++ standard IAOEFLG options and have the same meaning. |
| 42 |
|
| 43 |
// FaCT++ register "IAOEFLG" option: |
| 44 |
// Option 'IAOEFLG' define the priorities of different operations in TODO list. Possible values are |
| 45 |
// 7-digit strings with only possible digit are 0-6. The digits on the places 1, 2, ..., 7 are for |
| 46 |
// priority of Id, And, Or, Exists, Forall, LE and GE operations respectively. The smaller number means |
| 47 |
// the higher priority. All other constructions (TOP, BOTTOM, etc) has priority 0. |
| 48 |
|
| 49 |
// The operations are ordered in a priority queue and are applied also from lower to highest priority. |
| 50 |
//symAccessPri[CCATOM] = 2; |
| 51 |
//symAccessPri[CCAND] = 3; |
| 52 |
//symAccessPri[CCOR] = 7; |
| 53 |
//symAccessPri[CCSOME] = 4; |
| 54 |
//symAccessPri[CCALL] = 1; |
| 55 |
//symAccessPri[CCATLEAST] = 1; |
| 56 |
//symAccessPri[CCATMOST] = 6; |
| 57 |
cint64 nextPriority = 14; |
| 58 |
|
| 59 |
|
| 60 |
symAccessPri[CCTOP] = nextPriority; |
| 61 |
symAccessPri[-CCBOTTOM] = nextPriority; |
| 62 |
symAccessPri[CCATOM] = nextPriority; |
| 63 |
symAccessPri[-CCATOM] = nextPriority; |
| 64 |
|
| 65 |
nextPriority = 13; |
| 66 |
|
| 67 |
symAccessPri[CCAND] = nextPriority; |
| 68 |
symAccessPri[-CCOR] = nextPriority; |
| 69 |
symAccessPri[CCSUB] = nextPriority; |
| 70 |
symAccessPri[CCEQ] = nextPriority; |
| 71 |
symAccessPri[CCIMPLTRIG] = nextPriority; |
| 72 |
symAccessPri[CCBRANCHTRIG] = nextPriority; |
| 73 |
symAccessPri[CCPBINDTRIG] = nextPriority; |
| 74 |
symAccessPri[CCPBINDAND] = nextPriority; |
| 75 |
symAccessPri[CCVARBINDTRIG] = nextPriority; |
| 76 |
symAccessPri[CCVARBINDAND] = nextPriority; |
| 77 |
symAccessPri[CCVARPBACKTRIG] = nextPriority; |
| 78 |
symAccessPri[CCBACKACTIVTRIG] = nextPriority; |
| 79 |
|
| 80 |
symAccessPri[CCVARBINDPREPARE] = nextPriority; |
| 81 |
symAccessPri[CCVARBINDFINALZE] = nextPriority; |
| 82 |
|
| 83 |
symAccessPri[CCOR] = nextPriority; |
| 84 |
symAccessPri[-CCAND] = nextPriority; |
| 85 |
symAccessPri[-CCEQ] = nextPriority; |
| 86 |
symAccessPri[CCDATATYPE] = nextPriority; |
| 87 |
symAccessPri[-CCDATATYPE] = nextPriority; |
| 88 |
symAccessPri[CCDATALITERAL] = nextPriority; |
| 89 |
symAccessPri[-CCDATALITERAL] = nextPriority; |
| 90 |
symAccessPri[CCDATARESTRICTION] = nextPriority; |
| 91 |
symAccessPri[-CCDATARESTRICTION] = nextPriority; |
| 92 |
|
| 93 |
mDisjDelConsidPriOffset = -9.0; |
| 94 |
mDisjDelProcessPriOffset = -11.5; |
| 95 |
|
| 96 |
|
| 97 |
nextPriority = 12; |
| 98 |
|
| 99 |
symAccessPri[CCALL] = nextPriority; |
| 100 |
symAccessPri[-CCSOME] = nextPriority; |
| 101 |
symAccessPri[CCAQALL] = nextPriority; |
| 102 |
symAccessPri[CCIMPLALL] = nextPriority; |
| 103 |
symAccessPri[CCBRANCHALL] = nextPriority; |
| 104 |
symAccessPri[CCIMPLAQALL] = nextPriority; |
| 105 |
symAccessPri[CCBRANCHAQALL] = nextPriority; |
| 106 |
symAccessPri[CCPBINDALL] = nextPriority; |
| 107 |
symAccessPri[CCVARBINDALL] = nextPriority; |
| 108 |
symAccessPri[CCVARBINDAQALL] = nextPriority; |
| 109 |
symAccessPri[CCVARPBACKAQALL] = nextPriority; |
| 110 |
symAccessPri[CCVARPBACKALL] = nextPriority; |
| 111 |
|
| 112 |
nextPriority = 11; |
| 113 |
|
| 114 |
symAccessPri[CCAQAND] = nextPriority; |
| 115 |
symAccessPri[CCIMPLAQAND] = nextPriority; |
| 116 |
symAccessPri[CCBRANCHAQAND] = nextPriority; |
| 117 |
symAccessPri[CCPBINDAQAND] = nextPriority; |
| 118 |
symAccessPri[CCVARBINDAQAND] = nextPriority; |
| 119 |
symAccessPri[CCVARPBACKAQAND] = nextPriority; |
| 120 |
|
| 121 |
nextPriority = 10; |
| 122 |
|
| 123 |
symAccessPri[CCAQCHOOCE] = nextPriority; |
| 124 |
symAccessPri[-CCAQCHOOCE] = nextPriority; |
| 125 |
|
| 126 |
nextPriority = 9; |
| 127 |
|
| 128 |
symAccessPri[CCIMPL] = nextPriority; |
| 129 |
symAccessPri[CCNOMINALIMPLI] = nextPriority; |
| 130 |
symAccessPri[CCDATATYPEIMPLI] = nextPriority; |
| 131 |
symAccessPri[CCDATALITERALIMPLI] = nextPriority; |
| 132 |
symAccessPri[CCDATARESTRICTIONIMPLI]= nextPriority; |
| 133 |
symAccessPri[CCBRANCHIMPL] = nextPriority; |
| 134 |
symAccessPri[CCPBINDIMPL] = nextPriority; |
| 135 |
symAccessPri[CCPBINDVARIABLE] = nextPriority; |
| 136 |
symAccessPri[CCPBINDCYCLE] = nextPriority; |
| 137 |
symAccessPri[CCVARBINDJOIN] = nextPriority; |
| 138 |
symAccessPri[CCVARBINDVARIABLE] = nextPriority; |
| 139 |
symAccessPri[CCBACKACTIVIMPL] = nextPriority; |
| 140 |
symAccessPri[CCVARBINDIMPL] = nextPriority; |
| 141 |
|
| 142 |
nextPriority = 8; |
| 143 |
symAccessPri[CCSELF] = nextPriority; |
| 144 |
symAccessPri[-CCSELF] = nextPriority; |
| 145 |
symAccessPri[CCVALUE] = nextPriority; |
| 146 |
symAccessPri[-CCVALUE] = nextPriority; |
| 147 |
|
| 148 |
// intermediately processing limit |
| 149 |
|
| 150 |
nextPriority = 7; |
| 151 |
|
| 152 |
symAccessPri[CCNOMINAL] = nextPriority; |
| 153 |
symAccessPri[-CCNOMINAL] = nextPriority; |
| 154 |
|
| 155 |
|
| 156 |
nextPriority = 6; |
| 157 |
|
| 158 |
symAccessPri[CCPBINDGROUND] = nextPriority; |
| 159 |
symAccessPri[CCVARBINDGROUND] = nextPriority; |
| 160 |
symAccessPri[-CCPBINDGROUND] = nextPriority; |
| 161 |
symAccessPri[-CCVARBINDGROUND] = nextPriority; |
| 162 |
|
| 163 |
nextPriority = 5; |
| 164 |
|
| 165 |
symAccessPri[CCATLEAST] = nextPriority; |
| 166 |
symAccessPri[-CCATMOST] = nextPriority; |
| 167 |
|
| 168 |
nextPriority = 4; |
| 169 |
|
| 170 |
symAccessPri[CCSOME] = nextPriority; |
| 171 |
symAccessPri[-CCALL] = nextPriority; |
| 172 |
symAccessPri[CCAQSOME] = nextPriority; |
| 173 |
|
| 174 |
// deterministic processing limit |
| 175 |
|
| 176 |
nextPriority = 3; |
| 177 |
|
| 178 |
symAccessPri[CCATMOST] = nextPriority; |
| 179 |
symAccessPri[-CCATLEAST] = nextPriority; |
| 180 |
|
| 181 |
nextPriority = 2; |
| 182 |
|
| 183 |
// disjunctions + processing offsets |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
mVariableBindingsPreparationDelaying = false; |
| 188 |
|
| 189 |
|
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
CConcreteConceptProcessingOperatorPriorityStrategy::~CConcreteConceptProcessingOperatorPriorityStrategy() { |
| 194 |
delete [] priorities; |
| 195 |
} |
| 196 |
|
| 197 |
void CConcreteConceptProcessingOperatorPriorityStrategy::readCalculationConfig(CSatisfiableCalculationTask* satCalcTask) { |
| 198 |
mVariableBindingsPreparationDelaying = false; |
| 199 |
CCalculationConfigurationExtension *config = satCalcTask->getCalculationConfiguration(); |
| 200 |
|
| 201 |
CSatisfiableTaskAnswererBindingPropagationAdapter* answererMessageAdapter = satCalcTask->getSatisfiableAnswererBindingPropagationAdapter(); |
| 202 |
if (answererMessageAdapter) { |
| 203 |
CAnsweringPropagationSteeringController* propagationSteeringController = answererMessageAdapter->getAnswererPropagationSteeringController(); |
| 204 |
if (propagationSteeringController) { |
| 205 |
if (propagationSteeringController->finalizeWithClashing()) { |
| 206 |
mVariableBindingsPreparationDelaying = true; |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
double CConcreteConceptProcessingOperatorPriorityStrategy::getPriorityOffsetForDisjunctionDelayedConsidering(CConceptDescriptor *conceptDescriptor, CIndividualProcessNode *individual) { |
| 214 |
return mDisjDelConsidPriOffset; |
| 215 |
} |
| 216 |
|
| 217 |
double CConcreteConceptProcessingOperatorPriorityStrategy::getPriorityOffsetForDisjunctionDelayedProcessing(CConceptDescriptor *conceptDescriptor, CIndividualProcessNode *individual) { |
| 218 |
return mDisjDelProcessPriOffset; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
CConceptProcessPriority CConcreteConceptProcessingOperatorPriorityStrategy::getPriorityForConcept(CConceptDescriptor *conceptDescriptor, CIndividualProcessNode *individual) { |
| 223 |
qint64 cCode = conceptDescriptor->getData()->getOperatorCode(); |
| 224 |
bool negated = false; |
| 225 |
if (conceptDescriptor->isNegated()) { |
| 226 |
cCode *= -1; |
| 227 |
negated = true; |
| 228 |
} |
| 229 |
double priority = 0; |
| 230 |
priority = symAccessPri[cCode]; |
| 231 |
|
| 232 |
if (cCode == CCVARBINDPREPARE) { |
| 233 |
if (!conceptDescriptor->getData()->getVariable()) { |
| 234 |
if (mVariableBindingsPreparationDelaying) { |
| 235 |
priority = 3.5; |
| 236 |
} else if (!individual->isNominalIndividualNode()) { |
| 237 |
priority = 3.5; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
CSortedNegLinker<CConcept *> *opConLinkerIt = conceptDescriptor->getData()->getOperandList(); |
| 243 |
if (cCode == CCATMOST) { |
| 244 |
qint64 param = conceptDescriptor->getData()->getParameter(); |
| 245 |
param = param - 1*negated; |
| 246 |
if (param <= 1 && !opConLinkerIt) { |
| 247 |
priority = 5.5; |
| 248 |
} else { |
| 249 |
double priorityOffset = (exp(-param / 1000.)) * 0.5; |
| 250 |
priority += priorityOffset; |
| 251 |
} |
| 252 |
} else if (cCode == CCATLEAST) { |
| 253 |
qint64 param = conceptDescriptor->getData()->getParameter(); |
| 254 |
param = param + 1*negated; |
| 255 |
if (param <= 2 && !opConLinkerIt) { |
| 256 |
priority = 5.0; |
| 257 |
} else { |
| 258 |
double priorityOffset = (1. - exp(-param / 1000.)) * 0.5; |
| 259 |
priority += priorityOffset; |
| 260 |
} |
| 261 |
} |
| 262 |
return CConceptProcessPriority(priority); |
| 263 |
} |
| 264 |
|
| 265 |
}; // end namespace Strategy |
| 266 |
|
| 267 |
}; // end namespace Kernel |
| 268 |
|
| 269 |
}; // end namespace Reasoner |
| 270 |
|
| 271 |
}; // end namespace Konclude |