| 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 "dlDag.h"cxx . . $ `<file>/Kernel/dlDag.h`/ |
| 21 | |
| 22 | #include "logging.h"cxx . . $ `<file>/Kernel/logging.h`/ |
| 23 | #include "tDataEntry.h"cxx . . $ `<file>/Kernel/tDataEntry.h`/ |
| 24 | #include "tConcept.h"cxx . . $ `<file>/Kernel/tConcept.h`/ |
| 25 | |
| 26 | DLDagcxx . . $ DLDag# :: DLDagcxx . . $ DLDag#DLDag(caa43d10477a9290). ( const ifOptionSetcxx . . $ ifOptionSet#* Options ) |
| 27 | : indexAndcxx . . $ DLDag#indexAnd.(*this) |
| 28 | , indexAllcxx . . $ DLDag#indexAll.(*this) |
| 29 | , indexLEcxx . . $ DLDag#indexLE.(*this) |
| 30 | { |
| 31 | Heapcxx . . $ DLDag#Heap..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70). ( new DLVertexcxx . . $ DLVertex# (dtBadcxx . . $ dtBad.) ); // empty vertex -- bpINVALID |
| 32 | Heapcxx . . $ DLDag#Heap..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70). ( new DLVertexcxx . . $ DLVertex# (dtTopcxx . . $ dtTop.) ); |
| 33 | |
| 34 | readConfigcxx . . $ DLDag#readConfig(caa43d10477a9290). ( Options ); |
| 35 | } |
| 36 | |
| 37 | DLDagcxx . . $ DLDag# :: ~cxx . . $ DLDag#`~DLDag`(49f6e7a06ebc5aa8).DLDagcxx . . $ DLDag#() |
| 38 | { |
| 39 | for ( HeapTypecxx . . $ DLDag#HeapType#::iteratorcxx . . $ std/vector#iterator# p = Heapcxx . . $ DLDag#Heap..begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_end = Heapcxx . . $ DLDag#Heap..endcxx . . $ std/vector#end(33b10a496a38335b).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 40 | delete *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p; |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | DLDagcxx . . $ DLDag# :: removeQuerycxx . . $ DLDag#removeQuery(49f6e7a06ebc5aa8). ( void ) |
| 45 | { |
| 46 | for ( size_tcxx . . $ size_t# i = sizecxx . . $ DLDag#size(fe4d2d262d4164a8).()-1; i >= finalDagSizecxx . . $ DLDag#finalDagSize.; --i ) |
| 47 | { |
| 48 | DLVertexcxx . . $ DLVertex#* v = Heapcxx . . $ DLDag#Heap.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i]; |
| 49 | switch ( v->Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() ) |
| 50 | { |
| 51 | case dtDatacxx . . $ `Kernel/dlVertex.h:90:9`!: |
| 52 | static_cast<TDataEntrycxx . . $ TDataEntry#*>(v->getConceptcxx . . $ DLVertex#getConcept(f3d19eb180c44c64).())->setBPcxx . . $ TDataEntry#setBP(d4f767463ce0a6b3).(bpINVALIDcxx . . $ bpINVALID.); |
| 53 | break; |
| 54 | case dtConceptcxx . . $ `Kernel/dlVertex.h:87:9`!: |
| 55 | static_cast<TConceptcxx . . $ TConcept#*>(v->getConceptcxx . . $ DLVertex#getConcept(f3d19eb180c44c64).())->clearcxx . . $ TConcept#clear(49f6e7a06ebc5aa8).(); |
| 56 | break; |
| 57 | default: |
| 58 | break; |
| 59 | } |
| 60 | delete v; |
| 61 | } |
| 62 | Heapcxx . . $ DLDag#Heap..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(finalDagSizecxx . . $ DLDag#finalDagSize.); |
| 63 | } |
| 64 | |
| 65 | void DLDagcxx . . $ DLDag# :: readConfigcxx . . $ DLDag#readConfig(caa43d10477a9290). ( const ifOptionSetcxx . . $ ifOptionSet#* Options ) |
| 66 | { |
| 67 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( Options != nullptr ); // safety check |
| 68 | |
| 69 | orSortSatcxx . . $ DLDag#orSortSat. = Options->getTextcxx . . $ ifOptionSet#getText(d33e27454d79bb74). ( "orSortSat"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d). ).c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).(); |
| 70 | orSortSubcxx . . $ DLDag#orSortSub. = Options->getTextcxx . . $ ifOptionSet#getText(d33e27454d79bb74). ( "orSortSub"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d). ).c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).(); |
| 71 | |
| 72 | if ( !isCorrectOptioncxx . . $ DLDag#isCorrectOption(c5f7da30cbc0f4e9).(orSortSatcxx . . $ DLDag#orSortSat.) || !isCorrectOptioncxx . . $ DLDag#isCorrectOption(c5f7da30cbc0f4e9).(orSortSubcxx . . $ DLDag#orSortSub.) ) |
| 73 | throw EFaCTPlusPluscxx . . $ EFaCTPlusPlus# ( "DAG: wrong OR sorting options" ); |
| 74 | } |
| 75 | |
| 76 | /// set defaults of OR orderings |
| 77 | void |
| 78 | DLDagcxx . . $ DLDag# :: setOrderDefaultscxx . . $ DLDag#setOrderDefaults(2fa786934fe80e24). ( const char* defSat, const char* defSub ) |
| 79 | { |
| 80 | // defaults should be correct |
| 81 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( isCorrectOption(defSat) && isCorrectOption(defSub) ); |
| 82 | |
| 83 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) ) |
| 84 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "orSortSat: initial=" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). orSortSatcxx . . $ DLDag#orSortSat. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", default=" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). defSat; |
| 85 | if ( orSortSatcxx . . $ DLDag#orSortSat.[0] == '0' ) |
| 86 | orSortSatcxx . . $ DLDag#orSortSat. = defSat; |
| 87 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) ) |
| 88 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", used=" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). orSortSatcxx . . $ DLDag#orSortSat. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n" |
| 89 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "orSortSub: initial=" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). orSortSubcxx . . $ DLDag#orSortSub. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", default=" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). defSub; |
| 90 | if ( orSortSubcxx . . $ DLDag#orSortSub.[0] == '0' ) |
| 91 | orSortSubcxx . . $ DLDag#orSortSub. = defSub; |
| 92 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) ) |
| 93 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", used=" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). orSortSubcxx . . $ DLDag#orSortSub. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 94 | } |
| 95 | |
| 96 | /// set OR sort flags based on given option string |
| 97 | void DLDagcxx . . $ DLDag# :: setOrderOptionscxx . . $ DLDag#setOrderOptions(85c52e162fed56f9). ( const char* opt ) |
| 98 | { |
| 99 | // 0x means not to use OR sort |
| 100 | if ( opt[0] == '0' ) |
| 101 | return; |
| 102 | |
| 103 | sortAscendcxx . . $ DLDag#sortAscend. = (opt[1] == 'a'); |
| 104 | preferNonGencxx . . $ DLDag#preferNonGen. = (opt[2] == 'p'); |
| 105 | |
| 106 | // all statistics use negative version (as it is used in disjunctions) |
| 107 | iSortcxx . . $ DLDag#iSort. = opt[0] == 'S' ? DLVertexcxx . . $ DLVertex#::getStatIndexSizecxx . . $ DLVertexStatistic#getStatIndexSize(9e1a662fef1ac081).(false) |
| 108 | : opt[0] == 'D' ? DLVertexcxx . . $ DLVertex#::getStatIndexDepthcxx . . $ DLVertexStatistic#getStatIndexDepth(9e1a662fef1ac081).(false) |
| 109 | : opt[0] == 'B' ? DLVertexcxx . . $ DLVertex#::getStatIndexBranchcxx . . $ DLVertexStatistic#getStatIndexBranch(9e1a662fef1ac081).(false) |
| 110 | : opt[0] == 'G' ? DLVertexcxx . . $ DLVertex#::getStatIndexGenercxx . . $ DLVertexStatistic#getStatIndexGener(9e1a662fef1ac081).(false) |
| 111 | : DLVertexcxx . . $ DLVertex#::getStatIndexFreqcxx . . $ DLVertexStatistic#getStatIndexFreq(9e1a662fef1ac081).(false); |
| 112 | |
| 113 | Recomputecxx . . $ DLDag#Recompute(49f6e7a06ebc5aa8).(); |
| 114 | } |
| 115 | |
| 116 | void |
| 117 | DLDagcxx . . $ DLDag# :: computeVertexStatcxx . . $ DLDag#computeVertexStat(d4f767463ce0a6b3). ( BipolarPointercxx . . $ BipolarPointer# p ) |
| 118 | { |
| 119 | DLVertexcxx . . $ DLVertex#& v = (*this)[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).p]; |
| 120 | bool pos = isPositivecxx . . $ isPositive(83c267b20bac841a).(p); |
| 121 | |
| 122 | // this vertex is already processed |
| 123 | if ( v.isProcessedcxx . . $ DLVertexTagDFS#isProcessed(962fae8be55e1d9).(pos) ) |
| 124 | return; |
| 125 | |
| 126 | // in case of cycle: mark concept as such |
| 127 | if ( v.isVisitedcxx . . $ DLVertexTagDFS#isVisited(962fae8be55e1d9).(pos) ) |
| 128 | { |
| 129 | v.setInCyclecxx . . $ DLVertexTagDFS#setInCycle(b45ddcbc8423892c).(pos); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | v.setVisitedcxx . . $ DLVertexTagDFS#setVisited(b45ddcbc8423892c).(pos); |
| 134 | |
| 135 | // ensure that the statistic is gather for all sub-concepts of the expression |
| 136 | switch ( v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() ) |
| 137 | { |
| 138 | case dtAndcxx . . $ dtAnd.: // check all the conjuncts |
| 139 | for ( DLVertexcxx . . $ DLVertex#::const_iteratorcxx . . $ DLVertex#const_iterator# q = v.begincxx . . $ DLVertex#begin(d2502ee2ca3b883a).(), q_end = v.endcxx . . $ DLVertex#end(d2502ee2ca3b883a).(); q <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). q_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 140 | computeVertexStatcxx . . $ DLDag#computeVertexStat(918ebd27a9ddbad3). ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q, pos ); |
| 141 | break; |
| 142 | case dtProjcxx . . $ dtProj.: |
| 143 | if ( !pos ) // ~Proj -- nothing to do |
| 144 | break; |
| 145 | // fallthrough |
| 146 | case dtNamecxx . . $ `Kernel/dlVertex.h:89:9`!: |
| 147 | case dtForallcxx . . $ dtForall.: |
| 148 | case dtChoosecxx . . $ dtChoose.: |
| 149 | case dtLEcxx . . $ dtLE.: // check a single referenced concept |
| 150 | computeVertexStatcxx . . $ DLDag#computeVertexStat(918ebd27a9ddbad3). ( v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).(), pos ); |
| 151 | break; |
| 152 | default: // nothing to do |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | v.setProcessedcxx . . $ DLVertexTagDFS#setProcessed(b45ddcbc8423892c).(pos); |
| 157 | |
| 158 | // here all the necessary statistics is gathered -- use it in the init |
| 159 | updateVertexStatcxx . . $ DLDag#updateVertexStat(d4f767463ce0a6b3).(p); |
| 160 | } |
| 161 | |
| 162 | void |
| 163 | DLDagcxx . . $ DLDag# :: updateVertexStatcxx . . $ DLDag#updateVertexStat(d4f767463ce0a6b3). ( BipolarPointercxx . . $ BipolarPointer# p ) |
| 164 | { |
| 165 | DLVertexcxx . . $ DLVertex#& v = (*this)[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).p]; |
| 166 | bool pos = isPositivecxx . . $ isPositive(83c267b20bac841a).(p); |
| 167 | |
| 168 | DLVertexcxx . . $ DLVertex#::StatTypecxx . . $ DLVertexStatistic#StatType# d = 0, s = 1, b = 0, g = 0; |
| 169 | |
| 170 | if ( !v.omitStatcxx . . $ DLVertex#omitStat(962fae8be55e1d9).(pos) ) |
| 171 | { |
| 172 | if ( isValidcxx . . $ isValid(83c267b20bac841a).(v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).()) ) |
| 173 | updateVertexStatcxx . . $ DLDag#updateVertexStat(ab0e588a24d66dd3). ( v, v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).(), pos ); |
| 174 | else |
| 175 | for ( DLVertexcxx . . $ DLVertex#::const_iteratorcxx . . $ DLVertex#const_iterator# q = v.begincxx . . $ DLVertex#begin(d2502ee2ca3b883a).(), q_end = v.endcxx . . $ DLVertex#end(d2502ee2ca3b883a).(); q <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). q_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 176 | updateVertexStatcxx . . $ DLDag#updateVertexStat(ab0e588a24d66dd3). ( v, *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q, pos ); |
| 177 | } |
| 178 | |
| 179 | // correct values wrt POS |
| 180 | d = v.getDepthcxx . . $ DLVertexStatistic#getDepth(27106ebd64dc40f5).(pos); |
| 181 | switch ( v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() ) |
| 182 | { |
| 183 | case dtAndcxx . . $ dtAnd.: |
| 184 | if ( !pos ) |
| 185 | ++b; // OR is branching |
| 186 | break; |
| 187 | case dtForallcxx . . $ dtForall.: |
| 188 | ++d; // increase depth |
| 189 | if ( !pos ) |
| 190 | ++g; // SOME is generating |
| 191 | break; |
| 192 | case dtLEcxx . . $ dtLE.: |
| 193 | ++d; // increase depth |
| 194 | if ( !pos ) |
| 195 | ++g; // >= is generating |
| 196 | else if ( v.getNumberLEcxx . . $ DLVertex#getNumberLE(ddd8539a2fcdd4ce).() != 1 ) |
| 197 | ++b; // <= is branching |
| 198 | break; |
| 199 | case dtProjcxx . . $ dtProj.: |
| 200 | if ( pos ) |
| 201 | ++b; // projection sometimes involves branching |
| 202 | break; |
| 203 | default: |
| 204 | break; |
| 205 | } |
| 206 | |
| 207 | v.updateStatValuescxx . . $ DLVertexStatistic#updateStatValues(115ca1feb1740ab2). ( d, s, b, g, pos ); |
| 208 | } |
| 209 | |
| 210 | /// gather vertex freq statistics |
| 211 | void |
| 212 | DLDagcxx . . $ DLDag# :: computeVertexFreqcxx . . $ DLDag#computeVertexFreq(d4f767463ce0a6b3). ( BipolarPointercxx . . $ BipolarPointer# p ) |
| 213 | { |
| 214 | DLVertexcxx . . $ DLVertex#& v = (*this)[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).p]; |
| 215 | bool pos = isPositivecxx . . $ isPositive(83c267b20bac841a).(p); |
| 216 | |
| 217 | if ( v.isVisitedcxx . . $ DLVertexTagDFS#isVisited(962fae8be55e1d9).(pos) ) // avoid cycles |
| 218 | return; |
| 219 | |
| 220 | v.incFreqValuecxx . . $ DLVertexStatistic#incFreqValue(b45ddcbc8423892c).(pos); // increment frequency of current vertex |
| 221 | v.setVisitedcxx . . $ DLVertexTagDFS#setVisited(b45ddcbc8423892c).(pos); |
| 222 | |
| 223 | if ( v.omitStatcxx . . $ DLVertex#omitStat(962fae8be55e1d9).(pos) ) // negation of primitive concept-like |
| 224 | return; |
| 225 | |
| 226 | // increment frequency of all sub-vertices |
| 227 | if ( isValidcxx . . $ isValid(83c267b20bac841a).(v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).()) ) |
| 228 | computeVertexFreqcxx . . $ DLDag#computeVertexFreq(918ebd27a9ddbad3). ( v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).(), pos ); |
| 229 | else |
| 230 | for ( DLVertexcxx . . $ DLVertex#::const_iteratorcxx . . $ DLVertex#const_iterator# q = v.begincxx . . $ DLVertex#begin(d2502ee2ca3b883a).(), q_end = v.endcxx . . $ DLVertex#end(d2502ee2ca3b883a).(); q !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). q_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 231 | computeVertexFreqcxx . . $ DLDag#computeVertexFreq(918ebd27a9ddbad3). ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q, pos ); |
| 232 | } |
| 233 | |
| 234 | void |
| 235 | DLDagcxx . . $ DLDag# :: gatherStatisticcxx . . $ DLDag#gatherStatistic(49f6e7a06ebc5aa8). ( void ) |
| 236 | { |
| 237 | // gather main statistics for disjunctions |
| 238 | for ( StatVectorcxx . . $ DLDag#StatVector#::iteratorcxx . . $ std/vector#iterator# p = listAndscxx . . $ DLDag#listAnds..begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_end = listAndscxx . . $ DLDag#listAnds..endcxx . . $ std/vector#end(33b10a496a38335b).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 239 | computeVertexStatcxx . . $ DLDag#computeVertexStat(d4f767463ce0a6b3).(inversecxx . . $ inverse(7864480464b09eea).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)); |
| 240 | |
| 241 | // if necessary -- gather frequency |
| 242 | if ( orSortSatcxx . . $ DLDag#orSortSat.[0] != 'F' && orSortSubcxx . . $ DLDag#orSortSub.[0] != 'F' ) |
| 243 | return; |
| 244 | |
| 245 | clearDFScxx . . $ DLDag#clearDFS(49f6e7a06ebc5aa8).(); |
| 246 | |
| 247 | for ( BipolarPointercxx . . $ BipolarPointer# i = (BipolarPointercxx . . $ BipolarPointer#)sizecxx . . $ DLDag#size(fe4d2d262d4164a8).()-1; i > 1; --i ) |
| 248 | { |
| 249 | if ( isCNameTagcxx . . $ isCNameTag(7b512e7165d9f2af).((*this)[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).i].Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).()) ) |
| 250 | computeVertexFreqcxx . . $ DLDag#computeVertexFreq(d4f767463ce0a6b3).(i); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | //--------------------------------------------------- |
| 255 | // change order of ADD elements with respect to Freq |
| 256 | //--------------------------------------------------- |
| 257 | |
| 258 | /// return true if p1 is less than p2 using chosen sort order |
| 259 | |
| 260 | // the overall sorted entry structure looks like |
| 261 | // fffA..M..Zlll if sortAscend set, and |
| 262 | // fffZ..M..Alll if sortAscend cleared. |
| 263 | // here 's' means "always first" entries, like neg-primconcepts, |
| 264 | // and 'l' means "always last" entries, like looped concepts |
| 265 | |
| 266 | // note that the statistics is given for disjunctions, |
| 267 | // so inverted (neg) values are taken into account |
| 268 | bool DLDagcxx . . $ DLDag# :: lesscxx . . $ DLDag#less(88e30549ca55c866). ( BipolarPointercxx . . $ BipolarPointer# p1, BipolarPointercxx . . $ BipolarPointer# p2 ) const |
| 269 | { |
| 270 | # ifdef ENABLE_CHECKING |
| 271 | fpp_assert ( isValid(p1) && isValid(p2) ); |
| 272 | # endif |
| 273 | |
| 274 | // idea: any positive entry should go first |
| 275 | if ( preferNonGencxx . . $ DLDag#preferNonGen. ) |
| 276 | { |
| 277 | if ( isNegativecxx . . $ isNegative(83c267b20bac841a).(p1) && isPositivecxx . . $ isPositive(83c267b20bac841a).(p2) ) |
| 278 | return true; |
| 279 | if ( isPositivecxx . . $ isPositive(83c267b20bac841a).(p1) && isNegativecxx . . $ isNegative(83c267b20bac841a).(p2) ) |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | const DLVertexcxx . . $ DLVertex#& v1 = (*this)[cxx . . $ DLDag#`operator[]`(5fe3b8e96045ba2c).p1]; |
| 284 | const DLVertexcxx . . $ DLVertex#& v2 = (*this)[cxx . . $ DLDag#`operator[]`(5fe3b8e96045ba2c).p2]; |
| 285 | /* |
| 286 | // prefer non-cyclical |
| 287 | if ( !v1.isInCycle(false) && v2.isInCycle(false) ) |
| 288 | return true; |
| 289 | if ( !v2.isInCycle(false) && v1.isInCycle(false) ) |
| 290 | return false; |
| 291 | */ |
| 292 | DLVertexcxx . . $ DLVertex#::StatTypecxx . . $ DLVertexStatistic#StatType# key1 = v1.getStatcxx . . $ DLVertexStatistic#getStat(bf63e0e82e9313b7).(iSortcxx . . $ DLDag#iSort.); |
| 293 | DLVertexcxx . . $ DLVertex#::StatTypecxx . . $ DLVertexStatistic#StatType# key2 = v2.getStatcxx . . $ DLVertexStatistic#getStat(bf63e0e82e9313b7).(iSortcxx . . $ DLDag#iSort.); |
| 294 | |
| 295 | // return "less" wrt sortAscend |
| 296 | if ( sortAscendcxx . . $ DLDag#sortAscend. ) |
| 297 | return key1 < key2; |
| 298 | else |
| 299 | return key2 < key1; |
| 300 | } |
| 301 | |
| 302 | #ifdef RKG_PRINT_DAG_USAGE |
| 303 | /// print usage of DAG |
| 304 | void DLDag :: PrintDAGUsage ( std::ostream& o ) const |
| 305 | { |
| 306 | unsigned int n = 0; // number of no-used DAG entries |
| 307 | unsigned int total = Heap.size()*2-2; // number of total DAG entries |
| 308 | |
| 309 | for ( HeapType::const_iterator i = Heap.begin(), i_end = Heap.end(); i < i_end; ++i ) |
| 310 | { |
| 311 | if ( (*i)->getUsage(true) == 0 ) // positive and... |
| 312 | ++n; |
| 313 | if ( (*i)->getUsage(false) == 0 ) // negative ones |
| 314 | ++n; |
| 315 | } |
| 316 | |
| 317 | o << "There are " << n << " unused DAG entries (" << (unsigned long)(n*100/total) |
| 318 | << "% of " << total << " total)\n"; |
| 319 | } |
| 320 | #endif |