| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "dlCompletionTree.h"cxx . . $ `<file>/Kernel/dlCompletionTree.h`/ |
| 21 | |
| 22 | /// check if transitive R-successor of the NODE labelled with C |
| 23 | const DlCompletionTreecxx . . $ DlCompletionTree#* |
| 24 | DlCompletionTreecxx . . $ DlCompletionTree# :: isTSuccLabelledcxx . . $ DlCompletionTree#isTSuccLabelled(36354e590de20f49). ( const TRolecxx . . $ TRole#* R, BipolarPointercxx . . $ BipolarPointer# C ) const |
| 25 | { |
| 26 | if ( isLabelledBycxx . . $ DlCompletionTree#isLabelledBy(4a668f6de69bf818).(C) ) |
| 27 | return this; |
| 28 | // don't check nominal nodes (prevent cycles) |
| 29 | if ( isNominalNodecxx . . $ DlCompletionTree#isNominalNode(50ce9a9e25b4a850).() ) |
| 30 | return nullptr; |
| 31 | |
| 32 | // check all other successors |
| 33 | const DlCompletionTreecxx . . $ DlCompletionTree#* ret = nullptr; |
| 34 | for ( const_edge_iteratorcxx . . $ DlCompletionTree#const_edge_iterator# p = begincxx . . $ DlCompletionTree#begin(d3473f034184ffc9).(), p_end = endcxx . . $ DlCompletionTree#end(d3473f034184ffc9).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 35 | if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isSuccEdgecxx . . $ DlCompletionTreeArc#isSuccEdge(50ce9a9e25b4a850).() && |
| 36 | (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isNeighbourcxx . . $ DlCompletionTreeArc#isNeighbour(81d69a9c8508a392).(R) && |
| 37 | !(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isReflexiveEdgecxx . . $ DlCompletionTreeArc#isReflexiveEdge(50ce9a9e25b4a850).() && // prevent cycles |
| 38 | (ret = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).()->isTSuccLabelledcxx . . $ DlCompletionTree#isTSuccLabelled(36354e590de20f49).(R,C)) != nullptr ) |
| 39 | return ret; |
| 40 | |
| 41 | // not happens |
| 42 | return nullptr; |
| 43 | } |
| 44 | |
| 45 | /// check if transitive R-predecessor of the NODE labelled with C; skip FROM node |
| 46 | const DlCompletionTreecxx . . $ DlCompletionTree#* |
| 47 | DlCompletionTreecxx . . $ DlCompletionTree# :: isTPredLabelledcxx . . $ DlCompletionTree#isTPredLabelled(f31e00b7016a43da). ( const TRolecxx . . $ TRole#* R, BipolarPointercxx . . $ BipolarPointer# C, const DlCompletionTreecxx . . $ DlCompletionTree#* from ) const |
| 48 | { |
| 49 | if ( isLabelledBycxx . . $ DlCompletionTree#isLabelledBy(4a668f6de69bf818).(C) ) |
| 50 | return this; |
| 51 | // don't check nominal nodes (prevent cycles) |
| 52 | if ( isNominalNodecxx . . $ DlCompletionTree#isNominalNode(50ce9a9e25b4a850).() ) |
| 53 | return nullptr; |
| 54 | |
| 55 | // check all other successors |
| 56 | const DlCompletionTreecxx . . $ DlCompletionTree#* ret = nullptr; |
| 57 | for ( const_edge_iteratorcxx . . $ DlCompletionTree#const_edge_iterator# p = begincxx . . $ DlCompletionTree#begin(d3473f034184ffc9).(), p_end = endcxx . . $ DlCompletionTree#end(d3473f034184ffc9).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 58 | if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isSuccEdgecxx . . $ DlCompletionTreeArc#isSuccEdge(50ce9a9e25b4a850).() && (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isNeighbourcxx . . $ DlCompletionTreeArc#isNeighbour(81d69a9c8508a392).(R) && (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).() != from && |
| 59 | (ret = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).()->isTSuccLabelledcxx . . $ DlCompletionTree#isTSuccLabelled(36354e590de20f49).(R,C)) != nullptr ) |
| 60 | return ret; |
| 61 | |
| 62 | // check predecessor |
| 63 | if ( hasParentcxx . . $ DlCompletionTree#hasParent(50ce9a9e25b4a850).() && isParentArcLabelledcxx . . $ DlCompletionTree#isParentArcLabelled(81d69a9c8508a392).(R) ) |
| 64 | return getParentNodecxx . . $ DlCompletionTree#getParentNode(19e040716207bced).()->isTPredLabelledcxx . . $ DlCompletionTree#isTPredLabelled(f31e00b7016a43da). ( R, C, this ); |
| 65 | else |
| 66 | return nullptr; |
| 67 | } |
| 68 | |
| 69 | const DlCompletionTreecxx . . $ DlCompletionTree#* |
| 70 | DlCompletionTreecxx . . $ DlCompletionTree# :: isNSomeApplicablecxx . . $ DlCompletionTree#isNSomeApplicable(36354e590de20f49). ( const TRolecxx . . $ TRole#* R, BipolarPointercxx . . $ BipolarPointer# C ) const |
| 71 | { |
| 72 | for ( DlCompletionTreecxx . . $ DlCompletionTree#::const_edge_iteratorcxx . . $ DlCompletionTree#const_edge_iterator# p = begincxx . . $ DlCompletionTree#begin(d3473f034184ffc9).(), p_end = endcxx . . $ DlCompletionTree#end(d3473f034184ffc9).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 73 | if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isNeighbourcxx . . $ DlCompletionTreeArc#isNeighbour(81d69a9c8508a392).(R) && (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).()->isLabelledBycxx . . $ DlCompletionTree#isLabelledBy(4a668f6de69bf818).(C) ) |
| 74 | return (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).(); // already contained such a label |
| 75 | |
| 76 | return nullptr; |
| 77 | } |
| 78 | |
| 79 | const DlCompletionTreecxx . . $ DlCompletionTree#* |
| 80 | DlCompletionTreecxx . . $ DlCompletionTree# :: isTSomeApplicablecxx . . $ DlCompletionTree#isTSomeApplicable(36354e590de20f49). ( const TRolecxx . . $ TRole#* R, BipolarPointercxx . . $ BipolarPointer# C ) const |
| 81 | { |
| 82 | const DlCompletionTreecxx . . $ DlCompletionTree#* ret = nullptr; |
| 83 | |
| 84 | for ( DlCompletionTreecxx . . $ DlCompletionTree#::const_edge_iteratorcxx . . $ DlCompletionTree#const_edge_iterator# p = begincxx . . $ DlCompletionTree#begin(d3473f034184ffc9).(), p_end = endcxx . . $ DlCompletionTree#end(d3473f034184ffc9).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 85 | if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isNeighbourcxx . . $ DlCompletionTreeArc#isNeighbour(81d69a9c8508a392).(R) ) |
| 86 | { |
| 87 | if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isPredEdgecxx . . $ DlCompletionTreeArc#isPredEdge(50ce9a9e25b4a850).() ) |
| 88 | ret = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).()->isTPredLabelledcxx . . $ DlCompletionTree#isTPredLabelled(f31e00b7016a43da).(R,C,this); |
| 89 | else |
| 90 | ret = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).()->isTSuccLabelledcxx . . $ DlCompletionTree#isTSuccLabelled(36354e590de20f49).(R,C); |
| 91 | |
| 92 | if ( ret ) |
| 93 | return ret; // already contained such a label |
| 94 | } |
| 95 | |
| 96 | return nullptr; |
| 97 | } |
| 98 | |
| 99 | #ifdef RKG_IR_IN_NODE_LABELcxx . . $ `Kernel/globaldef.h:69:9`! |
| 100 | //---------------------------------------------- |
| 101 | // inequality relation methods |
| 102 | //---------------------------------------------- |
| 103 | |
| 104 | // check if IR for the node contains C |
| 105 | bool DlCompletionTreecxx . . $ DlCompletionTree# :: inIRwithCcxx . . $ DlCompletionTree#inIRwithC(cacefedd615bba0c). ( const ConceptWDepcxx . . $ ConceptWDep#& C, DepSetcxx . . $ DepSet#& dep ) const |
| 106 | { |
| 107 | if ( IRcxx . . $ DlCompletionTree#IR..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 108 | return false; |
| 109 | |
| 110 | for ( const auto& cwd: IRcxx . . $ DlCompletionTree#IR. ) |
| 111 | if ( cwd.bpcxx . . $ ConceptWDep#bp(455f465bc33b4cdf).() == C.bpcxx . . $ ConceptWDep#bp(455f465bc33b4cdf).() ) |
| 112 | { |
| 113 | dep +=cxx . . $ TDepSet#`operator+=`(6a948e2ed08fa462). cwd.getDepcxx . . $ ConceptWDep#getDep(bce6462a16d96b29).(); |
| 114 | dep +=cxx . . $ TDepSet#`operator+=`(6a948e2ed08fa462). C.getDepcxx . . $ ConceptWDep#getDep(bce6462a16d96b29).(); |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | // check if the NODE's and current node's IR are labeled with the same level |
| 122 | bool DlCompletionTreecxx . . $ DlCompletionTree# :: nonMergeablecxx . . $ DlCompletionTree#nonMergeable(1fdb8df2fde94811). ( const DlCompletionTreecxx . . $ DlCompletionTree#* node, DepSetcxx . . $ DepSet#& dep ) const |
| 123 | { |
| 124 | if ( IRcxx . . $ DlCompletionTree#IR..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() || node->IRcxx . . $ DlCompletionTree#IR..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 125 | return false; |
| 126 | |
| 127 | for ( const auto& cwd: node->IRcxx . . $ DlCompletionTree#IR. ) |
| 128 | if ( inIRwithCcxx . . $ DlCompletionTree#inIRwithC(cacefedd615bba0c). ( cwd, dep ) ) |
| 129 | return true; |
| 130 | |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | /// update IR of the current node with IR from NODE and additional clash-set; @return restorer |
| 135 | TRestorercxx . . $ TRestorer#* DlCompletionTreecxx . . $ DlCompletionTree# :: updateIRcxx . . $ DlCompletionTree#updateIR(7616d0d20370b11b). ( const DlCompletionTreecxx . . $ DlCompletionTree#* node, const DepSetcxx . . $ DepSet#& toAdd ) |
| 136 | { |
| 137 | if ( node->IRcxx . . $ DlCompletionTree#IR..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 138 | return nullptr; // nothing to do |
| 139 | |
| 140 | // save current state |
| 141 | TRestorercxx . . $ TRestorer#* ret = new IRRestorercxx . . $ DlCompletionTree#IRRestorer#(this); |
| 142 | |
| 143 | // copy all elements from NODE's IR to current node. |
| 144 | // FIXME!! do not check if some of them are already in there |
| 145 | for ( const auto& cwd: node->IRcxx . . $ DlCompletionTree#IR. ) |
| 146 | IRcxx . . $ DlCompletionTree#IR..emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35). ( cwd, toAdd ); |
| 147 | |
| 148 | return ret; |
| 149 | } |
| 150 | #endif // RKG_IR_IN_NODE_LABEL |
| 151 | |
| 152 | // saving/restoring |
| 153 | void DlCompletionTreecxx . . $ DlCompletionTree# :: savecxx . . $ DlCompletionTree#save(9a922c1c7ac46c1a). ( SaveStatecxx . . $ DlCompletionTree#SaveState#* nss ) const |
| 154 | { |
| 155 | nss->curLevelcxx . . $ DlCompletionTree#SaveState#curLevel. = curLevelcxx . . $ DlCompletionTree#curLevel.; |
| 156 | nss->nNeighbourscxx . . $ DlCompletionTree#SaveState#nNeighbours. = Neighbourcxx . . $ DlCompletionTree#Neighbour..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 157 | Labelcxx . . $ DlCompletionTree#Label..savecxx . . $ CGLabel#save(43ad53af99fa0458).(nss->labcxx . . $ DlCompletionTree#SaveState#lab.); |
| 158 | |
| 159 | logSRNodecxx . . $ DlCompletionTree#logSRNode(acfedb98bf840c77).("SaveNode"); |
| 160 | } |
| 161 | |
| 162 | void DlCompletionTreecxx . . $ DlCompletionTree# :: restorecxx . . $ DlCompletionTree#restore(4fcc177ae5126665). ( SaveStatecxx . . $ DlCompletionTree#SaveState#* nss ) |
| 163 | { |
| 164 | if ( nss == nullptr ) |
| 165 | return; |
| 166 | |
| 167 | // level restore |
| 168 | curLevelcxx . . $ DlCompletionTree#curLevel. = nss->curLevelcxx . . $ DlCompletionTree#SaveState#curLevel.; |
| 169 | |
| 170 | // label restore |
| 171 | Labelcxx . . $ DlCompletionTree#Label..restorecxx . . $ CGLabel#restore(82e04a944f46c11c). ( nss->labcxx . . $ DlCompletionTree#SaveState#lab., getCurLevelcxx . . $ DlCompletionTree#getCurLevel(ddd8539a2fcdd4ce).() ); |
| 172 | |
| 173 | // remove new neighbours |
| 174 | if ( RKG_USE_DYNAMIC_BACKJUMPINGcxx . . $ `Kernel/globaldef.h:52:10`! ) |
| 175 | { // FIXME!! do nothing for now |
| 176 | // for ( int j = Neighbour.size()-1; j >= 0; --j ) |
| 177 | // if ( Neighbour[j]->getNode()->creLevel <= getCurLevel() ) |
| 178 | // { |
| 179 | // Neighbour.resize(j+1); |
| 180 | // break; |
| 181 | // } |
| 182 | } |
| 183 | else |
| 184 | Neighbourcxx . . $ DlCompletionTree#Neighbour..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(nss->nNeighbourscxx . . $ DlCompletionTree#SaveState#nNeighbours.); |
| 185 | |
| 186 | // it's cheaper to dirty affected flag than to consistently save nodes |
| 187 | affectedcxx . . $ DlCompletionTree#affected. = true; |
| 188 | |
| 189 | // clear memory |
| 190 | delete nss; |
| 191 | |
| 192 | logSRNodecxx . . $ DlCompletionTree#logSRNode(acfedb98bf840c77).("RestNode"); |
| 193 | } |
| 194 | |
| 195 | // output |
| 196 | void DlCompletionTreecxx . . $ DlCompletionTree# :: PrintBodycxx . . $ DlCompletionTree#PrintBody(490063bd7e6d8d5d). ( std::ostreamcxx . . $ std/ostream#& o ) const |
| 197 | { |
| 198 | o <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). idcxx . . $ DlCompletionTree#id.; |
| 199 | if ( isNominalNodecxx . . $ DlCompletionTree#isNominalNode(50ce9a9e25b4a850).() ) |
| 200 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "o" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getNominalLevelcxx . . $ DlCompletionTree#getNominalLevel(72085aa11f4b6e09).(); |
| 201 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '(' <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). getCurLevelcxx . . $ DlCompletionTree#getCurLevel(ddd8539a2fcdd4ce).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ')'; |
| 202 | |
| 203 | // data node? |
| 204 | if ( isDataNodecxx . . $ DlCompletionTree#isDataNode(50ce9a9e25b4a850).() ) |
| 205 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "d"; |
| 206 | |
| 207 | // label (if any) |
| 208 | Labelcxx . . $ DlCompletionTree#Label..printcxx . . $ CGLabel#print(490063bd7e6d8d5d).(o); |
| 209 | |
| 210 | // blocking status information |
| 211 | logNodeBStatuscxx . . $ DlCompletionTree#logNodeBStatus(490063bd7e6d8d5d).(o); |
| 212 | } |