| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2006-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 | #ifndef CGLABEL_H |
| 21 | #define CGLABEL_Hcxx . . $ `Kernel/CGLabel.h:21:9`! |
| 22 | |
| 23 | #include "CWDArray.h"cxx . . $ `<file>/Kernel/CWDArray.h`/ |
| 24 | #include "dlVertex.h"cxx . . $ `<file>/Kernel/dlVertex.h`/ // for DagTag |
| 25 | |
| 26 | /// class implementing a label in a node of a completion graph |
| 27 | class CGLabelcxx . . $ CGLabel# |
| 28 | { |
| 29 | public: // type interface |
| 30 | /// RO iterator on label |
| 31 | typedef CWDArraycxx . . $ CWDArray#::const_iteratorcxx . . $ CWDArray#const_iterator# const_iteratorcxx . . $ CGLabel#const_iterator#; |
| 32 | |
| 33 | public: // external classes |
| 34 | /// class for save/restore |
| 35 | class SaveStatecxx . . $ CGLabel#SaveState# |
| 36 | { |
| 37 | public: |
| 38 | /// states for simple-, complex- and extra labels |
| 39 | CWDArraycxx . . $ CWDArray#::SaveStatecxx . . $ CWDArray#SaveState# sccxx . . $ CGLabel#SaveState#sc., cccxx . . $ CGLabel#SaveState#cc.; |
| 40 | }; // SaveState |
| 41 | |
| 42 | protected: // members |
| 43 | /// all simple concepts, labelled a node |
| 44 | CWDArraycxx . . $ CWDArray# scLabelcxx . . $ CGLabel#scLabel.; |
| 45 | /// all complex concepts (ie, FORALL, GE), labelled a node |
| 46 | CWDArraycxx . . $ CWDArray# ccLabelcxx . . $ CGLabel#ccLabel.; |
| 47 | |
| 48 | public: // static methods |
| 49 | /// @return true iff TAG represents complex concept |
| 50 | static bool isComplexConceptcxx . . $ CGLabel#isComplexConcept(7b512e7165d9f2af). ( DagTagcxx . . $ DagTag# tag ) |
| 51 | { |
| 52 | switch(tag) |
| 53 | { |
| 54 | case dtForallcxx . . $ dtForall.: |
| 55 | case dtLEcxx . . $ dtLE.: |
| 56 | case dtIrrcxx . . $ dtIrr.: |
| 57 | case dtNNcxx . . $ dtNN.: |
| 58 | case dtChoosecxx . . $ dtChoose.: |
| 59 | return true; |
| 60 | default: |
| 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | public: // interface |
| 66 | /// init newly created node |
| 67 | void initcxx . . $ CGLabel#init(49f6e7a06ebc5aa8). ( void ); |
| 68 | |
| 69 | //---------------------------------------------- |
| 70 | // Label access interface |
| 71 | //---------------------------------------------- |
| 72 | |
| 73 | // label iterators |
| 74 | |
| 75 | /// begin() iterator for a label with simple concepts |
| 76 | const_iteratorcxx . . $ CGLabel#const_iterator# begin_sccxx . . $ CGLabel#begin_sc(e55d760a93e9f197). ( void ) const { return scLabelcxx . . $ CGLabel#scLabel..begincxx . . $ CWDArray#begin(e55d760a93e9f197).(); } |
| 77 | /// end() iterator for a label with simple concepts |
| 78 | const_iteratorcxx . . $ CGLabel#const_iterator# end_sccxx . . $ CGLabel#end_sc(e55d760a93e9f197). ( void ) const { return scLabelcxx . . $ CGLabel#scLabel..endcxx . . $ CWDArray#end(e55d760a93e9f197).(); } |
| 79 | /// begin() iterator for a label with complex concepts |
| 80 | const_iteratorcxx . . $ CGLabel#const_iterator# begin_cccxx . . $ CGLabel#begin_cc(e55d760a93e9f197). ( void ) const { return ccLabelcxx . . $ CGLabel#ccLabel..begincxx . . $ CWDArray#begin(e55d760a93e9f197).(); } |
| 81 | /// end() iterator for a label with complex concepts |
| 82 | const_iteratorcxx . . $ CGLabel#const_iterator# end_cccxx . . $ CGLabel#end_cc(e55d760a93e9f197). ( void ) const { return ccLabelcxx . . $ CGLabel#ccLabel..endcxx . . $ CWDArray#end(e55d760a93e9f197).(); } |
| 83 | |
| 84 | //---------------------------------------------- |
| 85 | // Label access interface |
| 86 | //---------------------------------------------- |
| 87 | /// get (RW) label associated with the concepts defined by the flag |
| 88 | CWDArraycxx . . $ CWDArray#& getLabelcxx . . $ CGLabel#getLabel(ad96fabd6ffb3e80). ( bool isComplex ) { return isComplex ? ccLabelcxx . . $ CGLabel#ccLabel. : scLabelcxx . . $ CGLabel#scLabel.; } |
| 89 | /// get (RO) label associated with the concepts defined by the flag |
| 90 | const CWDArraycxx . . $ CWDArray#& getLabelcxx . . $ CGLabel#getLabel(ca01410c9270c655). ( bool isComplex ) const { return isComplex ? ccLabelcxx . . $ CGLabel#ccLabel. : scLabelcxx . . $ CGLabel#scLabel.; } |
| 91 | /// get (RW) label associated with the concepts defined by TAG |
| 92 | CWDArraycxx . . $ CWDArray#& getLabelcxx . . $ CGLabel#getLabel(f501173caf11fe67). ( DagTagcxx . . $ DagTag# tag ) { return getLabelcxx . . $ CGLabel#getLabel(ad96fabd6ffb3e80).(isComplexConceptcxx . . $ CGLabel#isComplexConcept(7b512e7165d9f2af).(tag)); } |
| 93 | /// get (RO) label associated with the concepts defined by TAG |
| 94 | const CWDArraycxx . . $ CWDArray#& getLabelcxx . . $ CGLabel#getLabel(b736cd54e89c5a41). ( DagTagcxx . . $ DagTag# tag ) const { return getLabelcxx . . $ CGLabel#getLabel(ca01410c9270c655).(isComplexConceptcxx . . $ CGLabel#isComplexConcept(7b512e7165d9f2af).(tag)); } |
| 95 | |
| 96 | // TODO table interface |
| 97 | |
| 98 | /// get ToDoEntry offset by given SC labels' iterator |
| 99 | int getSCOffsetcxx . . $ CGLabel#getSCOffset(f30316450779e1c3). ( const_iteratorcxx . . $ CGLabel#const_iterator# p ) const { return int(p-cxx . . $ __gnu_cxx/operator-(a40477c209547c13).begin_sccxx . . $ CGLabel#begin_sc(e55d760a93e9f197).()); } |
| 100 | /// get ToDoEntry offset by given CC labels' iterator |
| 101 | int getCCOffsetcxx . . $ CGLabel#getCCOffset(f30316450779e1c3). ( const_iteratorcxx . . $ CGLabel#const_iterator# p ) const { return int(-(p-cxx . . $ __gnu_cxx/operator-(a40477c209547c13).begin_cccxx . . $ CGLabel#begin_cc(e55d760a93e9f197).()+1)); } |
| 102 | /// get the index of the latest (ie just inserted) concept in the label |
| 103 | int getLastcxx . . $ CGLabel#getLast(6006887bf52ae696). ( DagTagcxx . . $ DagTag# tag ) const |
| 104 | { |
| 105 | if ( isComplexConceptcxx . . $ CGLabel#isComplexConcept(7b512e7165d9f2af).(tag) ) |
| 106 | return getCCOffsetcxx . . $ CGLabel#getCCOffset(f30316450779e1c3).(end_cccxx . . $ CGLabel#end_cc(e55d760a93e9f197).()-cxx . . $ __gnu_cxx/__normal_iterator#operator-(d0cb2d2ebd313f38).1); // complex concept |
| 107 | else |
| 108 | return getSCOffsetcxx . . $ CGLabel#getSCOffset(f30316450779e1c3).(end_sccxx . . $ CGLabel#end_sc(e55d760a93e9f197).()-cxx . . $ __gnu_cxx/__normal_iterator#operator-(d0cb2d2ebd313f38).1); // simple concept |
| 109 | } |
| 110 | /// get the concept by given index in the node's label |
| 111 | const ConceptWDepcxx . . $ ConceptWDep#& getConceptcxx . . $ CGLabel#getConcept(ea7a63ba58262a62). ( int n ) const |
| 112 | { |
| 113 | if ( n < 0 ) |
| 114 | return ccLabelcxx . . $ CGLabel#ccLabel..getConceptcxx . . $ CWDArray#getConcept(220b2e4a19f0cb4f).(size_tcxx . . $ std/size_t#(-n-1)); |
| 115 | else |
| 116 | return scLabelcxx . . $ CGLabel#scLabel..getConceptcxx . . $ CWDArray#getConcept(220b2e4a19f0cb4f).(size_tcxx . . $ std/size_t#(n)); |
| 117 | } |
| 118 | /// get CC offset of a complex concept BP that appears in the label |
| 119 | int getCCOffsetcxx . . $ CGLabel#getCCOffset(7ccb52b1bfe01045). ( BipolarPointercxx . . $ BipolarPointer# bp ) const |
| 120 | { |
| 121 | for ( const_iteratorcxx . . $ CGLabel#const_iterator# p = begin_cccxx . . $ CGLabel#begin_cc(e55d760a93e9f197).(), p_end = end_cccxx . . $ CGLabel#end_cc(e55d760a93e9f197).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 122 | if ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p ==cxx . . $ ConceptWDep#`operator==`(4a668f6de69bf818). bp ) |
| 123 | return getCCOffsetcxx . . $ CGLabel#getCCOffset(f30316450779e1c3).(p); |
| 124 | // BP should appear in the label |
| 125 | fpp_unreachablecxx . . $ EFPPAssertion#(); |
| 126 | } |
| 127 | |
| 128 | // check if node is labelled by given concept |
| 129 | |
| 130 | /// check whether node is labelled by (arbitrary) concept P |
| 131 | bool containscxx . . $ CGLabel#contains(4a668f6de69bf818). ( BipolarPointercxx . . $ BipolarPointer# p ) const; |
| 132 | /// check whether node is labelled by simple concept P |
| 133 | bool containsSCcxx . . $ CGLabel#containsSC(4a668f6de69bf818). ( BipolarPointercxx . . $ BipolarPointer# p ) const { return scLabelcxx . . $ CGLabel#scLabel..containscxx . . $ CWDArray#contains(4a668f6de69bf818).(p); } |
| 134 | /// check whether node is labelled by complex concept P |
| 135 | bool containsCCcxx . . $ CGLabel#containsCC(4a668f6de69bf818). ( BipolarPointercxx . . $ BipolarPointer# p ) const { return ccLabelcxx . . $ CGLabel#ccLabel..containscxx . . $ CWDArray#contains(4a668f6de69bf818).(p); } |
| 136 | |
| 137 | //---------------------------------------------- |
| 138 | // Blocking support |
| 139 | //---------------------------------------------- |
| 140 | |
| 141 | /// check whether LABEL is a superset of a current one |
| 142 | bool operatorcxx . . $ CGLabel#`operator<=`(210e00e1c3e71bb8). <= ( const CGLabelcxx . . $ CGLabel#& label ) const |
| 143 | { |
| 144 | return ( scLabelcxx . . $ CGLabel#scLabel. <=cxx . . $ CWDArray#`operator<=`(eccb636064975658). label.scLabelcxx . . $ CGLabel#scLabel. ) && ( ccLabelcxx . . $ CGLabel#ccLabel. <=cxx . . $ CWDArray#`operator<=`(eccb636064975658). label.ccLabelcxx . . $ CGLabel#ccLabel. ); |
| 145 | } |
| 146 | /// check whether LABEL is a subset of a current one |
| 147 | bool operatorcxx . . $ CGLabel#`operator>=`(210e00e1c3e71bb8). >= ( const CGLabelcxx . . $ CGLabel#& label ) const { return label <=cxx . . $ CGLabel#`operator<=`(210e00e1c3e71bb8). *this; } |
| 148 | /// check whether LABEL is the same as a current one |
| 149 | bool operatorcxx . . $ CGLabel#`operator==`(210e00e1c3e71bb8). == ( const CGLabelcxx . . $ CGLabel#& label ) const |
| 150 | { return (*this <=cxx . . $ CGLabel#`operator<=`(210e00e1c3e71bb8). label) && (label <=cxx . . $ CGLabel#`operator<=`(210e00e1c3e71bb8). *this); } |
| 151 | |
| 152 | //---------------------------------------------- |
| 153 | // Save/restore interface |
| 154 | //---------------------------------------------- |
| 155 | |
| 156 | /// save label using given SS |
| 157 | void savecxx . . $ CGLabel#save(43ad53af99fa0458). ( SaveStatecxx . . $ CGLabel#SaveState#& ss ) const |
| 158 | { |
| 159 | scLabelcxx . . $ CGLabel#scLabel..savecxx . . $ CWDArray#save(a4a380d2389ee4f2).(ss.sccxx . . $ CGLabel#SaveState#sc.); |
| 160 | ccLabelcxx . . $ CGLabel#ccLabel..savecxx . . $ CWDArray#save(a4a380d2389ee4f2).(ss.cccxx . . $ CGLabel#SaveState#cc.); |
| 161 | } |
| 162 | /// restore label to given LEVEL using given SS |
| 163 | void restorecxx . . $ CGLabel#restore(82e04a944f46c11c). ( const SaveStatecxx . . $ CGLabel#SaveState#& ss, unsigned int level ) |
| 164 | { |
| 165 | scLabelcxx . . $ CGLabel#scLabel..restorecxx . . $ CWDArray#restore(5b817809b2ca3f56).(ss.sccxx . . $ CGLabel#SaveState#sc.,level); |
| 166 | ccLabelcxx . . $ CGLabel#ccLabel..restorecxx . . $ CWDArray#restore(5b817809b2ca3f56).(ss.cccxx . . $ CGLabel#SaveState#cc.,level); |
| 167 | } |
| 168 | |
| 169 | //---------------------------------------------- |
| 170 | // Output |
| 171 | //---------------------------------------------- |
| 172 | |
| 173 | /// print the whole label |
| 174 | void printcxx . . $ CGLabel#print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const |
| 175 | { |
| 176 | scLabelcxx . . $ CGLabel#scLabel..printcxx . . $ CWDArray#print(490063bd7e6d8d5d).(o); |
| 177 | ccLabelcxx . . $ CGLabel#ccLabel..printcxx . . $ CWDArray#print(490063bd7e6d8d5d).(o); |
| 178 | } |
| 179 | }; // CGLabel |
| 180 | |
| 181 | inline void |
| 182 | CGLabelcxx . . $ CGLabel# :: initcxx . . $ CGLabel#init(49f6e7a06ebc5aa8). ( void ) |
| 183 | { |
| 184 | // init label with reasonable size |
| 185 | scLabelcxx . . $ CGLabel#scLabel..initcxx . . $ CWDArray#init(2c44cd906ae4e829).(8); // FIXME!! correct size later on |
| 186 | ccLabelcxx . . $ CGLabel#ccLabel..initcxx . . $ CWDArray#init(2c44cd906ae4e829).(4); // FIXME!! correct size later on |
| 187 | } |
| 188 | |
| 189 | inline bool |
| 190 | CGLabelcxx . . $ CGLabel# :: containscxx . . $ CGLabel#contains(4a668f6de69bf818). ( BipolarPointercxx . . $ BipolarPointer# p ) const |
| 191 | { |
| 192 | #ifdef ENABLE_CHECKING |
| 193 | fpp_assert ( isCorrect(p) ); // sanity checking |
| 194 | #endif |
| 195 | switch(p) |
| 196 | { |
| 197 | case bpTOPcxx . . $ bpTOP.: return true; |
| 198 | case bpBOTTOMcxx . . $ bpBOTTOM.: return false; |
| 199 | default: return containsSCcxx . . $ CGLabel#containsSC(4a668f6de69bf818).(p) || containsCCcxx . . $ CGLabel#containsCC(4a668f6de69bf818).(p); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | #endif |