| 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 "COptimizedComplexBuildingPropertyVariableCompositionsItem.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Answerer { |
| 29 |
|
| 30 |
|
| 31 |
COptimizedComplexBuildingPropertyVariableCompositionsItem::COptimizedComplexBuildingPropertyVariableCompositionsItem(CComplexQueryExpressionProcessingData* queryProcessingData) |
| 32 |
: COptimizedComplexBuildingVariableCompositionsItem(queryProcessingData) { |
| 33 |
|
| 34 |
mInitializedBaseRoleVariableItems = false; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
COptimizedComplexBuildingPropertyVariableCompositionsItem::~COptimizedComplexBuildingPropertyVariableCompositionsItem() { |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* COptimizedComplexBuildingPropertyVariableCompositionsItem::addVariableComplexSuperRole(CPropertyVariableExpression* varExp, CRole* role) { |
| 43 |
mVarSuperRoleHash.insert(varExp, role); |
| 44 |
mRemainingVarExpSet.insert(varExp); |
| 45 |
mAllVarExpSet.insert(varExp); |
| 46 |
return this; |
| 47 |
} |
| 48 |
|
| 49 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* COptimizedComplexBuildingPropertyVariableCompositionsItem::addVariableComplexSubRole(CPropertyVariableExpression* varExp, CRole* role) { |
| 50 |
mVarSubRoleHash.insert(varExp, role); |
| 51 |
mRemainingVarExpSet.insert(varExp); |
| 52 |
mAllVarExpSet.insert(varExp); |
| 53 |
return this; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
bool COptimizedComplexBuildingPropertyVariableCompositionsItem::isWaitingComputation() { |
| 59 |
return hasWaitingVariableCompositionItems() || isWaitingSubVariableBuildingItems(); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
QSet<CPropertyVariableExpression*>* COptimizedComplexBuildingPropertyVariableCompositionsItem::getRemainingVariableExpressionSet() { |
| 65 |
return &mRemainingVarExpSet; |
| 66 |
} |
| 67 |
|
| 68 |
QSet<CPropertyVariableExpression*>* COptimizedComplexBuildingPropertyVariableCompositionsItem::getAllVariableSet() { |
| 69 |
return &mAllVarExpSet; |
| 70 |
} |
| 71 |
|
| 72 |
QList<CRole*> COptimizedComplexBuildingPropertyVariableCompositionsItem::getVariableSuperRoles(CPropertyVariableExpression* varExp) { |
| 73 |
return mVarSuperRoleHash.values(varExp); |
| 74 |
} |
| 75 |
|
| 76 |
QList<CRole*> COptimizedComplexBuildingPropertyVariableCompositionsItem::getVariableSubRoles(CPropertyVariableExpression* varExp) { |
| 77 |
return mVarSubRoleHash.values(varExp); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
bool COptimizedComplexBuildingPropertyVariableCompositionsItem::isInitializedBaseRoleVariableItems() { |
| 83 |
return mInitializedBaseRoleVariableItems; |
| 84 |
} |
| 85 |
|
| 86 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* COptimizedComplexBuildingPropertyVariableCompositionsItem::setInitializedBaseRoleVariableItems(bool initialized) { |
| 87 |
mInitializedBaseRoleVariableItems = initialized; |
| 88 |
return this; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
QSet<QPair<CExpressionVariable*, CExpressionVariable*>>* COptimizedComplexBuildingPropertyVariableCompositionsItem::getVariableSubSuperPropagationSet() { |
| 95 |
return &mVariableSubSuperPropagationSet; |
| 96 |
} |
| 97 |
|
| 98 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* COptimizedComplexBuildingPropertyVariableCompositionsItem::addVariableSubSuperPropagation(CExpressionVariable* subVar, CExpressionVariable* superVar) { |
| 99 |
mVariableSubSuperPropagationSet.insert(QPair<CExpressionVariable*, CExpressionVariable*>(subVar, superVar)); |
| 100 |
mVariableSubPropagationHash.insertMulti(superVar, subVar); |
| 101 |
mVariableSuperPropagationHash.insertMulti(subVar, superVar); |
| 102 |
return this; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* COptimizedComplexBuildingPropertyVariableCompositionsItem::removeVariableSubSuperPropagation(CExpressionVariable* subVar, CExpressionVariable* superVar) { |
| 107 |
mVariableSubSuperPropagationSet.remove(QPair<CExpressionVariable*, CExpressionVariable*>(subVar, superVar)); |
| 108 |
return this; |
| 109 |
} |
| 110 |
|
| 111 |
bool COptimizedComplexBuildingPropertyVariableCompositionsItem::hasVariableSubSuperPropagation(CExpressionVariable* subVar, CExpressionVariable* superVar) { |
| 112 |
return mVariableSubSuperPropagationSet.contains(QPair<CExpressionVariable*, CExpressionVariable*>(subVar, superVar)); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
QSet<QPair<CExpressionVariable*, CExpressionVariable*>> COptimizedComplexBuildingPropertyVariableCompositionsItem::getVariableRemainingSubSuperPropagationSet(CExpressionVariable* varExp) { |
| 117 |
QSet<QPair<CExpressionVariable*, CExpressionVariable*>> variableSubSuperPropagationSet; |
| 118 |
QList<CExpressionVariable*> subVarList = mVariableSubPropagationHash.values(varExp); |
| 119 |
QList<CExpressionVariable*> superVarList = mVariableSuperPropagationHash.values(varExp); |
| 120 |
for (CExpressionVariable* subVarExp : subVarList) { |
| 121 |
if (!mVariableSubSuperPropagationSet.contains(QPair<CExpressionVariable*, CExpressionVariable*>(subVarExp, varExp))) { |
| 122 |
variableSubSuperPropagationSet.insert(QPair<CExpressionVariable*, CExpressionVariable*>(subVarExp, varExp)); |
| 123 |
} |
| 124 |
} |
| 125 |
for (CExpressionVariable* superVarExp : superVarList) { |
| 126 |
if (!mVariableSubSuperPropagationSet.contains(QPair<CExpressionVariable*, CExpressionVariable*>(varExp, superVarExp))) { |
| 127 |
variableSubSuperPropagationSet.insert(QPair<CExpressionVariable*, CExpressionVariable*>(varExp, superVarExp)); |
| 128 |
} |
| 129 |
} |
| 130 |
return variableSubSuperPropagationSet; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
bool COptimizedComplexBuildingPropertyVariableCompositionsItem::isRemovingPropagationDisconnecting(CExpressionVariable* varExp, CExpressionVariable* subVar, CExpressionVariable* superVar) { |
| 137 |
|
| 138 |
CExpressionVariable* otherVarEpx = superVar; |
| 139 |
if (varExp == superVar) { |
| 140 |
otherVarEpx = subVar; |
| 141 |
} |
| 142 |
QSet<CExpressionVariable*> reachedVarExpSet; |
| 143 |
QList<CExpressionVariable*> testingVarExpList; |
| 144 |
testingVarExpList.append(otherVarEpx); |
| 145 |
reachedVarExpSet.insert(otherVarEpx); |
| 146 |
|
| 147 |
while (!testingVarExpList.isEmpty()) { |
| 148 |
CExpressionVariable* testingVarEpx = testingVarExpList.takeFirst(); |
| 149 |
QSet<QPair<CExpressionVariable*, CExpressionVariable*>> variableSubSuperPropagationSet = getVariableRemainingSubSuperPropagationSet(testingVarEpx); |
| 150 |
for (QPair<CExpressionVariable*, CExpressionVariable* > variableSubSuperPair : variableSubSuperPropagationSet) { |
| 151 |
if (variableSubSuperPair.first != subVar && variableSubSuperPair.second != superVar) { |
| 152 |
CExpressionVariable* testConnOtherVar = variableSubSuperPair.first; |
| 153 |
if (testConnOtherVar == testingVarEpx) { |
| 154 |
testConnOtherVar = variableSubSuperPair.second; |
| 155 |
} |
| 156 |
if (testConnOtherVar == varExp) { |
| 157 |
return false; |
| 158 |
} |
| 159 |
if (!reachedVarExpSet.contains(testConnOtherVar)) { |
| 160 |
reachedVarExpSet.insert(testConnOtherVar); |
| 161 |
testingVarExpList.append(testConnOtherVar); |
| 162 |
} |
| 163 |
|
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
return true; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* COptimizedComplexBuildingPropertyVariableCompositionsItem::setVariableExpressionUnhandled(CPropertyVariableExpression* varExp) { |
| 173 |
mRemainingVarExpSet.insert(varExp); |
| 174 |
return this; |
| 175 |
} |
| 176 |
|
| 177 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* COptimizedComplexBuildingPropertyVariableCompositionsItem::setVariableExpressionHandled(CPropertyVariableExpression* varExp) { |
| 178 |
mRemainingVarExpSet.remove(varExp); |
| 179 |
return this; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
}; // end namespace Answerer |
| 185 |
|
| 186 |
}; // end namespace Reasoner |
| 187 |
|
| 188 |
}; // end namespace Konclude |