| 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 "CBranchingTree.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
namespace Dependency { |
| 33 |
|
| 34 |
|
| 35 |
CBranchingTree::CBranchingTree(CProcessContext* processContext) { |
| 36 |
mPocessContext = processContext; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
CBranchingTree* CBranchingTree::initBranchingTree(CBranchingTree* tree) { |
| 41 |
mRootNode = nullptr; |
| 42 |
mCurrNode = nullptr; |
| 43 |
mPrevCurrNode = nullptr; |
| 44 |
mBaseDepNode = nullptr; |
| 45 |
if (tree) { |
| 46 |
mPrevCurrNode = tree->mPrevCurrNode; |
| 47 |
mRootNode = tree->mRootNode; |
| 48 |
mBaseDepNode = tree->mBaseDepNode; |
| 49 |
} |
| 50 |
return this; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
CBranchTreeNode* CBranchingTree::getBranchTreeNode(Task::CSatisfiableCalculationTask* task, bool forceBranchCreation) { |
| 55 |
if (mCurrNode) { |
| 56 |
if (mCurrNode->getSatisfiableCalculationTask() != task) { |
| 57 |
CBranchTreeNode* branchNode = CObjectParameterizingAllocator< CBranchTreeNode,CProcessContext* >::allocateAndConstructAndParameterize(mPocessContext->getUsedMemoryAllocationManager(),mPocessContext); |
| 58 |
branchNode->initBranchingCopyNode(mCurrNode,task); |
| 59 |
mCurrNode = branchNode; |
| 60 |
mPrevCurrNode = mCurrNode; |
| 61 |
if (branchNode->isRootNode()) { |
| 62 |
mRootNode = branchNode; |
| 63 |
} |
| 64 |
} |
| 65 |
if (forceBranchCreation) { |
| 66 |
CBranchTreeNode* branchNode = CObjectParameterizingAllocator< CBranchTreeNode,CProcessContext* >::allocateAndConstructAndParameterize(mPocessContext->getUsedMemoryAllocationManager(),mPocessContext); |
| 67 |
branchNode->initBranchingChildNode(mCurrNode,task); |
| 68 |
mCurrNode = branchNode; |
| 69 |
mPrevCurrNode = mCurrNode; |
| 70 |
} |
| 71 |
} else if (!mCurrNode) { |
| 72 |
if (mPrevCurrNode) { |
| 73 |
CBranchTreeNode* branchNode = CObjectParameterizingAllocator< CBranchTreeNode,CProcessContext* >::allocateAndConstructAndParameterize(mPocessContext->getUsedMemoryAllocationManager(),mPocessContext); |
| 74 |
branchNode->initBranchingChildNode(mPrevCurrNode,task); |
| 75 |
mCurrNode = branchNode; |
| 76 |
mPrevCurrNode = mCurrNode; |
| 77 |
} else { |
| 78 |
CBranchTreeNode* branchNode = CObjectParameterizingAllocator< CBranchTreeNode,CProcessContext* >::allocateAndConstructAndParameterize(mPocessContext->getUsedMemoryAllocationManager(),mPocessContext); |
| 79 |
branchNode->initBranchingRootNode(task); |
| 80 |
mCurrNode = branchNode; |
| 81 |
mRootNode = branchNode; |
| 82 |
mPrevCurrNode = mCurrNode; |
| 83 |
} |
| 84 |
} |
| 85 |
return mCurrNode; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
CDependencyNode* CBranchingTree::getBaseDependencyNode(bool create) { |
| 90 |
if (!mBaseDepNode && create) { |
| 91 |
CIndependentBaseDependencyNode* indBaseDepNode = CObjectParameterizingAllocator< CIndependentBaseDependencyNode,CProcessContext* >::allocateAndConstructAndParameterize(mPocessContext->getUsedMemoryAllocationManager(),mPocessContext); |
| 92 |
indBaseDepNode->initIndependentBaseDependencyNode(); |
| 93 |
mBaseDepNode = indBaseDepNode; |
| 94 |
} |
| 95 |
return mBaseDepNode; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
}; // end namespace Dependency |
| 100 |
|
| 101 |
}; // end namespace Process |
| 102 |
|
| 103 |
}; // end namespace Kernel |
| 104 |
|
| 105 |
}; // end namespace Reasoner |
| 106 |
|
| 107 |
}; // end namespace Konclude |